Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/src/submodules/Utilities/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ with model cache MOIU.GenericModel{Float64,MOIU.ModelFunctionConstraints{Float64
with optimizer MOIU.GenericOptimizer{Float64,MOIU.VectorOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Complements}}
```

!!! info
Calling `MOI.empty!(model)` also resets the state to `EMPTY_OPTIMIZER`.
So after emptying a model, the modification will only be applied to the
cache.

Use [`Utilities.drop_optimizer`](@ref) to go from any state to `NO_OPTIMIZER`:
```jldoctest pathoptimizer
julia> MOI.Utilities.drop_optimizer(model)
Expand Down
1 change: 1 addition & 0 deletions src/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ function MOI.empty!(m::CachingOptimizer)
MOI.empty!(m.model_cache)
if m.state == ATTACHED_OPTIMIZER
MOI.empty!(m.optimizer)
m.state = EMPTY_OPTIMIZER
end
m.model_to_optimizer_map = IndexMap()
m.optimizer_to_model_map = IndexMap()
Expand Down
11 changes: 11 additions & 0 deletions test/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ end
in mode MANUAL
with model cache $(MOIU.Model{Float64})
with optimizer nothing""")

MOI.empty!(s)
MOIU.reset_optimizer(m, s)
@test MOIU.state(m) == MOIU.EMPTY_OPTIMIZER
MOIU.attach_optimizer(m)
@test MOIU.state(m) == MOIU.ATTACHED_OPTIMIZER
MOI.empty!(m)
@test MOIU.state(m) == MOIU.EMPTY_OPTIMIZER
end

@testset "CachingOptimizer AUTOMATIC mode" begin
Expand Down Expand Up @@ -486,6 +494,9 @@ end
in mode AUTOMATIC
with model cache $(MOIU.Model{Float64})
with optimizer $(MOIU.MockOptimizer{MOIU.Model{Float64}})""")

MOI.empty!(m)
@test MOIU.state(m) == MOIU.EMPTY_OPTIMIZER
end

@testset "Constructor with optimizer" begin
Expand Down