From 16ce8f7fb490f576e24d9ca09bce8509081107ff Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 17 Jun 2019 19:59:07 -0500 Subject: [PATCH 1/3] Add tests for ZeroOne variables with variable bounds --- src/Test/UnitTests/constraints.jl | 48 +++++++++++++++++++++++++++++++ test/Test/unit.jl | 25 +++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/Test/UnitTests/constraints.jl b/src/Test/UnitTests/constraints.jl index 920fb7f5b2..5ef9edfad6 100644 --- a/src/Test/UnitTests/constraints.jl +++ b/src/Test/UnitTests/constraints.jl @@ -310,3 +310,51 @@ 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_zeroone_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 in Interval(0.0, 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_zeroone_with_bounds_1"] = solve_zeroone_with_bounds_1 + +function solve_zeroone_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 in Interval(0.0, 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_zeroone_with_bounds_2"] = solve_zeroone_with_bounds_2 + +function solve_zeroone_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 in Interval(0.2, 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_zeroone_with_bounds_3"] = solve_zeroone_with_bounds_3 diff --git a/test/Test/unit.jl b/test/Test/unit.jl index e0b2c9313e..7ceea0d034 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_zeroone_with_bounds_1", + "solve_zeroone_with_bounds_2", + "solve_zeroone_with_bounds_3" ]) MOI.empty!(model) end @@ -306,6 +309,26 @@ end MOIT.solve_time(mock, config) end + @testset "solve_zeroone_with_bounds_1" 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_zeroone_with_bounds_1(mock, config) + MOIT.solve_zeroone_with_bounds_2(mock, config) + MOIT.solve_zeroone_with_bounds_3(mock, config) + end end @testset "modifications" begin From c6b167b0be1a9f7450fa3c4cb3dac966f55def31 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 18 Jun 2019 08:36:47 -0500 Subject: [PATCH 2/3] Address comments --- src/Test/UnitTests/constraints.jl | 9 ++++++--- test/Test/unit.jl | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Test/UnitTests/constraints.jl b/src/Test/UnitTests/constraints.jl index 5ef9edfad6..2a8714fb73 100644 --- a/src/Test/UnitTests/constraints.jl +++ b/src/Test/UnitTests/constraints.jl @@ -317,7 +317,8 @@ function solve_zeroone_with_bounds_1(model::MOI.ModelLike, config::TestConfig) variables: x maxobjective: 2.0x c1: x in ZeroOne() - c2: x in Interval(0.0, 1.0) + c2: x >= 0.0 + c3: x <= 1.0 """) x = MOI.get(model, MOI.VariableIndex, "x") test_model_solution(model, config; @@ -333,7 +334,8 @@ function solve_zeroone_with_bounds_2(model::MOI.ModelLike, config::TestConfig) variables: x maxobjective: 2.0x c1: x in ZeroOne() - c2: x in Interval(0.0, 0.5) + c2: x >= 0.0 + c3: x <= 0.5 """) x = MOI.get(model, MOI.VariableIndex, "x") test_model_solution(model, config; @@ -349,7 +351,8 @@ function solve_zeroone_with_bounds_3(model::MOI.ModelLike, config::TestConfig) variables: x maxobjective: 2.0x c1: x in ZeroOne() - c2: x in Interval(0.2, 0.5) + c2: x >= 0.2 + c3: x <= 0.5 """) x = MOI.get(model, MOI.VariableIndex, "x") if config.solve diff --git a/test/Test/unit.jl b/test/Test/unit.jl index 7ceea0d034..6d2b985621 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -309,7 +309,7 @@ end MOIT.solve_time(mock, config) end - @testset "solve_zeroone_with_bounds_1" begin + @testset "solve_zeroone_with_bounds" begin MOIU.set_mock_optimize!(mock, (mock::MOIU.MockOptimizer) -> begin MOIU.mock_optimize!( From 21efbd393b4afd0403aa7b41f41e062d1acf4949 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 18 Jun 2019 09:11:50 -0500 Subject: [PATCH 3/3] zeroone -> zero_one --- src/Test/UnitTests/constraints.jl | 12 ++++++------ test/Test/unit.jl | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Test/UnitTests/constraints.jl b/src/Test/UnitTests/constraints.jl index 2a8714fb73..74ac63813e 100644 --- a/src/Test/UnitTests/constraints.jl +++ b/src/Test/UnitTests/constraints.jl @@ -311,7 +311,7 @@ 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_zeroone_with_bounds_1(model::MOI.ModelLike, config::TestConfig) +function solve_zero_one_with_bounds_1(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) MOIU.loadfromstring!(model,""" variables: x @@ -326,9 +326,9 @@ function solve_zeroone_with_bounds_1(model::MOI.ModelLike, config::TestConfig) variable_primal = [(x, 1.0)] ) end -unittests["solve_zeroone_with_bounds_1"] = solve_zeroone_with_bounds_1 +unittests["solve_zero_one_with_bounds_1"] = solve_zero_one_with_bounds_1 -function solve_zeroone_with_bounds_2(model::MOI.ModelLike, config::TestConfig) +function solve_zero_one_with_bounds_2(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) MOIU.loadfromstring!(model,""" variables: x @@ -343,9 +343,9 @@ function solve_zeroone_with_bounds_2(model::MOI.ModelLike, config::TestConfig) variable_primal = [(x, 0.0)] ) end -unittests["solve_zeroone_with_bounds_2"] = solve_zeroone_with_bounds_2 +unittests["solve_zero_one_with_bounds_2"] = solve_zero_one_with_bounds_2 -function solve_zeroone_with_bounds_3(model::MOI.ModelLike, config::TestConfig) +function solve_zero_one_with_bounds_3(model::MOI.ModelLike, config::TestConfig) MOI.empty!(model) MOIU.loadfromstring!(model,""" variables: x @@ -360,4 +360,4 @@ function solve_zeroone_with_bounds_3(model::MOI.ModelLike, config::TestConfig) @test MOI.get(model, MOI.TerminationStatus()) == MOI.INFEASIBLE end end -unittests["solve_zeroone_with_bounds_3"] = solve_zeroone_with_bounds_3 +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 6d2b985621..11051277ea 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -39,9 +39,9 @@ end "solve_objbound_edge_cases", "raw_status_string", "solve_time", - "solve_zeroone_with_bounds_1", - "solve_zeroone_with_bounds_2", - "solve_zeroone_with_bounds_3" + "solve_zero_one_with_bounds_1", + "solve_zero_one_with_bounds_2", + "solve_zero_one_with_bounds_3" ]) MOI.empty!(model) end @@ -309,7 +309,7 @@ end MOIT.solve_time(mock, config) end - @testset "solve_zeroone_with_bounds" begin + @testset "solve_zero_one_with_bounds" begin MOIU.set_mock_optimize!(mock, (mock::MOIU.MockOptimizer) -> begin MOIU.mock_optimize!( @@ -325,9 +325,9 @@ end MOIU.mock_optimize!(mock, MOI.INFEASIBLE) end ) - MOIT.solve_zeroone_with_bounds_1(mock, config) - MOIT.solve_zeroone_with_bounds_2(mock, config) - MOIT.solve_zeroone_with_bounds_3(mock, config) + 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