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 last index position is included in a column and all other index positions are included in rows.
Thus with a ten dimensional item, each spreadsheet row would depict one combination of the set elements within the first nine index positions and each column would represent an element of the last index position.

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

 

_img93

 

the second  a matrix with one index in the rows and two in the columns as follows

 

_img94

 

and the last a column vector with many rows.

 

_img95

 

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:

When writing to a spreadsheet, special values such as Eps, NA and Inf will be written but this can be changed as discussed below.  When reading data from a spreadsheet, the ASCII strings for these special character stings will be used to write corresponding special values to the GDX file.
Cells that are empty or zero will not be written to the GDX file.

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.