Dynamic Control Objectives

Learning outcomes

  • Formulate a soft output constraint with a slack variable and choose its price so it binds only when the hard limit cannot be met.
  • Write an economic MPC objective and compare it with a tracking objective.
  • Relate a Lagrange multiplier to the change in optimal cost when a limit is relaxed.

Book chapter: Control in Chemical Plants (Volume 13), Chapter 11, Real-Time Optimization of a Williams–Otto Reactor Whose Model Lacks a Reaction (PDF).
Practice in 15 minutes: 20 · One Plan or Three Loops, With Preview, 23 · Economic MPC and the Value of a Forecast, 24 · Real-Time Optimization With the Wrong Model
Model: Any dynamic model used by an MPC; the objective decides what the model is asked to achieve.
Decision: The controller chooses inputs that minimize tracking error, move cost, constraint violation or economic cost over the horizon.
Learning: Prices and weights are often tuned from operating data; the multipliers report what each constraint costs.

The dynamic control objective function is a mathematical statement that is minimized or maximized to find a best solution among all possible feasible solutions for a controller. The form of this objective function is critical to give desirable solutions for driving a system to a desirable state or along a desired trajectory. Common objective statements relate to economic, safety, operability, environmental, or related objectives.

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

# initialize GEKKO model
m = GEKKO()

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

# constants
mass = 500

# Parameters
b = m.Param(value=50)
K = m.Param(value=0.8)
# Manipulated variable
p = m.MV(value=0, lb=0, ub=100)

# Controlled Variable
v = m.CV(value=0,name='v')

# Equations
m.Equation(mass*v.dt() == -v*b + K*b*p)

m.options.IMODE = 6 # control

# MV tuning
p.STATUS = 1 #allow optimizer to change
p.DCOST = 0.1 #smooth out MV
p.DMAX = 20 #slow down change of MV

# CV tuning
v.STATUS = 1 #add the CV to the objective
m.options.CV_TYPE = 1 #Dead-band
v.SPHI = 42 #set point
v.SPLO = 38 #set point
v.TR_INIT = 1 #setpoint trajectory
v.TAU = 5 #time constant of setpoint trajectory

# Solve
m.solve()

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

# Plot solution
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',lw=2,label='MV')
plt.legend(loc='best')
plt.ylabel('gas')
plt.subplot(2,1,2)
plt.plot(m.time,results['v.tr_lo'],'k-',label='SPHI')
plt.plot(m.time,results['v.tr_hi'],'k-',label='SPLO')
plt.plot(m.time,v.value,'r--',lw=2,label='CV')
plt.legend(loc='best')
plt.ylabel('velocity')
plt.xlabel('time')
plt.show()

Two common objective functions are shown below as squared error and l1-norm forms1.

Squared Error Objective

The squared error objective is the most common form used in the literature. It penalizes deviation of the current measured value of the controlled variable from the desired target value.

$$\min_{x,y,u} \Phi = \left(y-y_t\right)^T W_t \left(y-y_t\right) + y^T w_y + u^T w_u + \Delta u^T W_{\Delta u} \Delta u$$

$$\mathrm{subject\;\;to}$$

$$0 = f\left(\frac{dx}{dt},x,y,u\right)$$

$$0 \le g\left(\frac{dx}{dt},x,y,u\right)$$

$$\tau_c \frac{dy_t}{dt} + y_t = sp$$

l1-norm Objective

The l1-norm objective is the absolute value of the difference between the current measured value of the controlled variable and the desired target value. The absolute value operator (abs(x)) does not have a continuous first and second derivative at x=0 (see absolute value function alternatives). Slack variables give the same absolute value function but with continuous first and second derivatives.

$$\min_{x,y,u} \Phi = w_{hi}^T e_{hi} + w_{lo}^T e_{lo} + y^T w_y + u^T w_u + w_{\Delta u}^T \left(\Delta u_U+\Delta u_L\right)$$

$$\mathrm{subject\;\;to}$$

$$0 = f\left(\frac{dx}{dt},x,y,u\right)$$

$$0 \le g\left(\frac{dx}{dt},x,y,u\right)$$

$$\tau_c \frac{dy_{t,hi}}{dt} + y_{t,hi} = sp_{hi}$$

$$\tau_c \frac{dy_{t,lo}}{dt} + y_{t,lo} = sp_{lo}$$

$$e_{hi} \ge y - y_{t,hi}$$

$$e_{lo} \ge y_{t,lo} - y$$

$$\Delta u_U \ge u_i - u_{i-1}$$

$$\Delta u_L \ge u_{i-1} - u_i$$

$$e_{hi}, e_{lo}, \Delta u_U, \Delta u_L \ge 0$$

Nomenclature

$$\Phi=\mathrm{Objective\,Function}$$

$$y=\mathrm{model\,predictions}$$

$$y_t,y_{t,hi},y_{t,lo}=\mathrm{reference\,trajectory\,or\,range}$$

$$W_t,w_{hi}, w_{lo}=\mathrm{penalty\,outside\,reference\,trajectory\,(WSP,WSPHI,WSPLO)}$$

$$W_{\Delta u}, w_{\Delta u}=\mathrm{manipulated\,variable\,movement\,penalty\,(DCOST)}$$

$$w_{u}, w_{y}=\mathrm{weight\,on\,input\,and\,output\,(COST)}$$

$$y,x,u=\mathrm{outputs,\,states,\,and\,inputs}$$

$$\Delta u=\mathrm{manipulated\,variable\,change}$$

$$f,g=\mathrm{equality\,and\,inequality\,constraints}$$

$$e_{hi},e_{lo}=\mathrm{upper\,and\,lower\,error\,outside\,dead-band}$$

$$\Delta u_U,\Delta u_L=\mathrm{upper\,and\,lower\,manipulated\,variable\,change}$$

In formulating an objective function and model equations follow the following tips for improved convergence.

  1. Rearrange to equation in residual form to:
    1. Avoid divide by zero
    2. Minimize use of functions like sqrt, log, exp, etc.
    3. Have continuous first and second derivatives
    4. Fit the equation into a linear or quadratic form
  2. Bounds
    1. Include variable bounds to exclude infeasible solutions
    2. Variable bounds to avoid regions of strong nonlinearity
    3. Caution: watch for infeasible solutions
  3. Scaling:
    1. Scale absolute value of variables to 1e-3 to 1e3
    2. Scale absolute value of equation residuals to 1e-3 to 1e3
    3. Better that 1st derivative values are closer to 1.0
  4. Good initial conditions:
    1. Starting near a solution can improve convergence
    2. Try multiple initial conditions to verify global solution (non-convex problems)
    3. Explicitly calculate intermediate values
  5. Check iteration summary for improved convergence

Soft Constraints, Economic Objectives and Prices

Soft constraints. A hard limit on an output can make the problem infeasible when a disturbance pushes the output past it, and an infeasible controller gives no move at all. A soft limit adds a slack `s_j \ge 0` with a price `\rho`:

$$y_j \le y_U + s_j, \qquad s_j \ge 0, \qquad \Phi \leftarrow \Phi + \rho \sum_{j} s_j$$

With a linear penalty and `\rho` larger than the multiplier of the hard constraint, the soft problem gives exactly the hard solution whenever that solution exists, and the smallest violation when it does not. Input limits are kept hard: a valve cannot open past 100%.

Economic objective. In place of distance to a setpoint, economic MPC minimizes the cost of operation directly, with prices `c_u` on inputs (energy, feed) and values `c_y` on outputs (product), over a horizon of `N` steps of length `\Delta t`:

$$\min_{u_0, \ldots, u_{N-1}} \; \sum_{j=0}^{N-1} \left( c_u^T u_j - c_y^T y_j \right) \Delta t \quad \text{s.t. the model and limits}$$

Comfort bands or quality limits become constraints. The controller then chooses where to operate, which a tracking MPC leaves to a real-time optimizer above it. With a forecast of prices or loads it also chooses when to act, such as cooling a building before electricity becomes expensive.

Prices of constraints. For `\min J(z)` subject to `g(z) \le b`, the multiplier `\lambda` of the constraint at the optimum is the rate at which the optimal cost `J^*` falls when the limit is relaxed:

$$\frac{\partial J^*}{\partial b} = -\lambda, \qquad \lambda \ge 0, \qquad \lambda \left( g(z^*) - b \right) = 0$$

An inactive constraint has `\lambda = 0`. The MPC faceplates in the apps list the price of each binding constraint, which tells an operator which limit is worth moving.

Custom Reference Trajectory

Some applications require a custom reference trajectory that does not fit a standard form. A custom reference trajectory is specified by creating a new error (e) variable that is the difference between the specified trajectory (sinusoidal, sawtooth, random, etc) and the model output. This error is specified as a controlled variable (CV) with an upper and lower dead-band denoted as SPHI and SPLO. The CV can also be a value of zero with a squared error objective (e.SP=0, m.options.CV_TYPE=2) to drive to a target instead of a dead-band range.

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

# initialize GEKKO model
m = GEKKO()

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

# constants
mass = 500

# Parameters
b = m.Param(value=50)
K = m.Param(value=0.8)
# Manipulated variable
p = m.MV(value=0, lb=-100, ub=100)

# Reference trajectory
sine = 10*np.sin(m.time/20*4*np.pi)
traj = m.Param(value=sine)

# Controlled Variable
v = m.SV(value=0,name='v')

# Error
e = m.CV(value=0,name='e')

# Equations
m.Equation(mass*v.dt() == -v*b + K*b*p)
m.Equation(e==v-traj)

m.options.IMODE = 6 # control

# MV tuning
p.STATUS = 1 #allow optimizer to change
p.DCOST = 0.1 #smooth out MV
p.DMAX = 50 #slow down change of MV

# CV tuning
e.STATUS = 1 #add the CV to the objective
m.options.CV_TYPE = 1 #Dead-band
db = 2
e.SPHI = db #set point
e.SPLO = -db #set point
e.TR_INIT = 0 #setpoint trajectory
e.TAU = 5 #time constant of setpoint trajectory

# Solve
m.solve()

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

# Plot solution
plt.figure(figsize=(6,4))
plt.subplot(3,1,1)
plt.plot(m.time,p.value,'b-',lw=2,label='MV')
plt.legend(loc='best')
plt.ylabel('MV')
plt.subplot(3,1,2)
plt.plot(m.time,sine+db,'k-',label='SPHI')
plt.plot(m.time,sine-db,'k-',label='SPLO')
plt.plot(m.time,v.value,'r--',lw=2,label='CV')
plt.legend(loc='best')
plt.ylabel('CV')
plt.subplot(3,1,3)
plt.plot(m.time,results['e.tr_hi'],'k-',label='SPHI')
plt.plot(m.time,results['e.tr_lo'],'k-',label='SPLO')
plt.plot(m.time,e.value,'r--',lw=2,label='Error')
plt.legend(loc='best')
plt.ylabel('Error')
plt.xlabel('time')
plt.tight_layout()
plt.show()

Generative AI Learning

"My MPC has a hard upper limit of 400 K on reactor temperature and goes infeasible when the feed temperature jumps. Rewrite the limit as a soft constraint with a slack variable, tell me how large the slack price must be, and explain how I would read that price from the solver output."

Check the answer: Solve your problem once with the hard limit in a case where it is feasible and read the limit's multiplier from the solver. Set the slack price below and then above that multiplier and solve the soft version. Below it, the soft version should violate the limit even though it need not; above it, the two solutions should match.

References

  1. Hedengren, J. D. and Asgharzadeh Shishavan, R., Powell, K.M., and Edgar, T.F., Nonlinear Modeling, Estimation and Predictive Control in APMonitor, Computers and Chemical Engineering, Volume 70, pg. 133–148, 2014. Article

Discussion Questions

  1. The squared-error MPC objective tracks a reference trajectory; the l1 objective tracks a dead-band between SPHI and SPLO. With measurement noise on the CV, which controller keeps moving the manipulated variable inside the band, what does that cost in actuator wear and energy, and why do many industrial MPCs default to the l1 form?
  2. The reference trajectory time constant (TAU) is a tuning knob, not a plant property. What happens when TAU is set faster than the plant can physically respond - where does the un-trackable error go, and which penalty term absorbs it?
  3. Both objective forms add a Delta-u movement penalty. Remove it entirely: what does the optimizer do with a plant model that is even slightly wrong, and why is the resulting MV profile a fingerprint of inverse-response or model-mismatch amplification?
  4. A dead-band of zero makes the l1 objective a pure absolute-error tracker. Why is the gradient discontinuity at zero error not a problem in the slack-variable formulation, and what would it do to a naive solver applied to |e| directly?

Tip: Formulation-audit prompt: "Here is my GEKKO MPC objective setup {CV_TYPE, SP or SPHI/SPLO, TAU, TR_INIT, WSP or WSPHI/WSPLO, DCOST}. As an adversarial reviewer, tell me what closed-loop behavior these choices imply (noise response, actuator movement, overshoot), which two settings conflict, and ask me to defend the dead-band width against my sensor's noise level."

Course Information

TCLab

Project

Applications

Advanced Control Exercises

Exams

Modeling

Machine Learning

Estimation

Control

Reinforcement Learning

Related Courses

Admin