## 3 Mathematical Formulation
### Optimization System
#### 3.2.1 Evo
\[C_{cyc}=\frac{\$_{bat}}{2 NE_{bat}} \tag{10}\]  
\[C_{cal}=\frac{\$_{bat}E_{bat}}{1-SOH_{col}} \tag{11}\]  
\[f(E_{EV_{k}}^{ev})=m_{cal}((t_{k-1}+t_{k})^{b}-t_{k-1}^{b})\frac{E_{EV_{k}}^{ ev}}{E_{EV_{max}}} \tag{12}\]  
where \(\$_{bat}\) is the price per kWh, \(E_{bat}\) is the size of the battery, \(SOH_{col}\) is the end of life state of health, \(t_{k-1}\) is the time since the battery's initial commissioning, \(t_{k}\) is the charging and idle time per time slot, and \(m_{cal}\) and \(b\) are coefficients of the linear approximation of the nonlinear calendar degradation function described in [40; 41].  
The minimization problem should consider operational and technical constraints that ensure safe and economic EV charging events. Equations (13)-(29) mathematically represent these constraints. Equation (13) defines the microgrid power balance constraint, (14)-(17) represent the power limits for the grid, PV installation, and charging and discharging of the second-life battery, (18) and (19) guarantees that the second-life battery do not charge and discharge at the same time, (20) is the energy balance of the second-life battery, (21)-(25) define a piecewise linear approximation for the nonlinear charging profile of each EV for a generic s-pieces function, (26) and (27) define the operating range for the charging power and energy available of each EV, respectively, (28) defines the energy balance of each EV, and (29) defines the aggregated charging power requested by the EV fleet.  
\[P_{\$}+P_{pv_{k}}+P_{SESS_{k}}=P_{l_{k}}+P_{flert_{k}},\forall k\in H \tag{13}\]  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]0  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]1  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]2  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]3\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]4  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]5  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]6  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]7  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]8  
\[Grid_{\$}=\sum_{k=1}^{h}C_{k}^{\$}P_{g_{k}}\delta_{t} \tag{7}\]9  
\[SESS_{\$}=C_{SESS}\sum_{k=1}^{h}P_{SESS_{k}}\delta_{t} \tag{8}\]0  
\[SESS_{\$}=C_{SESS}\sum_{k=1}^{h}P_{SESS_{k}}\delta_{t} \tag{8}\]1  
\[SESS_{\$}=C_{SESS}\sum_{k=1}^{h}P_{SESS_{k}}\delta_{t} \tag{8}\]2  
\[SESS_{\$}=C_{SESS}\sum_{k=1}^{h}P_{SESS_{k}}\delta_{t} \tag{8}\]3  
\[SESS_{\$}=C_{SESS}\sum_{k=1}^{h}P_{SESS_{k}}\delta_{t} \tag{8}\]4  
\[SESS_{\$}=C_{SESS}\sum_{k=1}^{h}P_{SESS_{k}}\delta_{t} \tag{8}\]5  
where \(P_{pv_{k}}\) is the power requested for the PV installation, \(P_{lk}\) and \(P_{flele_{k}}\) are the power demanded by the building and EV charging infrastructure, respectively, \(P_{smx}\), \(P_{pv_{max}}\), \(P_{SESS_{max}}\), and \(P_{SESS_{max}}^{dis}\) are the maximum power of the grid, the PV, and the second-life SESS charging and discharging limits, respectively, \(B_{k}^{ch}\) and \(B_{k}^{dis}\) are Boolean variables that indicate whether SESS is charging or discharging, \(P_{SESS_{k}}^{ch}\) and \(P_{SESS_{k}}^{dis}\) are the SESS charging and discharging power, respectively, \(E_{SESS_{k}}\) is the energy available in the SESS, \(P_{EV_{max}}^{ev}\) is the maximum charging power for each \(ev\), and \(E_{EV_{k}}^{ev}\) and \(W_{EV_{k}}^{ev}\) are the energy available in each EV battery and the estimated consumed energy of each EV per time slot.