Why is the solution for binary variables 0.999999?
AnsweredHello
In my program, I have set a set of binary decision variables, with code
Zeta = md.addVars(V, vtype=GRB.BINARY, name='Zeta[i]')
During the process of adjusting the constraints, I found that the solution for this set of decision variables can be different from 0 or 1. If the solution of this decision variable is 0 or 1, then this decision variable is normally effective. If it is a different value, then this decision variable is not functioning properly. I would like to know what may be causing this problem. Thank you for your reply.
(1)Invalid
Zeta:
10: 0.999999 11: 0.9999979999979998 12: 0.999998999999
(2)Effective
Zeta:
12: 1.0
-
Hi Tianyu,
As explained in the article Why does Gurobi sometimes return non-integral values for integer variables?, the solution value of a binary variable can deviate from 0 or 1. The tolerance for such deviation is defined by the IntFeasTol parameter (default value 1e-5).
If the problem with binary variables having a value like 0.999.. only occurs when you try to read them after optimization, you can simply round the values once the optimization process is done. Otherwise, you can try setting the IntegralityFocus parameter to 1, which will prompt Gurobi to take extra steps to remove the integrality violation while maintaining feasibility.
Best regards,
Simran
1 -
Thank you for your reply! I found your explanation very helpful.
0
Please sign in to leave a comment.
Comments
2 comments