Optimal Power Sharing in Microgrids Using the Artiﬁcial Bee Colony Algorithm

: In smart grids, a hybrid renewable energy system that combines multiple renewable energy sources (RESs) with storage and backup systems can provide the most cost-effective and stable energy supply. However, one of the most pressing issues addressed by recent research is how best to design the components of hybrid renewable energy systems to meet all load requirements at the lowest possible cost and with the best level of reliability. Due to the difﬁculty of optimizing hybrid renewable energy systems, it is critical to ﬁnd an efﬁcient optimization method that provides a reliable solution. Therefore, in this study, power transmission between microgrids is optimized to minimize the cost for the overall system and for each microgrid. For this purpose, artiﬁcial bee colony (ABC) is used as an optimization algorithm that aims to minimize the cost and power transmission from outside the microgrid. The ABC algorithm outperforms other population-based algorithms, with the added advantage of requiring fewer control parameters. The ABC algorithm also features good resilience, fast convergence, and great versatility. In this study, several experiments were conducted to show the productivity of the proposed ABC-based approach. The simulation results show that the proposed method is an effective optimization approach because it can achieve the global optimum in a very simple and computationally efﬁcient way.


Introduction
Today, the world's greatest challenges are the rapidly growing demand for electrical energy [1], rising electricity prices, the increasing use of non-renewable energy, the limits of conventional energy for power generation, global warming, global climate change, and related environmental problems [2]. All these challenges have resulted in the world being in a catastrophic economic and political crisis. Because of this, every government in the world is eager to expand renewable energy generation [3]. Renewable energy generation can help nations achieve their long-term development goal of providing safe, cheap, clean, environmentally friendly, and sustainable energy [4]. Despite the many advantages offered by renewable energy compared to conventional energy, they all have weaknesses in common, such as high weather vulnerability, low stability, and high unpredictability [5], all of which lead to low reliability and efficiency of energy generation [6]. Consequently, the hybrid renewable energy system can solve important problems and constraints in efficiency, reliability, and economy [7], which makes it an effective choice to meet the load requirements and support and improve the system [8]. The use of a central control unit to control the integrated power management of microgrids improves the efficiency, flexibility, and response time to fluctuations. The optimal power flow in the grid, the voltage level in each bus, and the transmission losses are all essential variables to be considered in efficient power systems [9]. The actual problem is an MILP problem, and the constraints on the optimal power flow are linear. For this purpose, a stochastic two-stage model of the interactions between the distribution system operator and many microgrids on the distribution line is used in [10]. A microgrid (MG), as shown in Figure 2, consists of various distributed energy sources (DERs), responsive loads, and critical loads. A common connection point (PCC) connects the MG to the main grid [12]. Each DER is connected to the power electronic interface (PEI) in both grid-connected and islanded modes to perform control, measurement, protection, and plug-and-play functions. An MG in the grid-connected mode benefits from sharing power with the main grid. However, in the event of a fault or failure of the main grid, MG switches to the islanded mode to ensure system stability. In this mode, critical loads are continuously supplied with power by efficiently integrating DERs, demand response (DR), and load shedding (LS). The central microgrid controller (MGCC) and local controllers (LCs) manage and coordinate the entire MG operation [13]. Efficient DER management and coordination in MG lead to higher system performance and longterm development [14]. Due to increased environmental awareness, socioeconomic growth, and the need to reduce greenhouse gas emissions, MGs are mainly composed of sustainable energy systems, such as renewable energy sources and energy-efficient systems that use local heat waste [15]. Various energy storage technologies that have potential for high penetration and integration in microgrids are mentioned in [16]. Different energy trading systems are examined for interactive energy trading, multienergy management, and resilient operations in [17]. The DSM technique is used in [18] to reduce the operating cost of the grid-connected microgrid. An optimization-based energy management system is used to reduce the generation and curtailment costs [19]. In [20], an optimization controller is developed to control the energy management system for distributed energy sources in microgrids. A microgrid (MG), as shown in Figure 2, consists of various distributed energy sources (DERs), responsive loads, and critical loads. A common connection point (PCC) connects the MG to the main grid [12]. Each DER is connected to the power electronic interface (PEI) in both grid-connected and islanded modes to perform control, measurement, protection, and plug-and-play functions. An MG in the grid-connected mode benefits from sharing power with the main grid. However, in the event of a fault or failure of the main grid, MG switches to the islanded mode to ensure system stability. In this mode, critical loads are continuously supplied with power by efficiently integrating DERs, demand response (DR), and load shedding (LS). The central microgrid controller (MGCC) and local controllers (LCs) manage and coordinate the entire MG operation [13]. Efficient DER management and coordination in MG lead to higher system performance and long-term development [14]. Due to increased environmental awareness, socioeconomic growth, and the need to reduce greenhouse gas emissions, MGs are mainly composed of sustainable energy systems, such as renewable energy sources and energy-efficient systems that use local heat waste [15]. Various energy storage technologies that have potential for high penetration and integration in microgrids are mentioned in [16]. Different energy trading systems are examined for interactive energy trading, multienergy management, and resilient operations in [17]. The DSM technique is used in [18] to reduce the operating cost of the grid-connected microgrid. An optimization-based energy management system is used to reduce the generation and curtailment costs [19]. In [20], an optimization controller is developed to control the energy management system for distributed energy sources in microgrids. Table 1 shows a few examples of sustainable energy being used to run the energy management system from the literature review.
The microgrid EMS is a decision-making technique. For sustainable development, these techniques improve system efficiency, boost system reliability, decrease energy consumption, reduce DER operating costs, decrease system losses, and eliminate GHG emissions.
This paper presents a model for a hybrid renewable energy system integrated with a smart grid. The hybrid system includes wind turbines (WTs), photovoltaic (PV) systems, an electricity distribution company (Disco), gas turbines (GTs), and battery storage. Each component of the generation and load side is represented by a model. The hourly data of the wind speed and solar radiation on a daily basis are used as a case study in this paper. The proposed approach is used to optimize the power-sharing in the MGs to minimize the total cost of the system and the cost of each integrated microgrid. An artificial bee colony (ABC), as the optimization algorithm, is designed here to deal with the proposed model, with the objective of minimizing the cost and power imported from outside the MG. The idea of this paper is represented in Figure 3.   [29][30][31] The microgrid EMS is a decision-making technique. For sustainable development, these techniques improve system efficiency, boost system reliability, decrease energy consumption, reduce DER operating costs, decrease system losses, and eliminate GHG emissions.
This paper presents a model for a hybrid renewable energy system integrated with a smart grid. The hybrid system includes wind turbines (WTs), photovoltaic (PV) systems, an electricity distribution company (Disco), gas turbines (GTs), and battery storage. Each component of the generation and load side is represented by a model. The hourly data of the wind speed and solar radiation on a daily basis are used as a case study in this paper. The proposed approach is used to optimize the power-sharing in the MGs to minimize the total cost of the system and the cost of each integrated microgrid. An artificial bee colony (ABC), as the optimization algorithm, is designed here to deal with the proposed model, with the objective of minimizing the cost and power imported from outside the MG. The idea of this paper is represented in Figure 3.  Figure 3 shows a microgrid (MG) connected to a distribution network. This MG contains multiple small MGs, which are connected with each other by electric lines. The electric line can be allowed to export and impart energy from small MGs. The small MG contains a mixture of components that consume and produce electricity (solar and wind plants) in addition to electricity storage units. The operational status of the small MG is divided into three sections: first, self-sufficiency in the event of equal production and consumption, so the MG will neither import nor export energy; second, import, which occurs when consumption is greater than production, as the MG needs energy; and third, export, which occurs when there is a surplus of energy within the MG and it needs to be exported.
Optimization is a mathematical problem that may be found in all engineering domains. This term's literal definition is "best possible or desirable". Because optimization problems are so broad and varied, it is a significant academic field.
Optimization algorithms are classified into two types: deterministic and stochastic. Previously, tackling optimization issues required tremendous computational effort, which frequently failed as the problem size grew larger. This is why bio-inspired stochastic optimization algorithms are being used as computationally efficient alternatives to deterministic approaches. Metaheuristics are based on the iterative improvement of either a population of solutions (evolutionary algorithms or swarm-based algorithms) or a single solution (Tabu Search) to solve a given optimization problem, and they primarily use randomization and local search.
The literature on bio-inspired algorithms (BIAs) for solving a wide variety of issues is vast, and various studies have reported on the usefulness of such tactics for handling difficult problems in the main disciplines of engineering in recent years. The two most prevalent and successful BIA classes or routes are evolutionary algorithms and swarmbased algorithms, both inspired by animals' collective behavior and natural development. In order to obtain a broader view on the subject, the algorithms were divided into regions based on where the inspiration for them came from in nature.
Swarm intelligence is a novel and rising paradigm used for creating adaptive systems in bio-inspired computing. In this sense, evolutionary computation (EC) is an extension of this. Swarm intelligence is based on organisms' collective social behaviors, whereas  Figure 3 shows a microgrid (MG) connected to a distribution network. This MG contains multiple small MGs, which are connected with each other by electric lines. The electric line can be allowed to export and impart energy from small MGs. The small MG contains a mixture of components that consume and produce electricity (solar and wind plants) in addition to electricity storage units. The operational status of the small MG is divided into three sections: first, self-sufficiency in the event of equal production and consumption, so the MG will neither import nor export energy; second, import, which occurs when consumption is greater than production, as the MG needs energy; and third, export, which occurs when there is a surplus of energy within the MG and it needs to be exported.
Optimization is a mathematical problem that may be found in all engineering domains. This term's literal definition is "best possible or desirable". Because optimization problems are so broad and varied, it is a significant academic field.
Optimization algorithms are classified into two types: deterministic and stochastic. Previously, tackling optimization issues required tremendous computational effort, which frequently failed as the problem size grew larger. This is why bio-inspired stochastic optimization algorithms are being used as computationally efficient alternatives to deterministic approaches. Metaheuristics are based on the iterative improvement of either a population of solutions (evolutionary algorithms or swarm-based algorithms) or a single solution (Tabu Search) to solve a given optimization problem, and they primarily use randomization and local search.
The literature on bio-inspired algorithms (BIAs) for solving a wide variety of issues is vast, and various studies have reported on the usefulness of such tactics for handling difficult problems in the main disciplines of engineering in recent years. The two most prevalent and successful BIA classes or routes are evolutionary algorithms and swarmbased algorithms, both inspired by animals' collective behavior and natural development. In order to obtain a broader view on the subject, the algorithms were divided into regions based on where the inspiration for them came from in nature.
Swarm intelligence is a novel and rising paradigm used for creating adaptive systems in bio-inspired computing. In this sense, evolutionary computation (EC) is an extension of this. Swarm intelligence is based on organisms' collective social behaviors, whereas evolutionary algorithms are based on species' genetic adaptability. Swarm intelligence, as defined in the literature, is the use of the collective intelligence of groups of simple organisms to solve problems, based on the behavior of actual insect swarms. The term "swarm" refers to the chaotic movement of particles in the affected region. Some important SI algorithms are particle swarm optimization (PSO), the ant colony optimization algorithm (ACO), the fish swarm algorithm (FSA), the firefly algorithm, and the artificial bee colony (ABC) methods, which have all been employed as optimization methodologies. In the foraging process, these algorithms, which were inspired by animals' collective behavior, exhibit decentralized self-organized patterns. However, the artificial bee colony (ABC) approach was used in this article [32].
The ABC algorithm outperforms or is similar to other population-based algorithms, with the added advantage of requiring fewer control parameters. The ABC algorithm also features good resilience, fast convergence, and great versatility.
The ABC algorithm, developed by Karaboga and Basturk, replicates the intelligent foraging behavior of a honeybee swarm. The ABC algorithm's artificial bee colony is made up of three categories of bees: hired bees, bystanders, and scouts. An employed bee is a spectator who does not participate in the dance but instead travels to the food source being frequented by the observer. The scout bee, on the other hand, performs random searches for fresh sources. The quality (or fitness) of a solution may be measured by comparing the location of a food source to the amount of nectar it generates. Beehives are built and then released into the two-dimensional search space. Bees build social relationships with one another while foraging for nectar. Intense bee-bee interactions are essential to the discovery of a solution.

ABC Algorithm
In 2005, Karaboga discovered the ABC algorithm, influenced by honey bee behavior. The algorithm of a honey bee colony has the ability to find the best quality food sources in nature with ease. Therefore, the concept of ABC was derived from the clever foraging behavior of honey bees to find suitable solutions to optimization problems. Generally, bee colonies are classified into three types according to their foraging ability: employed bees, onlooker bees, and scout bees. The employed bees are responsible for collecting nectar (food). They investigate the location of the food supply in advance and alert the scout bees about the quality of the food. Based on the information relayed by the employed bees, the scout bees wait in the swarm and decide whether to take advantage of a food source. The scout bees randomly search the environment for a new nectar supply, either from internal motivation or from likely external cues [33]. The quality (fitness) of the feasible solution to the optimization questions is related to the profitability of a nectar source. The presence of a nectar source indicates a feasible solution to the optimization issues. Each nectar source is visited by only one honey bee. In other words, the number of employed or onlooker bees is proportional to the number of nectar sources [34]. Employed bees maintain an excellent solution, onlooker bees accelerate convergence, and scout bees improve the ability to eliminate local optimums [35,36].

ABC Algorithm Iteration Steps
ABC algorithm's main steps are listed as follows [37,38]: 1. Initialization. Generate N random solutions (food sources) Xi (i = 1, 2, 3, . . . , N) in a dimensional searching space D, where N represents the number of food sources, which is half the size of the colony Xi (i = 1, 2, 3, . . . , D) is a D-dimensional solution vector. For i = 1, 2, 3, . . . , N, the ith food source in the original population, and the number of optimization population parameters is denoted by D.
2. During the honey collection stage, each employed bee creates a new nectar source in the food source's vicinity. When a new nectar source is compared to the previous one, the high probability will be memorized. Each onlooker bee assesses the attractiveness of nectar sources received from all employed bees and selects a food source with a high probability. Like the employed bees, she changes the source location in her memory and maintains a higher nectar supply. In these two phases, the following formula is employed to regenerate nectar sources: where i (k = 1, 2, 3, . . . , N), (j = 1, 2, 3, . . . , D), and θ[0, 1] is a random number that determines the generation range of hij s neighborhoods. As the search comes closer to an optimal solution, the number of neighborhoods available will decrease. 3. Food source selection. In the next step, the onlooker bees compare the probability calculated by the fitness value to select a food source. Nectar sources with a high probability are chosen with a high degree of certainty. The chance of being chosen for food sources is computed using the equation below: The fitness value of the ith solution, Fit i i(i = 1, 2, 3, . . . , N) may be determined using following equation: If the quality of the new food source location is the same as or better than the previous one, the old one is updated with a new one, where f i is the value of the objective function for i = 1, 2, 3, . . . , N, which is unique to the optimization problem. Otherwise, the old one will be kept the same as the stage of employed bees.
4. Population elimination. A solution is considered to have fallen into a local optimum solution if it has not improved significantly after a specified number of trials, known as "max iteration", and the starting position is abandoned. As a consequence, the matching employed bees will become scout bees, and a new solution, which may be described as follows, will be generated at random in place of the discarded solution: where h_maxj and h_minj are the jth and ith individual maximum and lowest values, respectively, and i and j are the same (1). The ABC algorithm may be expressed in the following stages based on the preceding phases [39].Flowchart of ABC algorithm is shown in Figure 4.

Mathematical Modeling
The microgrid architecture studied in this paper is represented in Figure 5. It includes wind turbines (WTs), gas turbines (GTs), photovoltaic (PV), batteries (BT), additional storage components, general loads, and essential loads with different characteristics. The connection point, also known as the point of common coupling (PCC), is the interface between this architecture's utility and microgrid systems. As a result, there are two types of modes.

Mathematical Modeling
The microgrid architecture studied in this paper is represented in Figure 5. It includes wind turbines (WTs), gas turbines (GTs), photovoltaic (PV), batteries (BT), additional storage components, general loads, and essential loads with different characteristics. The connection point, also known as the point of common coupling (PCC), is the interface between this architecture's utility and microgrid systems. As a result, there are two types of modes.

Mathematical Modeling
The microgrid architecture studied in this paper is represented in Figure 5. It includes wind turbines (WTs), gas turbines (GTs), photovoltaic (PV), batteries (BT), additional storage components, general loads, and essential loads with different characteristics. The connection point, also known as the point of common coupling (PCC), is the interface between this architecture's utility and microgrid systems. As a result, there are two types of modes.   When the MG is connected to the main grid via PCC, it is in the grid-connected mode, and when it does not connect with the main grid, it is in the islanded mode.
Renewable energy sources (RESs) can be connected via a DC, AC, or a hybrid DC/AC bus. For most generators and loads, the appropriate configuration is determined by the type of output power. Therefore, DC bus coupling is preferred when both loads and generators are DC [40]. When the loads and generators are AC, then AC bus coupling is preferred [41] when the generation and load are mixed, such as AC and DC hybrid renewable energy sources (HRESs). A hybrid AC, DC bus coupling system is used [42], as shown in Figure 6. When the MG is connected to the main grid via PCC, it is in the grid-connected mode, and when it does not connect with the main grid, it is in the islanded mode.
Renewable energy sources (RESs) can be connected via a DC, AC, or a hybrid DC/AC bus. For most generators and loads, the appropriate configuration is determined by the type of output power. Therefore, DC bus coupling is preferred when both loads and generators are DC [40]. When the loads and generators are AC, then AC bus coupling is preferred [41] when the generation and load are mixed, such as AC and DC hybrid renewable energy sources (HRESs). A hybrid AC, DC bus coupling system is used [42], as shown in Figure 6.

Hybrid Wind/PV/Battery Storage/Gas Turbine
The configuration shown in Figure 6 consists of wind energy, a PV energy system, battery storage, a gas turbine, and the main load. The response of this configuration is simple and easy to understand. Due to the bidirectional converter, the WT and the PV system are mainly responsible for supplying the main load. The excess power generated by wind and/or PV is stored in a battery storage system until the battery is fully charged to . Excess power generated above is supplied to dedicated loads, i.e., dummy loads, such as loads for cooling, home appliances and heating, and charging the batteries of emergency lights when the battery storage is full. When the load power exceeds the generated power, the batteries are used to make up the difference until they reach the minimum ( ). Suppose the battery is fully discharged by and the hybrid renewable energy sources cannot meet the microgrid's load demand. In this case, it imports energy from another microgrid. Moreover, when it is unable to purchase energy from another microgrid, the microgrid purchases power from the main grid to balance the load demand [43].

Wind Energy System
Wind generation depends on both the wind speed and the height of the hub at a given location. The power-law equation [44] is used to calculate the wind speed at the hub height of WT using data collected at the anemometer height: (ℎ) and (ℎ ) are the wind speeds at the hub height (ℎ) and the anemometer height (ℎ ), respectively, and is the roughness factor. The value changes from location to location and over time at the same location:

Hybrid Wind/PV/Battery Storage/Gas Turbine
The configuration shown in Figure 6 consists of wind energy, a PV energy system, battery storage, a gas turbine, and the main load. The response of this configuration is simple and easy to understand. Due to the bidirectional converter, the WT and the PV system are mainly responsible for supplying the main load. The excess power generated by wind and/or PV is stored in a battery storage system until the battery is fully charged to SOC max . Excess power generated above SOC max is supplied to dedicated loads, i.e., dummy loads, such as loads for cooling, home appliances and heating, and charging the batteries of emergency lights when the battery storage is full. When the load power exceeds the generated power, the batteries are used to make up the difference until they reach the minimum SOC (SOC min ). Suppose the battery is fully discharged by SOC min and the hybrid renewable energy sources cannot meet the microgrid's load demand. In this case, it imports energy from another microgrid. Moreover, when it is unable to purchase energy from another microgrid, the microgrid purchases power from the main grid to balance the load demand [43].

Wind Energy System
Wind generation depends on both the wind speed and the height of the hub at a given location. The power-law equation [44] is used to calculate the wind speed at the hub height of WT using data collected at the anemometer height: u(h) and u(hg) are the wind speeds at the hub height (h) and the anemometer height (hg), respectively, and α is the roughness factor. The value changes from location to location and over time at the same location: where V(h) and V h g are the wind speeds at hub height h and anemometer height h g . α is a roughness factor and varies from location to location and time to time. The output power of WT from the typical WT curve is as follows [45]: where p wt is the output power of the wind turbine, p r is the rated output power of the wind turbine, v ci is the cut in wind speed of WT, v r is the rated wind speed of WT, and v co is the cut off wind speed of the wind turbine.

PV Energy System
The solar radiation on a tilted surface (Ht) can be calculated using solar insolation, the ambient temperature, data from the PV panel manufacturer, the PV panel slope, and the site latitude and longitude [46,47]. The following equation [48] is used to compute the PV system's output power: where µ c (t) is the PV system's hourly generating efficiency, which may be calculated in terms of the cell temperature using Equation (8) [49]: where β t is the temperature coefficient, µ cr and T cr are the solar cell efficiency and temperature at maximum radiation solar flux T c (t), It is an hourly solar cell temperature at ambient temperature (T a ): where λ (Ross coefficient) is a coefficient that represents how the temperature increases above ambient as solar flux increases. The overall output of the PV array is: where p s is the PV array output power, G pv is the irradiation of solar, G o is the solar irradiance under standard test conditions (1000 W/m 2 ). p r is the rated power of solar [49]. Table 2 represents the PV parameter values.

Battery Storage
The state of charge (SOC) of a battery is determined based on the energy balance between the wind, PV energy systems, and the load as given by the following equations after a particular time (t): where (11) is the battery charging mode equation: where (12) is the battery discharging mode equation. E b is the energy of the battery bank, and η bc , η bd is the charging and discharging efficiency of the battery storage system. It is considered to be 90% and 85%, respectively, in [50], where σ is the battery self-discharge rate and is assumed to be 0.2% per day for most batteries [51]. Ps is the surplus power, and p d is the deficit power. The battery bank should always follow the following limitations: where E b,max and E b,min are the battery bank's maximum and minimum storage capacity, respectively. The following equation can be used to calculate E b,min : where E b is the battery nominal storage capacity, and DOD is the depth of discharge of a battery opposite to the SOC of a battery.

Mathematical Modeling of the Proposed Approach
The proposed approach of this article is to optimize the power transfer between microgrids to minimize the overall cost of the system and each microgrid. For this purpose, a mathematical model is designed for a net load for each microgrid first. The proposed idea is represented in Figure 3, and the proposed work is represented by the flowchart shown in Figure 7.
The proposed approach has two main tasks: storage; the other is energy sharing in the first part, which is energy storage. If the net load is greater than zero, storage is used to discharge energy to meet the load requirements. If the net load is less than zero, the extra system energy is either shared with other microgrids or stored in the storage system to reduce the total cost of electricity. Data about the load, PV, and wind in each MG is calculated. After obtaining data of the load, PV, and wind in each MG, the sharing parameters are initialized, such as the SOC of the battery, the size of the battery, and the minimum and maximum generation in each MG, the net load is calculated using the generation and load balance equations.
The proposed work shown in Figure 7 is about energy management in small MGs and is an attempt to reduce imports from energy distribution networks as much as possible, by linking several small microgrids together. These MGs contain different mixtures of energy production and consumption, which helps to increase the reliability of these small MGs and gradually dispense with power distribution networks. The novelty is that the difference in the energy mix between these small MGs and linking them together will help dispense with distribution networks, which will reduce energy losses and the price of electricity and provides the possibility for small consumers to benefit from the production and sale of energy.
Suppose a microgrid has a battery energy storage system. In this case, it will have two possibilities if the net load exceeds zero. The SOC of a battery is checked to observe whether it is above 20%, and the battery will be discharged to meet the load requirements. Still, if the net load is not greater than zero, there is some extra energy in the system, which may be used to charge the battery if the SOC of a battery is less than the maximum storage capacity. In the second task of the proposed approach, whether the net load is greater than or less than zero is checked. If it is greater than zero, the microgrid will import energy from other microgrids or the main grid. If the net load is less than zero, the microgrid will export energy to other microgrids or the main grid.
The above process is iterated until optimal power-sharing among the microgrids is achieved.

Microgrids' Net Load
The mathematical equation for Disco is: where is the load of the distribution company (Disco) and is the conventional generation in Disco: where is the load of 1, is the rated power of PV in 1, and is the 24 h PV profile : In the second task of the proposed approach, whether the net load is greater than or less than zero is checked. If it is greater than zero, the microgrid will import energy from other microgrids or the main grid. If the net load is less than zero, the microgrid will export energy to other microgrids or the main grid.
The above process is iterated until optimal power-sharing among the microgrids is achieved.

Microgrids' Net Load
The mathematical equation for Disco is: where L D is the load of the distribution company (Disco) and G D is the conventional generation in Disco: where L MG1 is the load of MG1, PV MG1 is the rated power of PV in MG1, and PF PV is the 24 h PV profile: where L MG2 is the load of MG2, G D1 , G D2 are the generation of conventional generators 1 and 2, WT MG2 is the wind turbine generation in MG2, and PF WT is the wind profile of 24 h L MG3 is the load of MG3, PV MG3 is the rated PV power, and PF PV is the PV profile for 24 h.
L MG4 is the load of MG4, WT MG4 is the wind turbine generation in MG4, PF WT is the 24 h wind profile: where L MG5 is the load of MG5, G D is the generation of a conventional generator, WT MG5 is the wind generation in MG5, and PF WT is the 24 h wind profile. The net load is the difference between the load and generation inside the MG itself. It is used to determine whether the microgrid has a shortage or excess of energy to import or export to other microgrids with a shortage of energy, store it in battery energy storage, or sell it to the main grid.

Energy Management Strategy
The proposed HRES management algorithm is described in the following strategy. If the amount of power generated by RES surpasses the amount needed to meet the load requirements, the excess power will be used to charge the batteries until they reach their maximum capacity, E b,max . The extra power in the batteries will be used to power the dummy load, P dummy . The reason behind this can be described as follows: i f P g (t) > P L (t) and SOC < E b,max then; P bc = [P w (t) − P L (t) + P PV (t)]η bc Charging Process (22) i f P g > P L (t) and SOC ≥ E b,max then P bc (t) = 0 P d (t) = [P w (t) − P L (t) + P PV (t)] (23) where P d is the power to the dummy load: Equation (24) shows the charging process: i f P w (t)< P L (t) and (P w (t) + P PV (t)) >P L (t) and SOC > E b,max then; P bc (t) = 0 P d (t) = [P w (t) − P L (t) + P PV (t)] (25)  If the load demand requires more power than RES can provide, the battery will meet the demand until it is reduced to its minimal level E b,min . If there is still a power shortage, the DG will make up for the deficit load demand. The equations that describe this logic are as follows: i f [P w (t) + P PV (t)]< P L (t) and SOC >E b,min then; where P bd (t) is discharging power, and this is a discharging process: i f [P wt (t) + P PV (t)] < P L (t) and SOC < E b,min then; P bd (t) = 0 All the above equations and details of the generation, load, and storage indicate how the energy management strategy is effectively working in this case. When the generation of HRES in the microgrid is higher than the load, the surplus energy is stored in the battery energy storage system. When the generation of the HRES is less than the load of the microgrid, then the shortage of energy is met by the battery storage system. If the generation of HRES is less than the load and the battery energy is less than the minimum level of stored energy, then the microgrid will import energy from another microgrid to meet the demand. In the above equations, SOC is the state of the charge of the battery, P bc is the power used to charge the battery, and P bd is the discharging power of the battery. η bc , η bd is the battery charging and discharging efficiencies, respectively.
The power flow constraints of the HRES and battery are as follows: 0 ≤ P PV ≤ P max PV Generation (28) 0 ≤ P wt ≤ P max WT Generation (29) P min ≤ P b ≤ P max Battery power (30)

Microgrid Energy Sharing Problem
The microgrid has an excess or shortage of energy. The microgrid with excess energy will export the energy to other microgrids, which need a power through-line between them (S1, S2, S3, . . . , S15). The microgrid with a shortage of energy will import the energy from other microgrids, which have an excess power through-line between them (S1, S2, S3, . . . , S15). If all microgrids do not have enough energy to cover the shortage in the system, the system will import energy from the main grid. If we consider a sequence of 1 : Disco, 2 : MG1, 3 : MG2, 4 : MG3, 5 : MG4, 6 : MG5, if sending end SN = 1 and receiving end RN = 2, it means the line is connected from Disco to MG1 and so on.

Power Balance
The power balance in the generation and load is represented as: MG Load + Export Energy − MG Generation − Import Energy = 0 (33)

Objective Function
The objective function is a cost reduction of the generated power, transfer power, and import and export power: where C G is the total conventional generation cost, C Dis is the total transfer energy cost from Disco to MG, C MG is the total transfer energy cost from MG to MG, C B is the total energy cost from the battery, and C P is the penalty cost for the unsupplied energy. Mathematically, all of the above costs are represented as: where G Dis is conventional generation in Disco, G1 MG2 is conventional generation in MG2, G2 MG2 is conventional generation in MG2, G5 MG5 is conventional generation in MG5, and P gas is the gas price: C Dis = (S1 + S2 + S3 + S4 + S5) * P Dis (36) where S1, S2, S3, S4, S5 transfer power from Disco to MG1, MG2, MG3, MG4, MG5, respectively, and P Dis is the energy cost of Disco: where (S6 + S7 + S8 + · · · + S15) is the power transfer from MG to MG, and P MG is the cost of energy from MG to MG: In Equation (38), BES Disco is the energy of the battery in Disco, BES MG2 is the energy of the battery in MG2, BES MG4 is the energy of the battery in MG4, BES MG5 is the energy of the battery in MG5, and P B is the cost of energy from the battery: where E ns is the unsupplied energy and P P is the penalty price that is fixed [49]. Table 3 represents the cost data of different parameters (also taken from [49]).

Simulations and Results Analysis
As discussed above, in all the mathematical formulations regarding the objective functions and microgrid components, an ABC optimization technique reduces the system's total cost and minimal sharing cost of all the microgrids. Microgrids consist of conventional generation and intermittent energy sources, such as PV, wind, and battery energy storage systems. Among all the sources, conventional generators produce 24 h electricity, and wind generation is wind speed dependent and PV dependent on solar irradiations. Conventional generation occurs in Disco, MG2, and MG5. If their capacity fails to meet the desired load demands, they will import energy from the main grid if there is an unavailability of energy from other microgrids.
A cost convergence curve is shown below in Figure 8, which shows how the best solution deals with each iteration. We can see the best solution decreases when the iteration increases until it reaches the best one. The maximum number of iterations considered in the proposed idea is 150, upon which it converges to an optimal value. Energies 2022, 15, x FOR PEER REVIEW 15 of 21 A cost convergence curve is shown below in Figure 8, which shows how the best solution deals with each iteration. We can see the best solution decreases when the iteration increases until it reaches the best one. The maximum number of iterations considered in the proposed idea is 150, upon which it converges to an optimal value. Regarding the MG with only PV generation source, Figure 9 shows that it can only generate power according to the solar irradiance data in the PVWT profile. For the rest of the hours, it imports energy from outside, and from 11 to 13 h, it sells energy as it exceeds the load demand. MG1 has only one PV generation source, and as per Equation (7), PV generation is dependent on thee tilted surface, PV array, and its efficiency. Maximum generation is achieved when maximum sunlight is available for the tilted surface, and it is generally from 7 to 19 h that power is generated. Moreover, the intensity of light is very high, from 11 to 13 h, during which the generated power reaches th maximum and is available to sell to other MGs or the main grid. In the absence of sunlight, MG1 will not generate electricity. Hence, it will purchase electricity from other MGs. Regarding the MG with only PV generation source, Figure 9 shows that it can only generate power according to the solar irradiance data in the PVWT profile. For the rest of the hours, it imports energy from outside, and from 11 to 13 h, it sells energy as it exceeds the load demand. MG1 has only one PV generation source, and as per Equation (7), PV generation is dependent on thee tilted surface, PV array, and its efficiency. Maximum generation is achieved when maximum sunlight is available for the tilted surface, and it is generally from 7 to 19 h that power is generated. Moreover, the intensity of light is very high, from 11 to 13 h, during which the generated power reaches th maximum and is available to sell to other MGs or the main grid. In the absence of sunlight, MG1 will not generate electricity. Hence, it will purchase electricity from other MGs.
Microgrid 2 contains wind generation, battery storage, and 2 thermal units. The wind is almost always the available generation source, as shown in Figure 10. From 1-6 h, the load demand can easily be met by the wind generation source and thermal unit generation. During this time, extra power is used for charging the battery. From 7-8 h, EES is used to meet the load demand along with the wind and thermal generation sources. From 9-23 h, wind generation, thermal generation, and EES are not able to meet the load demand; hence, electricity is purchased from outside. Microgrid 3 has one source of PV and load demand, as shown in Figure 11. To meet the load demand with just one PV source, it will purchase electricity from other microgrids in the absence of sunlight. When sunlight becomes available, it will gradually overcome the load demand and at high intensity, sunlight from 11-13 h MG3 will be able to meet the entire demand. The extra amount of electricity will be sold to other MGs. the load demand. MG1 has only one PV generation source, and as per Equation (7), PV generation is dependent on thee tilted surface, PV array, and its efficiency. Maximum generation is achieved when maximum sunlight is available for the tilted surface, and it is generally from 7 to 19 h that power is generated. Moreover, the intensity of light is very high, from 11 to 13 h, during which the generated power reaches th maximum and is available to sell to other MGs or the main grid. In the absence of sunlight, MG1 will not generate electricity. Hence, it will purchase electricity from other MGs. Microgrid 2 contains wind generation, battery storage, and 2 thermal units. The wind is almost always the available generation source, as shown in Figure 10. From 1-6 h, the load demand can easily be met by the wind generation source and thermal unit generation. During this time, extra power is used for charging the battery. From 7-8 h, EES is used to meet the load demand along with the wind and thermal generation sources. From 9-23 h, wind generation, thermal generation, and EES are not able to meet the load demand; hence, electricity is purchased from outside. Microgrid 3 has one source of PV and load demand, as shown in Figure 11. To meet the load demand with just one PV source, it will purchase electricity from other microgrids in the absence of sunlight. When sunlight becomes available, it will gradually overcome the load demand and at high intensity, sunlight from 11-13 h MG3 will be able to meet the entire demand. The extra amount of electricity will be sold to other MGs. MG4 contains wind generation and battery storage, and the load demand is shown in the Figure 12. The result in Figure 12 shows that from 1-6 h, wind generation is able to meet the required load demand and the extra amount of electricity will be used to charge the battery. Due to the intermittent nature of wind, it will purchase electricity if the wind generation is less than the load demand. As shown in Figure 12, from 7-10 h, the load demand exceeds wind generation; hence, EES is used to meet the load demand along with wind generation, and some energy is still required to meet the required demand, it will be purchased from other microgrids. From 11-24 h, wind generation cannot meet the required load demand; hence, the extra amount of electricity needed will be purchased from other microgrids. Microgrid 3 has one source of PV and load demand, as shown in Figure 11. To meet the load demand with just one PV source, it will purchase electricity from other microgrids in the absence of sunlight. When sunlight becomes available, it will gradually overcome the load demand and at high intensity, sunlight from 11-13 h MG3 will be able to meet the entire demand. The extra amount of electricity will be sold to other MGs. MG4 contains wind generation and battery storage, and the load demand is shown in the Figure 12. The result in Figure 12 shows that from 1-6 h, wind generation is able to meet the required load demand and the extra amount of electricity will be used to charge the battery. Due to the intermittent nature of wind, it will purchase electricity if the wind generation is less than the load demand. As shown in Figure 12, from 7-10 h, the load demand exceeds wind generation; hence, EES is used to meet the load demand along with wind generation, and some energy is still required to meet the required demand, it will be purchased from other microgrids. From 11-24 h, wind generation cannot meet the required load demand; hence, the extra amount of electricity needed will be purchased from other microgrids. MG5 contains wind generation, battery storage, and one thermal unit. The load demand is shown in Figure 13. Wind generation is available 24 h as shown in the figure. From 1-6 h, the load demand is met by wind and thermal generation and the extra amount of electricity is used to charge the battery. From 7-8 h, the load demand exceeds the wind and thermal generation; hence, EES is used to meet the required demand. From 9-24 h, as the load demand is higher than the inside generation, the extra energy required to meet the demand is purchased from other microgrids. MG5 contains wind generation, battery storage, and one thermal unit. The load demand is shown in Figure 13. Wind generation is available 24 h as shown in the figure. From 1-6 h, the load demand is met by wind and thermal generation and the extra amount of electricity is used to charge the battery. From 7-8 h, the load demand exceeds the wind and thermal generation; hence, EES is used to meet the required demand. From 9-24 h, as the load demand is higher than the inside generation, the extra energy required to meet the demand is purchased from other microgrids.

Power (kW)
MG5 contains wind generation, battery storage, and one thermal unit. The load demand is shown in Figure 13. Wind generation is available 24 h as shown in the figure. From 1-6 h, the load demand is met by wind and thermal generation and the extra amount of electricity is used to charge the battery. From 7-8 h, the load demand exceeds the wind and thermal generation; hence, EES is used to meet the required demand. From 9-24 h, as the load demand is higher than the inside generation, the extra energy required to meet the demand is purchased from other microgrids. Disco contains battery storage and one thermal unit. The thermal generation is a constant source of generation as shown in Figure 14, and the load demand of Disco is shown in the figure. From 1-6 h, thermal generation alone cannot meet the load demand. Therefore, energy is purchased from other microgrids at the optimal rate and the battery is charged during this time. From 7-8 h, thermal generation and EES are both used, and the extra amount needed to meet the load demand is purchased from outside. From 9-24 h, thermal generation is used, but the generation is not sufficient to meet the required demand. Therefore, the extra amount is purchased from outside. Disco contains battery storage and one thermal unit. The thermal generation is a constant source of generation as shown in Figure 14, and the load demand of Disco is shown in the figure. From 1-6 h, thermal generation alone cannot meet the load demand. Therefore, energy is purchased from other microgrids at the optimal rate and the battery is charged during this time. From 7-8 h, thermal generation and EES are both used, and the extra amount needed to meet the load demand is purchased from outside. From 9-24 h, thermal generation is used, but the generation is not sufficient to meet the required demand. Therefore, the extra amount is purchased from outside. The cost optimization results of the microgrids and total systems are shown in Figure  15. It is clearly shown in the figure that the total cost of MG2, MG4, and MG5 is zero, which means that they do not import energy from other microgrids or the amount of electricity that is bought or sold is the same; hence, they compensate for their cost effects, which is why their cost is zero.  The cost optimization results of the microgrids and total systems are shown in Figure 15. It is clearly shown in the figure that the total cost of MG2, MG4, and MG5 is zero, which means that they do not import energy from other microgrids or the amount of electricity that is bought or sold is the same; hence, they compensate for their cost effects, which is why their cost is zero. The cost optimization results of the microgrids and total systems are shown in Figure  15. It is clearly shown in the figure that the total cost of MG2, MG4, and MG5 is zero, which means that they do not import energy from other microgrids or the amount of electricity that is bought or sold is the same; hence, they compensate for their cost effects, which is why their cost is zero.

Conclusions and Future Work
The microgrid has emerged as a new paradigm shift for global energy systems to replace remote centralized power plants with more efficient, localized, and distributed generation systems, especially in various cities and towns around the globe. It provides more stable, flexible, and energy-efficient solutions for the power grid so that an increasing number of loads can be handled without new infrastructure needing to be built. This work provides a new iterative ABC optimization method that addresses HRESs, such as solar, wind, GT, and battery. In particular, this work optimizes the power transmission between different microgrids to minimize the cost of each microgrid and the whole system while maintaining the load requirements and stability. The optimization problem was solved by the new iterative method ABC. This study also conducted several experiments with historical data to test the proposed method for the HRES model. The simulation results show that the proposed method is efficient in finding the best solution and adjusting the optimization parameters and constraints. This method can also be applied to any site with meteorological data and any WT with technical information.
Future research will focus on the use of hybrid swarm intelligence systems, such as the particle swarm algorithm and the artificial bee colony algorithm or the differential evolution algorithm, for the economic dispatch of microgrids. In addition, flexible switching techniques for real-time scheduling in microgrids that consider more constraint situations is an interesting future research direction.
Author Contributions: Conceptualization, K.U. and Q.J.; methodology, software and validation, K.U. formal analysis, investigation and resources, R.A.K.; writing-original draft preparation, K.U.; writing-review and editing, G.G.; visualization, S.R.; supervision, Q.J. All authors have read and agreed to the published version of the manuscript.

Data Availability Statement:
The data that support the study's findings, such as numerical simulation, model, or code generated or used during the study, are available upon request from the journal and the corresponding author.