Bug In Detecting Changed Constant in Objective Function

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:

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?

1 Like

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

@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.)

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

1 Like