## 4 Mathematical Implementation of the Problem
### Technical and Economical Constraints
#### H-MG n constraints  
**ES and TES constraints in H-MG n**  
\[CO_{h,e,n}^{ES^{sh}}=\pi_{h,e,n}^{ES^{sh}}\times P_{h,e,n}^{ES^{ sh}} \tag{19}\]  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]  
\[U_{h,e,n}^{ES_{d}}=\pi_{h,e,n}^{ES_{d}}\times P_{h,e,n}^{ES_{d}} \tag{21}\]  
\[0\leq\pi_{h,e,n}^{ES_{d}}\leq\lambda_{h,e}^{MCP} \tag{22}\]  
The cost of charging ES is obtained from Equation (19), where \(CO_{h,e,n}^{ES^{sh}}\), \(U_{h,e,n}^{ES}\),\(\pi_{h,e,n}^{ES^{sh}}\), and \(\pi_{h,e,n}^{ES_{d}}\), respectively, show the cost, revenue (utility), and price bid resulting from buying/selling electrical power by ES in H-MG n. Equations (23)-(25) present ES maximum and minimum charge/discharge in H-MG n. Equations (26) and (27) are the charge/discharge maximum limits for the energy in Equation (28). \[\hat{EN}_{n}^{ES}\leq EN_{h,e,n}^{ES}\leq\hat{EN}_{n}^{ES} \tag{23}\]  
\[P_{h,e,n}^{ES_{d}}\leq\hat{P}_{n}^{ES_{d}}\times m_{h,n}^{ES}P_{h,e,n}^{ES_{d} }\geq 0 \tag{24}\]  
\[P_{h,e,n}^{ES^{sh}}\leq\hat{P}_{h,e,n}^{ES^{sh}}\times m_{h,n}^{ES_{d}}P_{h,e, n}^{ES^{sh}}\geq 0 \tag{25}\]  
\[P_{h,e,n}^{ES_{d}}\times\Delta h\leq\left(\hat{EN}_{h-1}^{ES}-\hat{EN}^{ES,n}\right) \tag{26}\]  
\[P_{h,e,n}^{ES^{sh}}\times\Delta h\leq\left(\hat{EN}_{i}^{ES}-EN_{h-1,n}^{ES}\right) \tag{27}\]  
\[EN_{h,e,n}^{ES}=EN_{h-1,n}^{ES}+\left(P_{h-1,i}^{ES^{sh}}-P_{h-1,n}^{ES_{d}} \right)\times\Delta h \tag{28}\]  
Equation (29) depicts the cost resulting from buying thermal power by TES in the charging mode, while Equation (30) is the price bid interval for buying thermal power by TES. \[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]0  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]1In addition, \(U_{h,ht,n}^{TES_{d}}\) in Equation (31) is the revenue resulting from sales of thermal power generated by TES in the discharging mode and \(\pi_{h,ht,n}^{TES_{d}}\) in Equation (32) is the price bid variations range for selling thermal power by TES. \[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]2  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]3  
In Equations (33)-(35), TES maximum and minimum charge/discharge limitations are shown. \[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]4  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]5  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]6  
Equations (36) and (37) show the maximum discharge/charge limits for the energy in TES, while Equation (38) presents the energy equilibrium in TES. \[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]7  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]8  
\[0\leq\pi_{h,e,n}^{ES^{sh}}\leq\lambda_{h,e}^{MCP} \tag{20}\]9  
**EV constraints in H-MG n**  
\[U_{h,e,n}^{ES_{d}}=\pi_{h,e,n}^{ES_{d}}\times P_{h,e,n}^{ES_{d}} \tag{21}\]0  
Equation (39) illustrates that if \(\;m_{h,n}^{EV}=1\), then the battery can be charged between \(\hat{P}_{n}^{EV^{ch}}\)_and_\(\hat{P}_{h,e,n}^{EV^{ch}}\), as the lower and upper bounds, respectively. Equation (40) states that \(SOC_{h,n}^{EV}\) of the automobile battery during each time interval related to H-MG n, must be less than its maximum value. It should be noted that Equation (41) is the automobile battery power balance constraint. If the EV is unplugged or once \(SOC_{h,n}^{EV}\) has reached to the highest value, the charging process will be finished. In addition, Equation (42) indicates that, when the battery has been fully charged, no power is required to charge. \[U_{h,e,n}^{ES_{d}}=\pi_{h,e,n}^{ES_{d}}\times P_{h,e,n}^{ES_{d}} \tag{21}\]1  
\[U_{h,e,n}^{ES_{d}}=\pi_{h,e,n}^{ES_{d}}\times P_{h,e,n}^{ES_{d}} \tag{21}\]2  
\[SOC_{h,n}^{EV}=S\hat{\mathcal{O}}C_{n}^{EV}\;\Rightarrow\; \begin{cases}m_{h, n}^{EV}=0\\ P_{h,e,n}^{EV^{ch}}=0\end{cases}  \tag{42}\]  
Equation (43) is the cost of buying electrical power while Equation (44) indicates the offer price range for power bought by EV.