Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename m field of VariableRef to model. #1483

Merged
merged 2 commits into from
Sep 23, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,5 @@ false

```@docs
@variable
owner_model
```
15 changes: 8 additions & 7 deletions src/JuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,12 @@ Base.copy(x::Nothing, new_model::Model) = nothing
Base.copy(v::AbstractArray{VariableRef}, new_model::Model) = (var -> VariableRef(new_model, var.index)).(v)

function optimizer_index(v::VariableRef)
if mode(v.m) == Direct
model = owner_model(v)
if mode(model) == Direct
return index(v)
else
@assert caching_optimizer(v.m).state == MOIU.AttachedOptimizer
return caching_optimizer(v.m).model_to_optimizer_map[index(v)]
@assert caching_optimizer(model).state == MOIU.AttachedOptimizer
return caching_optimizer(model).model_to_optimizer_map[index(v)]
end
end

Expand Down Expand Up @@ -457,21 +458,21 @@ Return the value of the attribute `attr` from model's MOI backend.
"""
MOI.get(m::Model, attr::MOI.AbstractModelAttribute) = MOI.get(m.moi_backend, attr)
function MOI.get(m::Model, attr::MOI.AbstractVariableAttribute, v::VariableRef)
@assert m === v.m
@assert m === owner_model(v) # TODO: Improve the error message.
MOI.get(m.moi_backend, attr, index(v))
end
function MOI.get(m::Model, attr::MOI.AbstractConstraintAttribute, cr::ConstraintRef)
@assert m === cr.m
@assert m === cr.m # TODO: Improve the error message.
MOI.get(m.moi_backend, attr, index(cr))
end

MOI.set(m::Model, attr::MOI.AbstractModelAttribute, value) = MOI.set(m.moi_backend, attr, value)
function MOI.set(m::Model, attr::MOI.AbstractVariableAttribute, v::VariableRef, value)
@assert m === v.m
@assert m === owner_model(v) # TODO: Improve the error message.
MOI.set(m.moi_backend, attr, index(v), value)
end
function MOI.set(m::Model, attr::MOI.AbstractConstraintAttribute, cr::ConstraintRef, value)
@assert m === cr.m
@assert m === cr.m # TODO: Improve the error message.
MOI.set(m.moi_backend, attr, index(cr), value)
end

Expand Down
7 changes: 5 additions & 2 deletions src/parse_nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ function parseNLExpr_runtime(m::Model, x::Number, tape, parent, values)
end

function parseNLExpr_runtime(m::Model, x::VariableRef, tape, parent, values)
x.m === m || error("Variable in nonlinear expression does not belong to corresponding model")
if owner_model(x) !== m
error("Variable in nonlinear expression does not belong to the " *
"corresponding model")
end
push!(tape, NodeData(MOIVARIABLE, x.index.value, parent))
nothing
end
Expand Down Expand Up @@ -259,7 +262,7 @@ function checkexpr(m::Model, ex::Expr)
return
end
function checkexpr(m::Model, v::VariableRef)
v.m === m || error("Variable $v does not belong to this model")
owner_model(v) === m || error("Variable $v does not belong to this model.")
return
end
checkexpr(m::Model, ex) = nothing