diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index 040b06750d..f1a1012f23 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -733,27 +733,29 @@ function MOI.modify( end function MOI.set( - model::AbstractModel, + ::AbstractModel, ::MOI.ConstraintFunction, - ci::CI{MOI.SingleVariable}, - change::MOI.AbstractFunction, + ::MOI.ConstraintIndex{MOI.SingleVariable,<:MOI.AbstractSet}, + ::MOI.SingleVariable, ) return throw(MOI.SettingSingleVariableFunctionNotAllowed()) end + function MOI.set( model::AbstractModel, ::MOI.ConstraintFunction, - ci::CI, - change::MOI.AbstractFunction, -) + ci::MOI.ConstraintIndex{F,<:MOI.AbstractSet}, + change::F, +) where {F<:MOI.AbstractFunction} return _modify(model, ci, getconstrloc(model, ci), change) end + function MOI.set( model::AbstractModel, ::MOI.ConstraintSet, - ci::CI{MOI.SingleVariable}, - change::MOI.AbstractSet, -) + ci::MOI.ConstraintIndex{MOI.SingleVariable,S}, + change::S, +) where {S<:MOI.AbstractScalarSet} MOI.throw_if_not_valid(model, ci) flag = single_variable_flag(typeof(change)) if !iszero(flag & LOWER_BOUND_MASK) @@ -763,12 +765,13 @@ function MOI.set( model.upper_bound[ci.value] = extract_upper_bound(change) end end + function MOI.set( model::AbstractModel, ::MOI.ConstraintSet, - ci::CI, - change::MOI.AbstractSet, -) + ci::MOI.ConstraintIndex{<:MOI.AbstractFunction,S}, + change::S, +) where {S<:MOI.AbstractSet} return _modify(model, ci, getconstrloc(model, ci), change) end diff --git a/test/Utilities/model.jl b/test/Utilities/model.jl index fa7c24ed80..450c69051f 100644 --- a/test/Utilities/model.jl +++ b/test/Utilities/model.jl @@ -338,3 +338,21 @@ end MOI.modify(model, attr, MOI.ScalarCoefficientChange(x, 1.0)) @test attr in MOI.get(model, MOI.ListOfModelAttributesSet()) end + +@testset "Incorrect modifications" begin + model = MOIU.Model{Float64}() + x = MOI.add_variable(model) + c = MOI.add_constraint( + model, + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), + MOI.EqualTo(1.0), + ) + @test_throws( + ArgumentError, + MOI.set(model, MOI.ConstraintSet(), c, MOI.LessThan(1.0)), + ) + @test_throws( + ArgumentError, + MOI.set(model, MOI.ConstraintFunction(), c, MOI.SingleVariable(x)), + ) +end