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
11 changes: 6 additions & 5 deletions src/constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function check_belongs_to_model(con_ref::ConstraintRef, model::AbstractModel)
if owner_model(con_ref) !== model
throw(ConstraintNotOwned(con_ref))
end
return
end

Base.broadcastable(con_ref::ConstraintRef) = Ref(con_ref)
Expand Down Expand Up @@ -891,7 +892,8 @@ function constraint_object(
end

function check_belongs_to_model(con::ScalarConstraint, model)
return check_belongs_to_model(con.func, model)
check_belongs_to_model(con.func, model)
return
end

"""
Expand Down Expand Up @@ -990,9 +992,8 @@ function constraint_object(
end

function check_belongs_to_model(con::VectorConstraint, model)
for func in con.func
check_belongs_to_model(func, model)
end
check_belongs_to_model(con.func, model)
return
end

function _moi_add_constraint(
Expand All @@ -1016,7 +1017,7 @@ function _moi_add_constraint(
return MOI.add_constraint(model, f, s)
end

function check_belongs_to_model(f::Vector, model)
function check_belongs_to_model(f::AbstractVector, model)
for func in f
check_belongs_to_model(func, model)
end
Expand Down
14 changes: 8 additions & 6 deletions src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ struct NonlinearParameter <: AbstractJuMPScalar
index::Int
end

function check_belongs_to_model(arg::NonlinearParameter, model::AbstractModel)
return arg.model === model
end
# A pass-through. This is needed to catch wben a parameter is used with the new
# nonlinear API. It doesn't matter what the model is, because we're going to
# throw an error regardless.
check_belongs_to_model(::NonlinearParameter, ::AbstractModel) = nothing

variable_ref_type(arg::NonlinearParameter) = variable_ref_type(arg.model)

Expand Down Expand Up @@ -344,9 +345,10 @@ struct NonlinearExpression <: AbstractJuMPScalar
index::Int
end

function check_belongs_to_model(arg::NonlinearExpression, model::AbstractModel)
return arg.model === model
end
# A pass-through. This is needed to catch wben an expression is used with the
# new nonlinear API. It doesn't matter what the model is, because we're going to
# throw an error regardless.
check_belongs_to_model(::NonlinearExpression, ::AbstractModel) = nothing

variable_ref_type(arg::NonlinearExpression) = variable_ref_type(arg.model)

Expand Down
16 changes: 4 additions & 12 deletions src/objective.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ function set_objective_function(model::GenericModel, func::MOI.AbstractFunction)
return
end

function set_objective_function(model::GenericModel, func::AbstractJuMPScalar)
function set_objective_function(
model::GenericModel,
func::Union{AbstractJuMPScalar,AbstractVector{<:AbstractJuMPScalar}},
)
check_belongs_to_model(func, model)
set_objective_function(model, moi_function(model, func))
return
Expand All @@ -292,17 +295,6 @@ function set_objective_function(model::GenericModel{T}, func::Real) where {T}
return
end

function set_objective_function(
model::GenericModel,
func::AbstractVector{<:AbstractJuMPScalar},
)
for f in func
check_belongs_to_model(f, model)
end
set_objective_function(model, moi_function(model, func))
return
end

function set_objective_function(model::AbstractModel, func)
return error(
"""
Expand Down
1 change: 1 addition & 0 deletions src/quad_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ function check_belongs_to_model(q::GenericQuadExpr, model::AbstractModel)
check_belongs_to_model(variable_pair.a, model)
check_belongs_to_model(variable_pair.b, model)
end
return
end

"""
Expand Down
1 change: 0 additions & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ end

"""
check_belongs_to_model(x::AbstractJuMPScalar, model::AbstractModel)
check_belongs_to_model(x::AbstractConstraint, model::AbstractModel)

Throw [`VariableNotOwned`](@ref) if the [`owner_model`](@ref) of `x` is not
`model`.
Expand Down
Loading