diff --git a/src/MOI_wrapper.jl b/src/MOI_wrapper.jl index 96e7f60..37310f1 100644 --- a/src/MOI_wrapper.jl +++ b/src/MOI_wrapper.jl @@ -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. @@ -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 diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index b336159..929b848 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -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()