I have a small package in which I solve an optimization model. The sense
of the objective function is to be specified by the user. Now, I export MAX_SENSE
and MIN_SENSE
for the user to use them. A small example:
module MyPkg
using JuMP
using Gurobi
export solve, MAX_SENSE, MIN_SENSE
function solve(sense::MOI.OptimizationSense)
model = Model(Gurobi.Optimizer)
@variable(model, x[1:2] >= 0)
@constraint(model, sum(x) <= 2)
@objective(model, sense, 2*x[1]+x[2])
optimize!(model)
if termination_status == MOI.OPTIMAL
return objective_valule(model)
else
error("Not solved to optimality")
end
end
end
I have a couple of questions here:
- Is there another (more safe, neat, and probably more standard) way to allow users to allow specifying the objective without exporting
MIN_SENSE
andMAX_SENSE
. I want to keep the exported items to a minimum. - I haven’t explicitly added the following lines to my package:
using MathOptInterface
const MOI = MathOptInterface
However, I could still use MOI.OptimizationSense
and MOI.OPTIMAL
inside my package functions without any issue. So my question is, why is it working exactly? Also, I have seen some packages that actually add the lines mentioned above, so when do I actually need to add the using MathOptInterface; const MOI = MathOptInterface
lines to my package?
- How is
MOI.ObjectiveSense
related to theMOI.OptimizationSense
? I can find the documentation for the former here, but nothing on the latter. Any reference or explanation about the difference between the two would be appreciated.
Thanks!