Skip to main content

Small values is automatically considered as 0, how to solve it?

Answered

Comments

2 comments

  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    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,
    Matthias

    0
  • Jinping Zhao
    Gurobi-versary
    First Comment
    First Question

    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

Please sign in to leave a comment.