Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractScalarSet

::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)
Expand All @@ -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

Expand Down
18 changes: 18 additions & 0 deletions test/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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