Constant objective function is not supported on JuMP 0.19?

Good evening!

I have set my objective function as a constant to check if the constraints set is feasible and JuMP returns an error. It seems like JuMP does not allow constant objective functions.

Here is an example.

using JuMP, Gurobi
m = Model(with_optimizer(Gurobi.Optimizer))
@variable(m, x)
@objective(m, Min, 3)
optimize!(m)

This returns an error:

ERROR: LoadError: The objective function `3` is not supported by JuMP.
Stacktrace:
 [1] set_objective(::Model, ::MathOptInterface.OptimizationSense, ::Int64) at /Users/jipkim/.julia/packages/JuMP/jnmGG/src/objective.jl:87
 [2] top-level scope at /Users/jipkim/.julia/packages/JuMP/jnmGG/src/macros.jl:977

However, if I replace the constant objective by 0*x, then it works fine.

@objective(m, Min, 0*x)

I just verified that this does not happen on Julia 0.6.4/ JuMP v.018.
Is a constant objective function depreciated on JuMP v0.19? If so, is there any better way to check the model feasibility?

Thanks!

You can also simply omit the @objective statement in that case.
The reason for 0*x working is that this is recognized as an MOI.ScalarAffineFunction.

1 Like

Thanks! This is a bug in JuMP. I’ve opened an issue: Support constant-only objectives · Issue #1924 · jump-dev/JuMP.jl · GitHub

1 Like

Thanks for opening the issue!