Computers use finite double-precision (IEEE 754 standard) to represent real numbers, providing about 16 decimal digits of accuracy. Because real numbers are stored using a limited number of bits, many values cannot be represented exactly. This inexact representation can lead to floating-point round-off errors, which in turn may cause numerical issues inside the Gurobi Optimizer. For example, in double precision, the expression \(10^{10}+10^{-7}\) evaluates to \(10^{10}\), because the large difference in magnitude between the two terms causes the smaller one to be rounded away (loss of significance).
Models that contain very large or very small values are particularly susceptible to numerical instability. Specifically, the following can lead to problems:
A large matrix coefficient range
Large finite bounds
Large right-hand side (RHS) values
Large objective coefficients
Gurobi reports potential numerical instability in the log file using messages such as:
Coefficient statistics:
Matrix range [2e-09, 5e+05]
Objective range [3e-02, 4e+09]
Bounds range [0e+00, 1e+10]
RHS range [2e-01, 1e+16]
Warning: Model contains large matrix coefficient range
Warning: Model contains large objective coefficients
Warning: Model contains large rhs
Warning: Model contains large bounds
Consider reformulating model or setting NumericFocus parameter
to avoid numerical issues.The best way to deal with numerical issues is to avoid them at the formulation stage. Ideally:
-
Use reasonable variable units and scale constraints so that:
matrix coefficients span no more than six orders of magnitude, preferably within \([10^{-3}, 10^6]\)
RHS and bounds are on the order of \(10^6\) or less
Objective coefficients are scaled so that good solutions have objective values below \(10^6\)
The smallest meaningful coefficient is at least one order of magnitude larger than the feasibility/optimality tolerances (default \(10^{-6}\))
Avoid large BigM values by using indicator or SOS constraints
- Use multi-objective optimization instead of BigM values in the objective function
For more details, see Gurobi’s documentation on "Tolerances and User Scaling."
Gurobi also provides parameters that mitigate numerical issues by restricting or disabling more numerically sensitive algorithms. For a complete list, refer to "Solver Parameters to Manage Numerical Issues."
If there are warnings regarding numerical issues in the log, we also recommend checking the solution quality once the optimization finishes. This can be done using:
- The Quality Attributes (all APIs),
- The Model.printQuality() method (only for gurobipy), or
- The
--printqualityflag from the Gurobi Command-Line Tool,gurobi_cl(starting with Gurobi 12.0).