## 2 Methods
### Model Predictive Control
#### 2.5.2 Cost Function with Explicit Fuel Economy Objective  
As mentioned in the introduction, two different cost functions were formulated for the MPC implementation. Both attempt to realize the car-following objective while minimizing fuel consumption. Terms related to comfort and safety are also included to ensure a realistic implementation.  
The first cost function does not conform to a quadratic form and was formulated as follows:  
\[J_{\text{FC}}=\sum_{k=0}^{H_{p}-1}\left(w_{1}\dot{m}_{\text{fuel},k+1}+w_{2}e_{ \text{d},k+1}^{2}+w_{3}a_{k+1}^{2}+w_{4}u_{k}+w_{5}\zeta_{e,k}^{2}+w_{6}\zeta_{ u,k}^{2}\right) \tag{14}\]  
where \(H_{p}\) is the prediction horizon, \(w_{1},\dots,w_{6}\) are the weighting factors of each term of the cost function, and \(\zeta_{e},\zeta_{u}\) are slack variables, which are variables used to soften the constraints. Constraint softening is useful to improve the computational efficiency of the optimization problem and to guarantee that a solution is found even if no physical solution can be computed with the corresponding hard constraints. In such cases, the solver is allowed to search for a feasible solution outside the boundaries but penalizes this action using slack variables in the cost function [45].  
These constraints were formulated to achieve the car-following objective without violating the vehicle's acceleration limits:  
\[e_{d\text{min}}+\zeta_{e}\leq e_{\text{d}}\leq e_{d\text{max}}+ \zeta_{e} \tag{15}\] \[v_{\text{min}}\leq v\] (16) \[u_{\text{min}}+\zeta_{u}\leq u\leq u_{\text{max}}+\zeta_{u} \tag{17}\]  
where \(e_{d\text{min}}=0\), \(e_{d\text{max}}=25\), \(v_{\text{min}}=0\), \(u_{\text{min}}=-1\) and \(u_{\text{max}}=1\).  
Balancing different control objectives, constraint softening, and achieving satisfying performances requires accurate tuning of the controller parameters and hence the weighting factors. In this work these are determined through trial and error.  
As explained in Section 2.1, the fuel flow rate map (Equation (3)) is a linear interpolant; thus, it is not a smooth function, and its derivatives present discontinuities. While this is not a challenge for dynamic programming, it makes the MPC optimization problem significantly harder and might seriously hamper its real-time capabilities. To overcome this issue, the fuel flow rate map was approximated with a polynomial function. In particular, we found that a first-order polynomial was sufficient to achieve a reasonably accurate fit for our engine map:  
\[\dot{m}_{\text{fuel}}=p_{00}+p_{10}\omega_{\text{eng}}+p_{01}T_{\text{eng}} \tag{18}\]  
where \(p_{00},p_{01}\) and \(p_{10}\) represent the fit coefficients.  
Figure 1 shows the fuel flow rate obtained by simulating the vehicle on the UDDS driving cycle using the fuel consumption map and its polynomial approximation. As the figure shows, the first-order polynomial overestimates fuel consumption by approximately 6%.  
Equation (18) was then rewritten as a function of the state variables only, hence giving:  
\[\dot{m}_{\text{fuel}}=p_{00}+p_{10}\frac{x(2)}{r_{\text{wh}}}\tau_{\text{gb}} \tau_{\text{fd}}+p_{01}\frac{(f_{0}+f_{2}x(2)^{2}+mx(3))r_{\text{wh}}}{\tau_{ \text{gb}}\tau_{\text{fd}}}, \tag{19}\]  
so that the cost function can be written explicitly. We will refer to this controller as MPC\({}_{\text{FC}}\) in the following sections.