## 3 Optimal Control of the Hybrid Electric Powertrain
If it is known in advance, the optimal control variable \(\mathbf{u}^{*}\) will be obtained by finding the maximum of the Hamilton function with respect to Equations (11)-(17):  
\[\mathcal{H}^{*}=\max_{\mathbf{u}}\bigl{\{}-\dot{m}_{t}(\mathbf{u})+\lambda \cdot\dot{q}(\mathbf{u},q)\bigr{\}}. \tag{20}\]  
Usually, the Lagrange multiplier \(\lambda\) is a function of time and the vehicle's position such that Equation (20) can be carried out as a local optimization for a certain position of the vehicle. In the EMCS algorithm, the control variables of the powertrain are determined by means of this local optimization, where \(\lambda\) is obtained by a prediction (see Section 4). Another method for solving the optimization problem in Equations (11)-(18) is based on Dynamic Programming (DP). Here, the driving cycle is separated into discrete instants of time \(t_{k}=k\cdot T\), with the step size \(T\) and \(k=0\ldots N\). Additionally, the state and input variables are quantized by means of the state variable grid \(\mathbf{q}^{\mathcal{S}}=\left[q_{1}^{\mathcal{S}}\dots q_{n}^{\mathcal{S}} \right]^{T}\) and the input variable grids \(\mathbf{s}_{\mathbf{m}}^{\mathcal{S}}=\left[\mathbf{s}_{\mathbf{m},1}^{ \mathcal{S}}\dots\mathbf{s}_{\mathbf{m},o}^{\mathcal{S}}\right]^{T}\) and \(\mathbf{u}_{\text{ED}}^{\mathcal{S}}=\left[u_{\text{ED},1}^{\mathcal{S}}\dots u _{\text{ED},m}^{\mathcal{S}}\right]^{T}\). A cost matrix \(\mathbf{J}\) with \(n\) rows and \(N\) columns defines the accumulated costs for all possible state transitions from one time step to another. Each row is assigned to the corresponding state within \(\mathbf{q}^{\mathcal{S}}\) and each column to the instant of time \(t_{k}\). In order to obtain \(\mathbf{J}\), a backward computation beginning with \(k=N-1\) and ending with \(k=0\) is carried out. In each time step \(k\), the minimal costs must be determined for all \(i=1\ldots n\) as follows:  
\[J_{i,k}=\min_{\mathbf{u}_{k}}\Bigl{\{}J_{p,k+1}+T\cdot\dot{m}_{t}(\mathbf{u}_{ k})\Bigr{\}}. \tag{21}\]  
The minimum is determined by evaluating all possibilities for the control variable \(\mathbf{u}_{k}\) (i.e., all combinations of the elements within the grid vectors \(\mathbf{s}_{\mathbf{m}}^{\mathcal{S}}\) and \(\mathbf{u}_{\text{ED}}^{\mathcal{S}}\) with respect to the system boundaries defined in Equation (17). For the determination of the costs \(J_{p,k+1}\), the state equation is evaluated:  
\[q_{p}=q_{i}^{\mathcal{S}}+T\cdot\dot{q}\Bigl{(}\mathbf{u}_{k},q_{i}^{\mathcal{ S}}\Bigr{)}, \tag{22}\]  
where the index \(p\) denotes the row in \(\mathbf{q}^{\mathcal{S}}\) of \(\mathbf{J}\) assigned to \(q_{p}\). Since \(q\) describes a continuous variable, it might not match an element within the predefined state grid \(\mathbf{q}^{\mathcal{S}}\). In this case, \(J_{p,k+1}\) is interpolated based on the surrounding elements within \(\mathbf{q}^{\mathcal{S}}\)[21]. Once the cost matrix \(\mathbf{J}\) is known, the optimal control variable \(\mathbf{u}^{*}\) is obtained by means of a forward computation beginning with \(k=0\) and ending with \(k=N-1\):  
\[\mathbf{u}_{k}^{*}=\arg\min_{\mathbf{u}_{k}}\Bigl{\{}J_{p,k+1}+T\cdot\dot{m}_{ t}(\mathbf{u}_{k})\Bigr{\}}, \tag{23}\]where \(J_{p,k+1}\) is determined analogously to the backward computation based on the following state equation:  
\[q_{p}^{*}=q_{k}^{*}+T\cdot\dot{q}(\mathbf{u}_{k},q_{k}^{*}). \tag{24}\]  
Here, the optimal electric charge \(q_{k}^{*}\) and beginning with \(q_{0}^{*}\) relate to the initial state of charge \(SoC_{0}\) (see Equation (13)). Since DP can only be applied on a driving cycle, which is known in advance, it cannot be used as a real-time capable operating strategy. Furthermore, a very high computation effort is required when choosing a high resolution for the state and input variable grids. Nevertheless, DP can be used to predict \(\lambda\) for the ECMS and to compute the theoretically minimal fuel consumption for a given driving cycle.