## 2 Methodology
### Mixed Integer Linear Problem Formulation  
The general formulation of the MILP problem is reported in Equation (4), where \(f(\mathbf{x})\) is the linear objective function, \(\mathbf{A}\) and \(\mathbf{b}\) are the coefficient matrix and the known term vector of the inequality constraints, respectively; \(\mathbf{A_{eq}}\) and \(\mathbf{b_{eq}}\) are the coefficient matrix and the known term vector of the equality constraints, respectively; \(\underline{\mathbf{x}}\) and \(\overline{\mathbf{x}}\), respectively, are the lower and upper boundary vectors of the state variables:  
\[\begin{array}{c}\underset{\mathbf{x}}{\min}f(\mathbf{x})\\ s.t.\{\mathbf{\ \where the first two terms represent the cost for energy purchase and the revenue for power delivery at the grid connection point, whereas the third term accounts for the wearing cost of storage systems associated with both charge and discharge. The last term in Equation (5) is linked to EVs, and takes into account proper wearing costs, the revenue for EV discharge, and the cost for EV charge, considering the presence of an intermediate entity between EVs and the microgrid.  
Many of the unitary costs in Equation (5) are defined by proper tariff schemes. The wearing cost of storage system \(w_{i}\) is defined as a function of the maximum number of cycles \(\Phi_{i}\) at the desired level of depth-of-discharge \(DOD_{i}\)[49], as per the following expression:  
\[w_{i}=\left(\frac{1}{\Phi_{i,0}}-\frac{1}{\Phi_{i}}\right)\cdot K_{i}, \tag{6}\]  
where \(K_{i}\) is the purchasing and installation cost of the \(i\)-th storage system and \(\Phi_{i,0}\) is the maximum number of cycles at the full discharge rate. The degradation cost of EV batteries \(w_{j}\) is defined in the same way. The following constraints hold:  
\[P_{g}^{in}(t)\leq v_{g}(t)\cdot\overline{P}_{g}\quad\forall t, \tag{7}\]  
\[P_{g}^{out}(t)\leq\left(1-v_{g}(t)\right)\cdot\overline{P}_{g}\quad\forall t, \tag{8}\]  
\[P_{i}^{c}(t)\leq v_{i}(t)\cdot\overline{P}_{i}^{c}\quad\forall i,t, \tag{9}\]  
\[P_{i}^{d}(t)\leq(1-v_{i}(t))\cdot\overline{P}_{i}^{d}\quad\forall i,t, \tag{10}\]  
\[P_{j}^{c}(t)\leq v_{j}(t)\cdot\overline{P}_{j}^{c}\quad\forall j,t, \tag{11}\]  
\[P_{j}^{d}(t)\leq\left(1-v_{j}(t)\right)\cdot\overline{P}_{j}^{d}\quad\forall j,t, \tag{12}\]  
\[0\leq P_{g}^{in}(t)\leq\overline{P}_{g}\quad\forall t, \tag{13}\]  
\[0\leq P_{g}^{out}(t)\leq\overline{P}_{g}\quad\forall t, \tag{14}\]  
\[0\leq P_{i}^{c}(t)\leq\overline{P}_{i}^{c}\quad\forall i,t, \tag{15}\]  
\[P_{g}^{in}(t)\leq v_{g}(t)\cdot\overline{P}_{g}\quad\forall t, \tag{7}\]0  
\[P_{g}^{in}(t)\leq v_{g}(t)\cdot\overline{P}_{g}\quad\forall t, \tag{7}\]1  
\[P_{g}^{in}(t)\leq v_{g}(t)\cdot\overline{P}_{g}\quad\forall t, \tag{7}\]2  
\[P_{g}^{in}(t)\leq v_{g}(t)\cdot\overline{P}_{g}\quad\forall t, \tag{7}\]3  
\[P_{g}^{in}(t)\leq v_{g}(t)\cdot\overline{P}_{g}\quad\forall t, \tag{7}\]4  
\[ \begin{array}{l}\left[h_{g}(t)\cdot\left(1-\alpha_{g}(t)\right)\right]\cdot P _{g}^{in}(t)-\left[\frac{1}{h_{g}(t)}\cdot\left(1+\alpha_{g}(t)\right)\right] \cdot P_{g}^{out}(t)+\\ +\sum\limits_{i=1}^{N_{g}}\left[\left[h_{i}(t)\cdot\left(1-\alpha_{i}(t) \right)\right]\cdot P_{i}^{d}(t)-\left[\frac{1}{h_{i}(t)}\cdot\left(1+\alpha_ {i}(t)\right)\right]\cdot P_{i}^{c}(t)\right]+\\ +\sum\limits_{j=1}^{N_{g}}\left[\left[h_{j}(t)\cdot\left(1-\alpha_{j}(t) \right)\right]\cdot P_{j}^{d}(t)-\left[\frac{1}{h_{j}(t)}\cdot\left(1+\alpha_ {j}(t)\right)\right]\cdot P_{j}^{c}(t)\right]+\\ +\left[h_{PV}(t)\cdot\left(1-\alpha_{PV}(t)\right)\right]\cdot P_{PV}(t)=0 \qquad\forall t\\ S_{i}(t)=S_{i}(t-1)+\eta_{i}^{c}(t)\cdot P_{i}^{c}(t)\cdot\Delta T-\frac{1}{ \eta_{i}^{d}(t)}\cdot P_{i}^{d}(t)\cdot\Delta T-\rho_{i}\cdot\Delta T\quad \forall i,t[0,1],\end{array}