# How to pass the values of a variable of the first model to a parameter of the second model?

I am working on a scheduling problem which is NP-hard problem. Therefore, I decided to implement two-stage strategy to speed up the solution process. I need to pass the values of a variable from the first stage to a parameter in the second stage. I visited this link to do so. But it returned to me the error of dimension different. I appreciate any suggestion.

The variable R(t,l) has to pass its values to the parameter RR(t,l).

Since the model is very large, I am going to bring two simple models that are not real models:

Sets

T     SET OF TIME POINTS   /T1*T15/
L     INPUT NODES   /L1*L2/
I     BATCHES      /I1*I7/
;

parameter  RR(t,l)   It is going to be replaced by the vriable R of the first stage model  ;

POSITIVE VARIABLES

R(T,L)    THE VOLUME OF BATCH I INJECTED FROM INPUT S DURING RUN T
RP(T,L)   THE VOLUME P IN BATCH I INJECTED FROM INPUT L DURING RUN T
VD(T,L)   THE VOLUME OF BATCH I DIVERTED TO OUTPUT D DURING TIMESLOT T
SD(I)        THE VOLUME OF I DELIVERED FROM PART L-1 TO L DURING T

;

VARIABLES COST;

EQUATIONS
OBJ1
OBJ2
eq1
eq2
eq3
;

obj1 ..  R('t1','l1') =e=cost;
obj2 ..  R('t1','l1') =e=cost;
eq1 (t,l)..  VD(t,l)=e=7;

eq2 (i)     ..  SD(i)=e= 8;
eq3 (t,l)..   RR(t,l)*RP(t,l)=e=5;

OPTION LIMROW=500;
OPTION LIMCOL=100;
OPTION OPTCR=1E-3;
OPTION RESLIM=7200;
OPTION ITERLIM=90000000;
OPTION MIP=CPLEX;

MODEL AMIRPIP /OBJ1,eq1/
AMIR /OBJ2,eq2,eq3/;
SOLVE AMIRPIP USING MIP MINIMIZING cost;

RR(t,l)=VD.l;
SOLVE AMIR USING MIP MINIMIZING cost;


First of all, I assume that the mentioned model is just to reflect what you want to do otherwise, it needs more attention as the problem is infeasible. To capture a variable value and store that into a parameter, the following should work:

RR(T,L) = R.L(T,L);
DISPLAY RR;


Also, the value of $$R_{t,l}$$ from the first model is equal to zero. Since the parameter is already equal to zero.

----     24 VARIABLE R.L  THE VOLUME OF BATCH I INJECTED FROM INPUT S DURING RUN
T

( ALL       0.000 )
----     27 PARAMETER RR  It is going to be replaced by the vriable R of the fir
st stage model

( ALL       0.000 )


However, you can change the $$solve$$ section somewhat for better readability.

EQUATIONS OBJ1, OBJ2, eq1, eq2, eq3
;
obj1..      R('t1','l1') =e= cost;
eq1(t,l)..  VD(t,l) =e= 7;
;
MODEL AMIRPIP /OBJ1, eq1/;
SOLVE AMIRPIP USING MIP MINIMIZING cost;
DISPLAY COST.L, R.L, VD.L;
;
RR(T,L) = R.L(T,L);
DISPLAY RR;
;
obj2..      R('t1','l1') =e= cost;
eq2 (i)..   SD(i) =e= 8;
eq3 (t,l).. RR(t,l)*RP(t,l) =L= 5;
;
MODEL AMIR    /OBJ2, eq2, eq3/;
SOLVE AMIR USING MIP MINIMIZING cost;
DISPLAY COST.L, R.L, VD.L, SD.L, RP.L;

• Thanks a lot for your answer. Do I need to use solveopt in order to prevent the shared variables of the second model from inheriting the values from the first model? Feb 25 at 14:32
• @Baghban, The solveopt as you already know is for solver/GAMS options. AFAIK, interaction between the model structure, like parameters or variables, comes from your formulation and is not related to the solver options. Feb 25 at 14:38