Summation with parameter

Problems with syntax of GAMS
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Summation with parameter

Post by Renger »

I can't check your code without the initialization of your variables (the code to initialize the variable w for example).
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
mrv_ce
User
User
Posts: 19
Joined: 5 years ago

Re: Summation with parameter

Post by mrv_ce »

Hi Renger,

I sent my code to you in DM. Could you check it? I tried different index values (for k=1 and k=3) to check the generated constraints but they gave different results. Therefore I could not understand the problem in code and constraints. And also I can not understand the division by zero error. It should not give such an error.

I hope you can understand the problem of code. Please help me.
Thanks a lot again.
mrv_ce
User
User
Posts: 19
Joined: 5 years ago

Re: Summation with parameter

Post by mrv_ce »

Hello again,

I worked on the code again. And I noticed while checking all indices in a constraint; which is j and s; the constraint generates denominator as 0. Therefore, the code gives error of division by zero . To get rid of this problem, I should write the denominator part not equal to zero as a condition. But, I could not write this condition.

I think, the condition should be " aa(j,s)$(ord(s)=(r(k,j)-1))-aa(j,s)$(ord(s)=r(k,j)) " part is not equal to zero.

And also this condition will be in below constraint. But I can not place it.

class1(k)$(mapK_I(k,'1')).. sum(j, sum(s$(ord(s)<=r(k,j)-1), w(j,s))) + sum((j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)-aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)-1))-aa(j,s)$(ord(s)=r(k,j))))) - u('1') + epsplus(k) =g= 0.0001 ;

How can I write such a condition and where this condition should be in the constraint?

Please, can you help me for this conditional code part?

Thanks a lot.
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Summation with parameter

Post by Renger »

Hi
You can define a parameter like this:

Code: Select all

parameter cond(k,j,s);
cond(k,j,s)= (aa(j,s)$(ord(s)=(r(k
      ,j)-1))-aa(j,s)$(ord(s)=r(k,j)));
and then rewrite the equation as

Code: Select all

class1(k)$(mapK_I(k,'1'))..         sum(j, sum(s$(ord(s)<=r(k,j)-1), w(j,s))) + sum((j,s)$cond(k,j,s),w(j,s)$(ord(s)=r(k,j))*((a(k,j)-aa(j,s)$(ord(s)=r(k,j)))/(aa(j,s)$(ord(s)=(r(k,j)-1))-aa(j,s)$(ord(s)=r(k,j)))))  - u('1') + epsplus(k)  =g=  0.0001 ;
Same thing for the other equations.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply