Small values is automatically considered as 0, how to solve it?
AnsweredHi, I am using Gurobi 9.1.2 build v9.1.2rc0 (win64) to solve my MILP problem. I have some variables with very small values ([1e-8,1e-7], manually calculated), it seems that Gurobi automatically considers these values as 0. For example:
The values are: 4.12e-6 * 0.15 + 9.70E-09 = 0.6277e-6 and 4.12e-6 * 0.3 + 9.70E-09 = 1.24576e-6
output of program: (0, 0): <gurobi.Var pdt[0,0] (value 0.0)>
(0, 1): <gurobi.Var pdt[0,1] (value 1.2457000000000002e-06)>
I tried to set the tolerance using model.Params.IntFeasTol = 1e-09, unfortunately, it does not work. If there is any method to improve this? Thank you.
-
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 Jinping,
You should definitely scale your variables and constraints before formulating the model. It is bad practice to use such small coefficients and a frequent cause for errors.
The above constraint can for instance be scaled by 1e+6 to improve the numerics. Please refer to our Guidelines for Numerical Issues for further information.
Cheers,
Matthias0 -
Hi Matthias,
Thank you very much for answering my question. The small values are obtained before optimization. I checked the link you shared and the reference manual about how to scale variables. However, the approach for addressing this problem in the manual is not very clear to me (maybe because I am new with Gurobi and not very good at coding).
A small part of my constraints is:
P == slop * (X - x_ini) + p_ini
where slop, x_ini and p_ini are pre-determined values (very small, e.g., 4.12e-6, 0.0, and 9.70E-09 in the above-mentioned example). X is the variable from the upper level, and P is the output. I wonder if I multiply a term, e.g., 1e2 to the slop and p_ini, and the output is divided by this term, does this still can guarantee the accuracy?
For instance: Pnew == slop*1e2 * (X - x_ini) + p_ini*1e2, whether Pnew / 1e2 = P?
I feel it is worth mentioning that this small value problem appears in calculating P only, and in other constraints, I have non-linear terms such as A*B (A and B are variables) to determine X. I have set: model.params.NonConvex = 2
Thanks a lot.
0
Post is closed for comments.
Comments
3 comments