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.

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).

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;

);

this is my code at the attached file to understand my mistake clearly

SSP_tek ürünlü _emp_v2.gms (2.13 KB)

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