diff --git a/src/Test/UnitTests/constraints.jl b/src/Test/UnitTests/constraints.jl index 920fb7f5b2..74ac63813e 100644 --- a/src/Test/UnitTests/constraints.jl +++ b/src/Test/UnitTests/constraints.jl @@ -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 diff --git a/test/Test/unit.jl b/test/Test/unit.jl index e0b2c9313e..11051277ea 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -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 @@ -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