在 GAMS 中跟踪价值变化

track value changement in GAMS

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

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

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

提前致谢

在您的示例中,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 ;

希望对您有所帮助!

卢茨