Use an argument like
function solve(; maximize::Bool)
sense = maximize ? MOI.MAX_SENSE : MOI.MIN_SENSE
# ...
end
solve(; maximize = true)
- I haven’t explicitly added the following lines to my package:
JuMP exports the MOI constant, so using JuMP pulls MOI into scope.
- How is
MOI.ObjectiveSenserelated to theMOI.OptimizationSense?
ObjectiveSense is the attribute, as in MOI.ObjectiveSense(). OptimizationSense is the enum, as in MOI.MIN_SENSE.
help?> MOI.ObjectiveSense
ObjectiveSense()
A model attribute for the objective sense of the objective function, which must be an
OptimizationSense: MIN_SENSE, MAX_SENSE, or FEASIBILITY_SENSE. The default is FEASIBILITY_SENSE.
Interaction with ObjectiveFunction
====================================
Setting the sense to FEASIBILITY_SENSE unsets the ObjectiveFunction attribute. That is, if you
first set ObjectiveFunction and then set ObjectiveSense to be FEASIBILITY_SENSE, no objective
function will be passed to the solver.
In addition, some reformulations of ObjectiveFunction via bridges rely on the value of
ObjectiveSense. Therefore, you should set ObjectiveSense before setting ObjectiveFunction.
julia> MOI.OptimizationSense
Enum MathOptInterface.OptimizationSense:
MIN_SENSE = 0
MAX_SENSE = 1
FEASIBILITY_SENSE = 2