@@ -13,58 +13,75 @@ config = MOIT.TestConfig()
13
13
14
14
bridged_mock = MOIB. Variable. Vectorize {Float64} (mock)
15
15
16
- mock. optimize! = (mock:: MOIU.MockOptimizer ) -> MOIU. mock_optimize! (mock, [log (5 ), 0.0 ],
17
- (MOI. ScalarAffineFunction{Float64}, MOI. LessThan{Float64}) => [0.0 ],
18
- (MOI. VectorAffineFunction{Float64}, MOI. ExponentialCone) => [[- 1.0 , log (5 )- 1 , 1 / 5 ]])
19
- MOIT. exp3test (bridged_mock, config)
16
+ @testset " get scalar constraint" begin
17
+ x, cx = MOI. add_constrained_variable (bridged_mock, MOI. GreaterThan (1.0 ))
18
+ fx = MOI. SingleVariable (x)
19
+ func = 2.0 * fx
20
+ set = MOI. GreaterThan (5.0 )
21
+ err = MOI. ScalarFunctionConstantNotZero{
22
+ Float64, typeof (func), typeof (set)}(1.0 )
23
+ @test_throws err MOI. add_constraint (bridged_mock, func + 1.0 , set)
20
24
21
- vis = MOI. get (bridged_mock, MOI. ListOfVariableIndices ())
22
- @test length (vis) == 2
23
- y = vis[2 ]
25
+ c = MOI. add_constraint (bridged_mock, func, set)
26
+ @test MOI. get (bridged_mock, MOI. ConstraintFunction (), c) ≈ func
27
+ @test MOI. get (bridged_mock, MOI. ConstraintSet (), c) == set
28
+ end
24
29
25
- err = ErrorException (
26
- " Cannot add two `SingleVariable`-in-`MathOptInterface.LessThan{Float64}` " *
27
- " on the same variable MathOptInterface.VariableIndex(-1). "
28
- )
29
- @test_throws err MOI . add_constraint (bridged_mock, MOI . SingleVariable (y), MOI . LessThan ( 4.0 ) )
30
+ @testset " exp3 " begin
31
+ mock . optimize! = (mock :: MOIU.MockOptimizer ) -> MOIU . mock_optimize! (mock, [ log ( 5 ), 0.0 ],
32
+ (MOI . ScalarAffineFunction{Float64}, MOI . LessThan{Float64}) => [ 0.0 ],
33
+ (MOI . VectorAffineFunction{Float64}, MOI . ExponentialCone) => [[ - 1.0 , log ( 5 ) - 1 , 1 / 5 ]] )
34
+ MOIT . exp3test (bridged_mock, config )
30
35
31
- cis = MOI. get (bridged_mock, MOI. ListOfConstraintIndices{
32
- MOI. VectorAffineFunction{Float64}, MOI. ExponentialCone}())
33
- @test length (cis) == 1
36
+ vis = MOI. get (bridged_mock, MOI. ListOfVariableIndices ())
37
+ @test length (vis) == 2
38
+ y = vis[2 ]
39
+ @test y. value == - 1
34
40
35
- @testset " get `UnknownVariableAttribute``" begin
36
- err = ArgumentError (
37
- " Variable bridge of type `MathOptInterface.Bridges.Variable.VectorizeBridge{Float64,MathOptInterface.Nonpositives}`" *
38
- " does not support accessing the attribute `MathOptInterface.Test.UnknownVariableAttribute()`."
41
+ err = ErrorException (
42
+ " Cannot add two `SingleVariable`-in-`MathOptInterface.LessThan{Float64}`" *
43
+ " on the same variable MathOptInterface.VariableIndex(-1)."
39
44
)
40
- @test_throws err MOI. get (bridged_mock, MOIT. UnknownVariableAttribute (), y)
41
- end
45
+ @test_throws err MOI. add_constraint (bridged_mock, MOI. SingleVariable (y), MOI. LessThan (4.0 ))
42
46
43
- @testset " set `ConstraintSet`" begin
44
- ci = MOI. ConstraintIndex {MOI.SingleVariable, MOI.LessThan{Float64}} (y. value)
45
- attr = MOI. ConstraintSet ()
46
- err = MOI. SetAttributeNotAllowed (attr,
47
- " The variable `MathOptInterface.VariableIndex(12345676)` is bridged by the `VectorizeBridge`." )
48
- @test_throws err MOI. set (bridged_mock, attr, ci, MOI. LessThan (4.0 ))
49
- end
47
+ cis = MOI. get (bridged_mock, MOI. ListOfConstraintIndices{
48
+ MOI. VectorAffineFunction{Float64}, MOI. ExponentialCone}())
49
+ @test length (cis) == 1
50
50
51
- @testset " MultirowChange " begin
52
- change = MOI . MultirowChange (y, [( 3 , 0.0 )])
53
- message = " The change MathOptInterface.MultirowChange{Float64}(MathOptInterface.VariableIndex(-1), Tuple{Int64, Float64}[(3, 0.0)]) " *
54
- " contains variables bridged into a function with nonzero constant ."
55
- err = MOI . ModifyConstraintNotAllowed (cis[ 1 ], change, message )
56
- @test_throws err MOI. modify (bridged_mock, cis[ 1 ], change )
57
- end
51
+ @testset " get `UnknownVariableAttribute`` " begin
52
+ err = ArgumentError (
53
+ " Variable bridge of type ` MathOptInterface.Bridges.Variable.VectorizeBridge{ Float64,MathOptInterface.Nonpositives}` " *
54
+ " does not support accessing the attribute `MathOptInterface.Test.UnknownVariableAttribute()` ."
55
+ )
56
+ @test_throws err MOI. get (bridged_mock, MOIT . UnknownVariableAttribute (), y )
57
+ end
58
58
59
- @testset " ScalarCoefficientChange" begin
60
- change = MOI. ScalarCoefficientChange (y, 0.0 )
61
- attr = MOI. ObjectiveFunction {MOI.ScalarAffineFunction{Float64}} ()
62
- message = " The change MathOptInterface.ScalarCoefficientChange{Float64}(MathOptInterface.VariableIndex(-1), 0.0)" *
63
- " contains variables bridged into a function with nonzero constant."
64
- err = MOI. ModifyObjectiveNotAllowed (change, message)
65
- @test_throws err MOI. modify (bridged_mock, attr, change)
66
- end
59
+ @testset " set `ConstraintSet`" begin
60
+ ci = MOI. ConstraintIndex {MOI.SingleVariable, MOI.LessThan{Float64}} (y. value)
61
+ attr = MOI. ConstraintSet ()
62
+ err = MOI. SetAttributeNotAllowed (attr,
63
+ " The variable `MathOptInterface.VariableIndex(12345676)` is bridged by the `VectorizeBridge`." )
64
+ @test_throws err MOI. set (bridged_mock, attr, ci, MOI. LessThan (4.0 ))
65
+ end
66
+
67
+ @testset " MultirowChange" begin
68
+ change = MOI. MultirowChange (y, [(3 , 0.0 )])
69
+ message = " The change MathOptInterface.MultirowChange{Float64}(MathOptInterface.VariableIndex(-1), Tuple{Int64,Float64}[(3, 0.0)])" *
70
+ " contains variables bridged into a function with nonzero constant."
71
+ err = MOI. ModifyConstraintNotAllowed (cis[1 ], change, message)
72
+ @test_throws err MOI. modify (bridged_mock, cis[1 ], change)
73
+ end
67
74
68
- test_delete_bridged_variable (bridged_mock, y, MOI. LessThan{Float64}, 2 , (
69
- (MOI. VectorOfVariables, MOI. Nonpositives, 0 ),
70
- ))
75
+ @testset " ScalarCoefficientChange" begin
76
+ change = MOI. ScalarCoefficientChange (y, 0.0 )
77
+ attr = MOI. ObjectiveFunction {MOI.ScalarAffineFunction{Float64}} ()
78
+ message = " The change MathOptInterface.ScalarCoefficientChange{Float64}(MathOptInterface.VariableIndex(-1), 0.0)" *
79
+ " contains variables bridged into a function with nonzero constant."
80
+ err = MOI. ModifyObjectiveNotAllowed (change, message)
81
+ @test_throws err MOI. modify (bridged_mock, attr, change)
82
+ end
83
+
84
+ test_delete_bridged_variable (bridged_mock, y, MOI. LessThan{Float64}, 2 , (
85
+ (MOI. VectorOfVariables, MOI. Nonpositives, 0 ),
86
+ ))
87
+ end
0 commit comments