Stochastic Programming

LINGO 12.0 introduced a stochastic programming solver (SP) for multistage stochastic programs with recourse.  Details may be found in Chapter 14, Stochastic Programming.  Some additional programming features were also added for use with SP models.  These additional programming features are discussed below.

@SPLOADSCENE( SCENARIO_INDEX)

This function loads the solution for scenario index SCENARIO_INDEX. The solution for this scenario then becomes the current/active solution.  As an example, the following would load the solution for scenario 1:

@SPLOADSCENE( 1);

Suppose you have an SP model with an objective row call PROFIT_ROW.  The following code will compute the expected/average profit over each scenario:

I = 1;

EXP_PROFIT = 0;

@WHILE ( I #LE# @SPNUMSCENE()):

  @SPLOADSCENE( I);

  EXP_PROFIT = EXP_PROFIT + PROFIT_ROW;

  I = I + 1;

);

EXP_PROFIT = EXP_PROFIT / @SPNUMSCENE();

@WRITE( 'Expected Profit = ', EXP_PROFIT);

@SPMAX( VARIABLE|ROW)

Use @SPMAX to determine the maximum value across all scenarios for any specified variable or row name.

@SPMEAN( VARIABLE|ROW)

Use @SPMEAN to determine the mean across all scenarios for any specified variable or row name.

@SPMIN( VARIABLE|ROW)

Use @SPMIN to determine the minimum value across all scenarios for any specified variable or row name.

@SPNUMSCENE()

Use @SPNUMSCENE to retrieve the total number of scenarios in the model.  You can refer to the code example  above for an example of using @SPNUMSCENE to compute the expected/average profit over each scenario in an SP model.

@SPPRBSCENE( SCENARIO_INDEX)

Use @SPPRBSCENE to retrieve the probability of a specified scenario index, SCENARIO_INDEX.  In the following example, we loop to display the probabilities for each scenario in the model:

CALC:

  ! Solve the SP;

  @SOLVE();

 

  ! Loop to display scenario probabilities;

  I = 1;

  @WHILE( I #LE# @SPNUMSCENE():

     @WRITE( ' Scenario: ', I, ' Probability: ',

      @SPPRBSCENE( I), @NEWLINE( 1));

     I = I + 1;

  );

ENDCALC

The output from the loop is:

Scenario: 1 Probability: 0.1666666666666667

Scenario: 2 Probability: 0.3333333333333333

Scenario: 3 Probability: 0.5

@SPSTDDEV( VARIABLE|ROW)

Use @SPSTDDEV to determine the standard deviation of any variable or row across all scenarios.