|
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
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.
Put localfileidentifier optional other contents
where the localfileidentifier must match that found in an earlier file statement.
|