Hello,

I’m working on optimiziation of power system using GAMS interfaced with MATLAB. To come up with a generalized code which will work for any size of power system I want to send the set including size of the system (i.e., 33 bus system, 123 nodes system etc) from MATLAB to GAMS. I’ve found that this can be done using GDX files. In my GAMS code I need to define sets having value as “bus1,bus2,bus3,…,bus33”. If I create that string in MATLAB and export that as the structure value using the following code:

Is.name = ‘bi’;

Is.val = M; %M is the string containing bus1,bus2,bus3,…,bus33

Is.type = ‘set’;

wgdx(‘tstdat’, Is);

then it gives an error that “Input structure field .val must be double matrix”.

Then I changed that string and decided to use a vector 1:33 for the set value such as

M=1:33;

then it gives the error

“Input arg exceeds GDX dimension limit of 20”

But I have systems which can be very large, like 123 nodes, 500 nodes, 3000 nodes etc. How can I resolve this problem so that I can pass the vectors or string arrays of any size.

Thank you.

If you want to pass the number of buses as a string, you should not use GDX for that. Instead, just pass the string to gams as an argument. If you have this GAMS source in, say, power.gms:

```
* check that NBUS is set: if not, terminate with error
$if not set NBUS $abort 'NBUS must be set'
set bi / bus1 * bus%NBUS% /;
```

then run GAMS like this: gams power.gms --NBUS=30

But this isn’t really so helpful. You have to also pass the problem data that changes with the number of buses, so building a set bus1 * bus30 in GDX is just the start. I thought there was a nice Matlab technique to do what you’re looking for, and I found it by checking the GAMS docs for wgdx. They are available here:

https://www.gams.com/latest/docs/T_GDXMRW.html?search=wgdx

Here’s some Matlab code, showing two different ways to produce the data for the set:

```
s.name = 'bi';
s.uels = {'bus1', 'bus2', 'bus3'};
s.ts = 'bus data from Matlab';
guel = @(s,v) strcat(s,strsplit(num2str(v)));
t.name = 'bi2';
t.uels = {guel('bus',1:30)};
t.ts = 'more bus data from Matlab';
wgdx('busdata', s, t)
```

HTH,

-Steve