## 2 Methods
### Model Predictive Control  
2.5.1. MPC Algorithm and Implementation  
Model predictive control is suitable for online applications, predicting future states to optimize control actions. MPC uses a predictive model to compute a control sequence, minimizing a cost function over a finite horizon. The process involves iterating on the control sequence, applying only the first control input, and updating the model with new measurements at each time step. To facilitate the online application of the controller, a linear MPC approach was chosen, necessitating a linear plant model for predictions and a quadratic cost function. The linear model allows the MPC to predict the system states over the prediction horizon, consisting of \(H_{p}\) steps, each with a duration of \(T_{s}\).  
The MPC algorithm follows these steps:  
1. Prediction model: Use the vehicle model to predict future states over the prediction horizon based on the current state and control inputs.
2. Optimization: Solve an optimization problem to find the control inputs that minimize the cost function, subject to constraints.
3. Implementation: Apply the first control input from the optimized sequence.
4. Update: Update the model with new state measurements and repeat the process.  
The prediction model accounts for vehicle dynamics and the behavior of the lead vehicle. The optimization problem is solved using numerical methods, typically with a dedicated solver.  
The control inputs include throttle and brake commands, which are adjusted to achieve the desired speed and distance. The implementation of the first control input uses the detailed vehicle model to end up in the update phase with the new state measurements.  
The MPC controller was implemented in a MATLAB environment using the YALMIP toolbox [42], which allows for the formulation of optimization problems using algebraic equations and acts as an interface to an array of solvers. The optimization problem was transcribed in an implicit, and hence sparse, formulation [43] and solved with a semidefinite programming solver from the MOSEK software, 10.2.1 version number package [44]. As mentioned above, the problem is in a quadratic form; thus, the chosen solver is computationally efficient for this class of optimization problems. To ensure feasibility and stability, practical strategies were employed, including the introduction of soft constraints, as detailed in the following section, and the use of a sufficiently long prediction horizon.  
To meet the performance requirements, two formulations for the cost function are proposed. The first one includes fuel consumption, distance error, velocity, acceleration, and a penalty on control effort. The second one does not include fuel consumption. The reason behind this is that the control problem of a fuel consumption-oriented solution is typically not as simple as a linear problem with a quadratic cost function. In [15], the authors state that under certain conditions, the fuel consumption can be considered proportional to the acceleration. Our goal is to demonstrate that by appropriately tuning weights, the two controllers can achieve comparable results, and we validate their goodness by comparing them with DP.