Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 38 additions & 79 deletions test/Bridges/test_ComplementsVectorizeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
142 changes: 50 additions & 92 deletions test/Bridges/test_FlipSignBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading
Loading