I will use an example from the GAMS documentation for clarification (see below).
The parameter s_rep is used to store the probability for each scenario with the header “prob” and as a default its value is zero (if i understood that code bit correctly):
Set scen "scenarios" / s1*s3 /;
Parameter
s_d(scen) "demand realization by scenario"
s_x(scen) "units bought by scenario"
s_s(scen) "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 /;
However how does the syntax change if i have a 3D parameter instead of 2D e.g.
Set scen "scenarios" / s1*s3 /
wo "worlds" /w1*w10/;
Parameter
s_d(scen,wo) "demand realization by scenario"
s_x(scen,wo) "units bought by scenario"
s_s(scen,wo) "units sold by scenario"
s_rep(scen,wo,*) "scenario probability" / #????/;
Set dict / scen .scenario.''
d .randvar .s_d
s .level .s_s
x .level .s_x
'' .opt .s_rep /;
The syntax # just puts the elements of the specified set into the input at that point. Since you want a 3-D set, you need a 3-tuple to initialize set elements. You can do it like this:
Sets
scen "scenarios" / s1*s3 /
wo "worlds" / w1*w4 /;
Parameter
s2(scen,*) "scenario probability" / #scen.prob 0/
stuff(scen,wo,*) 'not a probability' / #scen.#wo.prob 2.5 /
;
display s2, stuff;
[/code
This is just a shorthand way of defining data within a declaration that avoids having to list each tuple separately, like:
parameter foo (scen,wo,*) /
s1.w1.prob 1.5
s1.w2.prob 1.5
s1.w3.prob 1.5
*etc etc
s3.w4.prob 1.5
/;
HTH,
-Steve
Your solution was also my first try but if i put the whole dictionary in some modelling context got a mismatch error (790 -dimension mismatch).
Is there something i do overlook?
Set wo /w1*w9/
Variable z "profit";
Positive Variables
x(wo) "units bought"
i(wo) "inventory"
l(wo) "lost sales"
s(wo) "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(wo) Reaktanz der Leitung l
/
w1 45
w2 49
w3 48
w4 35
w5 39
w6 44
w7 51
w8 39
w9 36
/;
Equations profit "profit to be maximized"
row1 "demand = UnitsSold + LostSales"
row2 "inventory = UnitsBought - UnitsSold";
profit.. z =e= sum(wo, v*s(wo) - c*x(wo) - h*i(wo) - p*l(wo));
row1(wo).. d(wo) =e= s(wo) + l(wo);
row2(wo).. i(wo) =e= x(wo) - s(wo);
$funclibin msllib lsadclib
Function setSeed / msllib.setSeed /
sampleNormal / msllib.sampleLSNormal /
getSampleValues / msllib.getSampleValues /;
parameter k(wo);
k(wo) = sampleNormal(d(wo),10,9);
Set g /1*9/; parameter sv1(g,wo);
loop(g,
sv1(g,wo) = getSampleValues(k(wo));
);
File emp / '%emp.info%' /;
put emp;
put 'randvar d discrete '; loop((g,wo), put (1/card(g)) ' ' sv1(g,wo) ' ');
$onput
stage 2 i(wo) l(wo) s(wo) d(wo)
stage 2 row1(wo) row2(wo)
$offput
putclose emp;
Set scen "scenarios" / s1*s3 /;
Parameter
s_d(scen,wo) "demand realization by scenario"
s_x(scen,wo) "units bought by scenario"
s_s(scen,wo) "units sold by scenario"
s_rep(scen,wo,*) "scenario probability" / #scen.#wo.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;
The srep parameter always depends on the scenarios only. It gives information about the scenarios (e.g. it’s probability) Why drag in set wo? So just change to
Moreover, your EMP syntax is wrong. You can either move an entire block of variables/equations to a stage or need to use individual variable/equation records:
$onput
stage 2 i l s d
stage 2 row1 row2
$offput
The running code is attached. Not sure if that’s what you want to do, but it solves okay.