02 Direct Methods
02 Direct Methods
2 Direct methods
4 Collocation methods
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 1/49
Continuous-time optimal control problems (OCP)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 2/49
Classification of optimal control methods
Figure inspired by Figure 9.2. in Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2024
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 3/49
Classification of optimal control methods
Figure inspired by Figure 9.2. in Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2024
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 3/49
Classification of optimal control methods
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 3/49
Direct single shooting
▶ discretize controls u(t) ∈ Rnu on a fixed grid 0 = t0 < t1 < . . . < tN = T , and regard
x(t) as depended variables
▶ parametrize controls by q = (q0 , . . . , qN −1 ) ∈ RN ·Nu
▶ use numerical integration and obtain state x(t; q) as function of q
0.1
0.05
-0.05
-0.1
u(t)
-0.15 x(t)
-0.2
-0.25
0 0.5 1 1.5 2 2.5 3
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 4/49
Direct single shooting
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 5/49
Numerical example with single shooting
Z 3
min x(t)2 + u(t)3 dt
x(·),u(·) 0
s.t. x(0) = x0 (initial value)
ẋ(t) = (1 + x)x + u, t ∈ [0, 3] (ODE)
−1 ≤ x(t) ≤ 1, t ∈ [0, 3] (path constraint)
−1 ≤ u(t) ≤ 1, t ∈ [0, 3] (path constraint)
x(3) = 0. (terminal constraint)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 6/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
initialization
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
1st iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
2nd iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
3rd iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
4th iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
5th iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
10th iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
15th iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
20th iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
23rd iteration - converged!
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Direct multiple shooting
0.05
-0.05
-0.1
-0.15
u(t)
x(t)
-0.2
0 0.5 1 1.5 2 2.5 3
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 8/49
Direct multiple shooting
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting
xn+1 = ψf (xn , un )
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting
xn+1 = ψf (xn , un )
0 ≥ h(xn , un ), n = 0, . . . N − 1.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct optimal control methods solve Nonlinear Programs (NLP)
s.t. x0 = x̄0
xn+1 = ψf (xn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN )
Variables w = (x, u)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 10/49
Direct optimal control methods solve Nonlinear Programs (NLP)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 10/49
Numerical example with multiple shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
initialization
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
1st iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
2nd iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
3rd iteration
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations
1 1
0.5 0.5
u(t)
x(t)
0 0
-0.5 -0.5
-1 -1
0 1 2 3 0 1 2 3
t t
5th iteration - converged!
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Work flow in smooth direct optimal control
First discretize, then optimize.
Single shooting
SQP
Integrator
OCP Multiple shooting NLP
Direct IPM
transcription
2 Direct methods
4 Collocation methods
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 14/49
Ordinary differential equations and controlled dynamical system
Let:
▶ t ∈ R be the time
▶ x(t) ∈ Rnx the differential states
▶ u(t) ∈ Rnu a given control function
▶ denote by ẋ(t) = dx(t)
dt
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 15/49
Ordinary differential equations and controlled dynamical system
Let:
▶ t ∈ R be the time
▶ x(t) ∈ Rnx the differential states
▶ u(t) ∈ Rnu a given control function
▶ denote by ẋ(t) = dx(t)
dt
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 15/49
Ordinary differential equations and controlled dynamical system
Let:
▶ t ∈ R be the time
▶ x(t) ∈ Rnx the differential states
▶ u(t) ∈ Rnu a given control function
▶ denote by ẋ(t) = dx(t)
dt
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Sufficient conditions for existence and uniqueness
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Sufficient conditions for existence and uniqueness
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Sufficient conditions for existence and uniqueness
˙
x̃(t) ≈ f (t, x̃(t), u(t)), t ∈ [0, T ]
x̃(0) = x(0) = x0
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 17/49
Basic definitions of numerical simulation
˙
x̃(t) ≈ f (t, x̃(t), u(t)), t ∈ [0, T ]
x̃(0) = x(0) = x0
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 17/49
Single step numerical simulation as discrete time system
xn+1 = ϕf (xn , zn , un ),
0 = ϕint (xn , zn , un ), n = 0, . . . , N − 1.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 18/49
Single step numerical simulation as discrete time system
xn+1 = ϕf (xn , zn , un ),
0 = ϕint (xn , zn , un ), n = 0, . . . , N − 1.
xn+1 = xn + hf (xn , un ),
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 18/49
Single step numerical simulation as discrete time system
xn+1 = ϕf (xn , zn , un ),
0 = ϕint (xn , zn , un ), n = 0, . . . , N − 1.
xn+1 = xn + hzn ,
0 = f (xn , un ) − zn .
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 18/49
Integration error
12
x(t)
10
2
e(t1 )
0
0 0.2 0.4 0.6 0.8 1 1.2
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error
12
x(t)
10
2 e(t2 )
0
0 0.2 0.4 0.6 0.8 1 1.2
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error
12
x(t)
10
4
e(t3 )
2
0
0 0.2 0.4 0.6 0.8 1 1.2
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error
12
x(t)
10
6 e(t4 )
4
0
0 0.2 0.4 0.6 0.8 1 1.2
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error
12
▶ Global integration error at t = T :
x(t)
10 e(t5 )
8
E(T ) = ∥x(T ) − xN ∥.
6
errors t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Convergence and integrator order
▶ Convergence
10 -4
lim E(T ) = 0 10 -6
h→0
E(T )
▶ Integrator has order p if 10 -8
10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order
▶ Convergence
10 -4
lim E(T ) = 0 10 -6
h→0
E(T )
▶ Integrator has order p if 10 -8
10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order
▶ Convergence
10 -4
lim E(T ) = 0 10 -6
h→0
E(T )
▶ Integrator has order p if 10 -8
10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order
▶ Convergence
10 -4
lim E(T ) = 0 10 -6
h→0
E(T )
▶ Integrator has order p if 10 -8
10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order
▶ Convergence
10 -4
lim E(T ) = 0 10 -6
h→0
E(T )
▶ Integrator has order p if 10 -8
10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order
10 -2
Integrator convergence and accuracy
10 -4
▶ Convergence
10 -6
lim E(T ) = 0
E(T )
h→0 10 -8
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Stability and convergence
1.5
1
lim E(T ) = 0
h→0
E(T )
x(t)
0
10
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
small x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence
h = 0:1
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10 5
O(h)
1
lim E(T ) = 0
h→0
E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5
h = 0:05
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10 5
O(h)
1
lim E(T ) = 0
h→0
E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5
h = 0:0125
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10 5
O(h)
1
lim E(T ) = 0
h→0
E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5
h = 0:00625
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10
5 O(h)
1
lim E(T ) = 0
h→0
E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5
h = 0:003125
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10
5 O(h)
1
lim E(T ) = 0
h→0
E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5
h = 0:0015625
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10
5 O(h)
1
lim E(T ) = 0
h→0
E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 22/49
Runge-Kutta method definition
Unknowns are derivatives at stage points
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method examples
Explicit Runge-Kutta 4
kn,1 = f (tn , xn )
h kn,1
kn,2 = f (tn + , xn + h )
2 2
h kn,2
kn,3 = f (tn + , xn + h )
2 2
kn,5 = f (tn + h, xn + hkn,3 )
1 2 2 1
xn+1 = xn + h( kn,1 + kn,2 + kn,3 + kn,4 )
6 6 6 6
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 24/49
Runge-Kutta method examples
Explicit Runge-Kutta 4
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 24/49
Explicit vs implicit Runge-Kutta methods
The Butcher tableau
0
c2 a2,1
.. .. .. ..
. . . .
cns ans ,1 ans ,2 ... ans ,ns −1
b1 b2 ... bns −1 bns
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 25/49
Explicit vs implicit Runge-Kutta methods
The Butcher tableau
0
c2 a2,1
.. .. .. ..
. . . .
cns ans ,1 ans ,2 ... ans ,ns −1
b1 b2 ... bns −1 bns
10 0 ure 8.4.
Heun
c1
c2 aoptimal
02. Direct methods for smooth nonlinear 21 control A. Nurkanović 26/49
Differential-Algebraic Equations (DAE) - semi-explicit form
▶ Source problems: conservation laws, fast dynamics: ϵż(t) = g(x(t), z(t), u(t))), ϵ → 0.
▶ The usual case is index one, i.e. the Jacobian ∂g ∂z is invertible. If this is not the case,
dd
replace g(x, z, u) = 0 by dtd g = 0, until it is (higher index).
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 27/49
Runge-Kutta methods for differential algebraic equations
Unknowns are derivatives of states ki,j and algebraic states zi,j at stage points
is called a ns -stage Runge-Kutta (RK) method for DAEs of index 1. Here zn,i , i = 1, . . . , ns
are the stage values for the algebraic variables and zn+1 is the approximation of z(tn+1 ).
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 28/49
Runge-Kutta methods for differential algebraic equations
Unknowns are derivatives of states ki,j and algebraic states zi,j at stage points
is called a ns -stage Runge-Kutta (RK) method for DAEs of index 1. Here zn,i , i = 1, . . . , ns
are the stage values for the algebraic variables and zn+1 is the approximation of z(tn+1 ).
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 28/49
Outline of the lecture
2 Direct methods
4 Collocation methods
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 29/49
Collocation
Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation
Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation
Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation
Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
▶ The polynomial qn (t) ≈ x(t) satisfies the ODE on the collocation points:
Collocation equations
qn (tn ) = xn
q̇n (tn + ci h) = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation
Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
▶ The polynomial qn (t) ≈ x(t) satisfies the ODE on the collocation points:
Collocation equations
qn (tn ) = xn
q̇n (tn + ci h) = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation
Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
▶ The polynomial qn (t) ≈ x(t) satisfies the ODE on the collocation points:
Collocation equations
qn (tn ) = xn
q̇n (tn + ci h) = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation - how to implement it?
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
The Lagrange polynomials ℓi (τ )
0.5
`i (= )
0
-0.5 c1 c2 c3 c4 c5
-1
-1.5
-2
-2.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )
`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1
-1.5
-2
-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )
`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1
-1.5
-2
-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )
`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1
-1.5
-2
-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )
`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1
-1.5
-2
-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )
`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1
-1.5
-2
-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )
`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1
-1.5
ns
X -2
ℓi (t) = 1 -2.5
i=1 -0.2 0 0.2 0.4 0.6 0.8 1 1.2
=
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
Collocation - how to implement it - continued
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued
Collocation equations
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
All collocation methods are implicit Runge-Kuta method
Collocation equations
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
All collocation methods are implicit Runge-Kuta method
Collocation equations
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
All collocation methods are implicit Runge-Kuta method
Collocation equations
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
0
0h 1h 2h 3h 10!2 10!1
t h
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
0
0h 1h 2h 3h 10!2 10!1
t h
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
0
0h 1h 2h 3h 10!2 10!1
t h
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
0
0h 1h 2h 3h 10!2 10!1
t h
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2
10!10
0
GL6
-0.2
0h 1h 2h 3h 10!2 10!1
t h
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL8
0
0h 1h 2h 3h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL10
0
0h 1h 2h 3h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
0
0h 1h 2h 3h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
0
0h 1h 2h 3h 4h 5h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 11h 12h 13h 14h 15h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
0.2 10!10
0.1
GL4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
0.2 10!10
0.1
GL4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
0.2 10!10
0.1
GL4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2
10!10
0
GL4
GL6
-0.2
0h 1h 2h 3h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
GL6
0
0h 1h 2h 3h 4h 5h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
GL6
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
100
0.8
0.6
E(T )
10!5
x(t)
0.4
0.2 10!10
GL4
GL6
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 11h 12h 13h 14h 15h 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
0.2 10!10
GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
0.2 10!10
GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
0.2 10!10
GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization
0.9
100
0.8
0.7
0.6
E(T )
10!5
x(t)
0.5
0.4
0.3
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Direct collocation in optimal control
Collocation equations
ns
X
xn+1 = xn + h kn,i bi (next value)
i=1
ns
X
kn,1 = f (tn + c1 h, xn + h kn,j a1,j , un ) (stage Eq. 1)
j=1
..
.
ns
X
kn,ns = f (tn + cns h, xn + h kn,j ans ,j , un ), (stage Eq. ns )
j=1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Direct collocation in optimal control
Collocation equations
ns
X
xn+1 = xn + h kn,i bi (next value)
i=1
ns
X
0 = kn,1 − f (tn + c1 h, xn + h kn,j a1,j , un ) (stage Eq. 1)
j=1
..
.
ns
X
0 = kn,ns − f (tn + cns h, xn + h kn,j ans ,j , un ), (stage Eq. ns )
j=1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Direct collocation in optimal control
Collocation equations
ns
X
xn+1 = xn + h kn,i bi =: ϕf (xn , zn , un ) (next value)
i=1
Pns
kn,1 − f (tn + c1 h, xn + h j=1
kn,j a1,j , un )
..
0= =: ϕint (xn , zn , un ) (stage Eqs.)
. Pns
kn,ns − f (tn + cns h, xn + h j=1 kn,j ans ,j , un )
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Direct collocation in optimal control
Collocation equations
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Continious time OCP into Nonlinear Programs (NLP)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)
0 ≥ h(xn , un ), n = 0, . . . N − 1.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Direct optimal control methods solve Nonlinear Programs (NLP)
s.t. x0 = x̄0
xn+1 = ϕf (xn , zn , un )
0 = ϕint (xn , zn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN )
Variables w = (x, z, u)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 38/49
Direct optimal control methods solve Nonlinear Programs (NLP)
Variables w = (x, z, u)
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 38/49
Direct optimal control methods solve Nonlinear Programs (NLP)
r2ww L(w; 6; 7)
0
Nonlinear Program (NLP)
20
rw G(w)
0 40
60 min F (w)
w∈Rnx
80
50
0 50 100
s.t. G(w) = 0
100
nz = 196
120
H(w) ≥ 0
0 50 100
nz = 611
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 38/49
Work flow in smooth direct optimal control
First discretize, then optimize.
Single shooting
SQP
Integrator
OCP Multiple shooting NLP
Direct IPM
transcription
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 41/49
Reading recommendations
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 42/49
Free online video lectures
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 43/49
References used for this lecture
▶ Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2019.
▶ James B. Rawlings, David Q. Mayne, and Moritz Diehl. Model predictive control: theory,
computation, and design. Vol. 2. Madison, WI: Nob Hill Publishing, 2017.
▶ Gerhard Wanner, Ernst Hairer. ”Solving ordinary differential equations II.” Vol. 375. New
York: Springer Berlin Heidelberg, 1996.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 44/49
Direct collocation via state values
To discretize an optimal control problem with direct collocation we replace the continuous-time
dynamics
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 45/49
Direct collocation via state values
▶ choice of 0 = c0 < c1 < . . . < cns ≤ 1 determines the accuracy and stability properties of
the resulting method
▶ popular choices for ci are the Radau IIA or Gauss-Legendre points.
▶ Previously treated: interpolating polynomial q̇n (t) through the state derivatives
kn,1 , . . . , kn,ns .
▶ Here, finding the interpolating polynomial qn (t) through the initial value xn and state
values xn,1 , . . . , xn,ns at the stage points.
▶ We use of the Lagrangian polynomial basis. Using these time points, we define a basis for
our polynomials:
ns
Y τ − cj
ℓi (τ ) = , i = 0, . . . , ns . (2)
ci − cj
j=0, i̸=j
▶ Remark: in contrast to using state derivatives kn,i , the counter starts from i = 0, as we
include the point c0 = 0, since we interpolate through xn .
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 46/49
Direct collocation via state values
We approximate the state trajectory on [tn , tn+1 ] by a linear combination of the basis functions:
ns
t − tn
X
qn (t) = ℓj xn,j . (3)
j=0
h
The collocation equations must satisfy the ODE at every collocation point tn,i :
That is:
ns
1 X
Cj,i xn,j = f (xn,i , un ), i = 1, . . . ns . (5)
h j=0
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 47/49
Collocation: next step and cost integral approximation
The expression for the state at the end of an interval reads as:
ns
X ns
X
xn+1 = ℓi (1) xn,i := Di xn,i (6)
i=0 i=0
Moreover, using the obtained approximation qn (t) we can integrate the stage cost
Z T
L(x(t), u(t))dt,
0
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 48/49
Runge-Kutta method definition
Unknowns are states at stage points, cannot treat case of c1 = 0
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 49/49
Runge-Kutta method definition
Unknowns are states at stage points, cannot treat case of c1 = 0
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 49/49