diff --git a/src/Clp.jl b/src/Clp.jl index 0086741..9ea0b55 100644 --- a/src/Clp.jl +++ b/src/Clp.jl @@ -29,6 +29,10 @@ end include("MOI_wrapper/MOI_wrapper.jl") +if VERSION > v"1.4.2" + include("precompile.jl") +end + # TODO(odow): remove at Clp.jl v1.0.0. function ClpSolver(args...; kwargs...) error( diff --git a/src/MOI_wrapper/MOI_wrapper.jl b/src/MOI_wrapper/MOI_wrapper.jl index 677dc44..4fa5f45 100644 --- a/src/MOI_wrapper/MOI_wrapper.jl +++ b/src/MOI_wrapper/MOI_wrapper.jl @@ -266,9 +266,10 @@ function _index_map( ::Type{F}, ::Type{S}, ) where {F,S} + inner = index_map.con_map[F, S] for ci in MOI.get(src, MOI.ListOfConstraintIndices{F,S}()) row = MOI.Utilities.rows(src.constraints, ci) - index_map[ci] = MOI.ConstraintIndex{F,S}(row) + inner[ci] = MOI.ConstraintIndex{F,S}(row) end return end @@ -279,9 +280,10 @@ function _index_map( F::Type{MOI.VariableIndex}, ::Type{S}, ) where {S} + inner = index_map.con_map[F, S] for ci in MOI.get(src, MOI.ListOfConstraintIndices{F,S}()) col = index_map[MOI.VariableIndex(ci.value)].value - index_map[ci] = MOI.ConstraintIndex{F,S}(col) + inner[ci] = MOI.ConstraintIndex{F,S}(col) end return end diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 0000000..237c0d7 --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,16 @@ +function warmup() + bridge = MOI.instantiate(Optimizer; with_bridge_type=Float64) + no_bridge = MOI.instantiate(Optimizer) + cache = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) + MOI.optimize!(bridge, cache) + MOI.optimize!(no_bridge, cache) + return +end + +function _precompile_() + ccall(:jl_generating_output, Cint, ()) == 1 || return nothing + precompile(warmup, ()) + return +end + +_precompile_()