Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright 2017, Iain Dunning, Joey Huchette, Miles Lubin, and contributors | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
############################################################################# | ||
# JuMP | ||
# An algebraic modeling language for Julia | ||
# See http://github.com/JuliaOpt/JuMP.jl | ||
############################################################################# | ||
# This file contains objective-related functions | ||
|
||
""" | ||
objective_bound(model::Model) | ||
Return the best known bound on the optimal objective value after a call to | ||
`optimize!model)`. | ||
""" | ||
objective_bound(model::Model) = MOI.get(model, MOI.ObjectiveBound()) | ||
|
||
""" | ||
objective_value(model::Model) | ||
Return the objective value after a call to `optimize!model)`. | ||
""" | ||
objective_value(model::Model) = MOI.get(model, MOI.ObjectiveValue()) | ||
|
||
""" | ||
objective_sense(model::Model)::MathOptInterface.OptimizationSense | ||
Return the objective sense. | ||
""" | ||
function objective_sense(model::Model) | ||
return MOI.get(model, MOI.ObjectiveSense()) | ||
end | ||
|
||
""" | ||
set_objective_sense(model::Model, sense::MathOptInterface.OptimizationSense) | ||
Sets the objective sense of the model to the given sense. See | ||
[`set_objective_function`](@ref) to set the objective function. These are | ||
low-level functions; the recommended way to set the objective is with the | ||
[`@objective`](@ref) macro. | ||
""" | ||
function set_objective_sense(model::Model, sense::MOI.OptimizationSense) | ||
MOI.set(model, MOI.ObjectiveSense(), sense) | ||
end | ||
|
||
""" | ||
set_objective_function(model::Model, | ||
func::Union{AbstractJuMPScalar, | ||
MathOptInterface.AbstractScalarFunction}) | ||
Sets the objective function of the model to the given function. See | ||
[`set_objective_sense`](@ref) to set the objective sense. These are low-level | ||
functions; the recommended way to set the objective is with the | ||
[`@objective`](@ref) macro. | ||
""" | ||
function set_objective_function end | ||
|
||
function set_objective_function(model::Model, func::MOI.AbstractScalarFunction) | ||
attr = MOI.ObjectiveFunction{typeof(func)}() | ||
if !MOI.supports(model.moi_backend, attr) | ||
error("The solver does not support an objective function of type ", | ||
typeof(func), ".") | ||
end | ||
MOI.set(model, attr, func) | ||
# Keeping the explicit `return` is helpful for type inference because we | ||
# don't know what `MOI.set` will return. | ||
return | ||
end | ||
|
||
function set_objective_function(model::Model, func::AbstractJuMPScalar) | ||
set_objective_function(model, moi_function(func)) | ||
end | ||
|
||
function set_objective(model::Model, sense::MOI.OptimizationSense, | ||
func::AbstractJuMPScalar) | ||
set_objective_sense(model, sense) | ||
set_objective_function(model, func) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters