# Constant objective function is not supported on JuMP 0.19?

**URL:** <https://discourse.julialang.org/t/constant-objective-function-is-not-supported-on-jump-0-19/22775>\
**Category:** Optimization (Mathematical)\
**Created:** [April 4, 2019, 10:33pm UTC](https://discourse.julialang.org/t/constant-objective-function-is-not-supported-on-jump-0-19/22775 "2019-04-04T22:33:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SingingKim](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SingingKim](https://discourse.julialang.org/u/SingingKim)\
**Post date:** [April 4, 2019, 10:33pm UTC](https://discourse.julialang.org/t/constant-objective-function-is-not-supported-on-jump-0-19/22775/1 "2019-04-04T22:33:39Z")

</div>

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.

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

```

This returns an error:

```julia
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.

```julia
@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!

---

<div class="post-metadata">

**Author:** ![leethargo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leethargo/32/6004_2.png) [@leethargo](https://discourse.julialang.org/u/leethargo)\
**Post date:** [April 5, 2019, 6:34am UTC](https://discourse.julialang.org/t/constant-objective-function-is-not-supported-on-jump-0-19/22775/2 "2019-04-05T06:34:15Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [April 5, 2019, 3:34pm UTC](https://discourse.julialang.org/t/constant-objective-function-is-not-supported-on-jump-0-19/22775/3 "2019-04-05T15:34:38Z")

</div>

> [@SingingKim](#):
>
> using JuMP, Gurobi m = Model(with\_optimizer(Gurobi.Optimizer)) @variable(m, x) @objective(m, Min, 3) optimize!(m)

Thanks! This is a bug in JuMP. I’ve opened an issue: [Support constant-only objectives · Issue #1924 · jump-dev/JuMP.jl · GitHub](https://github.com/JuliaOpt/JuMP.jl/issues/1924)

---

<div class="post-metadata">

**Author:** ![SingingKim](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@SingingKim](https://discourse.julialang.org/u/SingingKim)\
**Post date:** [April 5, 2019, 6:15pm UTC](https://discourse.julialang.org/t/constant-objective-function-is-not-supported-on-jump-0-19/22775/4 "2019-04-05T18:15:05Z")

</div>

Thanks for opening the issue!
