Multiple run of Stochastic programming emp extension Topic is solved

questions about GAMS' tools
Post Reply
karacat
User
User
Posts: 6
Joined: 1 year ago

Multiple run of Stochastic programming emp extension

Post by karacat » 1 year ago

I try to solve a two stage stochastic programming and ı adjust demand randvar as poisson distribution with 100 scenario to obtain 100 random demand values according to poisson distribution. but I want to do 100 run to apply sample avarage approximation method (SAA) to this problem. I wrote "while loop" for solve statement to solve the problem multiple times to have converged solution. Gams solves problem multiple times but in every solution demand scenarios don't change and solutions stay same in every run. How can ı overcome this problem. Thank you for your help.

abhosekar
Moderator
Moderator
Posts: 232
Joined: 1 year ago

Re: Multiple run of Stochastic programming emp extension

Post by abhosekar » 1 year ago

Inside your while loop, you have to tell GAMS which scenario you want to solve. I assume demand (let's say d) is a parameter you are using in your formuation. You also have a parameter containing demands for all scenarios (let's say demands(sc)) where sc is the set of scenarios. You can loop over the set of scenarios, and inside the loop you have to set d = demands(sc).

karacat
User
User
Posts: 6
Joined: 1 year ago

Re: Multiple run of Stochastic programming emp extension

Post by karacat » 1 year ago

Thank you for your help. Could you please help me to understand where ı should add your suggestion in my code "d" is random var demand

file emp / '%emp.info%' /;
put emp '* problem %gams.i%'/;
$onput
randvar d poisson 10
stage 2 In Ls d
stage 2 cons2
$offput
putclose emp;

Set scen Scenarios / s1*s100 /;
Parameter
s_d(scen) Demand realization by scenario
s_In(scen) Units overproduction by scenario
s_Ls(scen) "units underproduction by scenario"
s_rep(scen,*) "scenario probability" / #scen.prob 0/;

Set dict / scen .scenario.''
d .randvar .s_d
In .level .s_In
Ls .level .s_Ls
'' .opt .s_rep
/;



option emp = lindo;
$echo STOC_NSAMPLE_STAGE = 100 > lindo.opt
SSP1.optfile = 1;


while (rpl le 10000,
solve SSP1 min z use emp scenario dict;
rpl=rpl+1;
Display s_d, s_In, s_Ls, s_rep,x.l,y.l,r.l,z.l;
);

karacat
User
User
Posts: 6
Joined: 1 year ago

Re: Multiple run of Stochastic programming emp extension

Post by karacat » 1 year ago

this is my code at the attached file to understand my mistake clearly
SSP_tek ürünlü _emp_v2.gms
(2.13 KiB) Downloaded 141 times

abhosekar
Moderator
Moderator
Posts: 232
Joined: 1 year ago

Re: Multiple run of Stochastic programming emp extension

Post by abhosekar » 1 year ago

It looks like the problem here is that after sampling random variable, you are interested in using it for your own solving strategy. However, you are finding it difficult to access the samples before solving.

One way to do this by separating sampling and solving. Please take a look at the relevant section in the documentation: https://www.gams.com/32/docs/UG_EMP_SP.html

- Atharv

Post Reply