Problem with EMP (Stochastic Program)

Problems with modeling
Post Reply
TheRstone
User
User
Posts: 5
Joined: 2 years ago

Problem with EMP (Stochastic Program)

Post by TheRstone »

Hi everyone,

I am still trying to figure out how EMP and Stochastic Programming work together.
Therefore I used the example from the Library https://www.gams.com/35/docs/UG_EMP_SP.html

I added a new set "t" so that the demand varies over time. However, I do not understand (even if I tried several options) how to solve the model with more than one entry in the set "t".
If I solve the model with more than one entry it abords due to the error " Distribution function for variable 10 is not parametric". From my perspective, this is an error connected to the emp.info. In specific this line:

Code: Select all

randvar d normal 45 10
As long as the value ("45") matches the value of the parameter d(t) ("45") everything is fine. Of course in another time period (e.g. t2) i want to have a different demand than 45. But than the error mentioned above pops up. Long story short... How can i implement different values in the EMP (without using LINDO).

I do not know how to solve it :/

Hopefully, someone can help!

This is the full code:

Code: Select all

Set t /t1*t2/
Variable  z      "profit";
Positive Variables
          x(t)   "units bought"
          i(t)   "inventory"
          l(t)   "lost sales"
          s(t)   "units sold";


Scalars   c      "purchase costs per unit"         / 30 /
          p      "penalty shortage cost per unit"  /  5 /
          h      "holding cost per leftover unit"  / 10 /
          v      "revenue per unit sold"           / 60 /

parameter d(t)       Demand
/
t1       45
t2       49
*t3       48
*t4       35
*
/;

Equations profit "profit to be maximized"
          row1   "demand = UnitsSold + LostSales"
          row2   "inventory = UnitsBought - UnitsSold";

profit..         z =e= sum(t, v*s(t) - c*x(t) - h*i(t) - p*l(t));
row1(t)..       d(t) =e= s(t) + l(t);
row2(t)..       i(t) =e= x(t) - s(t);


File emp / '%emp.info%' /;
put emp '* problem %gams.i%'/;
$onput
randvar d normal 45 10
sample d 3
stage 2 i l s d
stage 2 Row1 Row2
$offput
putclose emp;

Set scen           "scenarios" / s1*s3 /;
Parameter
     s_d(scen,t)     "demand realization by scenario"
     s_x(scen,t)     "units bought by scenario"
     s_s(scen,t)     "units sold by scenario"
     s_rep(scen,*) "scenario probability"  / #scen.prob 0 /;

Set dict / scen .scenario.''
           d    .randvar .s_d
           s    .level   .s_s
           x    .level   .s_x
           ''   .opt     .s_rep /;

Model nv / all /;
solve nv max z use EMP scenario dict;
execute_unload "EMP"
I know
Lutz
User
User
Posts: 60
Joined: 7 years ago

Re: Problem with EMP (Stochastic Program)

Post by Lutz »

Hi,

You need to define the distribution for each random variable, like this, for your example:

Code: Select all

File emp / '%emp.info%' /;
put emp '* problem %gams.i%'/;
$onput
randvar d('t1') normal 45 10
randvar d('t2') normal 55 8
sample d 3
stage 2 i l s d
stage 2 Row1 Row2
$offput
putclose emp;
You could also "script" this using put logic to loop over your set `t`. Here is an example where this is done: https://www.gams.com/latest/emplib_ml/l ... laksp.html

Hope that helps,
Lutz
Post Reply