Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Nov 6, 2024
1 parent 4f05770 commit fcbe7ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -805,16 +805,14 @@ end

function MOI.supports_add_constrained_variable(
::Optimizer,
::Type{MOI.GreaterThan{Float64}},
::Type{MOI.LessThan{Float64}},
::Type{Tuple{MOI.GreaterThan{Float64},MOI.LessThan{Float64}}},
)
return true
end

function MOI.add_constrained_variable(
model::Optimizer,
set_gt::MOI.GreaterThan{Float64},
set_lt::MOI.LessThan{Float64},
set::Tuple{MOI.GreaterThan{Float64},MOI.LessThan{Float64}},
)
# Initialize `_VariableInfo` with a dummy `VariableIndex` and a column,
# because we need `add_item` to tell us what the `VariableIndex` is.
Expand All @@ -826,13 +824,13 @@ function MOI.add_constrained_variable(
# Now, set `.index` and `.column`.
info.index = index
info.column = HighsInt(length(model.variable_info) - 1)
l, u = set_gt.lower, set_lt.upper
l, u = set[1].lower, set[2].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)
_update_info(info, set[1])
_update_info(info, set[2])
c_gt = MOI.ConstraintIndex{MOI.VariableIndex,(typeof(set[1]))}(index.value)
c_lt = MOI.ConstraintIndex{MOI.VariableIndex,(typeof(set[2]))}(index.value)
return index, (c_gt, c_lt)
end

Expand Down
15 changes: 15 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,21 @@ function test_active_bound()
return
end

function test_add_constrained_variable_tuple()
F = MOI.VariableIndex
model = HiGHS.Optimizer()
set = (MOI.GreaterThan(0.0), MOI.LessThan(1.0))
@requires MOI.supports_add_constrained_variable(model, typeof(set))
x, (c_l, c_u) = MOI.add_constrained_variable(model, set)
@test c_l == MOI.ConstraintIndex{F,MOI.GreaterThan{Float64}}(x.value)
@test c_u == MOI.ConstraintIndex{F,MOI.LessThan{Float64}}(x.value)
@test MOI.get(model, MOI.ConstraintFunction(), c_l) == x
@test MOI.get(model, MOI.ConstraintSet(), c_l) == set[1]
@test MOI.get(model, MOI.ConstraintFunction(), c_u) == x
@test MOI.get(model, MOI.ConstraintSet(), c_u) == set[2]
return
end

end # module

TestMOIHighs.runtests()

0 comments on commit fcbe7ee

Please sign in to comment.