## 2 Methods
### Dynamic Programming  
Dynamic programming is a mathematical optimization method used to solve multi-stage decision problems by breaking them down into simpler sub-problems. DP is particularly useful in problems where decisions need to be made sequentially and the outcome depends on previous decisions. At each stage, the system progresses according to its inherent dynamics and is affected by the decisions made. If the system's evolution is entirely predictable, the problem is classified as deterministic, as for the problem under investigation. Conversely, if random phenomena impact the system's evolution, the problem is considered stochastic.  
In ACC optimization, DP is used to compute the optimal speed and acceleration profiles that minimize fuel consumption while maintaining a safe distance from the lead vehicle and satisfactory driver comfort. The DP algorithm considers all possible acceleration and deceleration scenarios at each time step and evaluates their impact on the total cost over a finite horizon. The Bellman equation guides the recursive computation of the optimal policy, which minimizes the cumulative cost [38]:  
\[J^{*}(x_{k})=\min_{u_{k}}\{g(x_{k},u_{k})+J^{*}(x_{t+1})\}, \tag{10}\]  
where:  
* \(J^{*}(x_{k})\) is the optimal cost-to-go from state \(x_{k}\);
* \(g(x_{k},u_{k})\) is the immediate cost incurred by applying control \(u_{k}\) at state \(x_{k}\);
* \(x_{t+1}\) is the state at the next time step resulting from control \(u_{k}\).  
In our framework, the total cost \(J\) includes two terms. The first is the fuel flow rate to minimize the overall fuel consumption. The second is a penalty term to enforce acceleration constraints. The cost was formulated as follows:  
\[J=\sum_{t=0}^{T}\left(\dot{m}_{\text{fuel}}(t)\cdot T_{s}+w_{1}a^{2}(t)\right), \tag{11}\]  
where \(w_{1}\) is a weighting factor. The penalty term ensures that the vehicle avoids abrupt accelerations or decelerations that could compromise passenger comfort or safety.  
The optimization problem was implemented in a MATLAB environment, and a MATLAB tool for general-purpose DP optimization, called DynaProg [39], was used to solve the problem. For the current application, the optimization tool allows us to set unfeasibility, thus constraining the problem easily. For this reason, to ensure that the vehicle maintains a safe distance from the lead vehicle, constraints on the distance error are set. The minimum distance constraint is set to avoid collision between the two vehicles and is formulated as follows:\[e_{\text{d,min}}=max(-0.9\,t_{h,\text{des}}v_{\text{ego}},-20) \tag{12}\]  
By imposing this constraint, we ensure that the ego vehicle does not fall below the standstill distance. However, we allow the relative distance to be less than the predefined safe distance without risking a collision. The maximum distance error constraint is instead a constant value:  
\[e_{\text{d,max}}=30 \tag{13}\]  
Setting this threshold is crucial to prevent the inter-vehicle distance from becoming too large, which increases the likelihood of other vehicles cutting in. It is indeed important to take into account how other traffic participants react to ecological driving strategies [40; 41].