Question on allowing user to specify the optimization sense

Use an argument like

function solve(; maximize::Bool)
    sense = maximize ? MOI.MAX_SENSE : MOI.MIN_SENSE
    # ...
end

solve(; maximize = true)
  1. I haven’t explicitly added the following lines to my package:

JuMP exports the MOI constant, so using JuMP pulls MOI into scope.

  1. How is MOI.ObjectiveSense related to the MOI.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
1 Like