# How to initialize a parameter (belonging to the first stage model) in a two stage model, taking its value from second stage model?

I am working on a two stage approach in order to reduce the complexity of a scheduling model which is an NP-hard problem. I have to implement a while loop in order to repeat solving the models in case the solution achieved from the second stage model is not feasible for the first stage model.

The problem is that I need to use a parameter whose value realizes after solving the second stage model (that shows whether the solution of the second stage model is feasible for the first stage model or not). Therefore, I have to initialize the first stage model within which I have to use this parameter.

The hardness is where that the parameter is multi-dimensional, preventing me from initializing it by my own. This parameter is SD(i,d,l,t). Moreover, I have to pass the values of the first stage variables into the parameters of the second stage model. It is like being stuck in an unsolvable loop :)

Here is a simplified scheme:

Parameter SD(i,t,d,l);

While (conditional statement,

*****Initialize SD(i,t,d,l) from the second stage model*****
if( SD(i,t,d,l) GT 0,

****Add cut EQ to the first stage model and solve it****
MODEL First /OBJ1,EQ/;
SOLVE First USING MIP MINIMIZING cost;
);

else (
****Add cut EQ' to the first stage model and solve it****
MODEL First /OBJ1,EQ'/;
SOLVE First USING MIP MINIMIZING cost;
);

**** Form the second stage model  ****
Model Second /OBJ2,eq1, eq3,.../;
SOLVE Second USING MIP MINIMIZING cost;

);

• @A.Omidi Hi, may I ask you to solve this question? Mar 2 at 9:01
• Unfortunately, I do not have much experience with stochastic programming, but just as a point, what actually is the difference between both solve statements for the first stage? They seem to be the same! Mar 2 at 13:55
• One has EQ as its constraint and the other has EQ' together other constraints same as the other if statement. Mar 2 at 14:26
• Models and equations are declarative in GAMS, and they have to be before the loop. Parameters used in the model can be populated afterwards (inside the loop). Mar 2 at 15:24
• @ErwinKalvelagen Thanks a lot for your attention. To be honest, I can not understand the terms being declarative and being populated afterwards. Could you please explain more? Mar 2 at 19:58