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.

2 comments:

  1. While this idea helps with report reading, extending it a bit further would help with understanding the model from the GAMS code.

    SETS
    Period index of periods of time /t1*t4/
    Generator index of generators /gen1*gen3/

    Then looking at the objective and constraints of the model, what is being indexed is even more clear.

    EQUATIONS
    ...
    MeetDemand(Period) .. SUM(Generator,
    OrderQuantity(Generator, Period) =E=
    Demand(Period);

    Instead of

    EQUATIONS
    ...
    C1(K) .. SUM(J, Q(K,J) =E= D(K);

    ReplyDelete
  2. Absolutely. I personally like to use short names for heavily used identifiers and vice versa. E.g. for a time index that is used a lot I may decide to use 't' (probably never 'k' like in this fragment). If not used as much I may use 'period'.

    ReplyDelete