Lindo Systems

MODEL: !                                      (SPCapPlan.LNG0;

! Capacity Planning with Random Demand 
! Get input from, and send results to an open spreadsheet,
  see for example, spreadsheet, SPCapPlan.xlx.
Stage 0:  We decide what capacities to install 
          at four places(technologies, e.g. coal,
          gas, wind, nuclear).						
Stage 1, Beginning:
           Demands at three locations are revealed,						
Stage 1, End: 
           We satisfy demand at minimum cost 
          (by solving a transportation problem).

Optimal Obj = 381.8533;
! Keywords:  @OLE, Capacity planning, EVPI, Excel, LINGO, Recourse, 
    Scenario planning, Sequential decisions, Spreadsheet interface, 
    Stochastic programming, Transportation model, Uncertainty;

! Ref: Birge & Louveaux, Sec. 1.3;

! Core Model ---------------------------------------+;

SETS:
   TECHNOLOGY: COSTPU, COSTOP, X;
   DPOINT: TRANCOST, DEMAND;
   TXD( TECHNOLOGY, DPOINT): Y;

   ! The possible outcomes table;
   OUTCOMES: WGT;
   OXD( OUTCOMES, DPOINT): O_DEMAND;
ENDSETS

DATA:
   TECHNOLOGY, DPOINT, TRANCOST, COSTPU, COSTOP,
! Read the Budget amount from the range named BUDGET in only open spreadsheet;
    BUDGET = @OLE();
! Read the probability weights and demands from same spreadsheet;
   WGT, O_DEMAND = @OLE(, 'WGT', 'DEMAND');
ENDDATA

SUBMODEL MOD1:
! Budget constraint. Cost of installed capacity 
   <= budget;
 [R_BUDGET] 
   @SUM( TECHNOLOGY(i): COSTPU(i)* X(i)) <= BUDGET;

! Capacity constraints;
 @FOR( TECHNOLOGY(i): [R_CAP]
  ! Amount shipped out of i <= installed capacity;
   @SUM( DPOINT( j): Y(i,j)) <= X(i)
 );

! Demand constraints;
 @FOR( DPOINT(j): [R_DEM]
  ! Amount shipped to j must meet demand;
   @SUM( TECHNOLOGY( i): Y(i,j)) = DEMAND(j)
);

! Minimize total costs;
 [R_OBJ] MIN = @SUM( TECHNOLOGY(i): COSTPU(i)* X(i)) + 
  @SUM( TECHNOLOGY(i):
     @SUM( DPOINT(j): COSTOP(i)* TRANCOST(j)* Y(i,j)
  )
);

! SP (Scenario Planning) Declarations ----------------------------------+;

! The recourse/stochastic variables, are in stage 0;
 @FOR( TECHNOLOGY( i): @SPSTGVAR( 0, X( i)));

! Demand is a random variable, stage 1;
 @FOR( DPOINT( i): @SPSTGRNDV( 1, DEMAND( i)));

! Declare the distributions and their random variables.
   Demand is drawn randomly from the O_DEMAND table, with Probilities WGT;
 @SPDISTTABLE( O_DEMAND, DEMAND, WGT);
ENDSUBMODEL

! Reporting ----------------------------------------+;
 CALC:
   !Solve model;
   @SOLVE( MOD1);

   !Output installed capacity to the only open spreadsheet
    into range named X;
   @OLE(, 'X') = X;

   !Loop over the outcomes, to send shipments by scenario
     to only open spreadsheet;
   @FOR( OUTCOMES( I):
      @SPLOADSCENE( I);!Load scenario I;
      @OLE( , 'SHIP' + OUTCOMES( I)) = Y;
   );
 ENDCALC

END