## 3 Problem Formulation
### Upper-Level Model for DSO  
To optimize the DN operations, the objective function of the upper-level model aims to minimize the operating cost from the DSO perspective, including three terms. The first term represents the power losses, while the second term indicates the cost of purchasing/selling active power from/to the day-ahead wholesale market, and the third term is the cost of exchanging power at the tie-line between the DN and MG. If \(P_{tie}>0\), the DSO is selling power to the MG and if \(P_{tie}<0\), the DSO is purchasing power from the MG, and also if \(P_{tie}=0\), no power exchange takes place between the DSO and MGO. \[\min F=\sum_{t=1}^{T}[C_{loss}(t)+C_{M}(t)+C_{tie}(t)] \tag{8}\]  
where \(C_{loss}(t)\) is the cost of the power losses at time \(t\); \(C_{M}(t)\) is the cost of purchasing/selling active power from/to the day-ahead wholesale market at time \(t\); \(C_{tie}(t)\) is the cost of exchanging power at the tie-line between DN and MG at time \(t\). In general, the DN operating costs for renewable and storage energy are not considered when calculating the minimal operating cost, because the fuel costs are almost equal to zero. Therefore, these operating costs are not considered in our work. The detailed objective function is expressed as follows:  
\[\min F=\sum_{t=1}^{T}\Bigl{[}\rho_{loss}P_{loss}(t)+\rho_{M}(t)\Bigl{(}P_{M,p }(t)-P_{M,s}(t)\Bigr{)}+\rho_{e}(t)P_{tie}(t)\Bigr{]} \tag{9}\]  
where \(\rho_{loss}\) is the price for power losses, in $/kWh; \(P_{loss}(t)\) is the amount of active power losses; \(\rho_{M}(t)\) is the day-ahead clearing price in the wholesale market at time \(t\), in $/kWh; \(P_{M,p}(t)\)/\(P_{M,s}(t)\) is the power  
Figure 2: Overall scheme of a bi-level model. MGO: microgrid operator; DSO: distribution network operator; WT: wind turbine; PV: photovoltaic; MT: microturbine; BESS: battery energy storage system. purchased from/sold to the wholesale market at time \(t\), in $/kWh; \(\rho_{e}(t)\) is the day-ahead energy exchange price announced by the DSO for the MG at time \(t\), in $/kWh. Here, \(P_{M}(t)\) and \(\rho_{e}(t)\) are decision variables on the upper-level. The power flow equations for the DN, including the active and reactive power, are modified as follow:  
\[\left\{ \begin{array}{l}P_{Gmi,t}-P_{Lmi,t}-V_{i,t}\sum\limits_{j=1}^{n-1}V_{ j,t}(G_{ij}\cos\theta_{ij,t}+B_{ij}\sin\theta_{ij,t})=0\\ Q_{Gmi,t}-Q_{Lmi,t}-V_{i,t}\sum\limits_{j=1}^{n-1}V_{j,t}(G_{ij}\sin\theta_{ ij,t}-B_{ij}\cos\theta_{ij,t})=0\end{array} \right. \tag{10}\]  
where \(P_{Gmi,t}\) is the active power of the \(i\)th node with the MG at time \(t\); \(P_{Lmi,t}\) is the active power of the \(i\)th load node at time \(t\); \(V_{i,t}\) is the voltage of the \(i\)th node at time \(t\); \(V_{j,t}\) is the voltage of the \(j\)th node at time \(t\); \(G_{ij}\) is the conductance element of the DN admittance matrix; \(B_{ij}\) is the susceptance element of the DN admittance matrix; \(\theta_{ij,t}\) is the phase angle difference between the \(i\)th and \(j\)th nodes at time \(t\). The amount of active power loss is calculated as follows:  
\[P_{loss}(t)=\sum\limits_{i,j=1}^{N}R_{ij}\Bigg{(}\frac{P_{Gmij,t}^{2}+Q_{Gmij, t}^{2}}{V_{i,t}}\Bigg{)} \tag{11}\]  
where \(R_{ij}\) is the resistance of branch \(ij\).