From 6f80171314ab24b5588ea3c8b631d29db0014da4 Mon Sep 17 00:00:00 2001 From: joaquim Date: Sat, 2 Oct 2021 06:10:24 -0300 Subject: [PATCH 1/2] zero one conflic test actually testing integrality and no the UB = 1 --- src/Test/test_solve.jl | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/Test/test_solve.jl b/src/Test/test_solve.jl index 4f97acbdf1..38fd004292 100644 --- a/src/Test/test_solve.jl +++ b/src/Test/test_solve.jl @@ -1401,6 +1401,69 @@ function setup_test( return end +""" + test_solve_conflict_zeroone_ii(model::MOI.ModelLike, config::Config) + +Test the ConflictStatus API when an integrality is in the conflict. +In this test, integrality is the conflict and no the upper bound == 1. +""" +function test_solve_conflict_zeroone_ii( + model::MOI.ModelLike, + config::Config{T}, +) where {T} + @requires !(T<:Integer) + @requires _supports(config, MOI.compute_conflict!) + @requires _supports(config, MOI.optimize!) + try + MOI.get(model, MOI.ConflictStatus()) + catch + return # If this fails, skip the test. + end + x, c1 = MOI.add_constrained_variable(model, MOI.ZeroOne()) + c2 = MOI.add_constraint( + model, + MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(one(T), [x]), zero(T)), + MOI.EqualTo(div(one(T),T(2))), + ) + MOI.optimize!(model) + @test MOI.get(model, MOI.TerminationStatus()) == MOI.INFEASIBLE + MOI.compute_conflict!(model) + @test MOI.get(model, MOI.ConflictStatus()) == MOI.CONFLICT_FOUND + zeroone_conflict = MOI.get(model, MOI.ConstraintConflictStatus(), c1) + @test zeroone_conflict == MOI.MAYBE_IN_CONFLICT || + zeroone_conflict == MOI.IN_CONFLICT + @test MOI.get(model, MOI.ConstraintConflictStatus(), c2) == MOI.IN_CONFLICT + return +end + +function setup_test( + ::typeof(test_solve_conflict_zeroone), + model::MOIU.MockOptimizer, + ::Config, +) + MOIU.set_mock_optimize!( + model, + mock::MOIU.MockOptimizer -> begin + MOIU.mock_optimize!( + mock, + MOI.INFEASIBLE, + MOI.NO_SOLUTION, + MOI.NO_SOLUTION; + constraint_conflict_status = [ + (MOI.VariableIndex, MOI.ZeroOne) => + [MOI.IN_CONFLICT], + ( + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + ) => [MOI.IN_CONFLICT], + ], + ) + MOI.set(mock, MOI.ConflictStatus(), MOI.CONFLICT_FOUND) + end, + ) + return +end + function test_solve_SOS2_add_and_delete(model::MOI.ModelLike, config::Config) @requires _supports(config, MOI.optimize!) @requires MOI.supports_constraint( From 8666da211185a77612ed3238a24c88d57ad10a03 Mon Sep 17 00:00:00 2001 From: joaquim Date: Sat, 2 Oct 2021 16:12:20 -0300 Subject: [PATCH 2/2] fix test and format --- src/Test/test_solve.jl | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Test/test_solve.jl b/src/Test/test_solve.jl index 38fd004292..59614d7af5 100644 --- a/src/Test/test_solve.jl +++ b/src/Test/test_solve.jl @@ -1411,7 +1411,7 @@ function test_solve_conflict_zeroone_ii( model::MOI.ModelLike, config::Config{T}, ) where {T} - @requires !(T<:Integer) + @requires !(T <: Integer) @requires _supports(config, MOI.compute_conflict!) @requires _supports(config, MOI.optimize!) try @@ -1423,7 +1423,7 @@ function test_solve_conflict_zeroone_ii( c2 = MOI.add_constraint( model, MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(one(T), [x]), zero(T)), - MOI.EqualTo(div(one(T),T(2))), + MOI.EqualTo(div(one(T), T(2))), ) MOI.optimize!(model) @test MOI.get(model, MOI.TerminationStatus()) == MOI.INFEASIBLE @@ -1437,7 +1437,7 @@ function test_solve_conflict_zeroone_ii( end function setup_test( - ::typeof(test_solve_conflict_zeroone), + ::typeof(test_solve_conflict_zeroone_ii), model::MOIU.MockOptimizer, ::Config, ) @@ -1450,12 +1450,8 @@ function setup_test( MOI.NO_SOLUTION, MOI.NO_SOLUTION; constraint_conflict_status = [ - (MOI.VariableIndex, MOI.ZeroOne) => - [MOI.IN_CONFLICT], - ( - MOI.ScalarAffineFunction{Float64}, - MOI.EqualTo{Float64}, - ) => [MOI.IN_CONFLICT], + (MOI.VariableIndex, MOI.ZeroOne) => [MOI.IN_CONFLICT], + (MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) => [MOI.IN_CONFLICT], ], ) MOI.set(mock, MOI.ConflictStatus(), MOI.CONFLICT_FOUND)