Page 1 of 1

Zero division error in GAP calculation

Posted: Sat Jul 03, 2021 7:57 pm
by Kadir
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?

Re: Zero division error in GAP calculation

Posted: Thu Jul 08, 2021 4:25 pm
by Fred
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

Code: Select all

if(MODEL21.objval,
  gap = (MODEL21.objval-MODEL21.objest)*100/(MODEL21.objval);
else
  gap = +inf;
);   
Of course, this makes only sense if you know that the objective value can never be zero.

I hope this helps!

Fred