Using same as to comparing two dimensional parameter

Problems with syntax of GAMS
Post Reply
Lucas
User
User
Posts: 23
Joined: 5 years ago

Using same as to comparing two dimensional parameter

Post by Lucas »

Hi , I Can't code this term in GAMS

Code: Select all

if there exist 
k'<k s.t. for all s ,  b(s,k')=b(s,k)  then   b(s,k)=(b(s,k-1)+b(s,k-2))/2;
else  do not Change  b(s,k)  

[\code]

My try:

[Code]

         loop(k1$(k1.val<k.val ),
                 loop(s,
                         if( (B(s,k1)<>B(s,k1)),
                              Break;
                         else   b(s,k1)= (B(s,k1)+B(s,k1-1))/2  ;
                            );
                    );
             );
             
 [\code]
             
I don't know where I have to put Break. is it nessery to use loop over s? is teher a better way to code that?

[Code]
example: in below case for s=1 and s=4 , there exist b(s,k=1)=b(s,k=4) then we have to update b(s,'4')=(b(s,'3')+b(s,'4') )/2

iter=k=4, k'={1,2,3}, s={1,2,3};

b(1,1)=3, b(2,1)=7, b(3,1)=9,

b(1,2)=2, b(2,2)=4, b(3,2)=11,

b(1,3)=5, b(2,3)=12, b(3,3)=8,

b(1,4)=3, b(2,4)=7, b(3,4)=9,

[\code]

I used sameAs command too , but , when I used sameAs(b(s,k'),b(s,k)) (in the loop over k1) I got Error 121!
Fred
Posts: 373
Joined: 7 years ago

Re: Using same as to comparing two dimensional parameter

Post by Fred »

Lucas,

It would be much easier to help, if you would make sure that your posts are properly formatted, for example by using the "Preview" button.

Fred
Post Reply