diff --git a/test/Bridges/test_ComplementsVectorizeBridge.jl b/test/Bridges/test_ComplementsVectorizeBridge.jl index 9ade496..740c56b 100644 --- a/test/Bridges/test_ComplementsVectorizeBridge.jl +++ b/test/Bridges/test_ComplementsVectorizeBridge.jl @@ -10,6 +10,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestComplementsVectorizeBridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -21,37 +23,18 @@ end function test_GreaterThan_Nonnegatives() MOI.Bridges.runtests( MathOptComplements.Bridges.ComplementsVectorizeBridge{Float64}, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - f = MOI.VectorAffineFunction{Float64}( - [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x)), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, y)), - ], - [0.0, -3.0], - ) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end; + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [x, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [1.0 * x, 1.0 * y + -3.0] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """; cannot_unbridge = true, ) return @@ -60,33 +43,18 @@ end function test_LessThan_Nonpositives() MOI.Bridges.runtests( MathOptComplements.Bridges.ComplementsVectorizeBridge{Float64}, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - f = MOI.VectorAffineFunction{Float64}( - [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x)), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, y)), - ], - [0.0, 2.0], - ) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Nonpositives}(2), - ) - end; + """ + variables: x, y + x >= 0.0 + y <= -2.0 + [x, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """, + """ + variables: x, y + x >= 0.0 + y <= -2.0 + [1.0 * x, 1.0 * y + 2.0] in $M.ComplementsWithSetType{MOI.Nonpositives}(2) + """; cannot_unbridge = true, ) return @@ -95,27 +63,18 @@ end function test_EqualTo_Zeros() MOI.Bridges.runtests( MathOptComplements.Bridges.ComplementsVectorizeBridge{Float64}, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.EqualTo(2.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.EqualTo{Float64}}( - 2, - ), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.EqualTo(2.0)) - f = MOI.Utilities.operate(vcat, Float64, 1.0 * x, 1.0 * y - 2.0) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Zeros}(2), - ) - end; + """ + variables: x, y + x >= 0.0 + y == 2.0 + [x, y] in $M.ComplementsWithSetType{MOI.EqualTo{Float64}}(2) + """, + """ + variables: x, y + x >= 0.0 + y == 2.0 + [1.0 * x, 1.0 * y + -2.0] in $M.ComplementsWithSetType{MOI.Zeros}(2) + """; cannot_unbridge = true, ) return diff --git a/test/Bridges/test_FlipSignBridge.jl b/test/Bridges/test_FlipSignBridge.jl index 21a7b3c..918249f 100644 --- a/test/Bridges/test_FlipSignBridge.jl +++ b/test/Bridges/test_FlipSignBridge.jl @@ -9,6 +9,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestFlipSignBridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -20,27 +22,18 @@ end function test_Nonnegatives_Nonpositives() MOI.Bridges.runtests( MathOptComplements.Bridges.FlipSignBridge, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Nonpositives}(2), - ) - end; + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [-1.0 * x, y] in $M.ComplementsWithSetType{MOI.Nonpositives}(2) + """; cannot_unbridge = true, ) return @@ -49,25 +42,18 @@ end function test_Nonpositives_Nonnegatives() MOI.Bridges.runtests( MathOptComplements.Bridges.FlipSignBridge, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Nonpositives}(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end; + """ + variables: x, y + x <= 0.0 + y <= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonpositives}(2) + """, + """ + variables: x, y + x <= 0.0 + y <= 0.0 + [-1.0 * x, y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """; cannot_unbridge = true, ) return @@ -76,33 +62,18 @@ end function test_GreaterThan_LessThan() MOI.Bridges.runtests( MathOptComplements.Bridges.FlipSignBridge, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end; + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [x, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [-1.0 * x, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """; cannot_unbridge = true, ) return @@ -111,31 +82,18 @@ end function test_LessThan_GreaterThan() MOI.Bridges.runtests( MathOptComplements.Bridges.FlipSignBridge, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - f = MOI.Utilities.operate(vcat, Float64, -1.0 * x, 1.0 * y) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - end; + """ + variables: x, y + x <= 0.0 + y <= -2.0 + [x, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """, + """ + variables: x, y + x <= 0.0 + y <= -2.0 + [-1.0 * x, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + """; cannot_unbridge = true, ) return diff --git a/test/Bridges/test_NonlinearBridge.jl b/test/Bridges/test_NonlinearBridge.jl index 66dd8d3..b2e366e 100644 --- a/test/Bridges/test_NonlinearBridge.jl +++ b/test/Bridges/test_NonlinearBridge.jl @@ -10,6 +10,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestNonlinearBridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -21,23 +23,18 @@ end function test_Nonnegatives_lower_bound() MOI.Bridges.runtests( MathOptComplements.Bridges.NonlinearBridge, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - x2, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x1, x2]), - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - x2, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - # x1 * (x2 - 0) <= 0 - MOI.add_constraint(model, x1 * (x2 - 0.0), MOI.LessThan(0.0)) - end; + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 0.0 + 1.0 * x * y <= 0.0 + """; cannot_unbridge = true, ) return @@ -46,21 +43,18 @@ end function test_Nonpositives_upper_bound() MOI.Bridges.runtests( MathOptComplements.Bridges.NonlinearBridge, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x1, x2]), - MathOptComplements.ComplementsWithSetType{MOI.Nonpositives}(2), - ) - end, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - # x1 * (x2 - 0) <= 0 - MOI.add_constraint(model, x1 * (x2 - 0.0), MOI.LessThan(0.0)) - end; + """ + variables: x, y + x <= 0.0 + y <= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonpositives}(2) + """, + """ + variables: x, y + x <= 0.0 + y <= 0.0 + 1.0 * x * y <= 0.0 + """; cannot_unbridge = true, ) return @@ -69,27 +63,18 @@ end function test_GreaterThan_with_nonzero_bound() MOI.Bridges.runtests( MathOptComplements.Bridges.NonlinearBridge, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - x2, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x1, x2]), - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - end, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - x2, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - # x1 * (x2 - 3) <= 0 - MOI.add_constraint(model, x1 * (x2 - 3.0), MOI.LessThan(0.0)) - end; + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [x, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 3.0 + 1.0 * x * y + -3.0 * x <= 0.0 + """; cannot_unbridge = true, ) return @@ -97,11 +82,8 @@ end function test_Nonnegatives_with_unbounded_x1_lower_bound() inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - model = MOI.Bridges.Constraint.SingleBridgeOptimizer{ - MathOptComplements.Bridges.NonlinearBridge{Float64}, - }( - inner, - ) + B = MathOptComplements.Bridges.NonlinearBridge{Float64} + model = MOI.Bridges.Constraint.SingleBridgeOptimizer{B}(inner) x1 = MOI.add_variable(model) x2, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) MOI.add_constraint( @@ -120,11 +102,8 @@ end function test_Nonpositives_with_unbounded_x1_upper_bound() inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - model = MOI.Bridges.Constraint.SingleBridgeOptimizer{ - MathOptComplements.Bridges.NonlinearBridge{Float64}, - }( - inner, - ) + B = MathOptComplements.Bridges.NonlinearBridge{Float64} + model = MOI.Bridges.Constraint.SingleBridgeOptimizer{B}(inner) x1 = MOI.add_variable(model) x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) MOI.add_constraint( @@ -144,23 +123,18 @@ end function test_LessThan_with_nonzero_bound() MOI.Bridges.runtests( MathOptComplements.Bridges.NonlinearBridge, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x1, x2]), - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end, - model -> begin - x1, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - # x1 * (x2 - (-2)) <= 0 - MOI.add_constraint(model, x1 * (x2 + 2.0), MOI.LessThan(0.0)) - end; + """ + variables: x, y + x <= 0.0 + y <= -2.0 + [x, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """, + """ + variables: x, y + x <= 0.0 + y <= -2.0 + 1.0 * x * y + 2.0 * x <= 0.0 + """; cannot_unbridge = true, ) return @@ -168,11 +142,8 @@ end function test_FB_Nonnegatives_with_unbounded_x1() inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - model = MOI.Bridges.Constraint.SingleBridgeOptimizer{ - MathOptComplements.Bridges.NonlinearBridge{Float64}, - }( - inner, - ) + B = MathOptComplements.Bridges.NonlinearBridge{Float64} + model = MOI.Bridges.Constraint.SingleBridgeOptimizer{B}(inner) x1 = MOI.add_variable(model) x2, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) ci = MOI.add_constraint( @@ -199,11 +170,8 @@ end function test_FB_Nonpositives_with_unbounded_x1() inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - model = MOI.Bridges.Constraint.SingleBridgeOptimizer{ - MathOptComplements.Bridges.NonlinearBridge{Float64}, - }( - inner, - ) + B = MathOptComplements.Bridges.NonlinearBridge{Float64} + model = MOI.Bridges.Constraint.SingleBridgeOptimizer{B}(inner) x1 = MOI.add_variable(model) x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) ci = MOI.add_constraint( @@ -230,11 +198,8 @@ end function test_KS_Nonnegatives_with_unbounded_x1() inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - model = MOI.Bridges.Constraint.SingleBridgeOptimizer{ - MathOptComplements.Bridges.NonlinearBridge{Float64}, - }( - inner, - ) + B = MathOptComplements.Bridges.NonlinearBridge{Float64} + model = MOI.Bridges.Constraint.SingleBridgeOptimizer{B}(inner) x1 = MOI.add_variable(model) x2, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) ci = MOI.add_constraint( @@ -254,11 +219,8 @@ end function test_KS_Nonpositives_with_unbounded_x1() inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) - model = MOI.Bridges.Constraint.SingleBridgeOptimizer{ - MathOptComplements.Bridges.NonlinearBridge{Float64}, - }( - inner, - ) + B = MathOptComplements.Bridges.NonlinearBridge{Float64} + model = MOI.Bridges.Constraint.SingleBridgeOptimizer{B}(inner) x1 = MOI.add_variable(model) x2, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) ci = MOI.add_constraint( @@ -279,22 +241,15 @@ end function test_Zeros_equality() MOI.Bridges.runtests( MathOptComplements.Bridges.NonlinearBridge, - model -> begin - x1 = MOI.add_variable(model) - x2 = MOI.add_variable(model) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x1, x2]), - MathOptComplements.ComplementsWithSetType{MOI.Zeros}(2), - ) - end, - model -> begin - x1 = MOI.add_variable(model) - x2 = MOI.add_variable(model) - # Range relaxation with lb=0, ub=0: two constraints - MOI.add_constraint(model, x1 * (x2 - 0.0), MOI.LessThan(0.0)) - MOI.add_constraint(model, x1 * (x2 - 0.0), MOI.LessThan(0.0)) - end; + """ + variables: x, y + [x, y] in $M.ComplementsWithSetType{MOI.Zeros}(2) + """, + """ + variables: x, y + 1.0 * x * y <= 0.0 + 1.0 * x * y <= 0.0 + """; cannot_unbridge = true, ) return diff --git a/test/Bridges/test_SpecifySetTypeBridge.jl b/test/Bridges/test_SpecifySetTypeBridge.jl index edb0bd4..8c9b256 100644 --- a/test/Bridges/test_SpecifySetTypeBridge.jl +++ b/test/Bridges/test_SpecifySetTypeBridge.jl @@ -10,6 +10,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestSpecifySetTypeBridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -21,26 +23,18 @@ end function test_lower_bound_Nonnegatives() MOI.Bridges.runtests( MathOptComplements.Bridges.SpecifySetTypeBridge, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.Complements(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end; + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [x, y] in MOI.Complements(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """; cannot_unbridge = true, ) return @@ -49,30 +43,18 @@ end function test_lower_bound_GreaterThan() MOI.Bridges.runtests( MathOptComplements.Bridges.SpecifySetTypeBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.Complements(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - end; + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [x, y] in MOI.Complements(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 3.0 + [x, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + """; cannot_unbridge = true, ) return @@ -81,24 +63,17 @@ end function test_upper_bound_Nonpositives() MOI.Bridges.runtests( MathOptComplements.Bridges.SpecifySetTypeBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.Complements(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Nonpositives}(2), - ) - end; + """ + variables: x, y + y <= 0.0 + [x, y] in MOI.Complements(2) + """, + """ + variables: x, y + x <= 0.0 + y <= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonpositives}(2) + """; cannot_unbridge = true, ) return @@ -107,26 +82,17 @@ end function test_upper_bound_LessThan() MOI.Bridges.runtests( MathOptComplements.Bridges.SpecifySetTypeBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.Complements(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - y, _ = MOI.add_constrained_variable(model, MOI.LessThan(-2.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end; + """ + variables: x, y + y <= -2.0 + [x, y] in MOI.Complements(2) + """, + """ + variables: x, y + x <= 0.0 + y <= -2.0 + [x, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """; cannot_unbridge = true, ) return @@ -135,28 +101,16 @@ end function test_range_Interval() MOI.Bridges.runtests( MathOptComplements.Bridges.SpecifySetTypeBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.Complements(2), - ) - end, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Interval{Float64}}( - 2, - ), - ) - end; + """ + variables: x, y + y in Interval(0.0, 1.0) + [x, y] in MOI.Complements(2) + """, + """ + variables: x, y + y in Interval(0.0, 1.0) + [x, y] in $M.ComplementsWithSetType{MOI.Interval{Float64}}(2) + """; cannot_unbridge = true, ) return @@ -165,26 +119,15 @@ end function test_Free_variable_Zeros() MOI.Bridges.runtests( MathOptComplements.Bridges.SpecifySetTypeBridge, - model -> begin - x = MOI.add_variable(model) - y = MOI.add_variable(model) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.Complements(2), - ) - end, - model -> begin - x = MOI.add_variable(model) - y = MOI.add_variable(model) - # x1 must be zero - MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Zeros}(2), - ) - end; + """ + variables: x, y + [x, y] in MOI.Complements(2) + """, + """ + variables: x, y + 1.0 * x == 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Zeros}(2) + """; cannot_unbridge = true, ) return diff --git a/test/Bridges/test_SplitIntervalBridge.jl b/test/Bridges/test_SplitIntervalBridge.jl index af112cd..73a4b38 100644 --- a/test/Bridges/test_SplitIntervalBridge.jl +++ b/test/Bridges/test_SplitIntervalBridge.jl @@ -10,6 +10,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestSplitIntervalBridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -21,48 +23,20 @@ end function test_VectorOfVariables_input() MOI.Bridges.runtests( MathOptComplements.Bridges.SplitIntervalBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Interval{Float64}}( - 2, - ), - ) - end, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0)) - xp, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - xn, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - # x == xp + xn → x - xp - xn == 0 - MOI.add_constraint( - model, - 1.0 * x - 1.0 * xp - 1.0 * xn, - MOI.EqualTo(0.0), - ) - MOI.add_constraint( - model, - MOI.VectorOfVariables([xp, y]), - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - MOI.add_constraint( - model, - MOI.VectorOfVariables([xn, y]), - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end; + """ + variables: x, y + y in Interval(0.0, 1.0) + [x, y] in $M.ComplementsWithSetType{MOI.Interval{Float64}}(2) + """, + """ + variables: x, y, xp, xn + y in Interval(0.0, 1.0) + xp >= 0.0 + xn <= 0.0 + 1.0 * x + -1.0 * xp + -1.0 * xn == 0.0 + [xp, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + [xn, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """; cannot_unbridge = true, ) return @@ -71,55 +45,20 @@ end function test_VectorAffineFunction_input() MOI.Bridges.runtests( MathOptComplements.Bridges.SplitIntervalBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0)) - f = MOI.VectorAffineFunction{Float64}( - [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(2.0, x)), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, y)), - ], - [1.0, 0.0], - ) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Interval{Float64}}( - 2, - ), - ) - end, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.Interval(0.0, 1.0)) - xp, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - xn, _ = MOI.add_constrained_variable(model, MOI.LessThan(0.0)) - # 2x + 1 == xp + xn → 2x - xp - xn == -1 - MOI.add_constraint( - model, - 2.0 * x - 1.0 * xp - 1.0 * xn, - MOI.EqualTo(-1.0), - ) - MOI.add_constraint( - model, - MOI.VectorOfVariables([xp, y]), - MathOptComplements.ComplementsWithSetType{ - MOI.GreaterThan{Float64}, - }( - 2, - ), - ) - MOI.add_constraint( - model, - MOI.VectorOfVariables([xn, y]), - MathOptComplements.ComplementsWithSetType{MOI.LessThan{Float64}}( - 2, - ), - ) - end; + """ + variables: x, y + y in Interval(0.0, 1.0) + [2.0 * x + 1.0, y] in $M.ComplementsWithSetType{MOI.Interval{Float64}}(2) + """, + """ + variables: x, y, xp, xn + y in Interval(0.0, 1.0) + xp >= 0.0 + xn <= 0.0 + 2.0 * x + -1.0 * xp + -1.0 * xn == -1.0 + [xp, y] in $M.ComplementsWithSetType{MOI.GreaterThan{Float64}}(2) + [xn, y] in $M.ComplementsWithSetType{MOI.LessThan{Float64}}(2) + """; cannot_unbridge = true, ) return diff --git a/test/Bridges/test_ToSOS1Bridge.jl b/test/Bridges/test_ToSOS1Bridge.jl index a09931f..ea60a3e 100644 --- a/test/Bridges/test_ToSOS1Bridge.jl +++ b/test/Bridges/test_ToSOS1Bridge.jl @@ -10,6 +10,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestToSOS1Bridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -21,26 +23,18 @@ end function test_ToSOS1Bridge() MOI.Bridges.runtests( MathOptComplements.Bridges.ToSOS1Bridge, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end, - model -> begin - x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x, y]), - MOI.SOS1([1.0, 2.0]), - ) - end; + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [x, y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """, + """ + variables: x, y + x >= 0.0 + y >= 0.0 + [x, y] in SOS1([1.0, 2.0]) + """; cannot_unbridge = true, ) return diff --git a/test/Bridges/test_VerticalBridge.jl b/test/Bridges/test_VerticalBridge.jl index b4daab6..eadc815 100644 --- a/test/Bridges/test_VerticalBridge.jl +++ b/test/Bridges/test_VerticalBridge.jl @@ -10,6 +10,8 @@ using Test import MathOptComplements import MathOptInterface as MOI +const M = "TestVerticalBridge.MathOptComplements" + function runtests() is_test(name) = startswith("$name", "test_") @testset "$name" for name in filter(is_test, names(@__MODULE__; all = true)) @@ -21,37 +23,17 @@ end function test_Unbounded_RHS_with_constant_in_LHS_Complements() MOI.Bridges.runtests( MathOptComplements.Bridges.VerticalBridge, - model -> begin - x = MOI.add_variable(model) - z = MOI.add_variable(model) - y = MOI.add_variable(model) - w, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - f = MOI.VectorAffineFunction{Float64}( - [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(2.0, x)), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, z)), - MOI.VectorAffineTerm(3, MOI.ScalarAffineTerm(1.0, y)), - MOI.VectorAffineTerm(4, MOI.ScalarAffineTerm(1.0, w)), - ], - [3.0, 0.0, 0.0, 0.0], - ) - MOI.add_constraint(model, f, MOI.Complements(4)) - end, - model -> begin - x = MOI.add_variable(model) - z = MOI.add_variable(model) - y = MOI.add_variable(model) - w, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - # 2x + 3 = 0 → 2x in EqualTo(-3.0) (y is unbounded) - MOI.add_constraint(model, 2.0 * x, MOI.EqualTo(-3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([z, w]), - MOI.Complements(2), - ) - end; + """ + variables: w, x, y, z + w >= 0.0 + [2.0 * x + 3.0, 1.0 * z, 1.0 * y, 1.0 * w] in MOI.Complements(4) + """, + """ + variables: w, x, y, z + w >= 0.0 + 2.0 * x == -3.0 + [z, w] in MOI.Complements(2) + """; cannot_unbridge = true, ) return @@ -60,36 +42,17 @@ end function test_Expression_LHS_with_constant_ComplementsWithSetType() MOI.Bridges.runtests( MathOptComplements.Bridges.VerticalBridge, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - f = MOI.VectorAffineFunction{Float64}( - [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(2.0, x)), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, y)), - ], - [3.0, 0.0], - ) - MOI.add_constraint( - model, - f, - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end, - model -> begin - x = MOI.add_variable(model) - y, _ = - MOI.add_constrained_variable(model, MOI.GreaterThan(0.0)) - x1 = MOI.add_variable(model) - # 2x + 3 = x1 → 2x - x1 in EqualTo(-3.0) - MOI.add_constraint(model, 2.0 * x - 1.0 * x1, MOI.EqualTo(-3.0)) - MOI.add_constraint( - model, - MOI.VectorOfVariables([x1, y]), - MathOptComplements.ComplementsWithSetType{MOI.Nonnegatives}(2), - ) - end; + """ + variables: x, y + y >= 0.0 + [2.0 * x + 3.0, 1.0 * y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """, + """ + variables: x, y, z + y >= 0.0 + 2.0 * x + -1.0 * z == -3.0 + [z, y] in $M.ComplementsWithSetType{MOI.Nonnegatives}(2) + """; cannot_unbridge = true, ) return