@@ -1003,6 +1003,96 @@ function test_copy_to_sorted_sets()
10031003 return
10041004end
10051005
1006+ function test_deprecated_try_constrain_variables_scalar ()
1007+ src = MOI. Utilities. Model {Float64} ()
1008+ x, c_z = MOI. add_constrained_variable (src, MOI. ZeroOne ())
1009+ c = MOI. add_constraint (src, x, MOI. EqualTo (0.0 ))
1010+ dest = MOI. Utilities. Model {Float64} ()
1011+ index_map = MOI. Utilities. IndexMap ()
1012+ not_added = MOI. Utilities. _try_constrain_variables_on_creation (
1013+ dest,
1014+ src,
1015+ index_map,
1016+ MOI. ZeroOne,
1017+ )
1018+ @test isempty (not_added)
1019+ not_added = MOI. Utilities. _try_constrain_variables_on_creation (
1020+ dest,
1021+ src,
1022+ index_map,
1023+ MOI. EqualTo{Float64},
1024+ )
1025+ @test not_added == [c]
1026+ @test MOI. is_valid (dest, index_map[x])
1027+ @test MOI. is_valid (dest, index_map[c_z])
1028+ @test_throws KeyError index_map[c]
1029+ return
1030+ end
1031+
1032+ function test_deprecated_try_constrain_variables_vector ()
1033+ src = MOI. Utilities. Model {Float64} ()
1034+ x, c_z = MOI. add_constrained_variables (src, MOI. Nonnegatives (2 ))
1035+ y = MOI. add_variable (src)
1036+ c_duplicate = MOI. add_constraint (
1037+ src,
1038+ MOI. VectorOfVariables ([x[1 ], x[1 ]]),
1039+ MOI. Zeros (2 ),
1040+ )
1041+ c_already_added = MOI. add_constraint (
1042+ src,
1043+ MOI. VectorOfVariables ([y, x[1 ]]),
1044+ MOI. Nonpositives (2 ),
1045+ )
1046+ dest = MOI. Utilities. Model {Float64} ()
1047+ index_map = MOI. Utilities. IndexMap ()
1048+ not_added = MOI. Utilities. _try_constrain_variables_on_creation (
1049+ dest,
1050+ src,
1051+ index_map,
1052+ MOI. Nonnegatives,
1053+ )
1054+ @test isempty (not_added)
1055+ @test MOI. is_valid (dest, index_map[x[1 ]])
1056+ @test MOI. is_valid (dest, index_map[x[2 ]])
1057+ @test MOI. is_valid (dest, index_map[c_z])
1058+ not_added = MOI. Utilities. _try_constrain_variables_on_creation (
1059+ dest,
1060+ src,
1061+ index_map,
1062+ MOI. Zeros,
1063+ )
1064+ @test not_added == [c_duplicate]
1065+ not_added = MOI. Utilities. _try_constrain_variables_on_creation (
1066+ dest,
1067+ src,
1068+ index_map,
1069+ MOI. Nonpositives,
1070+ )
1071+ @test not_added == [c_already_added]
1072+ return
1073+ end
1074+
1075+ function test_deprecated_copy_free_variables ()
1076+ src = MOI. Utilities. Model {Float64} ()
1077+ x, c_z = MOI. add_constrained_variable (src, MOI. ZeroOne ())
1078+ y = MOI. add_variable (src)
1079+ dest = MOI. Utilities. Model {Float64} ()
1080+ index_map = MOI. Utilities. IndexMap ()
1081+ not_added = MOI. Utilities. _try_constrain_variables_on_creation (
1082+ dest,
1083+ src,
1084+ index_map,
1085+ MOI. ZeroOne,
1086+ )
1087+ MOI. Utilities. _copy_free_variables (dest, index_map, [x, y])
1088+ @test MOI. is_valid (dest, index_map[x])
1089+ @test MOI. is_valid (dest, index_map[y])
1090+ MOI. Utilities. _copy_free_variables (dest, index_map, [x, y])
1091+ @test MOI. is_valid (dest, index_map[x])
1092+ @test MOI. is_valid (dest, index_map[y])
1093+ return
1094+ end
1095+
10061096end # module
10071097
10081098TestCopy. runtests ()
0 commit comments