# Stochastic programming

In the field of mathematical optimization, stochastic programming is a framework for modeling optimization problems that involve uncertainty. Whereas deterministic optimization problems are formulated with known parameters, real world problems almost invariably include some unknown parameters. When the parameters are known only within certain bounds, one approach to tackling such problems is called robust optimization. Here the goal is to find a solution which is feasible for all such data and optimal in some sense. Stochastic programming models are similar in style but take advantage of the fact that probability distributions governing the data are known or can be estimated. The goal here is to find some policy that is feasible for all (or almost all) the possible data instances and maximizes the expectation of some function of the decisions and the random variables. More generally, such models are formulated, solved analytically or numerically, and analyzed in order to provide useful information to a decision-maker.

As an example, consider two-stage linear programs. Here the decision maker takes some action in the first stage, after which a random event occurs affecting the outcome of the first-stage decision. A recourse decision can then be made in the second stage that compensates for any bad effects that might have been experienced as a result of the first-stage decision. The optimal policy from such a model is a single first-stage policy and a collection of recourse decisions (a decision rule) defining which second-stage action should be taken in response to each random outcome.

Stochastic programming has applications in a broad range of areas ranging from finance to transportation to energy optimization. We present an example of optimizing an investment portfolio over time.

## Two-Stage Problems

The basic idea of two-stage stochastic programming is that (optimal) decisions should be based on data available at the time the decisions are made and should not depend on future observations. Two-stage formulation is widely used in stochastic programming. The general formulation of a two-stage stochastic programming problem is given by:

where $Q(x,\xi )$ is the optimal value of the second-stage problem

The classical two-stage linear stochastic programming problems can be formulated as

where $Q(x,\xi )$ is the optimal value of the second-stage problem

In such formulation $x\in \mathbb {R} ^{n}$ is the first-stage decision variable vector, $y\in \mathbb {R} ^{m}$ is the second-stage decision variable vector, and $\xi (q,T,W,h)$ contains the data of the second-stage problem. In this formulation, at the first stage we have to make a "here-and-now" decision $x$ before the realization of the uncertain data $\xi$ , viewed as a random vector, is known. At the second stage, after a realization of $\xi$ becomes available, we optimize our behavior by solving an appropriate optimization problem.

At the first stage we optimize (minimize in the above formulation) the cost $c^{T}x$ of the first-stage decision plus the expected cost of the (optimal) second-stage decision. We can view the second-stage problem simply as an optimization problem which describes our supposedly optimal behavior when the uncertain data is revealed, or we can consider its solution as a recourse action where the term $Wy$ compensates for a possible inconsistency of the system $Tx\leq h$ and $q^{T}y$ is the cost of this recourse action.

The considered two-stage problem is linear because the objective functions and the constraints are linear. Conceptually this is not essential and one can consider more general two-stage stochastic programs. For example, if the first-stage problem is integer, one could add integrality constraints to the first-stage problem so that the feasible set is discrete. Non-linear objectives and constraints could also be incorporated if needed.

### Distributional assumption

The formulation of the above two-stage problem assumes that the second-stage data $\xi$ can be modeled as a random vector with a known probability distribution (not just uncertain). This would be justified in many situations. For example $\xi$ could be information derived from historical data and the distribution does not significantly change over the considered period of time. In such situations one may reliably estimate the required probability distribution and the optimization on average could be justified by the Law of Large Numbers. Another example is that $\xi$ could be realizations of a simulation model whose outputs are stochastic. The empirical distribution of the sample could be used as an approximation to the true but unknown output distribution.

### Discretization

To solve the two-stage stochastic problem numerically, one often need to assume that the random vector $\xi$ has a finite number of possible realizations, called scenarios, say $\xi _{1},\dots ,\xi _{K}$ , with respective probability masses $p_{1},\dots ,p_{K}$ . Then the expectation in the first-stage problem's objective function can be written as the summation:

and, moreover, the two-stage problem can be formulated as one large linear programming problem (this is called the deterministic equivalent of the original problem, see section {{#invoke:Section link|main}}).

When $\xi$ has an infinite (or very large) number of possible realizations the standard approach is then to represent this distribution by scenarios. This approach raises three questions, namely:

1. How to construct scenarios, see {{#invoke:Section link|main}};
2. How to solve the deterministic equivalent. Optimizers such as CPLEX, GLPK and Gurobi can solve large linear/nonlinear problems. NEOS  server hosted at the Argonne National Laboratory allows free access to many modern solvers. The structure of a deterministic equivalent is particularly amenable to apply decomposition methods, such as Benders' decomposition or scenario decomposition;
3. How to measure quality of the obtained solution with respect to the "true" optimum.

These questions are not independent. For example, the number of scenarios constructed will affect both the tractability of the deterministic equivalent and the quality of the obtained solutions.

## Stochastic linear program

A stochastic linear program is a specific instance of the classical two-stage stochastic program. A stochastic LP is built from a collection of multi-period linear programs (LPs), each having the same structure but somewhat different data. The $k^{th}$ two-period LP, representing the $k^{th}$ scenario, may be regarded as having the following form:

The vectors $x$ and $y$ contain the first-period variables, whose values must be chosen immediately. The vector $z_{k}$ contains all of the variables for subsequent periods. The constraints $Tx+Uy=r$ involve only first-period variables and are the same in every scenario. The other constraints involve variables of later periods and differ in some respects from scenario to scenario, reflecting uncertainty about the future.

Note that solving the $k^{th}$ two-period LP is equivalent to assuming the $k^{th}$ scenario in the second period with no uncertainty. In order to incorporate uncertainties in the second stage, one should assign probabilities to different scenarios and solve the corresponding deterministic equivalent.

### Deterministic equivalent of a stochastic problem

With a finite number of scenarios, two-stage stochastic linear programs can be modelled as large linear programming problems. This formulation is often called the deterministic equivalent linear program, or abbreviated to deterministic equivalent. (Strictly speaking a deterministic equivalent is any mathematical program that can be used to compute the optimal first-stage decision, so these will exist for continuous probability distributions as well, when one can represent the second-stage cost in some closed form.) For example, to form the deterministic equivalent to the above stochastic linear program, we assign a probability $p_{k}$ to each scenario $k=1,\dots ,K$ . Then we can minimize the expected value of the objective, subject to the constraints from all scenarios:

We have a different vector $z_{k}$ of later-period variables for each scenario $k$ . The first-period variables $x$ and $y$ are the same in every scenario, however, because we must make a decision for the first period before we know which scenario will be realized. As a result, the constraints involving just $x$ and $y$ need only be specified once, while the remaining constraints must be given separately for each scenario.

## Scenario Construction

In practice it might be possible to construct scenarios by eliciting expert's opinions on the future. The number of constructed scenarios should be relatively modest so that the obtained deterministic equivalent can be solved with reasonable computational effort. It is often claimed that a solution that is optimal using only a few scenarios provides more adaptable plans than one that assumes a single scenario only. In some cases such a claim could be verified by a simulation. In theory some measures of guarantee that an obtained solution solves the original problem with reasonable accuracy. Typically in applications only the first stage optimal solution $x^{*}$ has a practical value since almost always a "true" realization of the random data will be different from the set of constructed (generated) scenarios.

Suppose $\xi$ contains $d$ independent random components, each of which has three possible realizations (for example, future realizations of each random parameters are classified as low, medium and high), then the total number of scenarios is $K=3^{d}$ . Such exponential growth of the number of scenarios makes model development using expert opinion very difficult even for reasonable size $d$ . The situation becomes even worse if some random components of $\xi$ have continuous distributions.

### Monte Carlo sampling and Sample Average Approximation (SAA) Method

A common approach to reduce the scenario set to a manageable size is by using Monte Carlo simulation. Suppose the total number of scenarios is very large or even infinite. Suppose further that we can generate a sample $\xi ^{1},\xi ^{2},\dots ,\xi ^{N}$ of $N$ replications of the random vector $\xi$ . Usually the sample is assumed to be independent identically distributed (i.i.d sample). Given a sample, the expectation function $q(x)=E[Q(x,\xi )]$ is approximated by the sample average

and consequently the first-stage problem is given by

This formulation is known as the Sample Average Approximation method. The SAA problem is a function of the considered sample and in that sense is random. For a given sample $\xi ^{1},\xi ^{2},\dots ,\xi ^{N}$ the SAA problem is of the same form as a two-stage stochastic linear programming problem with the scenarios $\xi ^{j}$ ., $j=1,\dots ,N$ , each taken with the same probability $p_{j}={\frac {1}{N}}$ .

## Statistical Inference

Consider the following stochastic programming problem

Suppose that we have a sample $\xi ^{1},\dots ,\xi ^{N}$ of $N$ realizations of the random vector $\xi$ . This random sample can be viewed as historical data of $N$ observations of $\xi$ , or it can be generated by Monte Carlo sampling techniques. Then we can formulate a corresponding sample average approximation

By the Law of Large Numbers we have that, under some regularity conditions ${\frac {1}{N}}\sum _{j=1}^{N}Q(x,\xi ^{j})$ converges pointwise with probability 1 to $E[Q(x,\xi )]$ as $N\rightarrow \infty$ . Moreover, under mild additional conditions the convergence is uniform. We also have $E[{\hat {g}}_{N}(x)]=g(x)$ , i.e., ${\hat {g}}_{N}(x)$ is an unbiased estimator of $g(x)$ . Therefore it is natural to expect that the optimal value and optimal solutions of the SAA problem converge to their counterparts of the true problem as $N\rightarrow \infty$ .

### Consistency of SAA estimators

Suppose the feasible set $X$ of the SAA problem is fixed, i.e., it is independent of the sample. Let $\vartheta ^{*}$ and $S^{*}$ be the optimal value and the set of optimal solutions, respectively, of the true problem and let ${\hat {\vartheta }}_{N}$ and ${\hat {S}}_{N}$ be the optimal value and the set of optimal solutions, respectively, of the SAA problem.

then ${\hat {\vartheta }}_{N}\rightarrow \vartheta ^{*}$ and $\mathbb {D} (S^{*},{\hat {S}}_{N})\rightarrow 0$ with probability 1 as $N\rightarrow \infty$ . Note that $\mathbb {D} (A,B)$ denotes the deviation of set $A$ from set $B$ , defined as

In some situations the feasible set $X$ of the SAA problem is estimated, then the corresponding SAA problem takes the form

where $X_{N}$ is a subset of $\mathbb {R} ^{n}$ depending on the sample and therefore is random. Nevertheless consistency results for SAA estimators can still be derived under some additional assumptions:

1. Suppose that there exists a compact set $C\subset \mathbb {R} ^{n}$ such that
then ${\hat {\vartheta }}_{N}\rightarrow \vartheta ^{*}$ and $\mathbb {D} (S^{*},{\hat {S}}_{N})\rightarrow 0$ with probability 1 as $N\rightarrow \infty$ .

## Multistage Portfolio Optimization

We now present an example from finance of multi-stage stochastic programming. Suppose that at time $t=0$ we have initial capital $W_{0}$ to invest in $n$ assets. Suppose further that we are allowed to rebalance our portfolio at times $t=1,\dots ,T-1$ but without injecting additional cash into it. At each period $t$ we make a decision about redistributing the current wealth $W_{t}$ among the $n$ assets. Let $x_{0}=(x_{10},\dots ,x_{n0})$ be the initial amounts invested in the n assets. We require that each $x_{i0}$ is nonnegative and that the balance equation $\sum _{i=1}^{n}x_{i0}=W_{0}$ should hold.

which depends on the realization of the random process and the decisions up to time $t$ .

Suppose the objective is to maximize the expected utility of this wealth at the last period, that is, to consider the problem

This is a multistage stochastic programming problem, where stages are numbered from $t=0$ to $t=T-1$ . Optimization is performed over all implementable and feasible policies. To complete the problem description one also needs to define the probability distribution of the random process $\xi _{1},\dots ,\xi _{T}$ . This can be done in various ways. For example, one can construct a particular scenario tree defining time evolution of the process. If at every stage the random return of each asset is allowed to have two continuations, independent of other assets, then the total number of scenarios is $2^{nT}$ .

In order to write dynamic programming equations, consider the above multistage problem backward in time. At the last stage $t=T-1$ , a realization $\xi _{[T-1]}=(\xi _{1},\dots ,\xi _{T-1})$ of the random process is known and $x_{T-2}$ has been chosen. Therefore, one needs to solve the following problem

Similarly, at stages $t=T-2,\dots ,1$ , one should solve the problem

## Biological applications

Stochastic dynamic programming is frequently used to model animal behaviour in such fields as behavioural ecology. Empirical tests of models of optimal foraging, life-history transitions such as fledging in birds and egg laying in parasitoid wasps have shown the value of this modelling technique in explaining the evolution of behavioural decision making. These models are typically many-staged, rather than two-staged.

## Economic applications

Stochastic dynamic programming is a useful tool in understanding decision making under uncertainty. The accumulation of capital stock under uncertainty is one example; often it is used by resource economists to analyze bioeconomic problems where the uncertainty enters in such as weather, etc.

## Software tools

### Modelling languages

All discrete stochastic programming problems can be represented with any algebraic modeling language, manually implementing explicit or implicit non-anticipativity to make sure the resulting model respects the structure of the information made available at each stage. An instance of an SP problem generated by a general modelling language tends to grow quite large (linearly in the number of scenarios), and its matrix looses the structure that is intrinsic to this class of problems, which could otherwise be exploited at solution time by specific decomposition algorithms. Extensions to modelling languages specifically designed for SP are starting to appear, see:

They both can generate SMPS instance level format, which conveys in a non-redundant form the structure of the problem to the solver.

### Solvers

• FortSP - solver for stochastic programming problems; it accepts SMPS input and implements various decomposition algorithms.
• NEOS Solvers - Three solvers are available in the Neos Server: Bouncing Nested Benders Solvers (BNBS) for multi-stage stochastic linear programs, ddsip for two-stage stochastic programs with integer recourse, and Stochastic Decomposition (SD) for two-stage stochastic linear programs.
• COIN-OR Stochastic Modeling Interface - An open source project within COIN-OR. It can read Stochastic MPS input format as well as supports direct interfaces for scenario input, and generates the deterministic equivalent linear program for solution by COIN-OR solvers.