Monday, October 27, 2008

gdxls: write xls files on Linux

The gdxls tool is a Java based alternative for GDXXRW on Linux and other non-Windows operating systems.


Besides converting xls→gdx (as described in http://yetanothermathprogrammingconsultant.blogspot.com/2008/10/gdxls-read-xls-files-on-linux.html) we can also convert gdx→xls.

As simple example model is shown below:
$onecho > trnsport2.properties
o=trnsport2.xls
i=trnsport2.gdx

parameter=c
rng=a1
rdim=1
cdim=1

parameter.2=c
rng.2=f1
rdim.2=2
cdim.2=0

parameter.3=c
rng.3=sheet1!A10
rdim.3=0
cdim.3=2

$offecho

$call gamslib trnsport
$call gams trnsport lo=2 gdx=trnsport2

$call ./gdxls -propertyfile trnsport2.properties

$call oocalc trnsport2.xls


We run the trnsport model from the Model Library and save the results in a gdx file. We then extract the c(i,j) parameter from the gdx file and write it to the spreadsheet in different formats.

Note that we use a numbered suffix in the properties file to indicate which options belong to the same item. No suffix is identical to suffix ".1". So we have three items to process and they are numbered 1,2,3.

The result rendered by Open Office Calc looks like the picture shown below (click to enlarge).

No comments:

Post a Comment