Skip to content

Commit 38bdd24

Browse files
committed
Add support for MOI.add_constrained_variable
1 parent 1a4f551 commit 38bdd24

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/MOI_wrapper.jl

+43
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,49 @@ function MOI.add_variable(model::Optimizer)
760760
return index
761761
end
762762

763+
function MOI.supports_add_constrained_variable(
764+
::Optimizer,
765+
::Type{
766+
<:Union{
767+
MOI.GreaterThan{Float64},
768+
MOI.LessThan{Float64},
769+
MOI.EqualTo{Float64},
770+
MOI.Interval{Float64},
771+
},
772+
},
773+
)
774+
return true
775+
end
776+
777+
function MOI.add_constrained_variable(
778+
model::Optimizer,
779+
set::S,
780+
) where {
781+
S<:Union{
782+
MOI.GreaterThan{Float64},
783+
MOI.LessThan{Float64},
784+
MOI.EqualTo{Float64},
785+
MOI.Interval{Float64},
786+
},
787+
}
788+
# Initialize `_VariableInfo` with a dummy `VariableIndex` and a column,
789+
# because we need `add_item` to tell us what the `VariableIndex` is.
790+
index = CleverDicts.add_item(
791+
model.variable_info,
792+
_VariableInfo(MOI.VariableIndex(0), HighsInt(0)),
793+
)
794+
info = _info(model, index)
795+
# Now, set `.index` and `.column`.
796+
info.index = index
797+
info.column = HighsInt(length(model.variable_info) - 1)
798+
lower, upper = _bounds(set)
799+
ret = Highs_addCol(model, 0.0, lower, upper, 0, C_NULL, C_NULL)
800+
_check_ret(ret)
801+
_update_info(info, set)
802+
return index, MOI.ConstraintIndex{MOI.VariableIndex,S}(index.value)
803+
end
804+
805+
763806
function MOI.is_valid(model::Optimizer, v::MOI.VariableIndex)
764807
return haskey(model.variable_info, v)
765808
end

0 commit comments

Comments
 (0)