Basics of put

Top  Previous  Next

The basic structure of the put instruction in its simplest form is:

 

put item;

 

where item is any type of output such as explanatory text, labels, parameters, variable attributes, equation attributes or model attributes.  However, in order that GAMS direct the output to the appropriate place, the user must first specify the name of output file then issue a command activating that file.  Thus a more general put file sequence is:

 

file localfileidentifier /externalfilelocation/;

put localfileidentifier ;

put item1;

put item2;

put item3;

 

In this basic structure, the lines

Defines the file which will receive the output from the put commands giving it a localfileidentifier (an internal item name) and an external file name possibly containing a path location.
Issues a put statement with the localfileidentifier and nothing else on the line which assigns the defined files as the current one to which all subsequent puts will be written until another internal file is referenced.
Lastly, the subsequent lines containing put commands each write to the current file.
Text from a file can be included in a put file with the Put_utility 'inc' syntax
Multiple lines of text  can be included in a put file with the $onput syntax

Example:

For illustration we specify an example in the context of the transportation model using the file putex1.gms.  The component of this file involving put commands is as follows:

 

file myputfile;

put myputfile;

put 'Run on ' system.date '  using source file  ' system.ifile ///;

put 'Run over scenario set ' scenarios.ts //;

loop(scenarios,

    Need(Destinaton)=demandscen(destinaton,scenarios);

    Solve tranport using LP minimizing totalcost ;

    report("total","cost",scenarios)=totalcost.l;

    report("demand shadow price",Destinaton,scenarios)

            = demandbal.m(Destinaton);

    report("supply shadow price",Source,scenarios)

          = Supplybal.m(Source);

                   savtransport(Source,Destinaton,scenarios)

=transport.l(Source,Destinaton);

    put 'Scenario name   ' scenarios.te(scenarios):14

    put ' Optimality status ' tranport.modelstat:2:0 /;

   )      ;

put //;

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 /;

      );

  put 'Quantity demanded ' @35

  loop(scenarios,

      put demandscen(destinaton,scenarios):10:0);

    put /;

    put 'Marginal Cost of meeting demand ' @35

    loop(scenarios,

      put report("demand shadow price",Destinaton, scenarios)

        :10:2);

    put //    );

 

The resultant output is placed on the file myputfile.put and is

 

Run on 01/05/02  using source file  C:\GAMS\GAMSPDF\PutEX1.GMS

 

Run over scenario set Four alternatives

 

Scenario name Base Case      optimality status  1

Scenario name No Chicago     optimality status  1

Scenario name No New York    optimality status  1

Scenario name No Topeka      optimality status  1

 

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

                                        base      scen1     scen2     scen3

Incoming From Seattle                     50       350         0         0

Incoming From San Diego                  275       275         0       525

Quantity demanded                        325       625         0       525

Marginal Cost of meeting demand       250.00    250.00    250.00    250.00

 

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

                                        base      scen1     scen2     scen3

Incoming From Seattle                    300         0       350       350

Incoming From San Diego                    0         0       275        25

Quantity demanded                        300         0       625       375

Marginal Cost of meeting demand       178.00    178.00    187.00    187.00

 

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

                                        base      scen1     scen2     scen3

Incoming From San Diego                  275       275       275         0

Quantity demanded                        275       275       275         0

Marginal Cost of meeting demand       151.00    151.00    151.00    151.00

Notes:

The file specification must always appear before any of the put commands and in general is as follows

 File localname / externalfilelocation/;

 

 More on the file specification appears below.

The second entry in any put a sequence must always be of the form

 Put localfileidentifier optional other contents

 

 where the localfileidentifier must match that found in an earlier file statement.

The subsequent put statements can contain
Quoted text as discussed below.
Set element labels as discussed below.
Set element explanatory text as discussed below.
GAMS item explanatory text (for sets, parameters, variables, equations, and models) as discussed below.
Parameter numeric data as discussed below.
Model solution numeric data as discussed below.
System information like source file name or date as discussed below.
Write position control characters as discussed below.
Item width, decimals and justification specifications as discussed below.
The output is structured assuming a proportional font is being used (like Courier New).  Non-proportional font features are not present.