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