|
Compile time imports from GDX files |
Top Previous Next |
|
A set of dollar commands can be used to cause GAMS to read data from a GDX file at compile time. The data read from the GDX file will be the data present in it at the time that the compile job is begun. The basic syntax involves a three-part sequence
$Gdxin filename $Load itemname $Gdxin
The first part is an initial $Gdxin command which also specifies the filename to be used. A file with this filename and the extension .GDX is looked for in the current working directory. In turn this command opens the GDX file and prepares it for reading. The second part of the sequence is one or more $Load commands or the alternative Loaddc (which eploys domain checking). These commands specify the items to be read from the GDX file. Several commands may be used and each line can read more than one item. For example, one could load several items with the command structure
$Gdxin filename $load itemname1 $loaddc itemname2 $load itemname3 $load itemname4 $Gdxin
or could use the structure
$Gdxin filename $load itemname1 itemname2 itemname3 itemname4 $loaddc itemname5 itemname6 itemname7 itemname8 $Gdxin
It is also possible to have different names for parameters in the GDX file and the GAMS program. In such a case the syntax is
$load internalname1=gdxfileitemname1 i2=gf2
Any parameter data can be loaded as can set data defining domains and variable/equation data. The third part of the sequence simply consists of another $Gdxin command which closes the GDX file. Actually the statements can be intermixed with GAMS calculations solves etc. but must eventually be closed with a $Gdxin. Example: In the model gdxintrnsport.gms we introduce the sequence
$GDXin tran2 Sets i canning plants j markets ; $load i j Parameters a(i) capacity of plant i in cases b(j) demand at market j in cases; $load a=sup $loaddc b=dem Parameter d(i,j) distance in thousands of miles; $load d Scalar f freight in dollars per case; $load f $GDXin
This loads data from the GDX file named tran2.gdx that was saved by the example gdxexectrnsport.gms. Notes:
|