Beruflich Dokumente
Kultur Dokumente
com/docs/excel/
A GDX file is a file that stores the values of one or more GAMS symbols such as sets,
parameters variables and equations. GDX files can be used to prepare data for a GAMS model,
present results of a GAMS model, store results of the same model using different parameters
etc. A GDX file does not store a model formulation or executable statements.
GDX files are binary files that are portable between different platforms. They are written using the
byte ordering native to the hardware platform they are created on, but can be read on a platform
using a different byte ordering.
In order to write data from GAMS to Excel, the user writes a GDX file and then writes the Excel
file from the GDX file.
GAMS ----> GDX ----> Excel
This is practically seamless for the user and requires few commands. The process to import data
from an Excel file to GAMS is similar:
Excel ----> GDX ----> GAMS
After the solve statement, we unload the data (x.L and x.M) to a GDX file using the
execute_unload command:
Note that the execute_unload command is executed during the actual execution phase (not
1 of 2 2/19/2007 2:45 PM
GAMS/Excel Using GDX http://www.gams.com/docs/excel/
during compilation time as $ control options) and creates a GDX file called results.gdx.
Now let us write the data from the GDX file to an Excel file called results.xls. We do this using the
GDXXRW utility
execute 'gdxxrw.exe results.gdx var=x.L'
execute 'gdxxrw.exe results.gdx var=x.M rng=NewSheet!f1:i4'
For the first call for x.L, there is no range specified and the data is written in cell A1 and beyond
in the first available sheet. For the marginals x.M data will be written to cells F1:I4 in the sheet
NewSheet. Note that we specified var=x.L and var=x.M. If the user wishes to write parameters to
the Excel file, the relevant command is par. See the GDX facilities in GAMS document for further
details.
Note that since we are using the $CALL command, this occurs during the compilation phase and
not during execution time. We specify that the data in the range A1:D3 is read in as a parameter
called Level. The resulting GDX file will be called results.gdx
Before we can read in the data, we must define a parameter called Level over the appropriate
sets:
Parameter Level(i,j);
$GDXIN results.gdx
$LOAD Level
$GDXIN
The GDXIN results.gdx command specifies that data will be read in from the appropriate GDX
file. We then import data structures values using the $LOAD command. When we are finished, we
terminate with $GDXIN.
In the example below, we then fix the level values of the variable x to the parameter Level so that
solving results in a trivial fixed model.
2 of 2 2/19/2007 2:45 PM