Set element names via .tl

Top  Previous  Next

Sometimes one wishes output wherein the set element names are used in labeling the printed data.  In the put file context this is done by putting an item in a put command which is setname.tl wherein the named set is varied by a loop command as discussed in the Control Structures chapter.  The orange entries just below all involve instances where the text for set element names is used in putting outt information within the example putex1.gms.

 

loop(Destinaton,

  put 'Report for ' , Destinaton.tl:15

  put @40 '------------  Scenario  ------------' /;

  put @41;

  loop(scenarios,put scenarios.tl:10);

  put /;

  loop(source$sum(scenarios,

        abs(savtransport(Source,Destinaton,scenarios))),

     put 'Incoming From ' source.tl @35;

     loop(scenarios,

       put savtransport(Source,Destinaton,scenarios):10:0);

     put /;

      );

 

The resultant output file follows with the orange entries corresponding to set element names generated by the put commands above.

 

Report for New York                    ------------  Scenario  ------------

                                        base      scen1     scen2     scen3

Incoming From Seattle                     50       350         0         0

Incoming From San Diego                  275       275         0       525

 

Report for Chicago                     ------------  Scenario  ------------

                                        base      scen1     scen2     scen3

Incoming From Seattle                    300         0       350       350

Incoming From San Diego                    0         0       275        25

 

Report for Topeka                      ------------  Scenario  ------------

                                        base      scen1     scen2     scen3

Incoming From San Diego                  275       275       275         0

Notes:

The extension .tl is used to cause printing of the text giving the set element name.
The set must be controlled by a loop statement, GAMS will not automatically cover all cases.
Default field width is 12 characters but alternative widths may be used as discussed below.
Default justification is left but alternative formatting may be used as discussed below.
The set element name capitalization rules follow those discussed in the chapter on Rules for Item Capitalization and Ordering.
One often finds the names need to be altered or made longer to improve their content.  This may be done using the .te syntax discussed just below.