0

我有一个名为 Lambda 的变量,我想跟踪这个值在每次迭代中是如何变化的。我在 GAMS 中使用了动态集,并定义了以下变量:

test1.l(S)=(trackvalue.l(S-1)+trackvalue.l(S))/trackvalue.l(S);

我不能在循环中使用它,任何人都可以帮助我将结果放入一个变量中吗?或者任何人都可以给我一些提示如何应用它?

先感谢您

4

1 回答 1

0

在您的示例中 trackvalue.l(S-1) 在您解决 S 的模型后不再可访问,因此您需要暂时存储它。这是一个基于执行此类操作的传输示例的小示例。看看最后几行:

  Sets
       i   canning plants   / seattle, san-diego /
       j   markets          / new-york, chicago, topeka / ;

  Parameters

       a(i)  capacity of plant i in cases
         /    seattle     350
              san-diego   600  /

       b(j)  demand at market j in cases
         /    new-york    325
              chicago     300
              topeka      275  / ;

  Table d(i,j)  distance in thousands of miles
                    new-york       chicago      topeka
      seattle          2.5           1.7          1.8
      san-diego        2.5           1.8          1.4  ;

  Scalar f  freight in dollars per case per thousand miles  /90/ ;

  Parameter c(i,j)  transport cost in thousands of dollars per case ;

            c(i,j) = f * d(i,j) / 1000 ;

  Variables
       x(i,j)  shipment quantities in cases
       z       total transportation costs in thousands of dollars ;

  Positive Variable x ;

  Equations
       cost        define objective function
       supply(i)   observe supply limit at plant i
       demand(j)   satisfy demand at market j ;

  cost ..        z  =e=  sum((i,j), c(i,j)*x(i,j)) ;

  supply(i) ..   sum(j, x(i,j))  =l=  a(i) ;

  demand(j) ..   sum(i, x(i,j))  =g=  b(j) ;

  Model transport /all/ ;

  set       s scenarios /1*3/;
  parameter test(s) change of z compared to previous scenario;
  scalar    lastZ solution for z of previous solve /0/;

  loop(s,
    Solve transport using lp minimizing z ;
    test(s) = (z.l-lastZ )/z.l;
    lastZ = z.l;
*   Change the demand a little for the next scenario to see some change
    b(j) = b(j)*uniform(0.95,1.1);
  )

  Display test ;

我希望,这有帮助!

卢茨

于 2016-06-03T10:42:37.337 回答