2

I want to assign values to a 3-D table in GAMS. But it seems it doesn't work as in Matlab.....Any luck ? Code is as followed and the problem is at the last few lines:

    Sets
         n           nodes                       / Sto , Lon , Par , Ber , War , Mad , Rom /
         i           scenarios                   / 1 * 4 /
         k           capacity level              / L, N, H /  ;

alias(n,m);

Table balance(n,i) traffic balance for different nodes
         1       2       3       4
Sto      50      50      -50     -50
Lon      -40     40      -40     40
Par      0       0       0       0
Ber      0       0       0       0
War      40      -40     40      -40
Mad      0       0       0       0
Rom      -50     -50     50      50  ;

Scalar r  fluctuation rate of the capacity level
/0.15/;

Parameter p(k) probability of each level
/ L   0.25
  N   0.5
  H   0.25 / ;

Table nor_cap(n,m) Normal capacity level from n to m
          Sto    Lon     Par     Ber     War     Mad     Rom
Sto       0      11      14      25      30      0       0
Lon       11     0       21      0       0       14      0
Par       14     21      0       22      0       31      19
Ber       25     0       22      0       26      0       18
War       30     0       0       26      0       18      22
Mad       0      14      31      0       18      0       15
Rom       0      0       19      18      22      15      0  ;

Table  max_cap(n,m,k) capacity level under each k
max_cap(n,m,'N')=nor_cap(n,m)
max_cap(n,m,'L')=nor_cap(n,m)*(1-r)
max_cap(n,m,'H')=nor_cap(n,m)*(1+r);
Serj-Tm
  • 16,581
  • 4
  • 54
  • 61
Lisa
  • 21
  • 3

1 Answers1

0

The final assignment to a 3-D matrix should be done with PARAMETER as opposed to TABLE. In general I would also note that TABLE is very restrictive (2 dimensional, text input inside the code). You might want to consider $GDXIN (or EXECUTE_LOAD) and some of the GAMS utilities for loading xls or csv files.

As a user of both MATLAB and GAMS I would note that GAMS depends on "indices" for every array, but otherwise they can be quite similar. In your case max_cap(n,m,k) would be something like the maximum capacity between from_city and to_city under each capacity level scenario. Your matrix needs to be declared as a PARAMETER which can be any n-dimensional (indexed) matrix, including even a SCALAR.

Also, try the GAMS mailing list if you really need an answer quickly, the number of proficient GAMS users globally can't be more than a few thousand, so it might be hard to find a quick answer on StackOverflow - awesome as it is for the more common languages.

Anton
  • 1,458
  • 1
  • 14
  • 28