Page 1 of 1

Loading 4D Tables

Posted: Tue Oct 01, 2019 10:33 pm
by ayledith
I'm familiar with loading 2D tables into GAMS, IE c_ij (cost of i going to j). But I need to do some analysis where the cost is from location i to location j at time t for station k. Is there a recommended way for loading high dimensional tables into GAMS?

Re: Loading 4D Tables

Posted: Wed Oct 02, 2019 8:24 am
by Renger
Hi
You can use, if the table is in Excel format, the gdxxrw utility (see the documentation). It allows you to read any kind of structured multidimensional table (e.g. dimensions as 4x1, 3x1, 1x3, 2x2) using the specification RDIM and CDIM. For csv files, you just have to have the data in long format (e.g. 4x1) and use readcsv (In the case of 4x1 you have an additional column name "Value").

I hope this helps
Renger

Re: Loading 4D Tables

Posted: Tue Nov 19, 2019 4:26 pm
by achristensen
Hi there ayledith,
If you are familar with python you can use a tool I wrote to get data into a GDX and then you can load that data into a gams model through a $GDXIN statement...

gdxtools can be installed with

Code: Select all

pip install gdxtools
an example file of several different read/write operations can be found in the example.py file located here: https://github.com/boxblox/gdxtools/blo ... example.py

A 4D table is simply defined as a python dictionary {key: value} but the key is a tuple {(dim1,dim2,dim3,dim4): value}. Note that you will need to install the gams python api first.

hope that might be helpful!
best,
adam