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

[DNM] - add variables and constraints in a single shot #244

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
30 changes: 30 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,36 @@ Return the 0-indexed column associated with `x` in `model`.
"""
column(model::Optimizer, x::MOI.VariableIndex) = _info(model, x).column

function MOI.Utilities.add_variable_and_bounds(
model::Optimizer,
lower_bound,
upper_bound,
)
# Initialize `_VariableInfo` with a dummy `VariableIndex` and a column,
# because we need `add_item` to tell us what the `VariableIndex` is.
index = CleverDicts.add_item(
model.variable_info,
_VariableInfo(MOI.VariableIndex(0), HighsInt(0)),
)
info = _info(model, index)
lb = -Inf
if lower_bound !== nothing
lb = lower_bound
_update_info(info, MOI.GreaterThan{Float64}(lb))
end
ub = Inf
if upper_bound !== nothing
ub = upper_bound
_update_info(info, MOI.LessThan{Float64}(ub))
end
# Now, set `.index` and `.column`.
info.index = index
info.column = HighsInt(length(model.variable_info) - 1)
ret = Highs_addCol(model, 0.0, lb, ub, 0, C_NULL, C_NULL)
_check_ret(ret)
return index
end

function MOI.add_variable(model::Optimizer)
# Initialize `_VariableInfo` with a dummy `VariableIndex` and a column,
# because we need `add_item` to tell us what the `VariableIndex` is.
Expand Down
Loading