Skip to content
Merged
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
35 changes: 23 additions & 12 deletions src/Utilities/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ function MOI.supports(
end
function MOI.set(
model::AbstractModel,
attr::MOI.ObjectiveFunction,
f::MOI.AbstractFunction,
)
attr::MOI.ObjectiveFunction{F},
f::F,
) where {F<:MOI.AbstractFunction}
if !MOI.supports(model, attr)
throw(MOI.UnsupportedAttribute(attr))
end
Expand Down Expand Up @@ -565,17 +565,17 @@ end
function MOI.set(
::AbstractModel,
::MOI.ConstraintFunction,
::CI{MOI.SingleVariable},
::MOI.ConstraintIndex{MOI.SingleVariable,<:MOI.AbstractScalarSet},
::MOI.SingleVariable,
)
return throw(MOI.SettingSingleVariableFunctionNotAllowed())
end
function MOI.set(
model::AbstractModel{T},
::MOI.ConstraintSet,
ci::CI{MOI.SingleVariable},
set::SUPPORTED_VARIABLE_SCALAR_SETS{T},
) where {T}
ci::MOI.ConstraintIndex{MOI.SingleVariable,S},
set::S,
) where {T,S<:SUPPORTED_VARIABLE_SCALAR_SETS{T}}
MOI.throw_if_not_valid(model, ci)
flag = single_variable_flag(typeof(set))
if !iszero(flag & LOWER_BOUND_MASK)
Expand All @@ -586,13 +586,24 @@ function MOI.set(
end
return
end

function MOI.set(
model::AbstractModel,
attr::Union{MOI.ConstraintFunction, MOI.ConstraintSet},
ci::MOI.ConstraintIndex,
func_or_set,
)
MOI.set(constraints(model, ci), attr, ci, func_or_set)
attr::MOI.ConstraintSet,
ci::MOI.ConstraintIndex{<:MOI.AbstractFunction,S},
set::S,
) where {S<:MOI.AbstractSet}
MOI.set(constraints(model, ci), attr, ci, set)
return
end

function MOI.set(
model::AbstractModel,
attr::MOI.ConstraintFunction,
ci::MOI.ConstraintIndex{F,<:MOI.AbstractSet},
func::F,
) where {F<:MOI.AbstractFunction}
MOI.set(constraints(model, ci), attr, ci, func)
return
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