Shuffling an array in GAMS

Hi Dear All;

I want to shuffle randomly an array’s ingredients, (e.g. A=[1 2 3 … 999 1000] =shuffle=> A=[534 876 761 902 75 … 310 599].

Is there any basic & fast way to do this in GAMS?

Bekir


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/jC1ElVVQ-q4J.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Hello,

something like:
scalar temp;
scalar new_position;
loop(n,
new_position = uniform_int(1,card(n));
temp = a(n);
a(n) = a(n1$ord(n1) == new_position);
a(n1$ord(n1) == new_position) = temp;
);

though this is untested and might need some work :wink:
Am Samstag, 14. Juli 2012 15:33:26 UTC+2 schrieb Bekir Sait Ciftler:

Hi Dear All;

I want to shuffle randomly an array’s ingredients, (e.g. A=[1 2 3 … 999 1000] =shuffle=> A=[534 876 761 902 75 … 310 599].

Is there any basic & fast way to do this in GAMS?

Bekir


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/7aPGkZp2J8QJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Thank you Johannes :slight_smile: I think it works!

24 Temmuz 2012 Salı 12:46:59 UTC+3 tarihinde Johannes Hedtrich yazdı:

Hello,

something like:
scalar temp;
scalar new_position;
loop(n,
new_position = uniform_int(1,card(n));
temp = a(n);
a(n) = a(n1$ord(n1) == new_position);
a(n1$ord(n1) == new_position) = temp;
);

though this is untested and might need some work :wink:
Am Samstag, 14. Juli 2012 15:33:26 UTC+2 schrieb Bekir Sait Ciftler:

Hi Dear All;

I want to shuffle randomly an array’s ingredients, (e.g. A=[1 2 3 … 999 1000] =shuffle=> A=[534 876 761 902 75 … 310 599].

Is there any basic & fast way to do this in GAMS?

Bekir


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/I_lywtiDpB4J.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.