File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -298,6 +298,7 @@ MOI.is_empty(m::CachingOptimizer) = MOI.is_empty(m.model_cache)
298298
299299function 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
Original file line number Diff line number Diff line change @@ -914,6 +914,38 @@ function test_copy_optimizer_attributes_2887()
914914 return
915915end
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+
917949end # module
918950
919951TestCachingOptimizer. runtests ()
You can’t perform that action at this time.
0 commit comments