Inner product grammar is neater than sum(index) in JuMP modeling, But triggers Warning?

For some/most cases. But there might be ones that we don’t have a good fallback for. @blegat can chime in here.

But maybe we should just remove the warning. I wonder if it does more harm than good. Are you happy with the performance of dot? If so, ignore the warning.

You can do

new_obj = @expression(model, expression)
set_objective_function(model, new_obj)

But really. Just use @objective(model, sense, expression).

If I had one comment about your code, is that it looks too “clever.” I would write your last example as:

import JuMP
import Gurobi
GRB_ENV = Gurobi.Env()
function gurobi_direct_model(;sense::JuMP.OptimizationSense, silent::Bool)
    model = JuMP.direct_model(Gurobi.Optimizer(GRB_ENV))
    JuMP.set_objective_sense(model, sense)
    if silent
        JuMP.set_silent(model)
    end
    return model
end
model = gurobi_direct_model(; sense = JuMP.MIN_SENSE, silent = true)
for i in 1:3
    obj = JuMP.@expression(model, i)
    JuMP.set_objective_function(model, obj)
end

At this point, we’re essentially not adding new functionality or macros to JuMP if there is a simple alternative (even if the alternative is a few extra lines of code). The bar is very high, and we won’t be adding a macro to set the objective function without modifying the objective sense.

1 Like