跟踪GAMS中的价值变化

时间:2016-06-02 19:28:47

标签: gams-math

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

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

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

提前谢谢

1 个答案:

答案 0 :(得分:0)

在您的示例中,在您解决S的模型后,无法再访问trackvalue.l(S-1),因此您需要临时存储它。这是一个基于传输示例的小例子,它做了类似的事情。看看最后几行:

  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 ;

我希望,这有帮助!

鲁兹