Thursday, December 27, 2012

Better element names

Sometimes I see GAMS code like:

SETS
  K
index of periods of time  /1*4/
  J
index of generators /1*3/

In general I don’t like plain numbers as set elements. I prefer something like:

SETS
  K
index of periods of time  /t1*t4/
  J
index of generators
/gen1*gen3/

This often improves the readability of the output. This is especially the case in the GDX viewer where we can swap rows and columns. Here is a some sample output:

Numerical

Id+Numerical

SETS
  K
index of periods of time  /1*4/
  J
index of generators /1*3/

SETS
  K
index of periods of time  /t1*t4/
  J
index of generators
/gen1*gen3/

----    110 VARIABLE p.L  output power of generator j at period k

 

            2           3           4

 

1     150.000     350.000     260.000

2                 100.000

3                  50.000     140.000

 

----    110 VARIABLE p.L  output power of generator j at period k

 

              t2          t3          t4

 

gen1     150.000     350.000     260.000

gen2                 100.000

gen3                  50.000     140.000

clip_image001

clip_image002

For this small example this is not terribly convincing, but for larger, high-dimensional data it surely helps in understanding output quickly.