gen2s.gms : Two stage stochastic program in the generic form

Description

Solves a two-stage stochastic linear program of the form:
min c'x + E[Q(x,s)] s.t. Ax = b, x >= 0, where
Q(x,s) = min q(s)'y(s) s.t. Wy(s) >= h(s) - T(s)x, y >= 0;

Data is from Dr. Janos Mayer from Univ of Zurich, documented in the paper: A
simulation-based approach to two-stage stochastic programming with recourse by
Alexander Sharpiro and Tito Homem-de-Mello, 1998.

In the given data, h is a normal vector with mean h_avg and standard devication
h_stddev.

The model is solved by the LINDO solver. The command-line parameter NSCEN is
used to set the number of samples to be generated by the solver.

Contributor: Yanchao Liu, January 2012.

  Can only be solved with Lindo


Small Model of Type : SP


Category : GAMS EMP library


Main file : gen2s.gms

$title Two stage stochastic program in the generic form (GEN2S,SEQ=91)

$ontext
Solves a two-stage stochastic linear program of the form:
min c'x + E[Q(x,s)] s.t. Ax = b, x >= 0, where
Q(x,s) = min q(s)'y(s) s.t. Wy(s) >= h(s) - T(s)x, y >= 0;

Data is from Dr. Janos Mayer from Univ of Zurich, documented in the paper: A
simulation-based approach to two-stage stochastic programming with recourse by
Alexander Sharpiro and Tito Homem-de-Mello, 1998.

In the given data, h is a normal vector with mean h_avg and standard devication
h_stddev.

The model is solved by the LINDO solver. The command-line parameter NSCEN is
used to set the number of samples to be generated by the solver.

Contributor: Yanchao Liu, January 2012.
$offtext

* Can only be solved with Lindo
$ifi not %GAMS.emp%==lindo $exit

$if not set NSCEN  $set NSCEN  100

Sets N1R Index of rows in first stage  / i1 *  i5 /
     N1C Index of cols in first stage  / j1 * j10 /
     N2R Index of rows in second stage / ii1*ii10 /
     N2C Index of cols in second stage / jj1*jj15 /;

Table FirstStageData(*,*)
          j1      j2      j3      j4      j5      j6      j7      j8      j9      j10     b
c         0.73    -2.16   -0.31   9.00    -5.33   4.30    5.80    6.17    -0.09   2.65
i1        0       -4.19   0       0       0       4.12    0       0       -3.53   0       -1.24
i2        -0.34   -1.88   0       0       0       0       -1.32   0       0       -4.54   -2.79
i3        0       3.04    8.34    3.41    -7.90   0       0       6.45    0       9.80    -8.00
i4        0       0       -9.97   0       0       0       5.26    0       0       -0.89   -1.94
i5        0       -0.92   0       6.57    0       0       2.05    0       2.17    -2.31   2.61;

Parameters
     A(N1R,N1C), c(N1C), b(N1R);

A(N1R,N1C) = FirstStageData(N1R,N1C);
c(N1C)     = FirstStageData('c',N1C);
b(N1R)     = FirstStageData(N1R,'b');

Table SecondStageData(*,*)
         jj1     jj2     jj3     jj4     jj5     jj6     jj7     jj8     jj9     jj10     jj11     jj12     jj13     jj14     jj15    h_avg  h_stddev
q        0       0       4.80    5.99    9.46    7.01    0       6.46    2.88    0        0        4.95     0        0        1.29
ii1      0       0       0       0       0       -2.3    0       0       0.18    -6.37    8.49     0        -18.45   0        0       -3.88  0.15
ii2      0       0       0       4.36    0        0      5.31    0       0       0        8.96     0        0        0        0       1.12   0.01
ii3      0       9.17    0        0      0        0      0       0       0       0        3.45     -6.02    0        0        -6.6    -4.63  0.21
ii4      -0.07   5.48    0        0      -1.6     5.38   0       -2.74   -5.49   -3.05    0        0.29     0        1.8      0       5.04   0.25
ii5      0        0      0        0      0        2.96   2.15    0       -7.52   0        2.41     0        0        0        0       2.05   0.04
ii6      0        0      7.93     9.69   0        0      1.65    0       -8.92   0        -10.36   0        0        0        0       5.19   0.27
ii7      0        0      -7.41    0      0        0      0       0       0       0        0        7.41     0        0        0       -5.53  0.31
ii8      0        -7.35  0        5.35   0        0      0       0       0       0        2.69     -0.69    0        0        0       3.80   0.14
ii9      0        0      0        0      0        0      -5.73   -2.58   0       0        0        5.27     3.05     0        0       1.81   0.03
ii10     0        0      0        0      7.43     3.74   2.09    0       8.96    -5.88    0        0        -16.36   0        0       -9.29  0.86;

Parameters
    q(N2C), W(N2R,N2C), h_avg(N2R), h_stddev(N2R), h(N2R);

W(N2R,N2C)    = SecondStageData(N2R,N2C);
q(N2C)        = SecondStageData('q',N2C);
h_avg(N2R)    = SecondStageData(N2R,'h_avg');
h_stddev(N2R) = SecondStageData(N2R,'h_stddev');
h(N2R)        = h_avg(N2R);

table T(N2R,N1C)
         j1      j2      j3      j4      j5      j6      j7      j8      j9      j10
ii1      -8.42   0       0       0       0       0       6.91    0       -2.07   0
ii2      -5.23   0       0       0       0       0       0       0       0       0
ii3      -2.14   0       0       0       1.16    0       0       0       0       0
ii4      1.19    0       0       0       0       0       0       -6.05   0       -4.82
ii5      0       0       5.48    0       0       0       0       -4.75   0       0
ii6      2.38    0       2.90    0       0       -0.88   0       0       0       0
ii7      0       0       0       0       0       0       0       1.04    0       0
ii8      2.61    0       0       -0.91   0       0       0       0       -4.93   0
ii9      -5.79   0       0       0       0       0       0       0       9.60    0
ii10     -2.64   0       0       0       0       0       0       0       0       0;

Positive variable x(N1C), y(N2C);
Variable z1, z2;

Equations
     o1      first stage objective
     c1(N1R) fist stage constraints
     o2      second stage objective
     c2(N2R) second stage constraints;

o1..      z1 =e= sum(N1C, c(N1C)*x(N1C)) + z2;
c1(N1R).. sum(N1C, A(N1R,N1C)*x(N1C)) =e= b(N1R);
o2..      z2 =e= sum(N2C,q(N2C)*y(N2C));
c2(N2R).. sum(N2C,W(N2R,N2C)*y(N2C)) =g= h(N2R) - sum(N1C, T(N2R,N1C)*x(N1C));

model gen2 /all/;

*solve gen2 min z1 using lp;

file emp / '%emp.info%' /;
put emp 'stage 2 z2 y h o2 c2';
loop(N2R, put / 'randvar ' h.tn(N2R) ' normal ' h_avg(N2R) ' ' h_stddev(N2R));
putclose;

Set  s scenarios / s1*s%NSCEN% /
Parameter
     s_h(s,N2R) random variable realization
     s_y(s,N2C) level of y by scenario
     s_z2(s)    z2 by scenario;

Set  dict / s.  scenario.''
            h.  randvar. s_h
            y.  level.   s_y
            z2. level.   s_z2 /;

$ifi not %GAMS.emp%==lindo $goto contsolve
$echo STOC_NSAMPLE_STAGE=%NSCEN% > lindo.opt
gen2.optfile = 1;

$label contsolve
solve gen2 min z1 using emp scenario dict;

display s_h, s_y, s_z2, x.l;