index of elements in GAMS Topic is solved

Problems with syntax of GAMS
Post Reply
Bahar_Mdi
User
User
Posts: 21
Joined: 4 years ago

index of elements in GAMS

Post 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 159 times
Last edited by Bahar_Mdi 2 years ago, edited 1 time in total.
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: index of elements in GAMS

Post 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
Bahar_Mdi
User
User
Posts: 21
Joined: 4 years ago

Re: index of elements in GAMS

Post 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.
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: index of elements in GAMS

Post 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
Bahar_Mdi
User
User
Posts: 21
Joined: 4 years ago

Re: index of elements in GAMS

Post by Bahar_Mdi »

Thanks a lot.
Post Reply