Closed rdeits closed 6 years ago
Gurobi doesn't support offsets in the objective(see below comment). Couldn't you just modify the tolerance to account for the constant term?
Alternatively, add a fixed variable, and add a constraint
using JuMP, Gurobi
model = Model(solver=GurobiSolver(OutputFlag=1))
@variable model x
@variable model y
@constraint model y == -1
@objective model Min x^2 + y
solve(model)
Oh, well, that's a pretty good reason for GurobiSolver to ignore them, then :smile:
Yeah, I definitely could, but was hoping I wouldn't have to. I like the fixed variable idea a lot, too. Thanks!
FWIW it looks like Gurobi supports constant offsets through their new multiobjective interface (GRBsetobjectiven
in the reference manual).
Let's reopen this so it can be implemented in the future.
Ok, thanks!
Gurobi doesn't support offsets in the objective
I was wrong. See http://www.gurobi.com/documentation/7.0/refman/objcon.html#attr:ObjCon
It appears that
GurobiSolver
ignores any constant terms in the JuMP model's cost function. For example:The gurobi output shows:
but the optimal objective value is actually
-1
, as confirmed by JuMP:Of course, for most optimization problems this is fine. Any constant term in the objective doesn't affect the minimizer, and JuMP still reports the correct final objective with
getvalue()
.However, there is one case in which this absolutely does matter: mixed-integer programming. When solving an MIP, Gurobi checks optimality by measuring (among other things), the relative gap between the best incumbent and the best bound. Since this gap is relative to the actual cost value, adding an arbitrary constant offset (or failing to add one) will affect whether the MIP gap is considered small enough.
This is causing some trouble for me, since I see very different solve times depending on how the particular initial state of my system affects the (eliminated) constant term in the cost.
Is there any way to turn this on in Gurobi.jl? I'd be happy to do the work myself, but I'd appreciate some pointers on where to look, since I haven't used the internal Gurobi interface at all.