2015-11-01 164 views
0

任何人都可以幫助我解決這個問題。我想通過一個添加到我一個放的X(I)的量等於1的每一步,所以我下面寫的,但它不工作如何在GAMS中編寫一個while循環

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; 
    ); 
); 

順便說一句,m是一個變量在此之前計算,在一個等式中。

回答

0

看看這個page有更好的想法如何在GAMS中創建while循環。也看看這個代碼,因爲它可以幫助你:

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; 
); 
+0

謝謝,但我問題是M是變量 –

+0

基於變量編寫while循環是不可能的? –

0

如果m是一個模型,它是之前解決的變量,你應該使用.l屬性檢查其級別:

... 
while(t>m.l, 
...