Skip to content
Open
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
BenchmarkTools = "0.4, 0.5"
BenchmarkTools = "0.4, 0.5, 0.6"
CodecBzip2 = "~0.6, 0.7"
CodecZlib = "~0.6, 0.7"
JSON = "~0.21"
Expand Down
99 changes: 99 additions & 0 deletions src/Test/UnitTests/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,102 @@ function solve_zero_one_with_bounds_3(model::MOI.ModelLike, config::TestConfig)
end
end
unittests["solve_zero_one_with_bounds_3"] = solve_zero_one_with_bounds_3

function solve_constrs_with_inf_bounds(model::MOI.ModelLike, config::TestConfig)
MOI.empty!(model)
x = MOI.add_variable(model)
y = MOI.add_variable(model)
objective_function = MOI.ScalarAffineFunction(
[MOI.ScalarAffineTerm(1.0, x), MOI.ScalarAffineTerm(-1.0, y)],
0.0
)
MOI.set(
model,
MOI.ObjectiveFunction{typeof(objective_function)}(),
objective_function,
)
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)

c1 = MOI.add_constraint(
model,
MOI.SingleVariable(x),
MOI.LessThan{Float64}(1.0)
)
c2 = MOI.add_constraint(
model,
MOI.SingleVariable(x),
MOI.GreaterThan{Float64}(-Inf)
)
c3 = MOI.add_constraint(
model,
MOI.SingleVariable(y),
MOI.LessThan{Float64}(Inf)
)
c4 = MOI.add_constraint(
model,
MOI.SingleVariable(y),
MOI.GreaterThan{Float64}(-1.0)
)

@test MOI.is_valid(model, c2)
@test MOI.is_valid(model, c3)

return test_model_solution(
model,
config;
objective_value = 2.0,
variable_primal = [(x, 1.0), (y, -1.0)],
)
end
unittests["solve_constrs_with_inf_bounds"] = solve_constrs_with_inf_bounds

function solve_one_sided_intervals(model::MOI.ModelLike, config::TestConfig)
MOI.empty!(model)
MOIU.loadfromstring!(
model,
"""
variables: x, y, z
maxobjective: x + -1y + z
c1: x in Interval(-Inf, 1.0)
c2: y in Interval(-1.0, Inf)
c3: z in Interval(-Inf, Inf)
c4: 1z <= 1.0
""",
)

x = MOI.get(model, MOI.VariableIndex, "x")
y = MOI.get(model, MOI.VariableIndex, "y")
z = MOI.get(model, MOI.VariableIndex, "z")

c1 = MOI.get(
model,
MOI.ConstraintIndex{MOI.SingleVariable, MOI.Interval{Float64}},
"c1"
)
c2 = MOI.get(
model,
MOI.ConstraintIndex{MOI.SingleVariable, MOI.Interval{Float64}},
"c2"
)
c3 = MOI.get(
model,
MOI.ConstraintIndex{MOI.SingleVariable, MOI.Interval{Float64}},
"c3"
)

@test MOI.get(model, MOI.ConstraintIndex, "c1") == c1
@test MOI.get(model, MOI.ConstraintIndex, "c2") == c2
@test MOI.get(model, MOI.ConstraintIndex, "c3") == c3

@test MOI.is_valid(model, c1)
@test MOI.is_valid(model, c2)
@test MOI.is_valid(model, c3)

return test_model_solution(
model,
config;
objective_value = 3.0,
variable_primal = [(x, 1.0), (y, -1.0), (z, 1.0)],
)
end
unittests["solve_one_sided_intervals"] = solve_one_sided_intervals
19 changes: 19 additions & 0 deletions test/Test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ end
"solve_zero_one_with_bounds_1",
"solve_zero_one_with_bounds_2",
"solve_zero_one_with_bounds_3",
"solve_constrs_with_inf_bounds",
"solve_one_sided_intervals",
"solve_unbounded_model",
"solve_single_variable_dual_min",
"solve_single_variable_dual_max",
Expand Down Expand Up @@ -346,6 +348,23 @@ end
MOIT.solve_zero_one_with_bounds_3(mock, config)
end

@testset "solve_constrs_inf_bounds" begin
MOIU.set_mock_optimize!(mock,
(mock::MOIU.MockOptimizer) -> begin
MOIU.mock_optimize!(
mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [1.0, -1.0])
)
end,
(mock::MOIU.MockOptimizer) -> begin
MOIU.mock_optimize!(
mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [1.0, -1.0, 1.0])
)
end
)
MOIT.solve_constrs_with_inf_bounds(mock, config)
MOIT.solve_one_sided_intervals(mock, config)
end

@testset "solve_unbounded_model" begin
MOIU.set_mock_optimize!(mock,
(mock::MOIU.MockOptimizer) -> begin
Expand Down