|
Rearranging rows and columns |
Top Previous Next |
|
By default Gdxxrw will choose a layout for multidimensional items that users may wish to change. Namely
The layout may be altered using a combination of the CDIM and RDIM parameters. In particular suppose I have an item x(i,j,k) and wish to place it in or read it from a spreadsheet in varying layouts as follows (Gdxxrwwrite.gms)
execute "Gdxxrw gdxxrwss.gdx par=threedim Rng=output!a1 cdim=3 rdim=0" execute "Gdxxrw gdxxrwss.gdx par=threedim Rng=output!a8 cdim=2 rdim=1" execute "Gdxxrw gdxxrwss.gdx par=threedim Rng=output!a15 cdim=1 rdim=2" execute "Gdxxrw gdxxrwss.gdx par=threedim Rng=output!a30 cdim=0 rdim=3"
where the first creates a row vector of numbers with all indices varied in the columns as in the output page of the spreadsheet gdxxrwss.xls
the second a matrix with one index in the rows and two in the columns as follows
and the last a column vector with many rows.
Reading data from the spreadsheet entails essentially the same commands. For example, in Gdxxrwread.gms the following lines appear which specify data layout
$call "Gdxxrw gdxxrwss.xls par=distance Rng=sheet1!a20:d23 rdim=1 cdim=1" execute "Gdxxrw gdxxrwss.xls par=distance2 Rng=sheet1!a20:d23" $call "Gdxxrw gdxxrwss.xls par=modedistance Rng=sheet1!a26:e31 rdim=1 cdim=2" $call "Gdxxrw gdxxrwss.xls par=modedistance2 Rng=sheet1!a52:e56 rdim=2 cdim=1"
where the second line uses a default rdim=1 cdim=1. One may also use DIM as below
$call "Gdxxrw gdxxrwss.xls par=distance Rng=sheet1!a20:d23 dim=2 cdim=1" execute "Gdxxrw gdxxrwss.xls par=distance2 Rng=sheet1!a20:d23 dim=2" $call "Gdxxrw gdxxrwss.xls par=modedistance Rng=sheet1!a26:e31 rdim=1 dim=3" $call "Gdxxrw gdxxrwss.xls par=modedistance2 Rng=sheet1!a52:e56 dim=3 cdim=1" Notes:
The ordering of the set elements within the resultant spreadsheet or within GAMS are controlled by the GAMS element ordering rules and the unique element list as discussed in the Rules for Item Capitalization and Ordering chapter. But this may be controlled using merge as discussed below. |