Skip to content

Commit 63ee291

Browse files
authored
Call final_touch in optimize in CachingOptimizer (#1754)
1 parent 63e177d commit 63ee291

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Utilities/cachingoptimizer.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ MOI.is_empty(m::CachingOptimizer) = MOI.is_empty(m.model_cache)
298298

299299
function MOI.optimize!(m::CachingOptimizer)
300300
if m.mode == AUTOMATIC && m.state == EMPTY_OPTIMIZER
301+
final_touch(m.model_cache, nothing)
301302
# Here is a special case for callbacks: we can't use the two-argument
302303
# call to optimize! because we need the `optimizer_to_model_map` to be
303304
# set _prior_ to starting the optimization process. Therefore, we need

test/Utilities/cachingoptimizer.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,38 @@ function test_copy_optimizer_attributes_2887()
914914
return
915915
end
916916

917+
mutable struct FinalTouchDetector <: MOI.ModelLike
918+
index_map::Any
919+
end
920+
921+
function MOI.Utilities.final_touch(model::FinalTouchDetector, index_map)
922+
model.index_map = index_map
923+
return
924+
end
925+
function MOI.copy_to(::MOI.Utilities.MockOptimizer, ::FinalTouchDetector)
926+
return MOI.Utilities.IndexMap()
927+
end
928+
function MOI.get(::FinalTouchDetector, ::MOI.ListOfOptimizerAttributesSet)
929+
return MOI.AbstractOptimizerAttribute[]
930+
end
931+
function MOI.get(::FinalTouchDetector, ::MOI.ListOfModelAttributesSet)
932+
return MOI.AbstractModelAttribute[]
933+
end
934+
935+
function test_final_touch_optimize()
936+
model = MOI.Utilities.CachingOptimizer(
937+
FinalTouchDetector(missing),
938+
MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()),
939+
)
940+
MOI.Utilities.attach_optimizer(model)
941+
@test model.model_cache.index_map === nothing
942+
MOI.Utilities.final_touch(model, missing)
943+
@test model.model_cache.index_map === missing
944+
MOI.Utilities.reset_optimizer(model)
945+
MOI.optimize!(model)
946+
@test model.model_cache.index_map === nothing
947+
end
948+
917949
end # module
918950

919951
TestCachingOptimizer.runtests()

0 commit comments

Comments
 (0)