Stochastic Optimal Control

Learning outcomes

  • Formulate a scenario-tree MPC with non-anticipativity constraints.
  • Derive the back-off that turns a Gaussian chance constraint into a deterministic one.
  • Compute the value of the stochastic solution and explain what it measures.

Book chapter: Model Predictive Control and Economic Optimization (Volume 9), Chapter 7, Reservoir Flood Control on an Ensemble Forecast With Scenario Trees (PDF).
Practice in 15 minutes: 18 · Offset-Free and Tube MPC on a Coupled Plant, 26 · Scenario Trees and Chance Constraints
Model: A dynamic model with uncertain parameters, delays or disturbances, described by samples or a distribution.
Decision: The controller chooses inputs that work across the scenarios, adapting later moves as uncertainty resolves.
Learning: Forecast ensembles and parameter distributions come from data; their spread sets how much the controller must hedge.

The underlying model or process parameters that describe a system are rarely known exactly. Optimizing a system with an inaccurate model leads to a sub-optimal solution. If the process model includes uncertain parameters that are described by a distribution function or other set of possible process values, this information can be used directly in the optimal control problem to optimize under uncertainty.

Scenarios, Chance Constraints and Tubes

Scenario trees. The exercises below choose one input profile for all sampled models. A scenario tree allows later inputs to differ by scenario `s` (probability `\pi_s`, parameters `p^{(s)}`) as the uncertainty is revealed, but forbids any input from depending on what has not yet been observed:

$$\begin{gathered} \min_{u^{(1)}, \ldots, u^{(n_s)}} \; \sum_{s=1}^{n_s} \pi_s\, J\big(x^{(s)}, u^{(s)}\big) \\ \text{s.t.}\quad x^{(s)}_{k+1} = f\big(x^{(s)}_k, u^{(s)}_k, p^{(s)}\big), \\ u^{(s)}_k = u^{(s')}_k \;\text{if } s, s' \text{ share the same history up to } k \end{gathered}$$

The last condition, non-anticipativity, makes at least the first move `u_0` the same in every scenario, which is the move applied to the plant.

Chance constraints. A limit that must hold with probability `1 - \varepsilon`, `\Pr(y_j \le y_U) \ge 1 - \varepsilon`, becomes deterministic when the prediction error is Gaussian with standard deviation `\sigma_j`:

$$\bar y_j \le y_U - z_{1-\varepsilon}\, \sigma_j$$

where `\bar y_j` is the mean prediction and `z_{1-\varepsilon}` the standard normal quantile (1.645 for `\varepsilon = 0.05`). The term `z_{1-\varepsilon}\sigma_j` is the back-off. Since `\sigma_j` grows along the horizon, the back-off grows too.

Tube MPC. A nominal plan `(z_k, v_k)` is computed for the model without disturbances, and a fixed feedback gain `K` keeps the real state near it:

$$u_k = v_k + K\left(x_k - z_k\right), \qquad z_{k+1} = A z_k + B v_k$$

The nominal plan satisfies constraints tightened by the size of the error set the feedback can guarantee, so the real state stays feasible for every bounded disturbance.

The number to report. The value of the stochastic solution compares the expected cost of the stochastic plan, `RP`, with the expected cost of applying the plan made for the mean model, `EEV`, both evaluated over the same scenarios:

$$\text{VSS} = EEV - RP \ge 0$$

A small VSS says the extra effort of the stochastic formulation bought little; a large one says planning for the mean would have been costly.

Exercise 1

Consider a system that has an uncertain parameter K that is uniformly distributed between 1.0 and 2.0. The process model is

$$10 \frac{dv}{dt} = -v + K p$$

where v is the controlled variable (CV) with target value of 40.0 and p is the manipulated variable (MV) that can be adjusted between 0 and 100. This is a simple first-order dynamic model that relates the adjustable input p (MV) to the target output v (CV). The rate of change of the MV is limited to 40 every seconds. Determine the stochastic optimal control solution by creating 10 instances of the model that randomly determine the value of K. Optimize this set of models to achieve the target CV value of 40, starting from an initial condition of 0.

Solution 1

import numpy as np
from gekko import GEKKO
import matplotlib.pyplot as plt

# uncertain parameter
n = 10
K = np.random.rand(n)+1.0

m = GEKKO()
m.time = np.linspace(0,20,41)

# manipulated variable
p = m.MV(value=0, lb=0, ub=100)
p.STATUS = 1
p.DCOST = 0.1  
p.DMAX = 20

# controlled variable
v = m.Array(m.CV,n)
for i in range(n):
    v[i].STATUS = 1
    v[i].SP = 40
    v[i].TAU = 5
    m.Equation(10*v[i].dt() == -v[i] + K[i]*p)

# solve optimal control problem
m.options.IMODE = 6
m.options.CV_TYPE = 2
m.solve()

# plot results
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',lw=2)
plt.ylabel('MV')
plt.subplot(2,1,2)
plt.plot([0,m.time[-1]],[40,40],'k-',lw=3)
for i in range(n):
    plt.plot(m.time,v[i].value,':',lw=2)
plt.ylabel('CV')
plt.xlabel('Time')
plt.show()

Exercise 2

Consider a system that has an uncertain delay that is uniformly distributed between 1.0 and 5.0. The process model is

$$2 \frac{dv}{dt} = -v + p (t-\theta)$$

where v is the controlled variable (CV) with target range between 38.0 and 40.0, p is the manipulated variable (MV) that can be adjusted between 0 and 100, and `\theta` is the delay. This is a simple first-order dynamic model that relates the adjustable input p (MV) to the target output v (CV). The rate of change of the MV is limited to 40 every seconds. Determine the stochastic optimal control solution by creating 6 instances of the model that randomly determine the delay. Optimize this set of models to achieve the target CV value of between 38 and 40, starting from an initial condition of 0.

Solution 2

import numpy as np
from gekko import GEKKO
import matplotlib.pyplot as plt

# uncertain delay instances
n = 6

m = GEKKO()
m.time = np.linspace(0,20,41)

# manipulated variable
p = m.MV(value=0, lb=0, ub=100)
p.STATUS = 1
p.DCOST = 0.1  
p.DMAX = 20

# controlled variable
v = m.Array(m.CV,n)
d = m.Array(m.Var,n)
for i in range(n):
    delay = np.random.randint(1,11)
    v[i].STATUS = 1
    v[i].SPHI = 40
    v[i].SPLO = 38
    v[i].TAU = 5
    v[i].TR_INIT = 1
    m.delay(p,d[i],delay)
    m.Equation(2*v[i].dt()==-v[i]+d[i])

# solve optimal control problem
m.options.IMODE = 6
m.options.CV_TYPE = 1
m.solve()

# get additional solution information
import json
with open(m.path+'//results.json') as f:
    results = json.load(f)

# plot results
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',lw=2)
plt.ylabel('MV')
plt.subplot(2,1,2)
plt.plot(m.time,results['v1.tr_hi'],'k--')
plt.plot(m.time,results['v1.tr_lo'],'k--')
for i in range(n):
    plt.plot(m.time,v[i].value,':',lw=2)
plt.ylabel('CV')
plt.xlabel('Time')
plt.show()

Generative AI Learning

"For Exercise 1 on this page, explain how to compute the value of the stochastic solution: what plan gives EEV, what plan gives RP, and over which scenarios each is evaluated. Then predict whether VSS will be large or small here and why."

Check the answer: Compute it: solve with K = 1.5 alone, then evaluate that input profile on all your sampled K values and average the cost (EEV). Compare with the average cost of the stochastic solution on the same samples (RP). VSS must be zero or positive; a negative value means the two were evaluated on different scenarios or costs.

Course Information

TCLab

Project

Applications

Advanced Control Exercises

Exams

Modeling

Machine Learning

Estimation

Control

Reinforcement Learning

Related Courses

Admin