Search code examples
linear-programmingcplex

Residual values such as 4e^-14 randomly appearing in Cplex LP model solution: How can I get rid of them?


While the result of the my linear programming model in Cplex seems to make sense, the q variable sometimes randomly (at least to me it seems random) shows tiny values such as 4e^-14. This doesn't have an effect on the decision variable but is still very irritating as I am not sure if something in my model isn't correct. You can see the results of the q variable with the mini residuals here: Results q variable. These residuals only started appearing in my model once I introduced binary variables.

q is defined as: dexpr float q [t in Years, i in Options] = (c[i] * (a[t+s[i]][i]-a[t+s[i]-1][i]));

a is a decision variable

This is a constraint q is subject to: q[i][t] == a[i] * p[i]* y[t][i])

Since y is a binary variable, q should either be the value of a[i] * p[i] or 0. This is why I am very irritated with the residual values.

Does anybody have any idea why these values appear and how to get rid of them? I have already spent a lot of time on this problem and no idea how to solve it.

Things I noticed while trying to solve it:

  • Turning all the input variables into integer variables doesn't change anything
  • Turning q into an integer variable solves the problem, but ruins the model since a[i][t] needs to be a float variable
  • Adding a constraint making q >= 0 does not eliminate the negative residual values such as -4e^-14
  • Adding a constraint making q = 0 for a specific t helps eliminate the residual values there, but of course also ruins the model

Thank you very much for your help!


Solution

  • This is a tolerance issue. MIP solvers such as Cplex have a bunch of them. The ones in play here are integer feasibility tolerance (epint) and the feasibility tolerance (eprhs). You can tighten them, but I usually leave them as they are. Sometimes it helps to round results before printing them or just use fewer digits in the formatting of the output.