Page 1 of 1

division by zero

Posted: Wed Mar 17, 2021 7:04 pm
by seydaseyda
Hi everyone!

I have a working code and I wanted to add a constraint and I defined a parameter.

<
parameters
K(i,j);
K(i,j)$(ord(i)<>ord(j))=1/power(x(i,j));
>

Whenever I try to run this code, it gives me division by zero error.
How can I ensure that
if x(i,j) is 0, K(i,j) directly 0
otherwise, K(i,j) will give the result 1/x(i,j)?


Thanks in advance,

Re: division by zero

Posted: Wed Mar 17, 2021 11:27 pm
by abhosekar
Please use code blocks for writing your code, provide as much information about your code as you can, and do not delete parts of the question once it has been answered. The answers and question might be useful for other users in the future.

There are several things that are wrong here.

I don't understand why you are trying to set a parameter value using a variable value. A variable value as you are using in the code has no meaning. You always have to use a variable with a suffix such as .fx, .l, .lo, .up.

Is power a variable in your model? Power is also a GAMS function which is used as power(x, y) for representing x^y.

You will get division by zero error whenever x is in the denominator as it can be 0.


- Atharv