From f86b37d7746edf775cb8b662f6a974194f4c97d8 Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 4 Nov 2024 09:27:58 +1300 Subject: [PATCH] Add support for two-set add_constrained_variable --- src/MOI_wrapper.jl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index 929ef75..96e7f60 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -803,6 +803,39 @@ function MOI.add_constrained_variable( return index, MOI.ConstraintIndex{MOI.VariableIndex,S}(index.value) end +function MOI.supports_add_constrained_variable( + ::Optimizer, + ::Type{MOI.GreaterThan{Float64}}, + ::Type{MOI.LessThan{Float64}}, +) + return true +end + +function MOI.add_constrained_variable( + model::Optimizer, + set_gt::MOI.GreaterThan{Float64}, + set_lt::MOI.LessThan{Float64}, +) + # 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) + # Now, set `.index` and `.column`. + info.index = index + info.column = HighsInt(length(model.variable_info) - 1) + l, u = set_gt.lower, set_lt.upper + ret = Highs_addCol(model, 0.0, l, u, 0, C_NULL, C_NULL) + _check_ret(ret) + _update_info(info, set_gt) + _update_info(info, set_lt) + c_gt = MOI.ConstraintIndex{MOI.VariableIndex,(typeof(set_gt))}(index.value) + c_lt = MOI.ConstraintIndex{MOI.VariableIndex,(typeof(set_lt))}(index.value) + return index, (c_gt, c_lt) +end + function MOI.is_valid(model::Optimizer, v::MOI.VariableIndex) return haskey(model.variable_info, v) end