## 5 A Case Study
### Mathematical Model  
The problem can be formally defined as an optimization problem, where \(V=\{1,2,\ldots,v\}\) is the set of the vehicles, and \(T=\{0,1,2,\ldots,24\}\) is the set of the times. For each vehicle, the departure time, denoted as \(d_{i}\in T\backslash\{0\}\), follows the arrival time \(a_{i}\in T\backslash\{24\}\). For each vehicle \(i\in V\), \(A_{i}:=\{t\in T:a_{i}\leq t<d_{i}\}\) corresponds to the set of availability hours. We denote \(e_{i}^{t}\) as the energy level of vehicle \(i\in V\) at time \(t\in T\), and \(c^{t}\) shows the electricity cost at time \(t\in T\). In addition, \(\hat{c}_{i}^{t}\) is the associated cost of the charging for the vehicle \(i\in V\) at time \(t\in T\), where \(\hat{c}_{i}^{t}=c^{t}(1-e_{i}^{t})\). Parameter \(\hat{s}_{i}^{t}\) is the saving price of energy for the vehicle \(i\in V\) at time \(t\in T\), where \(\hat{s}_{i}^{t}=c^{t}e_{i}^{t}\). Moreover, the binary variable \(x_{i}^{t}\) equals \(1\) if vehicle \(i\in V\) draws energy from the grid at time \(t\in T\), and \(0\) otherwise. Similarly, another binary variable \(y_{i}^{t}\) equals \(1\) if vehicle \(i\in V\) supplies energy to the grid at time \(t\in T\), and \(0\) otherwise. With these definitions, the mathematical formulation is as follows:  
\[\min \sum_{i\in V}\sum_{t\in T}(\hat{c}_{i}^{t}x_{i}^{t}-\hat{s}_{i}^{t }y_{i}^{t})\] (1) s.t. \[x_{i}^{t}+y_{i}^{t}\leq 1 \forall i\in V,\forall t\in T \tag{2}\] \[e_{i}^{t+1}=x_{i}^{t}+e_{i}^{t}(1-x_{i}^{t})(1-y_{i}^{t}) \forall i\in V,\forall t\in T\] (3) \[x_{i}^{t_{i}-1}=1 \forall i\in V\] (4) \[x_{i}^{t}=0 \forall i\in V,\forall t\in T\setminus A_{i}\] (5) \[y_{i}^{t}=0 \forall i\in V,\forall t\in T\setminus A_{i}\] (6) \[x_{i}^{t}\in\{0,1\} \forall i\in V,\forall t\in T\] (7) \[y_{i}^{t}\in\{0,1\} \forall i\in V,\forall t\in T \tag{8}\]  
The objective function (1) minimizes costs by considering whether a vehicle draws energy from the grid or supplies energy to it. Constraint (2) ensures that each vehicle can either draw energy from the grid or supply it to the grid but not both simultaneously. Constraint (3) ensures that vehicles drawing energy from the grid reach maximum energy capacity by the next hour (note that \(x_{i}^{t}=1\) and \(y_{i}^{t}=0\)), while the levels of vehicles that supply energy to the grid are set to \(0\), as \(x_{i}^{t}=0\) and \(y_{i}^{t}=1\). Moreover, if no action occurs, i.e., \(x_{i}^{t}=0=y_{i}^{t}\), for a vehicle at time \(t\in T\), its energy level remains constant. Constraint (4) guarantees that every vehicle is charged at its departure time. These constraints should only activate if the vehicle is not fully charged when the time arrives; however, if the vehicle is fully charged at time \(d_{i}-1\), its energy level will be equal to \(1\) and, therefore, setting \(x_{i}^{d-1}\) to \(1\) will not affect the total cost. Constraint (5) states that the vehicles can draw energy from the grid only during the time they are available since after the departure time, vehicles cannot draw energy from the grid. Similarly, constraint (6) defines the supplying energy for the grid only in the availability times of the vehicles. Finally, constraints (7) and (8) refer to the binary characteristics of the \(x_{i}^{t}\) and \(y_{i}^{t}\) variables, respectively.