From a2c3c5d850e27a787542d3c561ec11f3492f39fa Mon Sep 17 00:00:00 2001 From: Guillaume Marques Date: Fri, 29 Jan 2021 13:30:40 +0100 Subject: [PATCH 1/3] tests cases with infinite bounds --- src/Test/UnitTests/constraints.jl | 99 +++++++++++++++++++++++++++++++ test/Test/unit.jl | 2 + 2 files changed, 101 insertions(+) diff --git a/src/Test/UnitTests/constraints.jl b/src/Test/UnitTests/constraints.jl index 17e06a0e7e..6cb3da7956 100644 --- a/src/Test/UnitTests/constraints.jl +++ b/src/Test/UnitTests/constraints.jl @@ -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 \ No newline at end of file diff --git a/test/Test/unit.jl b/test/Test/unit.jl index 8cfe461be3..caa58fbf19 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -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", From 83d951013e4cd134abe2da9caea659ffb5b1f2e1 Mon Sep 17 00:00:00 2001 From: Guillaume Marques Date: Fri, 29 Jan 2021 21:34:29 +0100 Subject: [PATCH 2/3] add test for the test --- test/Test/unit.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/Test/unit.jl b/test/Test/unit.jl index caa58fbf19..abe5e501a6 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -348,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 From e7e7df78b126a512b12fe301cc54da20c36b243c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 10 Mar 2021 00:13:16 +0000 Subject: [PATCH 3/3] CompatHelper: bump compat for "BenchmarkTools" to "0.6" --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 47c442278e..57f3e8934c 100644 --- a/Project.toml +++ b/Project.toml @@ -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"