## index of elements in GAMS Topic is solved

Problems with syntax of GAMS
Bahar_Mdi
User
Posts: 21
Joined: 1 year ago

### index of elements in GAMS

Hi,

I have a set in MATLAB that I want to export it to GAMS and the order of elements in the set is important to me. As I know, the order that I define the set for the first time is the order that is defined for GAMS.
As an example, I have the below code in MATLAB:
Is.name='i';
Is.type='set';
Is.val=[3;2;1];
Is.dim=1;
wgdx('data',Is)

And the following code is in GAMS:
\$GDXIN 'data'
Sets
i ;
\$GDXIN

display i;

but the output for i is 1,2,3. but I want the order be 3,2,1.
the gdx file is attached.
data.gdx
Last edited by Bahar_Mdi 1 month ago, edited 1 time in total.

GFA
User
Posts: 26
Joined: 3 years ago

### Re: index of elements in GAMS

Hi,

At the start of your GAMS-code you could define a set that orders set elements (eg "set setord /3,2,1/;), this way every time these set-elements will be presented they will be ordered this way.
Downside is that you have to update this setord-list if your set-elements change..

Cheers,
GFA

Bahar_Mdi
User
Posts: 21
Joined: 1 year ago

### Re: index of elements in GAMS

Thans for your response. But I can not do your approach because the order of elements in the set may change during each iteration of my algorithm.

GFA
User
Posts: 26
Joined: 3 years ago

### Re: index of elements in GAMS

I assume you mean your algorithm in Matlab? I'm sure Matlab has some functionality to write .txt-files in which you could put the right set order after the algorithm is finished. Then you can include that file in your GAMS code to use this set order.

So Matlab txt-file contains for example:
3,2,1

Code: Select all

``````set setord /
\$include txtfile.txt
/;

\$GDXIN
....
``````
Cheers,
GFA

Bahar_Mdi
User
Posts: 21
Joined: 1 year ago

Thanks a lot.