Set element explanatory text via .te and .tf

Top  Previous  Next

Sometimes one wishes output wherein the explanatory text associated with set element names is used in labeling the printed data.  In a put file context this is done by entering an item in a put command which is the setname.te(setname2) wherein the set setname2 is varied by a loop command as discussed in the Control Structures chapter.  The blue entries just below all involve instances where the explanatory text associated with set element names are used in putting out information within the example putex3.gms.  The red entries identify the loop command and the set under control, the orange a case where explanatory set element text is used and the blue a case where the set from which the explanatory set element text is coming differs from the set being varied.

 

set j /a1*a3

        a4 this is element 4

        a5 has a crummy name/;

set i /1,2,3,4 this one is 4/

set newnames(j) /a1 Bolts,a2 Nuts,a3 Cars, a4 Trains, a5 /;

put /

   'Set EL        Explanatory Text        Exp. Text from Subset' //;

loop(j,put j.tl:10 ' !! ' j.te(j):20 ' $$ 'newnames.te(j):20 /);

 

The result with the set element names as output by .tl, the original explanatory set element text and the explanatory set element text coming from a different set which is a subset of the set being varied.

 

Set EL        Explanatory TextExp. Text from Subset

 

a1         !! a1$$ Bolts

a2         !! a2$$ Nuts
a3         !! a3$$ Cars
a4         !! this is element 4$$ Trains
a5         !! has a crummy name$$ a5

Notes:

The extension .te followed by the name of the set being varied is used to cause printing of the explanatory text for the set element.
The set being varied must be controlled by a loop statement, GAMS will not automatically cover all cases.
Default 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 descriptive text capitalization rules follow those discussed in the chapter on Rules for Item Capitalization Ordering.
It is often useful to modify the set element text to improve their content.  This may be done using subsets and the .te syntax as the blue case illustrates.
Tuples can be used with the .te command not with the .tl.  In such cases one gets a printout of either the set elements in the tuple or the text associated with the tuple element depending on the .tf setting as discussed next.
When .te is used but no explanatory text was entered then by default the set element name is used.  This can be changed using the .tf put file attribute where setting the following influences the text used to fill the empty explanatory text field via the rules below as used in putex5.gms
localfileidentifier.tf to 0 suppresses the fill of missing explanatory text with element names leaving blanks.
localfileidentifier.tf to 1 results in blank entries when an element is referenced which does not exist and does the default fill otherwise.
localfileidentifier.tf to 2 is the default and always fills empty explanatory text with the element name.
localfileidentifier.tf to 3 always fills the .te output with the element names not using the defined explanatory text.
localfileidentifier.tf to 4 puts out the .te as when .tf=3 in quotes with comma separators.  This can be used in generating code for reinclusion in GAMS.
localfileidentifier.tf to 5 is same as .tf=4 with periods as separators.
When a tuple is used with .te but no explanatory text is present one gets the names of the set elements defining the tuple separated by a period.

Example:

In the example putex3.gms which puts to the localfileidentifier file my1 this is done as follows

 

my1.tf=0;

put / 'Set EL        Explanatory Text        Exp. Text from Subset' //;

loop(j,put j.tl:10 '!!' j.te(j):20 '$$'newnames.te(j):20/);

 

yielding the output

 

Set EL        Explanatory Text        Exp. Text from Subset

 

a1         !!                      $$ Bolts

a2         !!                      $$ Nuts

a3         !!                      $$ Cars

a4         !! this is element 4    $$ Trains

a5         !! has a crummy name    $$

 

where in comparison with the output just above the entries for a1-a3 in the second column are suppressed as is the one for a5 in the last column due to a lack of explanatory text.