CasADi

optimal control problems

discretize-then-optimize

optimize-then-discretize

write your own OCP solver

CasADi

8

1

8

2

Van der Pol

( 8 . 1 )

In CasADi 's examples collection8.3, you find codes for solving optimal control problems using a variety of different methods.

In the following, we will discuss three of the most important methods, namely direct single shooting, direct collocation and direct collocation.

In the direct single shooting method, the control trajectory is parameterized using some piecewise smooth approximation, typically piecewise constant.

Using an explicit expression for the controls, we can then eliminate the whole state trajectory from the optimization problem, ending up with an NLP in only the discretized controls.

In CasADi 's examples collection, you will find the codes direct_single_shooting.py and direct_single_shooting.m for Python and MATLAB/Octave, respectively. These codes implement the direct single shooting method and solves it with IPOPT, relying on CasADi to calculate derivatives. To obtain the discrete time dynamics from the continuous time dynamics, a simple fixed-step Runge-Kutta 4 (RK4) integrator is implemented using CasADi symbolics. Simple integrator codes like these are often useful in the context of optimal control, but care must be taken so that they accurately solve the initial-value problem.

The code also shows how the RK4 scheme can be replaced by a more advanced integrator, namely the CVODES integrator from the SUNDIALS suite, which implements a variable stepsize, variable order backward differentiation formula (BDF) scheme. An advanced integrator like this is useful for larger systems, systems with stiff dynamics, for DAEs and for checking a simpler scheme for consistency.

direct_multiple_shooting.py

direct_multiple_shooting.m

CasADi

shooting nodes

The direct multiple shooting method is often superior to the direct single shooting method, since "lifting" the problem to a higher dimension is known to often improve convergence. The user is also able to initialize with a known guess for the state trajectory.

The drawback is that the NLP solved gets much larger, although this is often compensated by the fact that it is also much sparser.

direct_collocation.py

direct_collocation.m

The NLP in direct collocation is even larger than that in direct multiple shooting, but is also even sparser.

Travis CI User 2018-02-11