## 4 Mathematical Implementation of the Problem
### Technical and Economical Constraints
#### HHW constraints  
The modeling of HHW are presented in Equations (92)-(96). When the HHW temperature lies between the lower and upper bounds, \(\hat{T}_{n}^{HHW}\leq T_{h,n}^{HHW}\leq\hat{T}_{n}^{HHW}\), the HHW stays in off mode. Therefore, the temperature decreases due to the heat generation (Equation (93)). \[\begin{cases}m_{h,n}^{HHW}=0&;\ \ \hat{T}_{n}^{HHW}\leq T_{h,n}^{HHW}\leq\hat{T}_{n}^ {HHW}\\ m_{h,n}^{HHW}=1&;\  
corresponding to the highest sun exposure times, which has helped considerably in reducing the level of air pollution. Furthermore, the highest level of generation has been related to CHP, whose main reason is to maintain the energy independence of each of the H-MGs. One of the major goals of the optimization techniques is to allow H-MGs to independently produce and supply their power requirements while meeting all constraints. Figure 7: Load Demand Profile Consumed in: (**a**) H-MG #A; (**b**) H-MG #B; and (**c**) H-MG #C.  
As can be seen, the grid also plays a significant role in providing the generation powers. Consistently maintaining the energy independency in H-MGs is of great importance, but due to pollution constraints, optimization methods based upon selecting the minimum amount of pollution generated between the grid and CHP, have selected Grid to provide their required power. This is illustrated in Figure 9. As shown in several intervals, both CHP and the grid, have provided power for H-MGs, due to pollution constraints. CHPs can only produce enough power to meet the requirement of not exceeding the pollutant index. Therefore, the algorithm evaluates the amount of power required by H-MG and the amount of power generated by power purchases from the grid to purchase power from the network. The percentage of thermal power generated by each of the optimization methods is in accordance with Figure 9. In this section, similar to the electrical sector, the thermal equilibrium of each H-MG, as well as the set of H-MGs, must be met by implemented optimization algorithms. Figure 8: Percentage of electrical power produced by the implemented methods. As seen, GB has entered the service at times when the amount of TSP generation has been decreased and a growth in the load has occurred. Of course, the maintenance of GBs is subject to compliance with the pollution constraints, since GB can only generate heat to a degree that does not rule out the pollution index. The process of reducing air pollution by each of the PSO, BAT and DE methods is shown in Figure 10. As can be seen, in more than 90% of the intervals, the proposed algorithm succeeds in reducing pollution. In H-MG #A, DR has been based on price. In this section, the algorithm is only required to shift the power to cheaper times. In H-MG #A, the best performance has been to reduce the pollution associated with the DE method, but, since the maximum MCP price has been between 16:00 and 22:00, the algorithm should reduce the power demand surplus. Consequently, the algorithm in this interval should not buy the power from the network whilst using the least amount from CHP and GB. Therefore, considering Figure 10a  
Figure 10: Air pollution in H-MGs. In H-MG #B, DR is programmed based on pollution. In this H-MG, the algorithm allows CHP and GB to reach orbit so that the pollution index is not compromised. Despite the fact that all methods managed to reduce the pollution level to below 100%, the PSO method had the best performance in ER, which had a 64% reduction compared to Emax. The reason why the H-MG #B was less successful than the H-MG #A in the ER was that there was a 35% increase in load in the building B, and the algorithm had to use the maximum CHP and GB (taking into account the constraints). In H-MG #C, DR has been set based on price and pollution. In this H-MG, pollution was reduced over 87% of the timeframe. In this H-MG algorithm, in addition to a considerable reduction in costs (as shown in Figure 11, there has also been success in reducing pollution.