Why does Gurobi return non-integral values for integer/binary variables?
AnsweredHi,
I am solving my ILP model (4 variables) using Gurobi, where (alpha, beta) are binary variables and (x,y) are integer variables (defined as below).
# DECISION VARIABLES
# STAGE 1: alpha, x
alpha, x = {}, {}
for j in instance.fabric_roll_types:
for t in strips_t[j]:
x[j,t.id] = M3.addVar(obj=0, vtype=GRB.INTEGER, name='x[%s,%s]'%(j,t.id))
for s in strips_s[j,t]:
if (s.id >= t.id):
alpha[j,s.id,t.id] = M3.addVar(obj=0, vtype=GRB.BINARY, name='alpha[%s,%s,%s]'%(j,s.id,t.id))
# STAGE 2: beta, y
beta, y = {}, {}
for j in instance.fabric_roll_types:
for t in strips_t[j]:
for omega in range(1,instance.nb_scenario+1):
y[j,t.id,omega] = M3.addVar(obj=0, vtype=GRB.INTEGER, name='y[%s,%s,%s]'%(j,t.id,omega))
for j in instance.fabric_roll_types:
for t in strips_t[j]:
for s in strips_s[j,t]:
if (s.id >= t.id):
for omega in range(1,instance.nb_scenario+1):
beta[j,s.id,t.id,omega] = M3.addVar(obj=0, vtype=GRB.BINARY, name='beta[%s,%s,%s,%s]'%(j,s.id,t.id,omega))
But, when I checked my .sol file, I found that some of my variables are non-integer.
x[1,517] 7.9999981124292140e+02
alpha[1,522,517] 0
alpha[1,517,517] 9.9999976405543745e-01
In this case, how can I handle this problem (I have already checked my constraints, and everything seems to be correct)?
Best regards!
Khadija
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Khadija,
All numerical algorithms work with finite precision. This unfortunately results in integer variable not actually taking truly integer values but rather being almost integer (up to a given error). This error can be controlled via the IntFeasTol parameter. If you are interested in truly integer values, you should experiment with the IntegralityFocus parameter. Please note that setting these parameters may worsen performance significantly.
Best regards,
Jaromił0 -
Hi Jaromil,
I added the IntegralityFocus parameter, but I am getting the same problem again: non-integral value for some Integer/Binary variables.
m3.Params.IntegralityFocus = 1
Best regards,
Khadija
0 -
Hi Khadija,
Please note that setting the IntegralityFocus parameter does not guarantee to provide truly integer solutions. From the parameter documentation
More precisely, the solver tries to find solutions that are still (nearly) feasible if all integer variables are rounded to exact integral values. We should say that the solver won't always succeed in finding such solutions, and that this setting introduces a modest performance penalty, but the setting will significantly reduce the frequency and magnitude of such violations.
You could try decreasing the IntFeasTol parameter to \(\texttt{1e-9}\). If this does not help, you could try rounding the solution value by hand and checking whether the then truly integer solution is feasible (within tolerances).
Best regards,
Jaromił0 -
More information can be found in our Knowledge Base article Why does Gurobi sometimes return non-integral values for integer variables? -G
0
Post is closed for comments.
Comments
5 comments