|
Compile time selected item GDX file creation |
Top Previous Next |
|
A group of dollar commands can be used to write a GDX file containing selected data. The data written to the GDX file will be those present when the statement is encountered during compilation. The results of calculations and solves will not be reflected. (Note this should not ordinarily be used, it is safer to use the Execute_Unload as calculations and solves would be reflected in the result). The only way to guarantee that the data is current is to use the execution time command or to use a save then restart a file with the dump commands within them. The basic syntax involves a three-part sequence
$Gdxout filename $Unload itemname $Gdxout
The first part of the sequence is the initial $Gdxout command which also specifies the filename that the GDX file will be called. A file with this name will be placed in the current working directory with the extension .GDX. This opens the GDX file and prepares it for writing. Any existing files with the same name will be overwritten. The second part of the sequence is one or more $Unload commands. These commands specify the items to be placed in the GDX file. A statement can specify more than one item. For example, one could unload four items with the following commands
$Gdxout filename $unload itemname1 $unload itemname2 $unload itemname3 $unload itemname4 $Gdxout
or could accomplish the same using
$Gdxout filename $unload itemname1 itemname2 itemname3 itemname4 $Gdxout
It is also possible to have different names for parameters in the GDX file as opposed to the names used in the GAMS program. In such a case the syntax is
$unload internalname1=gdxfileitemname1 i2=gf2
which would result in the item with internalname1 being called gdxfileitemname1 in the GDX file and i2 being called gf2. The third part of the sequence simply consists of a $Gdxout command which closes the GDX file. Actually the statements can be intermixed with GAMS calculations solves etc. but must eventually be closed with a $Gdxout. Example: In the model gdxtrnsport.gms we introduce the sequence
d(i,j)=d(i,j)*10; $GDXout tran $unload i j $unload d $unload f $unload a=dem b=sup $GDXout
The result of this is a GDX file named tran.gdx that contains the data for the sets i and j as well as the parameters d, f, a and b. Note that the a and b items have been renamed dem and sup. Also note the d items will not have been multiplied by 10 but rather take on their compile time values. |