From ce5c5e056d199aeea534a1e0264a0e3051f8e891 Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 18 Nov 2021 17:44:56 +1300 Subject: [PATCH 1/2] Remove source of common test failure in LowerBoundAlreadySet This will decrease coverage for some solvers, but there is a serious bug in the bridging system that requires a much deeper fix. This PR removes the common source of failure and adds a broken test to remind us to fix it in future. --- src/Test/test_model.jl | 4 ---- test/Bridges/Constraint/semi_to_binary.jl | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Test/test_model.jl b/src/Test/test_model.jl index 520b295035..02110c8032 100644 --- a/src/Test/test_model.jl +++ b/src/Test/test_model.jl @@ -804,8 +804,6 @@ function test_model_LowerBoundAlreadySet( sets = [ MOI.EqualTo(lb), MOI.Interval(lb, lb), - MOI.Semicontinuous(lb, lb), - MOI.Semiinteger(lb, lb), ] set2 = MOI.GreaterThan(lb) for set1 in sets @@ -842,8 +840,6 @@ function test_model_UpperBoundAlreadySet( sets = [ MOI.EqualTo(ub), MOI.Interval(ub, ub), - MOI.Semicontinuous(ub, ub), - MOI.Semiinteger(ub, ub), ] set2 = MOI.LessThan(ub) for set1 in sets diff --git a/test/Bridges/Constraint/semi_to_binary.jl b/test/Bridges/Constraint/semi_to_binary.jl index b8811b30dc..09045aaf8d 100644 --- a/test/Bridges/Constraint/semi_to_binary.jl +++ b/test/Bridges/Constraint/semi_to_binary.jl @@ -235,6 +235,29 @@ function test_SemiToBinary() return end +""" + test_lower_bound_already_set() + +The second call to `add_constraint` is broken because it should throw: +```julia +MOI.LowerBoundAlreadySet{ + MOI.Semicontinuous{Float64}, + MOI.GreaterThan{Float64}, +} +``` +See MathOptInterface issue #1431. +""" +function test_lower_bound_already_set() + model = MOI.Utilities.Model{Float64}() + bridged = MOI.Bridges.Constraint.SemiToBinary{Float64}(model) + x = MOI.add_variable(bridged) + MOI.add_constraint(bridged, x, MOI.Semicontinuous(1.0, 2.0)) + @test_broken( + MOI.add_constraint(bridged, x, MOI.GreaterThan(0.0)) === nothing, + ) + return +end + end # module TestConstraintSemiToBinary.runtests() From 7c83976c193830a485eb6965388c017f800a62d9 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 19 Nov 2021 09:30:59 +1300 Subject: [PATCH 2/2] Update test_model.jl --- src/Test/test_model.jl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Test/test_model.jl b/src/Test/test_model.jl index 02110c8032..e30d5113fc 100644 --- a/src/Test/test_model.jl +++ b/src/Test/test_model.jl @@ -801,10 +801,7 @@ function test_model_LowerBoundAlreadySet( @requires _supports(config, MOI.delete) x = MOI.add_variable(model) lb = zero(T) - sets = [ - MOI.EqualTo(lb), - MOI.Interval(lb, lb), - ] + sets = [MOI.EqualTo(lb), MOI.Interval(lb, lb)] set2 = MOI.GreaterThan(lb) for set1 in sets if !MOI.supports_constraint(model, MOI.VariableIndex, typeof(set1)) @@ -837,10 +834,7 @@ function test_model_UpperBoundAlreadySet( x = MOI.add_variable(model) ub = zero(T) @requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.LessThan{T}) - sets = [ - MOI.EqualTo(ub), - MOI.Interval(ub, ub), - ] + sets = [MOI.EqualTo(ub), MOI.Interval(ub, ub)] set2 = MOI.LessThan(ub) for set1 in sets if !MOI.supports_constraint(model, MOI.VariableIndex, typeof(set1))