Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Commit

Permalink
Merge pull request #98 from JuliaOpt/bl/getobjT
Browse files Browse the repository at this point in the history
Fix get ObjectiveFunction{T}
  • Loading branch information
blegat authored Feb 13, 2018
2 parents 6af8e9d + 7a7a0ed commit 65cfefb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ MOI.canset(model::AbstractModel, ::MOI.ObjectiveSense) = true
function MOI.set!(model::AbstractModel, ::MOI.ObjectiveSense, sense::MOI.OptimizationSense)
model.sense = sense
end
MOI.get(model::AbstractModel, ::MOI.ObjectiveFunction) = model.objective
MOI.canget(model::AbstractModel, ::MOI.ObjectiveFunction{T}) where T = typeof(model.objective) == T
function MOI.get(model::AbstractModel, ::MOI.ObjectiveFunction{T})::T where T
if typeof(model.objective) != T
throw(InexactError())
end
model.objective
end
MOI.canset(model::AbstractModel, ::MOI.ObjectiveFunction) = true
function MOI.set!(model::AbstractModel, ::MOI.ObjectiveFunction, f::MOI.AbstractFunction)
# f needs to be copied, see #2
Expand Down Expand Up @@ -227,7 +233,6 @@ MOI.canget(model::AbstractModel, ::Union{MOI.NumberOfVariables,
MOI.NumberOfConstraints,
MOI.ListOfConstraints,
MOI.ListOfConstraintIndices,
MOI.ObjectiveFunction,
MOI.ObjectiveSense}) = true

MOI.canget(model::AbstractModel, ::Union{MOI.ConstraintFunction,
Expand Down

0 comments on commit 65cfefb

Please sign in to comment.