CAPÍTULO III: ORGANIZACIÓN Y DESIGUALDAD CARCELARIA
4. El Consejo de Delegados ¿Quién manda a quién?
As described in Section 7.2.2, each real-time iteration consists of different algorithmic steps. The most important ones are the integration of the dynamic system including the sensitivity generation, the condensing step and the solution of the condensed QP. Table 7.1 lists the runtimes for each of these steps for a typical real-time iteration when controlling the CSTR start-up using the tracking NMPC formulation. We see that the major fraction of the computation time is spent for the sensitivity generation.
Table 7.2 reports the runtimes for a typical real-time iteration with exact Hessian computation using the tracking NMPC formulation. When comparing the runtimes with the ones of Table 7.1, we see that the exact Hessian computation causes the integration and sensitivity generation to take longer, while the effort for all other algorithmic parts basically stays the same.
Next, Table 7.3 reports the runtimes for a typical real-time iteration with exact Hessian computation using the time-optimal NMPC formulation. The reported runtimes are very similar to the ones reported in Table 7.2. This comes at no
NUMERICAL EXAMPLE 139
surprise as all algorithmic steps are basically the same (however, the time-optimal NMPC formulation comprises T as an additional degree of freedom).
CPU time % Integration and sensitivity generation 10.5 ms 69 %
Condensing 3.0 ms 20 %
QP solution (with qpOASES) 0.6 ms 4 %
Remaining operations 1.1 ms 7 %
One complete real-time iteration 15.2 ms 100 %
Table 7.1: Typical runtime performance of one Gauss-Newton real-time iteration when controlling the CSTR start-up using the tracking NMPC formulation.
CPU time % Integration and sensitivity generation 29.1 ms 86 %
Condensing 3.0 ms 9 %
QP solution (with qpOASES) 0.6 ms 2 %
Remaining operations 1.1 ms 3 %
One complete real-time iteration 33.8 ms 100 %
Table 7.2: Typical runtime performance of one real-time iteration with exact Hessian computation when controlling the CSTR start-up using the tracking NMPC formulation.
CPU time % Integration and sensitivity generation 31.7 ms 87 %
Condensing 3.3 ms 9 %
QP solution (with qpOASES) 0.7 ms 2 %
Remaining operations 0.9 ms 2 %
One complete real-time iteration 36.6 ms 100 %
Table 7.3: Typical runtime performance of one real-time iteration with exact Hessian computation when controlling the CSTR start-up using the time-optimal NMPC formulation.
Chapter 8
Code Generation
for Nonlinear MPC
This chapter presents the ACADO Code Generation tool [80, 129] for generating real-time iteration algorithms for nonlinear MPC. Based on the symbolic syntax of the ACADO Toolkit, it allows the user to export highly efficient and self- containedCcode that is tailored to each respective MPC problem formulation. We explain its algorithmic components and investigate its computational performance. It is illustrated with small-scale NMPC examples that automatically generated NMPC algorithms can significantly outperform their counterparts implemented in a generic way. The ACADO Code Generation tool has been developed jointly with Boris Houska and is the second main contribution of the second part of this thesis.
8.1
Introduction
The idea to automatically generate tailored source code in order to speed-up the numerical solution of optimisation problems is not new. More than 20 years ago, a code generation environment to export tailored implementations of Karmarkar’s algorithm for solving LPs was presented [182]. It exported PASCAL source code implementing a customised Cholesky decomposition as well as further matrix- vector operations, but does not seem to have received much attention.
About one decade ago, code generation was proposed for use in nonlinear MPC. The software AutoGenU by Ohtsuka and Kodama [181, 180] provides Mathematica scripts to generate customised C code implementing the Continuation/GMRES method as described in Subsection 6.4.4. AutoGenU allows the user to specify the
MPC problem formulation together with initialisations in the symbolic syntax of Mathematica. Solving only one linear system per sampling instant, the exported NMPC algorithm has been used to control an experimental hovercraft setup at sampling times of 1.5 milliseconds [210].
Recently, code generation has attracted great attention due to the software package CVXGEN[169]. It is based on the Matlab front-end CVX [112, 113]—which provides a symbolic syntax to formulate and solve convex optimisation problems—and allows the user to generate customised interior-point solvers for small-scale LP and QP problems. In particular, linear MPC problems can be solved based on highly efficient, auto-generated code. The main ingredient of the exported code is a sparse Cholesky decomposition of the interior-point KKT system (6.23). CVXGEN automatically detects the respective sparsity pattern and determines a fixed pivoting that aims at avoiding fill-in in the Cholesky factors as far as possible. CVXGENis not freely available but can be tested by academic users via a dedicated web interface [168].
After this brief review of previous approaches to auto-generate code for solving optimisation problems, we want to summarise the two main advantages that motivate automatic code generation:
• Speeding-up computations by tailoring the code to each specific optimisation problem formulation. This can comprise an optimised memory management as problem dimensions and sparsity patterns can be detected and hard- coded beforehand. Moreover, computations of the exported code might be organised in such a way that they maximise the cache usage of the respective target hardware. Also loop unrolling and the correct choice of compiler settings might speed-up computations significantly. Finally, the numerical algorithm itself might be tailored to the specific application by leaving away unnecessary computations.
• Increased adaptivity of the numerical algorithm to be exported by influencing its programming syntax. For example, the code generator might offer options to choose between single and double precision arithmetic or to avoid certain programming constructs or calls to functions from standard libraries that are not available on the respective target hardware1. It might even be desired
to export one and the same optimisation code in different programming languages (like the Multi-Parametric Toolbox for explicit MPC that allows the user to generate the online look-up table both in C and in a language compatible with certain programmable logic controllers [153]).
1Up to a certain extend this could also be achieved by using preprocessor directives. However, this might greatly reduce readability and maintainability of the code.
AUTO-GENERATED REAL-TIME ITERATION ALGORITHMS 143
These benefits of code generation seem to be most relevant for real-time optimisation algorithms that need to solve optimisation problems at very high sampling rates. This is particularly true if these algorithms are designed to run on embedded hardware, as this imposes specific requirements on the implementation (see the discussion of Subsection 5.1.2). Thus, code generation looks like a promising technique, especially for small- to medium-scale nonlinear MPC problems.