@@ -1408,7 +1408,7 @@ function test_solve_SOS2_add_and_delete(model::MOI.ModelLike, config::Config)
14081408 MOI. VectorOfVariables,
14091409 MOI. SOS2{Float64},
14101410 )
1411- function add_SOS2 ( x, y, xp, yp)
1411+ function _add_SOS2 (model, x, y, xp, yp)
14121412 λ = MOI. add_variables (model, length (xp))
14131413 # 0 <= λ <= 1
14141414 MOI. add_constraint .(model, λ, MOI. LessThan (1.0 ))
@@ -1447,9 +1447,14 @@ function test_solve_SOS2_add_and_delete(model::MOI.ModelLike, config::Config)
14471447 end
14481448 x = MOI. add_variables (model, 2 )
14491449 y = MOI. add_variables (model, 2 )
1450- λ, c1 = add_SOS2 (x[1 ], y[1 ], [1.0 , 2.0 , 3.0 ], [2.0 , 2.0 , 1.0 ])
1450+ # !!! warning
1451+ # Make sure the variable returned from `_add_SOS2` is named something
1452+ # other than λ to avoid Julia's `Box`ing issue with closed over
1453+ # variables.
1454+ vλ, c1 = _add_SOS2 (model, x[1 ], y[1 ], [1.0 , 2.0 , 3.0 ], [2.0 , 2.0 , 1.0 ])
14511455 MOI. add_constraint (model, x[1 ], MOI. LessThan (2.5 ))
1452- η, c2 = add_SOS2 (x[2 ], y[2 ], [1.0 , 2.0 , 3.0 , 4.0 ], [0.5 , 1.0 , 0.2 , 2.0 ])
1456+ vη, c2 =
1457+ _add_SOS2 (model, x[2 ], y[2 ], [1.0 , 2.0 , 3.0 , 4.0 ], [0.5 , 1.0 , 0.2 , 2.0 ])
14531458 MOI. set (model, MOI. ObjectiveSense (), MOI. MIN_SENSE)
14541459 f = MOI. ScalarAffineFunction (MOI. ScalarAffineTerm .(1.0 , y), 0.0 )
14551460 MOI. set (model, MOI. ObjectiveFunction {typeof(f)} (), f)
@@ -1476,18 +1481,20 @@ function test_solve_SOS2_add_and_delete(model::MOI.ModelLike, config::Config)
14761481 @test isapprox (MOI. get (model, MOI. ObjectiveValue ()), 1.45 , config)
14771482 MOI. add_constraint (
14781483 model,
1479- MOI. VectorOfVariables (λ ),
1484+ MOI. VectorOfVariables (vλ ),
14801485 MOI. SOS2 {Float64} ([1.0 , 2.0 , 3.0 ]),
14811486 )
14821487 MOI. add_constraint (
14831488 model,
1484- MOI. VectorOfVariables (λ ),
1489+ MOI. VectorOfVariables (vη ),
14851490 MOI. SOS2 {Float64} ([1.0 , 2.0 , 3.0 , 4.0 ]),
14861491 )
14871492 @test MOI. get (model, attr) == 2
14881493 MOI. optimize! (model)
14891494 @test isapprox (MOI. get (model, MOI. VariablePrimal (), x[1 ]), 2.5 , config)
14901495 @test isapprox (MOI. get (model, MOI. VariablePrimal (), x[2 ]), 3.0 , config)
1496+ @test isapprox (MOI. get (model, MOI. VariablePrimal (), y[1 ]), 1.5 , config)
1497+ @test isapprox (MOI. get (model, MOI. VariablePrimal (), y[2 ]), 0.2 , config)
14911498 @test isapprox (MOI. get (model, MOI. ObjectiveValue ()), 1.7 , config)
14921499 return
14931500end
0 commit comments