# Hierarchical Optimization Method for Energy Scheduling of Multiple Microgrids
## 4 Optimization Scheduling
### Stackelberg Game for EMOs
#### 4.2.2 Achievement of Game Equilibrium  
It is known from (2) and (3) that the utility of MGs can be modified as  
\[U_{i}^{h}=\left\{ \begin{array}{ll}\theta pv_{i}^{h}+k_{i}^{h}\ln(1+l_{i}^{h} )-p_{cb}^{h}(l_{i}^{h}+e_{i}^{h}-pv_{i}^{h}),\;l_{i}^{h}+e_{i}^{h}-pv_{i}^{h}<0 \\ \theta pv_{i}^{h}+k_{i}^{h}\ln(1+l_{i}^{h})-p_{cs}^{h}(l_{i}^{h}+e_{i}^{h}-pv_ {i}^{h}),\;l_{i}^{h}+e_{i}^{h}-pv_{i}^{h}\geq 0\end{array} \right.. \tag{21}\]  
For the given internal prices \(p_{cb}^{h}\) and \(p_{cs}^{h}\), the optimal energy consumption \(l_{i}^{ho}\) can be easily obtained by making \(\partial U_{i}^{h}/\partial l_{i}^{h}=0\), which leads to  
\[l_{i}^{ho}=\left\{ \begin{array}{ll}k_{i}^{h}/p_{cb}^{h}-1,\;l_{i}^{h}+e_{i}^ {h}-pv_{i}^{h}<0\\ k_{i}^{h}/p_{cs}^{h}-1,\;l_{i}^{h}+e_{i}^{h}-pv_{i}^{h}>0\end{array} \right.. \tag{22}\]  
Equation (22) can be substituted into (7)-(9) to solve the optimal internal price of the EMO based on the role of energy sharing that each MG wants to play. The following section provides a discussion of the relationship between the optimal prices and the roles of MGs. For each MG acting as a buyer, the net energy \(nl_{i}^{h}\) satisfies \(l_{i}^{h}+e_{i}^{h}-pv_{i}^{h}\geq 0\). The range of energy consumption can be redefined as  
\[\max(l_{i}^{h,\text{min}},pv_{i}^{h}-e_{i}^{h})\leq l_{i}^{h}\leq l_{i}^{h, \text{max}}. \tag{23}\]  
Substituting the optimal value in (22) into the energy consumption in (23), we can obtain\[\frac{k_{i}^{h}}{l_{i}^{\max}+1}\leq p_{cs,i}^{h}\leq\frac{k_{i}^{h}}{\max(l_{i}^{ h,\min},pv_{i}^{h}-e_{i}^{h})+1}, \tag{24}\]  
where \(p_{cs,i}^{h}\) is the flexible selling price that the MG \(i\) as a buyer expects to trade with the EMO. If \(p_{cs}^{h}<k_{i}^{h}/(l_{i}^{\max}+1)\), the optimal energy consumption will be \(l_{i}^{\max}\); if \(p_{cs,i}^{h}>k_{i}^{h}/(\max(l_{i}^{h,\min},pv_{i}^{h}-e_{i}^{h})+1)\), the optimal energy consumption will be \(\max(l_{i}^{h,\min},pv_{i}^{h}-e_{i}^{h})\). Similarly, the flexible buying price \(p_{cb,i}^{h}\) of a seller is constrained by  
\[\frac{k_{i}^{h}}{\min(pv_{i}^{h}-e_{i}^{h},l_{i}^{h,\max})+1}\leq p_{cb,i}^{h} \leq\frac{k_{i}^{h}}{l_{i}^{\min}+1}. \tag{25}\]  
If \(p_{cb}^{h}<k_{i}^{h}/(\min(pv_{i}^{h}-e_{i}^{h},l_{i}^{h,\max})+1)\), the optimal energy consumption will be \(\min(pv_{i}^{h}-e_{i}^{h},l_{i}^{h,\max})\); if \(p_{cs}^{h}>k_{i}^{h}/(l_{i}^{h,\min}+1)\), the optimal energy consumption will be \(\max(l_{i}^{h,\min},pv_{i}^{h}-e_{i}^{h})\). As a result, we can simplify (24) and (25) into  
\[p_{cs,i}^{h}\in[p_{cs,i}^{h,\min},p_{cs,i}^{h,\max}], \tag{26}\]  
\[p_{cb,i}^{h}\in[p_{cb,i}^{h,\min},p_{cb,i}^{h,\max}]. \tag{27}\]  
Equation (26) expresses the feasible region of the optimal price for a seller and equation (27) expresses the feasible region of the optimal price for a buyer. Therefore, the profit functions of the EMO in (7)-(9) can be updated with the optimal energy consumption as  
\[E_{ex}^{ho}=\sum\limits_{p_{s,i}^{h,\min}\leq p_{cs}^{h}>p_{s,i}^{h,\max}}{( \frac{k_{i}^{h}}{p_{cs}^{h}}-1)D_{b,i}^{h}}+\sum\limits_{p_{cs}^{h}<p_{s,i}^{ h,\min}}{l_{i}^{h,\max}D_{b,i}^{h}}+\sum\limits_{p_{cs}^{h}>p_{s,i}^{h,\max}}{ \max(l_{i}^{h,\min},pv_{i}^{h}-e_{i}^{h})D_{b,i}^{h}}+\sum\limits_{D_{b,i}^{h} =1}{e_{i}^{h}}-pv_{i}^{h} \tag{28}\]  
\[E_{im}^{ho}=\sum\limits_{p_{h,i}^{h,\min}\leq p_{cs}^{h}>p_{hs}^{h,\max}}{( \frac{k_{i}^{h}}{p_{cs}^{h}}-1)D_{s,i}^{h}}+\sum\limits_{p_{cb}^{h}>p_{s,i}^{ h,\min}}{l_{i}^{h,\min}D_{s,i}^{h}}+\sum\limits_{p_{cb}^{h}>p_{s,i}^{h,\min}}{\min(pv_{i}^{h} -e_{i}^{h},l_{i}^{h,\max})D_{s,i}^{h}}+\sum\limits_{D_{b,i}^{h}=1}{e_{i}^{h}} -pv_{i}^{h} \tag{29}\]  
\[Pro_{\text{MGC}}^{h}=\left\{ \begin{array}{l}p_{cs}^{h}E_{ex}^{ho}-p_{cb}^{ h}E_{im}^{ho}+p_{gb}^{h}(E_{im}^{ho}-E_{ex}^{ho}),E_{im}^{ho}<E_{ex}^{ho}\\ p_{cs}^{h}E_{ex}^{ho}-p_{cb}^{h}E_{im}^{ho}+p_{gs}^{h}(E_{im}^{ho}-E_{ex}^{ho}),E_{ im}^{ho}\geq E_{ex}^{ho}\end{array}