Hi,
Suppose I have sets:
set i / 145 /;
set s(i) / 120 /;
set t(i) /31*45 /;
Does anyone know how can I loop over the set ‘t’ by random selection of elements from it?
Thanks.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Hi
This can be done using dynamic sets, but my question is: Why do you want to randomly loop? Why don’t you loop over all sets and then pick a subset of the results randomly?
If you want to solve a model, you probably want to set some of the model parameters randomly and solve for a subset of all the scenarios if it takes too long.
In that case you would first set the parameters randomly for the whole set and then run a subset of the scenarios.
Cheers
Renger
\
Modelworks
Gewerbestrasse 15
3600 Thun – Switzerland
+41 79 818 53 73
Info@modelworks.ch
blog.modelworks.ch
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of visvalley9@gmail.com
Sent: Dienstag, 15. April 2014 18:27
To: gamsworld@googlegroups.com
Subject: Looping over a set randomly.
Hi,
Suppose I have sets:
set i / 1*45 /;
set s(i) / 1*20 /;
set t(i) /31*45 /;
Does anyone know how can I loop over the set ‘t’ by random selection of elements from it?
Thanks.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Hi,
Thanks for your reply. Sorry for not being clear. To be specific, I want to run a loop by randomly selecting only one element from the set ‘t’ and then execute solve.
The final solution depends on the order in which the elements of the set are selected.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Hi Visvalley
Here is some code that runs with one small problem: the random numbers can occur more than once. I would do this in Excel, in which you can draw numbers without putting them back again (see http://www.ozgrid.com/VBA/RandomNumbers.htm), and then import the parameter using gdxxrw. (or another program where you can send the results to gams)
parameter
randomsetelement;
set r /31*45/;
*h do this in Excel
randomsetelement(r) = uniformInt(31,45);
parameter count;
loop(r,
loop(i$(ord(i) = randomsetelement(r)),
count = randomsetelement(r);
display count;
… solve your model
););
Renger
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of visvalley9@gmail.com
Sent: Mittwoch, 16. April 2014 18:26
To: gamsworld@googlegroups.com
Subject: Re: Looping over a set randomly.
Hi,
Thanks for your reply. Sorry for not being clear. To be specific, I want to run a loop by randomly selecting only one element from the set ‘t’ and then execute solve.
The final solution depends on the order in which the elements of the set are selected.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
–
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.