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
51 changes: 51 additions & 0 deletions src/Test/UnitTests/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,54 @@ function solve_affine_deletion_edge_cases(model::MOI.ModelLike, config::TestConf
)
end
unittests["solve_affine_deletion_edge_cases"] = solve_affine_deletion_edge_cases

function solve_zero_one_with_bounds_1(model::MOI.ModelLike, config::TestConfig)
MOI.empty!(model)
MOIU.loadfromstring!(model,"""
variables: x
maxobjective: 2.0x
c1: x in ZeroOne()
c2: x >= 0.0
c3: x <= 1.0
""")
x = MOI.get(model, MOI.VariableIndex, "x")
test_model_solution(model, config;
objective_value = 2.0,
variable_primal = [(x, 1.0)]
)
end
unittests["solve_zero_one_with_bounds_1"] = solve_zero_one_with_bounds_1

function solve_zero_one_with_bounds_2(model::MOI.ModelLike, config::TestConfig)
MOI.empty!(model)
MOIU.loadfromstring!(model,"""
variables: x
maxobjective: 2.0x
c1: x in ZeroOne()
c2: x >= 0.0
c3: x <= 0.5
""")
x = MOI.get(model, MOI.VariableIndex, "x")
test_model_solution(model, config;
objective_value = 0.0,
variable_primal = [(x, 0.0)]
)
end
unittests["solve_zero_one_with_bounds_2"] = solve_zero_one_with_bounds_2

function solve_zero_one_with_bounds_3(model::MOI.ModelLike, config::TestConfig)
MOI.empty!(model)
MOIU.loadfromstring!(model,"""
variables: x
maxobjective: 2.0x
c1: x in ZeroOne()
c2: x >= 0.2
c3: x <= 0.5
""")
x = MOI.get(model, MOI.VariableIndex, "x")
if config.solve
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.INFEASIBLE
end
end
unittests["solve_zero_one_with_bounds_3"] = solve_zero_one_with_bounds_3
25 changes: 24 additions & 1 deletion test/Test/unit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ end
"solve_integer_edge_cases",
"solve_objbound_edge_cases",
"raw_status_string",
"solve_time"
"solve_time",
"solve_zero_one_with_bounds_1",
"solve_zero_one_with_bounds_2",
"solve_zero_one_with_bounds_3"
])
MOI.empty!(model)
end
Expand Down Expand Up @@ -306,6 +309,26 @@ end
MOIT.solve_time(mock, config)
end

@testset "solve_zero_one_with_bounds" begin
MOIU.set_mock_optimize!(mock,
(mock::MOIU.MockOptimizer) -> begin
MOIU.mock_optimize!(
mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [1.0])
)
end,
(mock::MOIU.MockOptimizer) -> begin
MOIU.mock_optimize!(
mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [0.0])
)
end,
(mock::MOIU.MockOptimizer) -> begin
MOIU.mock_optimize!(mock, MOI.INFEASIBLE)
end
)
MOIT.solve_zero_one_with_bounds_1(mock, config)
MOIT.solve_zero_one_with_bounds_2(mock, config)
MOIT.solve_zero_one_with_bounds_3(mock, config)
end
end

@testset "modifications" begin
Expand Down