Loading 4D Tables

Problems with syntax of GAMS
Post Reply
ayledith
User
User
Posts: 2
Joined: 2 months ago

Loading 4D Tables

Post by ayledith » 2 months ago

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?

User avatar
Renger
Posts: 406
Joined: 3 years ago

Re: Loading 4D Tables

Post by Renger » 2 months ago

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
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

User avatar
achristensen
User
User
Posts: 14
Joined: 1 month ago

Re: Loading 4D Tables

Post by achristensen » 3 weeks ago

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

Post Reply