# Bug In Detecting Changed Constant in Objective Function

**URL:** <https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, gurobi\
**Created:** [December 4, 2022, 11:02pm UTC](https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235 "2022-12-04T23:02:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elipivo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elipivo/32/32916_2.png) [@elipivo](https://discourse.julialang.org/u/elipivo)\
**Post date:** [December 4, 2022, 11:02pm UTC](https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235/1 "2022-12-04T23:02:09Z")

</div>

I’m experiencing a bug where it appears the constant in the objective function doesn’t get updated using Gurobi, here is a quick example:

```julia
model = Model(() -> Gurobi.Optimizer(env))
@variable(model, x[1:2])
@constraint(model, [0, -1] .<= x .<= [1, 0])
exprs = [x[1]-1; x[2]+1]

expr = exprs[1]
@objective(model, Max, expr)
optimize!(model)
objective_value(model) # gives correct answer of 0

expr = exprs[2]
@objective(model, Max, expr)
optimize!(model)
objective_value(model) # gives me -1 but should be +1

```

When I run the same thing using HiGHS this doesn’t happen. Does anyone else see this behavior?

---

<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:** [December 4, 2022, 11:37pm UTC](https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235/2 "2022-12-04T23:37:42Z")

</div>

I can reproduce. This looks like a bug. Let me take a deeper look.

Opened an issue: [Bug when objective changed with different constant · Issue #492 · jump-dev/Gurobi.jl · GitHub](https://github.com/jump-dev/Gurobi.jl/issues/492)

---

<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:** [December 5, 2022, 12:11am UTC](https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235/3 "2022-12-05T00:11:43Z")

</div>

@elipivo, it looks like you found yourself a bug in Gurobi. Happily, it was fixed in Gurobi v10.0, so I suggest you update to the latest version of Gurobi.

(If you’re currently using Gurobi v10, let me know and I’ll take another look. I can reproduce on v9.5.1, but not on v10.0.)

---

<div class="post-metadata">

**Author:** ![elipivo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elipivo/32/32916_2.png) [@elipivo](https://discourse.julialang.org/u/elipivo)\
**Post date:** [December 5, 2022, 2:55pm UTC](https://discourse.julialang.org/t/bug-in-detecting-changed-constant-in-objective-function/91235/4 "2022-12-05T14:55:16Z")

</div>

@odow Updating to v10.0 fixed it, thanks so much for your help!
