Zero division error in GAP calculation

Problems with syntax of GAMS
Post Reply
Kadir
User
User
Posts: 9
Joined: 3 years ago

Zero division error in GAP calculation

Post 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?
Fred
Posts: 372
Joined: 7 years ago

Re: Zero division error in GAP calculation

Post 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
Post Reply