Real-Time Optimization and Nonlinear Model Predictive Control of Processes Governed by Differential-Algebraic Equations
Real-Time Optimization and Nonlinear Model Predictive Control of Processes Governed by Differential-Algebraic Equations
Real-Time Optimization and Nonlinear Model Predictive Control of Processes Governed by Differential-Algebraic Equations
with
t
0
< t
1
< . . . < t
N
t
f
we rst discretize the control function u . For simpli-
city, we assume here that it is parametrized as a piece-
wise constant vector function
u t u
i
; for t 2 t
i
; t
i1
;
but every parameterization with local support could be
used without changing the structure of the problem.
In a second step the DAE are parametrized by multiple
shooting. We decouple the DAE solution on the N
intervals t
i
; t
i1
by introducing the initial values s
x
i
and
s
z
i
(combined: s
i
) of dierential and algebraic states at
times t
i
as additional optimization variables.
On each subinterval t
i
; t
i1
we compute the trajec-
tories x
i
t and z
i
t as the solution of an initial value
problem:
B x
:
t f x
i
t ; z
i
t ; u
i
; p 8
0 g x
i
t ; z
i
t ; u
i
; p
i
t g s
x
i
; s
z
i
; u
i
; p
_ _
9
x
i
t
i
s
x
i
_ _
10
Here the subtrahend in (9) is deliberately introduced
to allow an ecient DAE solution for initial values and
controls s
x
i
, s
z
i
, u
i
that may violate temporarily the con-
sistency conditions (3). Therefore, we require for the sca-
lar damping factor that
i
t
i
1. For more details on
the relaxation of the DAE the reader is referred, e.g. to
Leineweber [7] or Schulz et al. [10]. Note that the trajec-
tories x
i
t and z
i
t on the interval t
i
; t
i1
are functions
of the initial values, controls, and parameters s
x
i
, s
z
i
, u
i
; p
only.
Analogously, the integral part of the cost function is
evaluated on each interval independently:
L
i
s
x
i
; s
z
i
; u
i
; p
_ _
_
t
i1
t
i
L x
i
t ; z
i
t ; u
i
; p dt:
3.2. The structured nonlinear programming problem
The parameterization of problem (1)(7) using multiple
shooting and a piecewise constant control representation
leads to the following structured nonlinear program-
ming (NLP) problem
min
u;s;p
N1
i0
L
i
s
x
i
; s
z
i
; u
i
; p
_ _
E S
x
N
; p
_ _
11
subject to the initial value and parameter constraint
s
x
0
x
0
; 12
p p
0
; 13
the continuity conditions
s
x
i1
x
i
t
i1
i 0; 1; . . . ; N 1 ; 14
and the consistency conditions
0 g s
x
i
; s
z
i
; u
i
; p
_ _
i 0; 1; . . . ; N: 15
Control and path constraints are imposed pointwise
at the multiple shooting nodes
h s
x
i
; s
z
i
; u
i
; p
_ _
50 i 0; 1; . . . ; N 16
as well as at the terminal point
r s
x
N
; p
_ _
5
_ _
0: 17
3.3. SQP for multiple shooting
The above NLP problem (11)(17) is solved by a
sequential quadratic programming (SQP) method tai-
lored to the multiple shooting structure.
The NLP can be summarized as
minF w
w
subject to
G w 0
H w 50;
_
18
where w contains all the multiple shooting state vari-
ables and controls as well as the model parameters:
w s
x
0
; s
z
0
; u
0
; s
x
1
; s
z
1
; u
1
; . . . ; s
x
N
; s
z
N
; p
_ _
:
The discretized dynamic model is included in the
equality constraints Gw 0.
Starting from an initial guess w
0
, an SQP method for
the solution of (18) iterates
w
k1
w
k
k
w
k
; k 0; 1; . . . ; 19
M. Diehl et al. / Journal of Process Control 12 (2002) 577585 579
where
k
2 0; 1 is a relaxation factor, and the search
direction w
k
is the solution of the quadratic program-
ming (QP) subproblem
min
w2O
k
rF w
k
_ _
T
w
1
2
w
T
A
k
w 20
subject to
G w
k
_ _
rG w
k
_ _
T
w 0
H w
k
_ _
rH w
k
_ _
T
w50:
A
k
denotes an approximation of the Hessian r
2
w
of
the Lagrangian function , w; l; F w l
T
G w
T
H w ; where l and are the Lagrange multipliers.
Some remarks are in order on how to exploit the
multiple shooting structure in the construction of a tai-
lored SQP method.
Due to our choice of state and control parameteriza-
tions the NLP problem and the resulting QP problems
have a particular structure: the Lagrangian function is
partially separable, i.e. it can be written in the form
w; l;
N
i0
i
w
i
; l;
where w
i
: s
i
; u
i
; p are the components of the primal
variables w which are eective on interval t
i
; t
i1
only.
This separation is possible if we simply interpret the
parameters p as piecewise constant continuous controls.
As a consequence, the Hessian of has a block diag-
onal structure with blocks r
2
w
i
i
w
i
; l; . Similarly, the
multiple shooting parameterization introduces a char-
acteristic block sparse structure of the Jacobian matrices
rGw
T
and rHw
T
.
It is of crucial importance for performance and
numerical stability of the direct multiple shooting
method that these structures of (18) are fully exploited.
A number of specic algorithmic developments con-
tribute to this purpose:
. For the exploitation of the block diagonal struc-
ture of the Hessian, three versions are recom-
mended for dierent purposes:
(a) A numerical calculation of the exact Hessian
corresponds to Newtons method. This version is
recommended if the computation of the Hessian is
cheap, or in the case of neighbouring feedback
control, where the Hessian can be computed and
stored in advance. The use of the exact Hessian
has excellent local convergence properties. For
globalisation, techniques based on trust regions
are needed, since the Hessian may become inde-
nite far from the optimal solution.
(b) Partitioned high rank updates as introduced by
Block and Plitt [6] speed up local convergence with
negligible computational eort for the Hessian
approximation.
(c) A third approach to obtain a cheap Hessian
approximation the constrained GaussNewton
method is recommended in the special case of a
least squares type cost function F w
1
2
C w
_
_
_
_
2
2
.
The matrix fr
w
Cr
w
C
T
is already available from
the gradient computation and provides an excel-
lent approximation of the Hessian, if the residual
Cw of the cost function is suciently small, as it
can easily be shown that
r
w
Cr
w
C
T
r
2
w
_
_
_
_
O C w
_
_
_
_
_ _
:
This method is especially recommended for tracking
problems that often occur in NMPC. However, the
involved least squares terms may arise in integral form:
_
t
i1
t
i
l x; z; u; p
_
_
_
_
2
2
dt:
Specially adapted integrators that are able to compute a
numerical approximation of r
w
Cr
w
C
T
for this type of
least squares term have been developed [11]. This
method was used to compute the Hessian approxima-
tion in the numerical calculations presented in this
paper.
. Special recursive QP solvers are used for problem
(20) that exploit the block sparse structure of (18).
Both active set strategies (as used in this paper)
and interior point methods are available for the
treatment of large systems of inequality con-
straints [6,7,12].
. Leineweber [7] developed a reduction technique
for DAE systems with a large share of algebraic
variables, which is also employed for the compu-
tations in this paper. He exploits the linearized
algebraic consistency conditions for a reduction in
variable space, so that only reduced gradients and
Hessian blocks need to be calculated, which cor-
respond to the dierential variables, controls and
parameters only [13,14].
. The solution of the DAE initial value problems
and the corresponding derivatives are computed
simultaneously by specially designed integrators
which use the principle of internal numerical dif-
ferentiation. In particular, the integrator DAESOL
[15,16], which is based on the backward-dier-
entiation-formulae (BDF), was used in the numer-
ical calculations presented in this paper.
. The DAE solution and derivative generation can
be performed in parallel on the dierent multiple
shooting intervals. The latest parallel implementa-
580 M. Diehl et al. / Journal of Process Control 12 (2002) 577585
tion of the direct multiple shooting method for
DAE shows considerable speedups. For the
numerical example presented in this paper, pro-
cessor eciencies in the range of 80% for 8 nodes
have been observed.
Important for the use of the above methods in the
real-time context is their excellent local convergence
behaviour. By proper strategies to select stepsizes
k
or
trust regions
k
or both, global convergence can be
theoretically proven. Reassuring as this property is, it is
of lesser importance in real-time optimization, as gen-
erally no runtime bounds can be established. For a
detailed description of globalisation strategies available
in the latest version of direct multiple shooting (MUS-
COD2) the reader is referred to Leineweber [7].
3.4. A close look at one full SQP iteration
During each SQP iteration a variety of computations
have to be performed. We will state them here for the
direct multiple shooting variant that is the basis for the
real-time algorithm described in Section 4. We will
describe in detail how to compute the direction w
k
that is needed to proceed from iterate w
k
to the next
iterate w
k1
w
k
w
k
cf. Eq. (19) with
k
1). For
notational convenience we will not employ the index k
for the subvectors of w
k
and write
w
k
s
x
0
; s
z
0
; u
0
; . . . ; p
_ _
:
The computations that are needed to formulate the
quadratic programming subproblem (20), i.e. the calcu-
lation of rF, A, G, rG, H, rH, and those that are needed
to actually solve it, are intertwined. The algorithm pro-
ceeds as follows:
1. Reduction: Linearize the consistency conditions
(15) and resolve the linear system to eliminate the
s
z
i
as a linear function of s
x
i
, u
i
and p.
2. DAE solution and derivative generation: linearize
the continuity conditions (14) by solving the
relaxed initial value problems (8)(10) and com-
puting directional derivatives with respect to s
x
i
,
u
i
and p. Simultaneously, compute the gra-
dient rF of the objective function (11), and the
Hessian approximation A according to the Gauss
Newton approach. Linearize also the remaining
constraints (16) and (17).
3. Condensing: using the linearized continuity condi-
tions (14), eliminate the variables s
x
1
, . . . s
x
N
.
Project the objective gradient rF onto the space of
the remaining variables s
x
0
, u
0
, bm9, u
N1
and
p, and also the Hessian A and the linearized
constraints (16) and (17). This step generates the
so called condensed QP in the variables s
x
0
, u
0
,
. . ., u
N1
and p only.
4. Step generation: solve the condensed QP with an
ecient dense QP solver using an active set strat-
egy. The solution yields the nal values of s
x
0
,
u
0
, . . ., u
N1
and of p. (Note that due to the
linear constraints (12) and (13) s
x
0
x
0
s
x
0
and
p p
0
p.)
5. Expansion: expand the solution to yield nal
values for s
x
1
, . . ., s
x
N
, and for s
z
0
, . . . s
z
N
.
The main computational burden lies in step 2. Note
that all steps before step 4 can be performed without
knowledge of x
0
and p
0
this will be exploited in the
real-time embedding strategy in the following section.
4. A real-time embedding strategy
In a real-time scenario we aim at solving a sequence of
optimal control problems. At each time point t
0
a dif-
ferent optimization problem (1)(7) is treated, with an
initial value x
0
that we do not know in advance. We
must also expect that some of the parameters p
0
, which
are assumed to be constant in the model, are subject to
disturbances.
The time for the solution of each optimization problem
must be short enough to guarantee a suciently fast
reaction to disturbances. Fortunately, we can assume
that we have to solve a sequence of neighbouring opti-
mization problems. Let us assume that a solution of the
optimization problem for values t
0
, x
0
, p
0
is available,
including function values, gradients and a Hessian
approximation, but that at time t
0
the real values of the
process are the deviated values (x
0
0
, p
0
0
)=(x
0
, p
0
) .
How to obtain an updated value for the feedback con-
trol u~ (x
0
0
, p
0
0
, t
f
t
0
) (resp. u~ (x
0
0
, p
0
0
) in the NMPC
case)? A conventional approach would be
. to start the SQP procedure as described above from
the deviated values x
0
0
, p
0
0
and to use the old control
values u
i
for an integration over the complete
interval t
f
t
0
, and
. to iterate until a given (strict) convergence criterion
is satised.
Note that in the meantime the old control variables
will be used, so that no response to the disturbed values
x
0
0
, p
0
0
is applied so far.
In time critical processes this may take much too long
to be able to cope with the nonlinear dynamics.
In contrast to this, the authors suggest an algorithm
which diers from this approach in two important
aspects:
First, we propose to start the SQP iterations from the
solution for the reference values x
0
, p
0
instead of the
deviated values, accepting an initial violation of the
constraints (12), (13). Due to the linearity of these con-
M. Diehl et al. / Journal of Process Control 12 (2002) 577585 581
straints their violation is immediately corrected after the
rst (full) SQP iteration. It turns out that the formula-
tion of these constraints, that can be considered as an
initial value embedding of the optimal control problem
into the manifold of perturbed problems, is crucial for
the real-time performance: an examination of the algo-
rithm of Section 3.4 shows that steps 1, 2 and 3 can be
performed without knowledge of the actual values x
0
0
,
p
0
0
, thus allowing to perform them in advance and
enabling a fast response at the moment when the dis-
turbance occurs. In our approach, the rst iteration is
available in a small fraction of the time of a whole SQP
iteration. This is in sharp contrast to the conventional
approach, where all steps of the rst SQP iteration have
to be performed after x
0
0
, p
0
0
are known.
Moreover, for a Newtons method, it is easy to show
that the error of this rst SQP iteration compared to
the solution of the full nonlinear problem is only
second order in the size of the perturbation . This
property that the rst iterate is already close to the
solution for small holds also for the generalized
Gauss-Newton method. Based on this observation, we
secondly propose not to iterate the SQP iterations to
convergence, but rather use the following real-time
iteration scheme, that repeats the following cycle:
(I) Feedback response: After observation of the cur-
rent values x
0
0
, p
0
0
perform step 4 and apply the
result a rst correction of the controls immedi-
ately to the real process. Maintain these control
values during some process duration which is
suciently long to perform all calculations of one
cycle.
(II) Preparation phase: During this period rst
expand the outcome of step 4 to the full QP solution
(expansion step 5), then calculate a new (full step)
iterate w
k1
w
k
w
k
, and based on this new
iterate, perform the steps 1, 2 and 3 to prepare the
feedback response for the following step. Go back
to I.
In each cycle the same steps as for one classical SQP
iteration are performed, but in a rotated order. Note,
however, that in the middle of the preparation phase,
the transition to a new optimization problem is per-
formed. For shrinking horizon problems e.g. for batch
processes this new problem will be on the remaining
time interval t
0
; t
f
only. The steps 1, 2, and 3 will
then only be performed on this shrunk horizon.
Note that the algorithm is prepared to react to a fur-
ther disturbance after each cycle time , taking the out-
come of the last iteration on the shrunk horizon as a
reference solution.
Remark 1. For moving horizon problems, as they arise
in NMPC, the horizon length T
p
is constant. There exist
two possibilities to perform the transition from the old
horizon t
0
; t
0
T
p
to the new horizon t
0
;
t
0
T
p
, before steps 1, 2 and 3 are performed:
. we either shift all problem variables by a time to
account for the progressing time horizon, or
. we take the iterate w
k1
without a shift for a warm
start.
For short sampling times , both strategies have shown
nearly identical performance [3]. In the numerical simu-
lations presented in Section 5.4 we have adopted the sec-
ond alternative.
Remark 2. Compared to conventional SQP methods,
the solution procedures for the real-time iterations have to
be modied considerably. First, steps 1, 2 and 3, and step
5 need to be clearly separated from step 4. The crucial
step 4 can even be further subdivided into parts that can
be solved without knowledge of the unknown values x
0
0
, p
0
0
;
these parts should actually become part of the preparation
phase to make the feedback response as fast as possible.
Remark 3. The feedback phase itself is typically orders
of magnitude shorter than the preparation phase. Thus,
our algorithm can be interpreted as the successive gen-
eration of immediate feedback laws that take state and
control inequality constraints on the complete horizon into
account. Experience shows that the active set does not
change much from one cycle to the next so that the com-
putation time is bounded in practice.
Remark 4. The time required for a full cycle depends
on the complexity of the model and the optimization pro-
blem, the numerical solution algorithms involved and the
available computer. If is not suciently small, a paral-
lelization of the expensive step 2 may be a remedy.
Remark 5. As the described real-time iterations corre-
spond each to a dierent optimization problem, general
convergence results are dicult to obtain. However, it can
be shown under reasonable assumptions that the correc-
tion steps w
k
will become smaller from cycle to cycle, if,
after an initial disturbance , the process behaves as pre-
dicted by the model. In the case of shrinking horizon pro-
blems, the value of the objective function on the complete
horizon t
0
; t
f
that is obtained by using the the real-time
iterations can be compared to that of an optimal feedback
control. It turns out that for an exact Newtons method
the loss of optimality is of fourth order in the size of the
initial disturbance . A proof that covers also the Gauss-
Newton method will appear in a forthcoming paper [17].
5. NMPC of a high-purity distillation column
As a realistic application example we consider the
control of a high purity binary distillation column with
582 M. Diehl et al. / Journal of Process Control 12 (2002) 577585
40 trays for the separation of Methanol and n-Propanol.
The column is modelled by a DAE with 42 dierential
states and 122 algebraic states, that is described in [9]. The
model assumes constant molar hold up on the trays and
ideal thermodynamics, but takes enthalpy balances into
account to determine the mass ows from tray to tray.
5.1. The distillation column
The binary mixture is fed in the column with ow rate
F and molar feed composition x
F
. Products are removed
at the top and bottom of the column with concentra-
tions x
B
and x
D
. The column is considered in L/V con-
guration, i.e. the liquid reux rate L and the vapor
ow rate V (resp. the heating power Q) are the control
inputs. The control problem is to maintain the speci-
cations on the product concentrations x
B
and x
D
despite
disturbances in the feed concentration x
F
.
As usual in distillation control, the product purities
x
B
and x
D
at reboiler and condenser are not controlled
directly instead, an inferential control scheme which
controls the deviation of the concentrations on trays 14
and 28 from a given setpoint is used. These two con-
centrations are much more sensitive to changes in the
inputs of the system than the product concentrations; if
they are kept constant, the product purities are safely
maintained for a large range of process conditions. As
concentrations are dicult to measure, we consider
instead the tray temperatures, which correspond directly
to the concentrations via the Antoine equation.
5.2. State estimation
To obtain an estimate of the 42 dierential systemstates
and of the model parameter x
F
by measurements of the
three temperatures T
14
, T
21
and T
28
, we have implemented
a variant of an Extended Kalman Filter (EKF).
An EKF is based on subsequent linearizations of the
system model at each current estimate; each measure-
ment is compared with the prediction of the nonlinear
model, and the estimated state is corrected according to
the deviation. The weight of past measurement infor-
mation is kept in a weighting matrix, which is updated
according to the current system linearization.
In contrast to a standard EKF our estimator can
incorporate additional knowledge about the possible
range of states and parameters in form of inequality
constraints. This is especially useful as the tray con-
centrations need to be constrained to be in the interval
[0,1] to make a reasonable simulation possible. The
performance of the estimator was such that step dis-
turbances in the model parameter x
F
were completely
detected after 600 seconds, as can be seen in the second
last graph of Fig. 1 for an example disturbance scenario.
5.3. Controller design
Given an estimate of the system parameters p
0
(here
x
F
), our controller rst determines an appropriate
desired steady-state for states and controls x
s
, z
s
, and u
s
.
This is done by formulating a steady-state constraint
Fig. 1. Closed-loop simulation result for step disturbances in x
F
, using N 5 control intervals.
M. Diehl et al. / Journal of Process Control 12 (2002) 577585 583
f x
s
; z
s
; u
s
; p
0
0 21
g x
s
; z
s
; u
s
; p
0
0 22
y x
s
; z
s
; u
s
; p
0
T
r
14
T
r
28
_ _
23
where the function y extracts the controlled tray tem-
peratures from the system state, so that Eq. (23) restricts
the steady-state to satisfy the inferential control aim of
keeping the temperatures T
14
, T
28
at xed reference
values T
r
14
, T
r
28
.
Secondly, the open-loop optimal control problem is
posed in the form(1)(7), with a quadratic Lagrange term:
L x; z; u; p l x; z; u; p
_
_
_
_
2
2
where
l x; z; u; p :
y x; z; u; p
T
r
14
T
r
28
_ _
R u u
s
_
_
_
_
:
Here, the second component is introduced for reg-
ularization, with a small diagonal weighting matrix R.
The control inputs u (i.e. Q and L) are bounded by
inequality constraints of the form (7) to avoid that
reboiler or condenser run empty.
To ensure nominal stability of the closed-loop system,
an additional prediction interval is appended to the
control horizon, with the controls xed to the setpoint
values u
s
determined by Eqs. (21)(23). The objective
contribution of this interval provides an upper bound of
the neglected future costs that are due after the end of
the control horizon, if its length is suciently close to
innity [18]. A length of 3600 s for this additional
interval was considered to be sucient and was used in
all performed simulations.
In our numerical solution approach, the determina-
tion of the current setpoint for given parameters and the
dynamic optimization problem are performed simulta-
neously, by adding Eqs. (21)(23) as additional equality
constraints to the dynamic optimization problem.
As system state and parameters are the (smoothed)
result of an EKF estimation, they only slightly vary
from one optimization problem to the next, so that
favourable conditions for the real-time iterations with
the initial value embedding strategy are given.
5.4. Numerical results
For a realistic test of the algorithm we have per-
formed closed-loop simulations where the simulation
model equals the optimization model and the three
temperature measurements are disturbed by Gaussian
noise with a standard deviation of 0.01
C.
In the disturbance scenario shown in Fig. 1 we consider
three step changes in the feed concentration x
F
: starting
from the nominal value, x
F
is rst reduced by 20%, later
increased by 40% and at the end reduced by 20% to reach
the nominal value again. In the closed-loop simulation in
Fig. 1 a prediction horizon of 600+3600 s is used, with
ve control intervals each of 120 s length. In the rst two
graphs the controlled tray temperatures T
14
andT
28
are
shown, which should be kept at the specied values
T
r
14
=70
C and T
r
28
88