Skip to content

MOI.Utilities violates the MethodError principle #1277

@odow

Description

@odow

function MOI.set(
model::AbstractModel,
::MOI.ConstraintFunction,
ci::CI,
change::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,
)
MOI.throw_if_not_valid(model, ci)
flag = single_variable_flag(typeof(change))
if !iszero(flag & LOWER_BOUND_MASK)
model.lower_bound[ci.value] = extract_lower_bound(change)
end
if !iszero(flag & UPPER_BOUND_MASK)
model.upper_bound[ci.value] = extract_upper_bound(change)
end
end
function MOI.set(
model::AbstractModel,
::MOI.ConstraintSet,
ci::CI,
change::MOI.AbstractSet,
)
return _modify(model, ci, getconstrloc(model, ci), change)
end

julia> c
MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}(5)

julia> MOI.set(model, MOI.ConstraintFunction(), c, MOI.SingleVariable(x))
ERROR: MethodError: no method matching _modifyconstr(::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.ScalarAffineFunction{Float64}, ::MathOptInterface.EqualTo{Float64}, ::MathOptInterface.SingleVariable)
Closest candidates are:
  _modifyconstr(::MathOptInterface.ConstraintIndex{F,S}, ::F, ::S, ::MathOptInterface.AbstractFunctionModification) where {F, S} at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:68
  _modifyconstr(::MathOptInterface.ConstraintIndex{F,S}, ::F, ::S, ::F) where {F, S} at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:60
  _modifyconstr(::MathOptInterface.ConstraintIndex{F,S}, ::F, ::S, ::S) where {F, S} at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:61
Stacktrace:
 [1] _modify(::Array{Tuple{MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}},MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}},1}, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::Int64, ::MathOptInterface.SingleVariable) at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:76
 [2] _modify(::MathOptInterface.Utilities.ModelScalarConstraints{Float64,MathOptInterface.ScalarAffineFunction{Float64}}, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::Int64, ::MathOptInterface.SingleVariable) at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:1292
 [3] _modify(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::Int64, ::MathOptInterface.SingleVariable) at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:1308
 [4] set(::MathOptInterface.Utilities.Model{Float64}, ::MathOptInterface.ConstraintFunction, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.EqualTo{Float64}}, ::MathOptInterface.SingleVariable) at /Users/oscar/.julia/dev/MathOptInterface/src/Utilities/model.jl:749
 [5] top-level scope at none:0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions