Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use add_constrained_variable with two sets when adding bounded variables #3865

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ JuMPDimensionalDataExt = "DimensionalData"
DimensionalData = "0.24, 0.25, 0.26.2, 0.27, 0.28"
LinearAlgebra = "<0.0.1, 1.6"
MacroTools = "0.5"
MathOptInterface = "1.25.2"
MathOptInterface = "1.34.0"
MutableArithmetics = "1.1"
OrderedCollections = "1"
Printf = "<0.0.1, 1.6"
Expand Down
20 changes: 17 additions & 3 deletions src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,15 @@ function _moi_add_constrained_variable(
return x
end

function _moi_add_constrained_variable(
moi_backend::MOI.ModelLike,
::Nothing,
set::Tuple{MOI.GreaterThan{T},MOI.LessThan{T}}
odow marked this conversation as resolved.
Show resolved Hide resolved
) where {T}
odow marked this conversation as resolved.
Show resolved Hide resolved
x, _ = MOI.add_constrained_variable(moi_backend, set)
return x
end

function _moi_add_variable(
moi_backend,
model::GenericModel{T},
Expand All @@ -1992,12 +2001,17 @@ function _moi_add_variable(
# variables.
index = nothing
info = v.info
if info.has_lb
if info.has_lb && info.has_ub
set = (
MOI.GreaterThan{T}(_to_value(T, info.lower_bound, "lower bound")),
MOI.LessThan{T}(_to_value(T, info.upper_bound, "upper bound")),
)
index = _moi_add_constrained_variable(moi_backend, index, set)
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
Loading