read multidim sets from Excel

Problems with syntax of GAMS
Post Reply
Flo
User
User
Posts: 1
Joined: 4 years ago

read multidim sets from Excel

Post by Flo »

Hi all,
would be great to get your help. I have three sets and want to import them from Excel without assigning values. I found ways to import n and u, but this multidimensional nu seems problematic.

ExcelTab (columns A and B)
n1; u1
n1;u2
n2;u3
n2;u4
...

sets
n Node
u Unit
nu NodeUnit

Perfect would be something like:
$Onecho > task.txt
Set=nu rng=ExcelTab!A1 rdim=1
$Offecho
$call GDXXRW ... @task.txt

At the end, I need the set nu(n,u)
/n1.u1
n1.u2
n2.u3
.../
Fred
Posts: 372
Joined: 7 years ago

Re: read multidim sets from Excel

Post by Fred »

Hi,

To read a 2 dimensional set in the described format from Excel you need rdim=2 cdim=0 (see https://www.gams.com/latest/docs/T_GDXXRW.html).

Assuming your data is stored in x.xlsx, the following example should do the trick (it also shows how to get sets n and u out of nu if you don't want to read them separately).

Code: Select all

set n,u,nu(n,u);
$call gdxxrw x.xlsx Set=nu rng=ExcelTab!A1 rdim=2 cdim=0
$ife errorlevel<>0 $abort 'problem with gdxxrw'
$gdxin x.gdx
$load n<nu.dim1 u<nu.dim2 nu

display n,u,nu;
I hope this helps!

Best,
Fred
Post Reply