Skip to content

Commit

Permalink
Use add_constrained_variable with two sets when adding bounded variables
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 3, 2024
1 parent be7d350 commit a908486
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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
Expand Down

0 comments on commit a908486

Please sign in to comment.