MODEL:                                         !(SP_NBsimpleL.lng);
 ! Newsvendor problem as a stochastic program in LINGO.
   How much should we stock, Q,  
   in anticipation of uncertain DEMAND? 
  Parameters:
    10 = cost/unit purchased and stocked,
    15 = revenue/unit sold;
! Keywords:  Newsboy problem, Newsvendor, Stochastic optimization;

! Step 1: Core model definition--------------------------------+;
   [R_OBJ] MAX = PROFIT;
   ! (Expected) Profit = 
       sales - purchase cost;
   PROFIT = 15 * SALES - 10 * Q;
   @FREE( PROFIT);  ! Allow negative PROFIT because
                     might have a loss in some scenarios;

   ! Set excess inventory or shortage = quantity stocked - demand;
   EXCESS - SHORT = Q - DEMAND; 
   SALES = DEMAND - SHORT;  

! SP related declarations --------------------------------------+;
! Step 2: staging info;
   @SPSTGVAR( 0, Q); ! Amount to purchase, Q, is a stage 0 decision;
   @SPSTGRNDV( 1, DEMAND); ! Demand is a random variable observed
                              in stage 1, at the beginning;

! Step 3: Distribution info;
   @SPDISTPOIS( 60, DEMAND); ! Demand has a Poisson distribution; 
  ! @SPDISTNORM( 60, 12, DEMAND); 
! Step 4: Sampling structure;
   @SPSAMPSIZE( 1, 200);  ! Specify the stage 1 sample size;
END