GAMS的使用

The General Algebraic Modeling System (GAMS)是一款數學規劃和優化的高級建模系統。本文簡單通過一個例子簡單介紹GAMS的用法。

GAMS官方網站:http://www.gams.com/

例子:運輸問題基本模型

代碼:

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 thousand 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 thousand of dollars per case;
              c(i,j) = f*d(i,j)/1000;
      variables
          x(i,j)
          z;
      positive variable x;
      equations
          cost
          supply(i)
          demand(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/
      solve transport using lp minimizing z;
      display x.l,x.m;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章