From e79694d00e2eb5855bec5b882606f974b802488d Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 26 Oct 2023 09:38:07 +1300 Subject: [PATCH] Fix one-sided bounds --- src/Test/test_linear.jl | 1 + src/Utilities/variables.jl | 2 +- test/Utilities/variables.jl | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Test/test_linear.jl b/src/Test/test_linear.jl index 05e396a8da..1dd66ebc02 100644 --- a/src/Test/test_linear.jl +++ b/src/Test/test_linear.jl @@ -2813,6 +2813,7 @@ function test_linear_SOS1_integration( @requires MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.SOS1{T}) @requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.LessThan{T}) v = MOI.add_variables(model, 3) + MOI.add_constraint.(model, v, MOI.GreaterThan(zero(T))) @test MOI.get(model, MOI.NumberOfVariables()) == 3 vc1 = MOI.add_constraint(model, v[1], MOI.LessThan(T(1))) @test vc1.value == v[1].value diff --git a/src/Utilities/variables.jl b/src/Utilities/variables.jl index 7191be063b..7f0ed67149 100644 --- a/src/Utilities/variables.jl +++ b/src/Utilities/variables.jl @@ -119,7 +119,7 @@ function get_bounds( if MOI.is_valid(model, ci) l, u = max(l, zero(T)), min(u, one(T)) end - if (l, u) == (typemin(T), typemax(T)) + if l == typemin(T) || u == typemax(T) return nothing end bounds_cache[x] = (l, u) diff --git a/test/Utilities/variables.jl b/test/Utilities/variables.jl index fda15c4152..b7b71a2900 100644 --- a/test/Utilities/variables.jl +++ b/test/Utilities/variables.jl @@ -115,6 +115,10 @@ function test_get_bounds_scalar_affine() @test MOI.Utilities.get_bounds(model, cache, 1.5 * x + z) == (1.5, 4.0) @test MOI.Utilities.get_bounds(model, cache, -1.0 * y) == nothing @test MOI.Utilities.get_bounds(model, cache, 1.0 * x + y) == nothing + MOI.add_constraint(model, y, MOI.GreaterThan(2.0)) + @test MOI.Utilities.get_bounds(model, cache, y) == nothing + MOI.add_constraint(model, y, MOI.LessThan(3.0)) + @test MOI.Utilities.get_bounds(model, cache, y) == (2.0, 3.0) return end