Skip to content

Commit

Permalink
Add support for two-set add_constrained_variable
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 3, 2024
1 parent 80bfb5a commit f86b37d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 806 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L806

Added line #L806 was not covered by tests
::Optimizer,
::Type{MOI.GreaterThan{Float64}},
::Type{MOI.LessThan{Float64}},
)
return true

Check warning on line 811 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L811

Added line #L811 was not covered by tests
end

function MOI.add_constrained_variable(

Check warning on line 814 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L814

Added line #L814 was not covered by tests
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(

Check warning on line 821 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L821

Added line #L821 was not covered by tests
model.variable_info,
_VariableInfo(MOI.VariableIndex(0), HighsInt(0)),
)
info = _info(model, index)

Check warning on line 825 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L825

Added line #L825 was not covered by tests
# 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)

Check warning on line 836 in src/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper.jl#L827-L836

Added lines #L827 - L836 were not covered by tests
end

function MOI.is_valid(model::Optimizer, v::MOI.VariableIndex)
return haskey(model.variable_info, v)
end
Expand Down

0 comments on commit f86b37d

Please sign in to comment.