Page 1 of 1

How to use loop to run model several times when some random data is being imported from excel.

Posted: Thu May 09, 2019 1:02 am
by mbh
Hi All,
I import some random data from excel into GAMS. So every time that I run the model the results change because the random numbers change. I'd like to use a loop to rum the model several times by that loop rather than running manually. I would appreciate it if anyone can help me. Sorry if the question is very basic.

Best,
Mary

Re: How to use loop to run model several times when some random data is being imported from excel.

Posted: Thu May 09, 2019 8:35 am
by Renger
Hi
If you want, for example, loop over 10 sets of random data, you could define your data indexed over your loop and read all of them before the loop.

Code: Select all

set 
	iteration /1*10/,
	sectors   /s1*s20/;

parameter randSectors(sectors, iteration) Random data for sectors;

** Pseudo code
* Read your data from Excel organized in a two-dimensional table (sectors * iteration)
**
loop(iteration,
      randData(sectors) = randSectors(sectors, iteration);
      solve mymodel
end;
      
Hope this helps!
Cheers
Renger

Re: How to use loop to run model several times when some random data is being imported from excel.

Posted: Thu May 09, 2019 1:07 pm
by mbh
Hi Renger,
Thank you very much for your help.

Best,
Mary