Search code examples
variablesgams-math

Passing a variable as a parameter for a new model in GAMS


I'm writing a program where I have two mathematical models that are solved sequentially in a way that the variable X7(f,p) from the first model becomes the parameter rwdemand(f,p) to the second.

Main code elements for the issue described above:

Sets
f  raw materials                 /f1*f14/
p  periods                       /p1*p4/;

Positive Variable    X7(f,p)    quantity of raw material f required in period p;

Equation
*First model
 r6_rwinventory(f,p).. X4(f,p-1) + X7(f,p-leadtime)=e= sum((t,m,sp),((rmconsumption(f,t,m)*X1(t,m,sp))+X4(f,p)));

 Parameter rmdemand(f,p);
           rmdemand(f,p)= X7.l;

 Equation
 *Second model
 r3_demand(f,p).. X4(f,p-1) + sum((s,d),X2(f,s,d,p-leadtime)) =e= rmdemand(f,p) + X4(f,p);

 Model First_model "real instance set for Lot sizing model (SMM-LS)." /fo,r1_produnits,r2_packsetup,r3_bulkinventory,r4_packinventory,r5_maxbulkinventory,r6_rwinventory,r7_usedinventory1/
       Second_model "real instance set for Raw material purchasing model (SMM-RMP)" /fo2,r1_maxd,r2_order,r3_demand,r4_maxinventory,r5_mininventory/;
 Solve First_model using mip minimizing Z
 Solve Second_model using mip minimizing A;
 Display Z.l,A.l;

Writing this way:

Parameter rmdemand(f,p);
          rmdemand(f,p)= X7.l;

It doesn't work and appears the error 141: Symbol declared but no values have been assigned. Check for missing data definition, assignment, data loading or implicit assignment via a solve statement.

How can I fix that?

Regards!


Solution

  • Ana! You can only use X7.l to obtain a value after you have solved the first model. So, I believe this might work:

    (...)
    Equation
    *First model
     r6_rwinventory(f,p).. X4(f,p-1) + X7(f,p-leadtime)=e= sum((t,m,sp),((rmconsumption(f,t,m)*X1(t,m,sp))+X4(f,p)));
    
     Parameter rmdemand(f,p);
     Equation
     *Second model
     r3_demand(f,p).. X4(f,p-1) + sum((s,d),X2(f,s,d,p-leadtime)) =e= rmdemand(f,p) + X4(f,p);
    
     Model First_model "real instance set for Lot sizing model (SMM-LS)." /fo,r1_produnits,r2_packsetup,r3_bulkinventory,r4_packinventory,r5_maxbulkinventory,r6_rwinventory,r7_usedinventory1/
           Second_model "real instance set for Raw material purchasing model (SMM-RMP)" /fo2,r1_maxd,r2_order,r3_demand,r4_maxinventory,r5_mininventory/;
     Solve First_model using mip minimizing Z;
    
    *Insert the attribution of value between the two solve statements
     rmdemand(f,p)= X7.l;
    
     Solve Second_model using mip minimizing A;
     Display Z.l,A.l;
    

    Hope it works :)