If you have a known solution, the first step is to check that this solution is feasible for your model. Create a fixed model by fixing the variables to their values in the known solution. To do this, set the lower and upper bound of each variable to its value in the solution.
If the fixed model is infeasible, your original model probably has a modeling error.
- Do you expect variables in your model to take negative values? If so, please ensure that you have defined the lower bounds of such variables to appropriate negative values. The default lower bound for variables in Gurobi is zero.
- What is the IIS for the fixed model? To compute the Irreducible Infeasible Subsystem (IIS) for the model, follow the instructions in the article How do I use 'compute IIS' to find a subset of constraints that are causing model infeasibility?
Numerical issues are another source of this discrepancy
Check if your model has numerical issues.
- Do you see warnings in the Gurobi log indicating variables or constraints violate feasibility tolerances?
- Are you working with very tight tolerances such as IntFeasTol = 1e-09 and FeasibilityTol = 1e-09? Working with very tight tolerances can sometimes lead to numerical precision issues. For example, an "almost 1" value of a binary variable is treated as 0 if it does not fulfil a tight tolerances value. This then results in a wrong variable fixing and an unexpected result. In general, we recommend that the smallest significant digit of your model should be larger than the feasibility tolerance.
- Do you have large Big-M values in your model? Large values of Big-Ms in a Big-M constraint can lead to the "Trickle Flows" issue. For example, if you have a constraint y <= 1000000 * x, where x is binary and y >=0. With the default value of IntFeasTol (1e-5), x = 0.0000099999, y = 9.9999 is integer feasible, implying that y can be positive even when x is zero. Such behaviour can lead to unexpected results. Try to use the smallest possible values of Big-M. See Dealing with big-M constraints.
- Are you using nonlinear functions? Try adjusting the granularity of piecewise linear approximations of your function constraints with parameters FuncPieces, FuncPieceLength, and FuncPieceError. Also, be sure to use the tightest bounds possible on the variables.
- Other parameters to try:
- However, the best way forward will be to reformulate/rescale your model to address the numerical issues. Please refer to our guidelines for numerical issues.