Hi everyone,
I have a put command that calculates the gap between the current objective value and the best integer solution, at a certain time. The code as follow;
(MODEL21.objval-MODEL21.objest)*100/(MODEL21.objval)
If GAMS can't find an initial solution in the time limit of 900 seconds, the "MODEL21.objval" becomes 0 and I get a zero division error (rare but serious problem). Although there are other models to solve, GAMS stops running because it gives an error here. I tried to solve the problem by adding a very small number to the denominator. However, I'm wondering if anyone has a more practical suggestion? Also, I'm wondering is there a way to tell GAMS to ignore errors (especially in "put commands") and continue solving the remaining models?
Zero division error in GAP calculation
Re: Zero division error in GAP calculation
Hi,
You can check whether MODEL21.objval is 0 before you do the calculation and for example use some other value (like +inf) if there is no feasible solution
Of course, this makes only sense if you know that the objective value can never be zero.
I hope this helps!
Fred
You can check whether MODEL21.objval is 0 before you do the calculation and for example use some other value (like +inf) if there is no feasible solution
Code: Select all
if(MODEL21.objval,
gap = (MODEL21.objval-MODEL21.objest)*100/(MODEL21.objval);
else
gap = +inf;
);
I hope this helps!
Fred