0

Can anyone help me with this problem please. I want to add to i one by one and put the amount of x(i) equal to 1 in each step, so i wrote it as below but it's not working

loop(i,
    x('0')=1;
    t('0')=1;
while(t>m,
      ord(i)=ord(i)+1;
      display i;
      x(i)=1;
      display x;
      t(i)=t(i-1) +1;
   );
 );

And by the way m is a variable which is calculated before this, in an equation.

Sepideh Gh
  • 97
  • 6

2 Answers2

1

If m is a variable from a model that was solved before, you should check its level using the .l attribute:

...
while(t>m.l,
...
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Lutz
  • 2,197
  • 1
  • 10
  • 12
0

Look at this page to have a better idea of how to make a while loop in GAMS. Also look at this code because it may help you:

root=minroot;
*find a sign switch
while(signswitch=0 and root le maxroot,
   root=root+inc;
   function_value2= a-b*root+c*sqr(root);
   if((sign(function_value1) ne sign(function_value2)
      and abs(function_value1) gt 0
      and abs(function_value2) gt tolerance),
         maxroot=root;
         signswitch=1
   else
      if(abs(function_value2) gt tolerance,
         function_value1=function_value2;
         minroot=root;);
      );
*  display 'inside',minroot,maxroot,function_value1,function_value2;
);
spaghettifunk
  • 1,936
  • 4
  • 24
  • 46