Page 1 of 1

index of elements in GAMS

Posted: Fri Jun 18, 2021 2:18 am
by Bahar_Mdi
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 ;
$load 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
(397 Bytes) Downloaded 173 times

Re: index of elements in GAMS

Posted: Mon Jul 12, 2021 9:37 pm
by GFA
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

Re: index of elements in GAMS

Posted: Mon Jul 12, 2021 10:57 pm
by Bahar_Mdi
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.

Re: index of elements in GAMS

Posted: Tue Jul 13, 2021 10:52 pm
by GFA
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

And in your GAMS-code include:

Code: Select all

set setord /
$include txtfile.txt
/;

$GDXIN
....
Cheers,
GFA

Re: index of elements in GAMS

Posted: Wed Jul 14, 2021 12:44 am
by Bahar_Mdi
Thanks a lot.