You can follow any of the following suggestions to help determine whether a model is experiencing numerical issues:
m = read('gurobi.rew')
m.printStats()
The output will look like:
Statistics for model (null) : Linear constraint matrix : 25050 Constrs, 15820 Vars, 94874 NZs Variable types : 14836 Continuous, 984 Integer Matrix coefficient range : [ 0.00099, 6e+06 ] Objective coefficient range : [ 0.2, 65 ] Variable bound range : [ 1, 5e+07 ] RHS coefficient range : [ 1, 5e+07 ]The range of numerical coefficients is one indication of potential numerical issues. As a very rough guideline, the ratio of the largest to the smallest coefficient should be less than
In this example, the matrix range is
m.read('gurobi.prm')
m.optimize()
Here are some examples of warning messages that suggest numerical issues:
Warning: Model contains large matrix coefficient range
Consider reformulating model or setting NumericFocus parameter
to avoid numerical issues.
Warning: Markowitz tolerance tightened to 0.5
Warning: switch to quad precision
Numeric error
Numerical trouble encountered
Restart crossover...
Sub-optimal termination
Warning: ... variables dropped from basis
Warning: unscaled primal violation = ... and residual = ...
Warning: unscaled dual violation = ... and residual = ...
m.printQuality()which provides a summary of solution quality:
Solution quality statistics for model Unnamed :
Maximum violation:
Bound : 2.98023224e-08 (X234)
Constraint : 9.30786133e-04 (C5)
Integrality : 0.00000000e+00
Violations that are larger than the tolerances are another indication of numerical issues. Also, for a pure LP (without integer variables), print the condition number via the following Python command:
m.KappaExactThe condition number measures the potential for error in linear calculations; a large condition number, such as