From a908486d633f3ffac9217431b0e5b7adb333989d Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 4 Nov 2024 10:26:20 +1300 Subject: [PATCH] Use add_constrained_variable with two sets when adding bounded variables --- src/variables.jl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/variables.jl b/src/variables.jl index 07912a8c5c4..46e8315b60d 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -1983,6 +1983,16 @@ function _moi_add_constrained_variable( return x end +function _moi_add_constrained_variable( + moi_backend::MOI.ModelLike, + ::Nothing, + set_gt::MOI.GreaterThan, + set_lt::MOI.LessThan, +) + x, _ = MOI.add_constrained_variable(moi_backend, set_gt, set_lt) + return x +end + function _moi_add_variable( moi_backend, model::GenericModel{T}, @@ -1994,12 +2004,17 @@ function _moi_add_variable( # variables. index = nothing info = v.info - if info.has_lb + if info.has_lb && info.has_ub + set_lb = + MOI.GreaterThan{T}(_to_value(T, info.lower_bound, "lower bound")) + set_ub = MOI.LessThan{T}(_to_value(T, info.upper_bound, "upper bound")) + index = + _moi_add_constrained_variable(moi_backend, index, set_lb, set_ub) + elseif info.has_lb set_lb = MOI.GreaterThan{T}(_to_value(T, info.lower_bound, "lower bound")) index = _moi_add_constrained_variable(moi_backend, index, set_lb) - end - if info.has_ub + elseif info.has_ub set_ub = MOI.LessThan{T}(_to_value(T, info.upper_bound, "upper bound")) index = _moi_add_constrained_variable(moi_backend, index, set_ub) end