Skip to content

Commit 2bd74b0

Browse files
committed
[DNM] - add variables and constraints in a single shot
1 parent 1a4f551 commit 2bd74b0

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/MOI_wrapper.jl

+30
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,36 @@ Return the 0-indexed column associated with `x` in `model`.
744744
"""
745745
column(model::Optimizer, x::MOI.VariableIndex) = _info(model, x).column
746746

747+
function MOI.Utilities.add_variable_and_bounds(
748+
model::Optimizer,
749+
lower_bound,
750+
upper_bound,
751+
)
752+
# Initialize `_VariableInfo` with a dummy `VariableIndex` and a column,
753+
# because we need `add_item` to tell us what the `VariableIndex` is.
754+
index = CleverDicts.add_item(
755+
model.variable_info,
756+
_VariableInfo(MOI.VariableIndex(0), HighsInt(0)),
757+
)
758+
info = _info(model, index)
759+
lb = -Inf
760+
if lower_bound !== nothing
761+
lb = lower_bound
762+
_update_info(info, MOI.GreaterThan{Float64}(lb))
763+
end
764+
ub = Inf
765+
if upper_bound !== nothing
766+
ub = upper_bound
767+
_update_info(info, MOI.LessThan{Float64}(ub))
768+
end
769+
# Now, set `.index` and `.column`.
770+
info.index = index
771+
info.column = HighsInt(length(model.variable_info) - 1)
772+
ret = Highs_addCol(model, 0.0, lb, ub, 0, C_NULL, C_NULL)
773+
_check_ret(ret)
774+
return index
775+
end
776+
747777
function MOI.add_variable(model::Optimizer)
748778
# Initialize `_VariableInfo` with a dummy `VariableIndex` and a column,
749779
# because we need `add_item` to tell us what the `VariableIndex` is.

0 commit comments

Comments
 (0)