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
1 change: 1 addition & 0 deletions src/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ MOI.is_empty(m::CachingOptimizer) = MOI.is_empty(m.model_cache)

function MOI.optimize!(m::CachingOptimizer)
if m.mode == AUTOMATIC && m.state == EMPTY_OPTIMIZER
final_touch(m.model_cache, nothing)
# Here is a special case for callbacks: we can't use the two-argument
# call to optimize! because we need the `optimizer_to_model_map` to be
# set _prior_ to starting the optimization process. Therefore, we need
Expand Down
32 changes: 32 additions & 0 deletions test/Utilities/cachingoptimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,38 @@ function test_copy_optimizer_attributes_2887()
return
end

mutable struct FinalTouchDetector <: MOI.ModelLike
index_map::Any
end

function MOI.Utilities.final_touch(model::FinalTouchDetector, index_map)
model.index_map = index_map
return
end
function MOI.copy_to(::MOI.Utilities.MockOptimizer, ::FinalTouchDetector)
return MOI.Utilities.IndexMap()
end
function MOI.get(::FinalTouchDetector, ::MOI.ListOfOptimizerAttributesSet)
return MOI.AbstractOptimizerAttribute[]
end
function MOI.get(::FinalTouchDetector, ::MOI.ListOfModelAttributesSet)
return MOI.AbstractModelAttribute[]
end

function test_final_touch_optimize()
model = MOI.Utilities.CachingOptimizer(
FinalTouchDetector(missing),
MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()),
)
MOI.Utilities.attach_optimizer(model)
@test model.model_cache.index_map === nothing
MOI.Utilities.final_touch(model, missing)
@test model.model_cache.index_map === missing
MOI.Utilities.reset_optimizer(model)
MOI.optimize!(model)
@test model.model_cache.index_map === nothing
end

end # module

TestCachingOptimizer.runtests()