Problem with loop Topic is solved

Problems with syntax of GAMS
Post Reply
Rofice
User
User
Posts: 28
Joined: 4 years ago

Problem with loop

Post by Rofice » 2 months ago

Dear all,

I am trying to perform few calculations using loop. However, the formulated syntax is not able to store the last value of parameter b(z) (722) to set u2(zz). Please see the attached model for more details. I will really appreciate it if someone helps me with correcting the codes.
syntax.gms
(459 Bytes) Downloaded 38 times
Best regards,
Rofice

GFA
User
User
Posts: 34
Joined: 3 years ago

Re: Problem with loop

Post by GFA » 2 months ago

Hi,

B(z+1) is declared in the same loop as u2(zz), so in the last loop iteration B(z+1) will have a value (772) but u2+1 won't.
One way to solve this is to declare u2(zz+1) in the same loop, but keep in mind that now you will miss the first value of u2(zz), but just like the first b-value you can also initialize the first u2 value with the same value as b.

Cheers,
GFA

Code: Select all


 set z  hours in a year / 1*8760 /

 alias (z,zz);

 scalar init stopping criteria ; init = 0;

 parameter

 a(z) number of days in january ,

 b(z) add interval of 24 hours ;

 set u2(zz) feasible elements should equal to b(z) ;

 init = 0;  a('1') = 1 ; b('1') = 2  ;
 u2("2") = yes;

 loop(z $ (init ne 1) ,

 a(z+1) = a(z) + 1;

 b(z+1) = b(z) + 24;

 u2(zz+1) $ (ord(zz)+1=b(z+1))  = yes ;

 init $ {a(z+1) eq 31} = 1;

 ) ;


 display a,b,u2;



Rofice
User
User
Posts: 28
Joined: 4 years ago

Re: Problem with loop

Post by Rofice » 1 month ago

Thanks GFA!

Best regards,
Rofice

Post Reply