Optimization of Demand Response and Power-Sharing in Microgrids for Cost and Power Losses

: The number of microgrids within a smart distribution grid can be raised in the future. Microgrid-based distribution network reconﬁguration is analyzed in this research by taking demand response programs and power-sharing into account to optimize costs and reduce power losses. The suggested method determined the ideal distribution network conﬁguration to fulﬁl the best scheduling goals. The ideal way of interconnecting switches between microgrids and the main grid was also identiﬁed. For each hour of operation, the ideal topology of microgrid-based distribution networks was determined using optimal power ﬂow. The results were produced with and without the use of a demand response program and power-sharing in each microgrid. Different load proﬁles, such as residential, industrial, commercial, and academic, were taken into account and modiﬁed using appropriate demand response programs and power-sharing using the Artiﬁcial Bee Colony algorithm. Various scenarios were explored independently to suit the diverse aims considered by the distribution network operator for improved observation. The ABC optimization in this research attempted to reduce the system’s total operation costs and power losses through efﬁcient networked microgrid reconﬁguration. The results of optimal microgrid topology revealed the effects of power-sharing and demand response (TOU) programs. The results obtained in the proposed idea shows that costs were reduced by 8.3% and power losses were reduced by 4%. The IEEE 33-bus test system was used to demonstrate the effectiveness of the proposed approach.


Introduction
A microgrid is an excellent way to integrate distributed generation. Uncertain renewable DG output and load demands can hinder energy management in microgrids. Price-based demand response can adapt loads to renewables [1]. Recent efforts to stabilize renewable energy microgrids using storage and demand response have been discussed in [2,3], who proposed a plan to reduce the uncertainty of the renewable energy sources and demand response to minimize the cost of the system. The impact of demand response both on grid-connected and islanded microgrids was investigated in [4]. Energy sharing based on demand response in microgrids is an important factor for meeting load demand at a low cost [5]. Demand response affects the system's price in domestic, commercial, and industrial settings [6]. Price-based demand response for both flexible and non-flexible load, and proper utilization of renewable energy resources use a PSO optimization method [7]. Cost optimization for large-scale plug-in electric vehicles and renewable energy resources in microgrids was investigated in [8]. In [9], a heuristic approach was used for energy management systems in microgrids.
(HHO) algorithm is used for the reconfiguration problem of current distribution networks (DN). The goal of reconfiguration is to reduce total power losses while maintaining a better DN voltage profile [12]. In [13], the Water Cycle Algorithm (WCA) was utilized to find a near-optimal solution for network reconfiguration, as well as DG scale and placement. Furthermore, the power factor of DG is designed to minimize power losses. An optimization model for a microgrid operating in day-ahead market operations was considered here, taking the uncertainties of distributed renewable energy generation, electrical load, and day-ahead market prices into account. The results show that implementing demand responses reduces the microgrid's operating costs. Demand response programs can shift the peak load from high-to low-price periods, reducing peak valley differences and stabilizing load curves [14]. In [15], the author established an optimal energy dispatch strategy for grid-connected and standalone microgrids with photovoltaic arrays, wind turbines, fuel cells, microturbines, distributed generation, and battery energy storage systems (ESS). The techno-economic benefits of hybrid power systems have been explored. This problem has been addressed so far solely to reduce operating costs. Figure 1 shows the microgrid setup. A multi-objective securityconstrained microgrid energy management system (MOSC-MEMS) based on a coordinated unit commitment-optimal power flow (UC-OPF) framework was introduced in [16]. As smart homes become more prevalent in distribution systems, scheduling microgrids in the presence of smart homes has become a critical issue. An energy management framework for microgrids with smart homes and demand response (DR) programs was presented in [17].
Furthermore, peak load is a problem in the power grid. Because loads are adjustable, demand-side strategies such as demand response (DR) are better suited to meet these challenges. The authors of [18] investigated how DR programs affect multi-microgrid operation (MMG). Demand response is the most crucial factor for cost reduction and energy management systems (EMS). The upstream network uses time of use (TOU) demand response [19]. Demand reaction (DR) is the end-users' behavior in response to pricing adjustments. For example, when wholesale market prices are high or the system's stability is affected, DR is characterized as an incentive payment. DR includes all intentional changes to the end-users' electricity consumption patterns intended to change the timing, level of instantaneous demand, or overall consumption.   Furthermore, peak load is a problem in the power grid. Because loads are adjustable, demand-side strategies such as demand response (DR) are better suited to meet these challenges. The authors of [18] investigated how DR programs affect multi-microgrid operation (MMG). Demand response is the most crucial factor for cost reduction and energy management systems (EMS). The upstream network uses time of use (TOU) demand response [19]. Demand reaction (DR) is the end-users' behavior in response to pricing adjustments. For example, when wholesale market prices are high or the system's stability is affected, DR is characterized as an incentive payment. DR includes all intentional changes to the end-users' electricity consumption patterns intended to change the timing, level of instantaneous demand, or overall consumption. Figure 2 shows various DR programs. These are incentive-based programs (IBPs) and price-based programs (PBPs). In PBPs, customers manage their power use in response to load service entity-determined prices, which include time of use (TOU), critical peak Market-based IBPs include DR programs, demand bidding, capacity markets, and ancillary services. Traditionally, IBP participants get a bill credit or a discount for participating. Participants in market-based schemes are compensated for reducing critical load. DLC initiatives enable utilities to turn off participants' equipment remotely. Air conditioners and water heaters are commonly remote-controlled. These programs may interest residential and small commercial customers [19]. A PSO algorithm is used to check the impact of TOU demand response to minimize the operational cost of the system and mitigate pollution [20]. A Robust Model Predictive Control (RMPC) technique was used in [21] to account for data uncertainties in the microgrid, with the goal of minimizing total economic costs while satisfying end-user comfort and energy demands. Demand management strategies can be used to optimize the management of customers' energy resources and demand profiles [22]. A microgrid's return on investment can be accelerated if it maximizes profits. Demand response can help to achieve this. The MG's loads can be shifted from peak to off-peak times or reduced during peak times [23]. programs may interest residential and small commercial customers [19]. A PSO algo is used to check the impact of TOU demand response to minimize the operational c the system and mitigate pollution [20]. A Robust Model Predictive Control (R technique was used in [21] to account for data uncertainties in the microgrid, with th of minimizing total economic costs while satisfying end-user comfort and energy dem Demand management strategies can be used to optimize the management of custo energy resources and demand profiles [22]. A microgrid's return on investment c accelerated if it maximizes profits. Demand response can help to achieve this. The loads can be shifted from peak to off-peak times or reduced during peak times [23].  The optimization problem includes demand response to show its implicatio effective energy dispatch as well as technological and economic advantages. Ta shows a few examples in the literature that worked on EMS and DR.  The optimization problem includes demand response to show its implications for effective energy dispatch as well as technological and economic advantages. Table 1 shows a few examples in the literature that worked on EMS and DR.  [24] Power loss, VDI [25] DRP's to control system operation [26] DRP(TOU) and EV's for economic and environmental assessment. [27] Optimal sizing of microgrid. [28] Cost [29] Cost [30] Cost [31] Cost [32] Cost and emissions [33] Cost and emissions [34] Cost [35] Losses and emissions [36] Stability, cost, emissions [37] Cost, stability, pollution This article Cost, losses In this article, the impact of power-sharing and demand response on cost and power losses using the ABC algorithm was studied, and it shows that the proposed idea produces optimal costs and minimizes power losses. The rest of the article is organized as follows: Section 2 describes the proposed work, Section 3 is about problem formulation, Section 4 is the mathematical modeling for the microgrid, Section 5 describes the demand response, Section 6 is about the power-sharing model in microgrids, Section 7 is the results and discussion; and finally, in Section 8, the article is concluded.

Proposed Work
The proposed work presents the impact of demand response and optimal powersharing in microgrids for cost and loss optimization using Artificial Bee Colony optimization. Solar photovoltaic panels, wind energy generation units, fuel cells, microturbines, and gas turbines are examples of distributed energy sources that provide clean energy. The term "microgrid" refers to a group of these microsources and loads that operate as a single controllable unit and provide electrical power to a particular area. In this work, microgrids have generation sources. e.g., wind generation or photovoltaic generation. Gas turbines and battery energy storage systems are used. In the proposed idea, the microgrids try to meet their demands from the generation sources. If the generated energy in the microgrid exceeds the required demand, the extra energy will be shared with other microgrids on an optimal basis. Demand response is used to reduce losses and optimize the cost of the system. The proposed idea consists of four different cases. In Case 1, the cost and loss are calculated using demand response and power-sharing. This is supposed to be the worst case. In Case 2, the cost and losses are calculated using the demand response but not power-sharing, and the impact is measured. In Case 3: cost and power losses are calculated using power-sharing but not demand response. In the last case, which is our proposed case (Case 4), both demand response and power-sharing in microgrids are considered. The overall impact of both the demand response and power-sharing was calculated, showing the lowest cost and minimum losses.
The proposed idea of optimal power-sharing and demand response in microgrids is presented in Figure 3. In this article, the impact of power-sharing and demand response on cost and power losses using the ABC algorithm was studied, and it shows that the proposed idea produces optimal costs and minimizes power losses. The rest of the article is organized as follows: Section 2 describes the proposed work, Section 3 is about problem formulation, Section 4 is the mathematical modeling for the microgrid, Section 5 describes the demand response, Section 6 is about the power-sharing model in microgrids, Section 7 is the results and discussion; and finally, in Section 8, the article is concluded.

Proposed Work
The proposed work presents the impact of demand response and optimal powersharing in microgrids for cost and loss optimization using Artificial Bee Colony optimization. Solar photovoltaic panels, wind energy generation units, fuel cells, microturbines, and gas turbines are examples of distributed energy sources that provide clean energy. The term "microgrid" refers to a group of these microsources and loads that operate as a single controllable unit and provide electrical power to a particular area. In this work, microgrids have generation sources. e.g., wind generation or photovoltaic generation. Gas turbines and battery energy storage systems are used. In the proposed idea, the microgrids try to meet their demands from the generation sources. If the generated energy in the microgrid exceeds the required demand, the extra energy will be shared with other microgrids on an optimal basis. Demand response is used to reduce losses and optimize the cost of the system. The proposed idea consists of four different cases. In Case 1, the cost and loss are calculated using demand response and powersharing. This is supposed to be the worst case. In Case 2, the cost and losses are calculated using the demand response but not power-sharing, and the impact is measured. In Case 3: cost and power losses are calculated using power-sharing but not demand response. In the last case, which is our proposed case (Case 4), both demand response and powersharing in microgrids are considered. The overall impact of both the demand response and power-sharing was calculated, showing the lowest cost and minimum losses.
The proposed idea of optimal power-sharing and demand response in microgrids is presented in Figure 3. In Figure 3, a 33-bus radial distribution system is categorized into six microgrids. 1 consists of a PV source, a BESS, and a residential load.
2 consists of a PV array, battery energy storage, and an academic load.
3 consists of a PV array, a gas turbine, WT, and a commercial load.
4 consists of a PV array, wind generation (WT), battery energy storage (BESS), and a residential load.
5 consists of a PV array, wind generation, and a residential load.
6 consists of a PV array, a wind turbine, battery energy storage, and an industrial load. The details of the loads are given in Table 2. In Figure 3, a 33-bus radial distribution system is categorized into six microgrids. MG1 consists of a PV source, a BESS, and a residential load. MG2 consists of a PV array, battery energy storage, and an academic load. MG3 consists of a PV array, a gas turbine, WT, and a commercial load. MG4 consists of a PV array, wind generation (WT), battery energy storage (BESS), and a residential load. MG5 consists of a PV array, wind generation, and a residential load. MG6 consists of a PV array, a wind turbine, battery energy storage, and an industrial load. The details of the loads are given in Table 2. The proposed idea was implemented using Artificial Bee Colony optimization for cost and power loss optimization. A detailed explanation of the ABC algorithm is presented in the next section.

Artificial Bee Colony Algorithm
Karaboga developed the ABC algorithm in 2005. Since then, Karaboga and Bastürk have studied the ABC algorithm's performance on unconstrained optimization problems [39]. The ABC algorithm divides a colony's bees into three categories: employed (foragers), onlookers (observers), and scouts. One employed bee is used for each food source. In other words, employed bees are equivalent to food sources. An abandoned food site's employed bee is forced to scout for random food sources. Employed bees inform onlooker bees to choose a food source to forage from. The ABC bees are more specialized, with two groups (foragers and observers), similar to the honeybee algorithm.
A swarm of ABC solutions (food sources) is generated randomly by the ABC. Let where X k is a randomly selected candidate solution with i = 1, 2, 3, . . . . . . , N and j = 1, 2, 3, . . . . . . , D, where i = k and ϕ i,j [−1, 1] is a random value ranging from −1 to 1. After generating V i , greedy selection is used. If V i s fitness value exceeds than X i s, the algorithm updates X i ; otherwise, it leaves X i Unchanged. The amount of nectar at a given location x can be encoded as F(x), and the probability P i of an onlooker bee selecting the best food source at X i can be defined as [40]: where S is the food source quantity. The intake efficiency of a food source is determined by the ratio F/r, where F is the amount of nectar and r is the time passed there. An abandoned food source has been tried/foraged at least a certain number of times without improvement [41], in which Fit i is the swarm fitness value. A better solution i increases the probability of selecting a better ith food source. The value of Fit i is determined by using Equation (3): where f i is the objective function. If the new value of the location is better, the old value is replaced. If the new value is not superior, then the old value is not changed. An abandoned food source cannot be upgraded over a specified number of cycles. We assume that the scout bee replaces X i , which is abandoned for a new food source: where x lbj and x ubj are jth the lower and upper bound values, respectively, and i and j are the same.

The ABC Algorithm Representation in Flowchart
Recent research has shown that the ABC can outperform PSO, differential evolution, and evolutionary algorithms (EA) for various test functions Figure 4. The amount of nectar at a given location x can be encoded as ( ), and the probability of an onlooker bee selecting the best food source at can be defined as [40]: where S is the food source quantity. The intake efficiency of a food source is determined by the ratio F/r, where F is the amount of nectar and r is the time passed there. An abandoned food source has been tried/foraged at least a certain number of times without improvement [41], in which Fit i is the swarm fitness value. A better solution increases the probability of selecting a better ℎ food source. The value of is determined by using Equation (3): where is the objective function. If the new value of the location is better, the old value is replaced. If the new value is not superior, then the old value is not changed.
An abandoned food source cannot be upgraded over a specified number of cycles. We assume that the scout bee replaces Xi, which is abandoned for a new food source: where and are ℎ the lower and upper bound values, respectively, and and are the same.

The ABC Algorithm Representation in Flowchart
Recent research has shown that the ABC can outperform PSO, differential evolution, and evolutionary algorithms (EA) for various test functions

Mathematical Modeling of Microgrid Components
A hybrid energy system in a microgrid may include renewable energy conversion components such as wind turbines, solar panels, and hydro turbines; non-renewable generators such as diesel generators and microturbines; and energy storage devices such as batteries. All or portion of it could be found in a hybrid energy system. A general setup of a microgrid is shown in Figure 1. Modeling individual components is the first step in appropriately selecting the components and subsystems for optimal system sizing. The modeling approach helps identify and understand the features of the components, and in decision-making. The performance of prediction accuracy is reflected in the modeling parameters; however, designing a precise model can be too complex or time-consuming. A suitable model should strike a balance between complexity and accuracy. An individual component's performance is modeled using either deterministic or probabilistic methods. The following is a description of the general methodology of modeling an energy system.
The following equation represents the power generated by a wind turbine [42]: In Equation (5), ρ is used for air density, v 3 is used for the velocity of the wind, R is the wind turbine's blade radius, and C(λ) is the tip speed ratio's λ coefficient. The λ is defined as the wind turbine's angular velocity with respect to wind speed.
Power generated by the solar panel array is represented in Equation (6) [43]: In Equation (6), p pv is the solar panel array output power, p max is the rated power generated by the PV array, G pv is the solar irradiance, and G o is a standard irradiance. This means the ratio of solar irradiance and standard irradiance will be less than or equal to 1. K is the coefficient of temperature, T c is the cell temperature, and T r is the reference temperature.
The third generation unit is a gas microturbine, which operates on the principles of microcombustion. Under specific conditions, a mixture of compressed air and fuel is burned at a constant pressure. When the hot gas expands, mechanical energy is produced. The gas microturbine has the potential to generate energy that renewable energy sources cannot [44]. We took the following technical inputs into account: installed capacity, maximum and minimum instantaneous power, ramp down and ramp up limits, and minimum start-up and shut-down times: where u µT t is a binary variable, whose value is either 0 or 1. When the microgrid is in an operational state, then u µT t is 1; when it is in an off state, then u µT t will be equal to 0. Moreover, p µT min is the minimum power generated by the microturbine and p µT max is the maximum power generated by the gas microturbine.
When the gas microturbine is operated, on the other hand, the variable P µT t will have values within a range based on the prior variable's value P µT t−1 . The difference between the generation level at time t − 1 and time t must stay within a defined range (R l , R u ). The machine's properties determine the range, and these restrictions are referred to as the ramp limits.
When the generated power exceeds the demand, it will charge the BESS. When the BESS is discharged, it produces electricity. Two sets of positive variables are used to represent the performance of the storage device because of this dual procedure.
Energies 2022, 15, 3274 8 of 22 Equation (9) represents the charging mode of the battery when the generated energy exceeds the demand [45].
In Equation (10), the battery is in discharging mode and η bdis shows the discharging efficiency of the battery.

Methodology
This section introduces the mathematical formulation of the concepts of the demand response programs and network reconfiguration.  [46]. Figure 2 shows this classification. The majority of incentive-based programs are based on rewards and penalties. Energy pricing in time-based DR programs is based on distinct periods, with high peak load prices and low off-peak prices in TOU, CPP, and RTP programs. Energy prices in TOU programs are categorized into three modes: peak, off-peak, and valley; however, the range of energy costs in RTP programs is significantly greater. During the critical peak in CPP schemes, the energy price is substantially higher than the normal peak price. The time of use (TOU) program is explored in this article.

Elasticity
Elasticity is measured by the amount of change in demand when the price of electricity increases or decreases by one unit or as the load's sensitivity to price changes. The elasticity parameter [47] is represented by Equation (11).
In Equation (11), ∂P d is the change in demand due to a change in the price ∂ρ, and ρ o and P do are the base price and demand. Elasticity is categorized in two types: self-elasticity (SE) and cross-elasticity (CE), according to the following definition. Self-elasticity (Ei, i) is the term for varying the amount of load in the ith period as a result of changing the price of electricity in the ith period, whereas cross-elasticity (Ei, j) is the term for varying the amount of load in the ith period as a result of changing the price of electricity in the jth period. SE is always negative, while CE is always positive. Self-elasticity and cross-elasticity are represented by Equations (12) and (13), respectively.
Equation (12) shows the self-elasticity for the change in demand ∂d(i) in the ith period due to a change in the price ∂ρ(i) in the ith period. Equation (13) shows the change in demand ∂d(i) in the ith period due to a change in the price ∂ρ(j) in the jth period.

Types of Load
There are different types of loads used in demand response. The different types of loads are represented in Figure 5.

Types of Load
There are different types of loads used in demand response. The different types of loads are represented in Figure 5.  For all of the types of loads above, the elasticity term must be explained using the demand response for the energy management system. The hourly loads and generation profiles are shown in Table 2.

Proposed Model
This part introduces the mathematical formulation and the concept of network reconfiguration in the proposed idea.

Proposed Model Methodology
This part introduces the suggested design and system model, which will be used as a framework throughout the article. The suggested model implies that the system contains many buses situated in a number of MGs, as shown in Figure 3. Each bus can act as a producer, consumer, or prosumer. Each bus can contain a variety of energy sources, including both renewable and non-renewable options. This work used optimal powersharing and demand response for cost reduction and power loss optimization. Four different cases are discussed in this article. Case 1: in this case, the cost and power losses are calculated to meet load demand without power-sharing or the demand response. Case 2: in this case, the cost and power losses are calculated using power-sharing but not demand response. Case 3: in this case, the cost and power losses are calculated in the microgrids to meet load demand using demand response but not power-sharing. Case 4 is related to calculating the cost and power losses using both demand response and power-sharing.

Power-Sharing, Costs, and Power Losses in Microgrids
Different generation and load sources are available in microgrids. The microgrids are interconnected, as shown in Figure 3. The following mathematical models were used in all four cases.
Wind generation (15) 0 ≤ ≤ battery storage For all of the types of loads above, the elasticity term must be explained using the demand response for the energy management system. The hourly loads and generation profiles are shown in Table 2.

Proposed Model
This part introduces the mathematical formulation and the concept of network reconfiguration in the proposed idea.

Proposed Model Methodology
This part introduces the suggested design and system model, which will be used as a framework throughout the article. The suggested model implies that the system contains many buses situated in a number of MGs, as shown in Figure 3. Each bus can act as a producer, consumer, or prosumer. Each bus can contain a variety of energy sources, including both renewable and non-renewable options. This work used optimal power-sharing and demand response for cost reduction and power loss optimization. Four different cases are discussed in this article. Case 1: in this case, the cost and power losses are calculated to meet load demand without power-sharing or the demand response. Case 2: in this case, the cost and power losses are calculated using power-sharing but not demand response. Case 3: in this case, the cost and power losses are calculated in the microgrids to meet load demand using demand response but not power-sharing. Case 4 is related to calculating the cost and power losses using both demand response and power-sharing.

Power-Sharing, Costs, and Power Losses in Microgrids
Different generation and load sources are available in microgrids. The microgrids are interconnected, as shown in Figure 3. The following mathematical models were used in all four cases.
PV gen = PV pro f ile ·PV cap PV generation (14) P wg = P wpro f ile ·W cap Wind generation (15) 0 ≤ BESS ≤ BESS cap battery storage (16) where L MG−net is the net load of MGs and PV MG is the PV generation in the MG s, P MG(GT) is gas turbine generation in the MG s, P MG(w) is the wind generation in the MGs, and L MG is the load of the MG s. In Equation (17), if the net load is positive, the generated power exceeds the demand; hence the extra power is used to charge the battery in MG1. However, if the generated power is less than the required demand, the battery will be discharged to meet the load demand. The charging and discharging of the battery are represented in mathematical form as: where, in Equation (24), P DL (t) is the power supplied to a dummy load.
0 ≤ P wt(Gen) ≤ P max(wt) wind generation (30) In Case 1, the cost function is: Cost wt = ∑ 6 i=3 CWT i wind turbine cost (32) The power loss function is:

Results and Discussion
Mathematical modeling for demand response and power-sharing in microgrids for different loads and generation sources produced the following results for different cases.

For Case 1, the Simulations for Cost
The details of Case 1 regarding the network cost, generation cost, total cost, and curtailed energy are shown in Figures 6 and 7 = .
battery storage cost (39) The power loss function is:

Results and Discussion
Mathematical modeling for demand response and power-sharing in microgrids for different loads and generation sources produced the following results for different cases.

For Case 1, the Simulations for Cost
The details of Case 1 regarding the network cost, generation cost, total cost, and curtailed energy are shown in Figures 6 and 7.

Case 2: Power-Sharing but Not Demand Response
We calculated the cost and loss with energy sharing but not demand response.
battery storage cost (39) The power loss function is:

Results and Discussion
Mathematical modeling for demand response and power-sharing in microgrids for different loads and generation sources produced the following results for different cases.

For Case 1, the Simulations for Cost
The details of Case 1 regarding the network cost, generation cost, total cost, and curtailed energy are shown in Figures 6 and 7.

Case 2: Power-Sharing but Not Demand Response
We calculated the cost and loss with energy sharing but not demand response.

Case 2: Power-Sharing but Not Demand Response
We calculated the cost and loss with energy sharing but not demand response.

Simulations and discussion for case 2:
In Microgrid 1, there is a PV source and battery storage, and the load is residential. The PV source is available from 6.00 a.m. to 6.00 p.m. The generation during this time is represented in Figure 8. From 1.00 a.m. to 5.00 a.m., and from 7.00 p.m. to 12.00 a.m., Microgrid 1 meets its demand either from the Disco network or battery storage. When the light intensity is high and the PV source produces more energy than the required demand, the extra energy is used to store energy in the battery storage system or sold to the external microgrids or Disco. All of these explanations are shown in Figure 8. For microgrids to share energy, the following equations must be used: In Microgrid 2, again we have a PV source and a battery energy storage system, but the load here is an academic load, which will be maximum from 7.00 a.m. to 7.00 p.m., during which maximum energy will be required, and the extra energy required beyond the generation range will be provided either by the storage system or by the Disco network. The load curve of Microgrid 2 is shown in Figure 9. In Microgrid 3, there are three generation sources: PV, WT, and a gas turbine, and the load is a commercial load. The commercial load will be high from 8.00 a.m. to 10.00 p.m. If the generation sources are capable of meeting the load demand, then no external For microgrids to share energy, the following equations must be used: In Microgrid 2, again we have a PV source and a battery energy storage system, but the load here is an academic load, which will be maximum from 7.00 a.m. to 7.00 p.m., during which maximum energy will be required, and the extra energy required beyond the generation range will be provided either by the storage system or by the Disco network. The load curve of Microgrid 2 is shown in Figure 9.
The PV source is available from 6.00 a.m. to 6.00 p.m. The generation during this time is represented in Figure 8. From 1.00 a.m. to 5.00 a.m., and from 7.00 p.m. to 12.00 a.m., Microgrid 1 meets its demand either from the Disco network or battery storage. When the light intensity is high and the PV source produces more energy than the required demand, the extra energy is used to store energy in the battery storage system or sold to the external microgrids or Disco. All of these explanations are shown in Figure 8.
For microgrids to share energy, the following equations must be used: In Microgrid 2, again we have a PV source and a battery energy storage system, but the load here is an academic load, which will be maximum from 7.00 a.m. to 7.00 p.m., during which maximum energy will be required, and the extra energy required beyond the generation range will be provided either by the storage system or by the Disco network. The load curve of Microgrid 2 is shown in Figure 9. In Microgrid 3, there are three generation sources: PV, WT, and a gas turbine, and the load is a commercial load. The commercial load will be high from 8.00 a.m. to 10.00 p.m. If the generation sources are capable of meeting the load demand, then no external In Microgrid 3, there are three generation sources: PV, WT, and a gas turbine, and the load is a commercial load. The commercial load will be high from 8.00 a.m. to 10.00 p.m. If the generation sources are capable of meeting the load demand, then no external energy needs to be imported from Disco or other microgrids. If the generation source cannot meet the load demand of the microgrid, it will either import energy from Disco or other microgrids. If the generated energy in the microgrid exceeds the required load demand, then the extra energy will be sold to other microgrids or Disco. The discussion above is illustrated in Figure 10. energy needs to be imported from Disco or other microgrids. If the generation source cannot meet the load demand of the microgrid, it will either import energy from Disco or other microgrids. If the generated energy in the microgrid exceeds the required load demand, then the extra energy will be sold to other microgrids or Disco. The discussion above is illustrated in Figure 10. Microgrid4 has same load curve as Microgrid 1 but has two PV sources, a wind turbine, and battery energy storage. If the demand is fulfilled by the generation source, then there is no need to import energy. If the generation sources are not producing a sufficient amount, then extra energy required will be imported from external microgrids or Disco. The load generation curve for Microgrid 4 is shown in Figure 11. Microgrid 5 has PV and wind sources and a residential load, as shown in Table 2. Residential load always remains high from 12.00 a.m. to 6.00 a.m. and from 6.00 pm to 11.00 p.m. During high load demand, energy is either imported from other microgrids or from Disco. During the daytime, the load demand is low and generation is high, as the PV and wind systems will both generate energy. The extra energy will be sold to other microgrids or Disco, as shown in Figure 12.
In Microgrid 6, the generation sources are PV and wind generation, and a BESS is also used in the microgrid for extra energy to be stored or so stored energy can be used in the microgrid. Microgrid4 has same load curve as Microgrid 1 but has two PV sources, a wind turbine, and battery energy storage. If the demand is fulfilled by the generation source, then there is no need to import energy. If the generation sources are not producing a sufficient amount, then extra energy required will be imported from external microgrids or Disco. The load generation curve for Microgrid 4 is shown in Figure 11. energy needs to be imported from Disco or other microgrids. If the generation source cannot meet the load demand of the microgrid, it will either import energy from Disco or other microgrids. If the generated energy in the microgrid exceeds the required load demand, then the extra energy will be sold to other microgrids or Disco. The discussion above is illustrated in Figure 10. Microgrid4 has same load curve as Microgrid 1 but has two PV sources, a wind turbine, and battery energy storage. If the demand is fulfilled by the generation source, then there is no need to import energy. If the generation sources are not producing a sufficient amount, then extra energy required will be imported from external microgrids or Disco. The load generation curve for Microgrid 4 is shown in Figure 11. Microgrid 5 has PV and wind sources and a residential load, as shown in Table 2. Residential load always remains high from 12.00 a.m. to 6.00 a.m. and from 6.00 pm to 11.00 p.m. During high load demand, energy is either imported from other microgrids or from Disco. During the daytime, the load demand is low and generation is high, as the PV and wind systems will both generate energy. The extra energy will be sold to other microgrids or Disco, as shown in Figure 12.
In Microgrid 6, the generation sources are PV and wind generation, and a BESS is also used in the microgrid for extra energy to be stored or so stored energy can be used in the microgrid. Microgrid 5 has PV and wind sources and a residential load, as shown in Table 2. Residential load always remains high from 12.00 a.m. to 6.00 a.m. and from 6.00 p.m. to 11.00 p.m. During high load demand, energy is either imported from other microgrids or from Disco. During the daytime, the load demand is low and generation is high, as the PV and wind systems will both generate energy. The extra energy will be sold to other microgrids or Disco, as shown in Figure 12. If the generated energy is less than the required demand, then energy will be imported from the external network (Disco) or from other microgrids. The load profile of Microgrid 6 is shown in Figure 13. In Microgrid 6, the generation sources are PV and wind generation, and a BESS is also used in the microgrid for extra energy to be stored or so stored energy can be used in the microgrid. If the generated energy is less than the required demand, then energy will be imported from the external network (Disco) or from other microgrids. The load profile of Microgrid 6 is shown in Figure 13. If the generated energy is less than the required demand, then energy will be imported from the external network (Disco) or from other microgrids. The load profile of Microgrid 6 is shown in Figure 13. The cost convergence curve for power-sharing using the ABC algorithm is shown in Figure 14. The cost is gradually reduced with the number of iterations. The optimal cost was achieved using an iterative ABC algorithm. The total cost, and the cost of each source and of energy-sharing are shown in Figure 15. The cost convergence curve for power-sharing using the ABC algorithm is shown in Figure 14. The cost is gradually reduced with the number of iterations. The optimal cost was achieved using an iterative ABC algorithm. If the generated energy is less than the required demand, then energy will be imported from the external network (Disco) or from other microgrids. The load profile of Microgrid 6 is shown in Figure 13. The cost convergence curve for power-sharing using the ABC algorithm is shown in Figure 14. The cost is gradually reduced with the number of iterations. The optimal cost was achieved using an iterative ABC algorithm. The total cost, and the cost of each source and of energy-sharing are shown in Figure 15. The total cost, and the cost of each source and of energy-sharing are shown in Figure 15.

Case 3: Cost and Loss Calculations with DR but Not Power-Sharing
In Case 3, the impact of demand response on the cost and power losses was calculated. Demand response was used to reduce the cost and power in each microgrid,

Case 3: Cost and Loss Calculations with DR but Not Power-Sharing
In Case 3, the impact of demand response on the cost and power losses was calculated. Demand response was used to reduce the cost and power in each microgrid, as there are different types of load, as mentioned in Table 2. For the demand response, the TOU price-based demand response was used here. The TOU rate allows consumers to better manage their electricity bills by moving consumption from the peak to mid-peak and off-peak times. Reducing the quantity of electricity required at peak load times allows the power system to meet consumers' needs without developing more expensive backup equipment and reducing GHG (greenhouse gas) emissions. The simulation results are shown and discussed here. A clear difference in losses and cost is observed in the figures. In Case 3, there is no power-sharing among the microgrids. The simulations are shown with no power-sharing.
For demand response (time of use), the following equation must be used: where TOU is the time of use demand response and E N is the network's energy. In Microgrid 1, the load is residential and the impact of demand response is shown in Figure 16. Initially, the losses increased due to the load shifting from on-peak to off-peak hours. During on-peak hours, the losses are reduced, as shown in Figure 16. There is no sharing of energy among the microgrids, as shown below in Figure 16.

Case 3: Cost and Loss Calculations with DR but Not Power-Sharing
In Case 3, the impact of demand response on the cost and power losses was calculated. Demand response was used to reduce the cost and power in each microgrid, as there are different types of load, as mentioned in Table 2. For the demand response, the TOU price-based demand response was used here. The TOU rate allows consumers to better manage their electricity bills by moving consumption from the peak to mid-peak and off-peak times. Reducing the quantity of electricity required at peak load times allows the power system to meet consumers' needs without developing more expensive backup equipment and reducing GHG (greenhouse gas) emissions. The simulation results are shown and discussed here. A clear difference in losses and cost is observed in the figures. In Case 3, there is no power-sharing among the microgrids. The simulations are shown with no power-sharing.
For demand response (time of use), the following equation must be used: Network energy cost (45) where TOU is the time of use demand response and is the network's energy. In Microgrid 1, the load is residential and the impact of demand response is shown in Figure 16. Initially, the losses increased due to the load shifting from on-peak to offpeak hours. During on-peak hours, the losses are reduced, as shown in Figure 16. There is no sharing of energy among the microgrids, as shown below in Figure 16. Microgrid 2 has an academic load, and the impact of demand response is shown in Figure 17. The losses are reduced during on-peak hours and are increased slightly during off-peak hours, as the load is shifted from on to off-peak hours.

OR PEER REVIEW 16 of 23
Microgrid 2 has an academic load, and the impact of demand response is shown in Figure 17. The losses are reduced during on-peak hours and are increased slightly during off-peak hours, as the load is shifted from on to off-peak hours. The impact of demand response on Microgrid 3 is shown in Figure 18. The load in Microgrid 3 is commercial, as shown in Table 2. The losses are reduced during on-peak hours and are slightly increased in off-peak hours as the load is shifted to off-peak hours.  The impact of demand response on Microgrid 3 is shown in Figure 18. The load in Microgrid 3 is commercial, as shown in Table 2. The losses are reduced during on-peak hours and are slightly increased in off-peak hours as the load is shifted to off-peak hours. Figure 17. Impact of DR on MG 2.
The impact of demand response on Microgrid 3 is shown in Figure 18. The load in Microgrid 3 is commercial, as shown in Table 2. The losses are reduced during on-peak hours and are slightly increased in off-peak hours as the load is shifted to off-peak hours. The losses in Microgrids 4 and 5 are reduced using a demand response program. Both the grids have residential loads. The impact on losses is shown in Figure 19. The losses in Microgrids 4 and 5 are reduced using a demand response program. Both the grids have residential loads. The impact on losses is shown in Figure 19. The impact of demand response on Microgrid 3 is shown in Figure 18. The load in Microgrid 3 is commercial, as shown in Table 2. The losses are reduced during on-peak hours and are slightly increased in off-peak hours as the load is shifted to off-peak hours. The losses in Microgrids 4 and 5 are reduced using a demand response program. Both the grids have residential loads. The impact on losses is shown in Figure 19. Microgrid 6 has an industrial load. There is no impact of the TOU demand response on power losses, as there is almost a constant load and the system has no possibility to shift the load inside the microgrid, as shown in Figure 20. Due to DR being used in other microgrids, the cost is reduced substantially. A real-time pricing demand response is used in industrial loads. Microgrid 6 has an industrial load. There is no impact of the TOU demand response on power losses, as there is almost a constant load and the system has no possibility to shift the load inside the microgrid, as shown in Figure 20. Due to DR being used in other microgrids, the cost is reduced substantially. A real-time pricing demand response is used in industrial loads. Microgrid 6 has an industrial load. There is no impact of the TOU demand response on power losses, as there is almost a constant load and the system has no possibility to shift the load inside the microgrid, as shown in Figure 20. Due to DR being used in other microgrids, the cost is reduced substantially. A real-time pricing demand response is used in industrial loads. The overall impact of demand response on the cost and power losses for Case 3 is presented in Figure 21.

Case 4: Cost and Loss Calculations with DR and Power-Sharing
In the last case, demand response and power-sharing are considered. In this case, the network is considered to be more flexible, as the extra amount of energy in microgrids The overall impact of demand response on the cost and power losses for Case 3 is presented in Figure 21. Microgrid 6 has an industrial load. There is no impact of the TOU demand response on power losses, as there is almost a constant load and the system has no possibility to shift the load inside the microgrid, as shown in Figure 20. Due to DR being used in other microgrids, the cost is reduced substantially. A real-time pricing demand response is used in industrial loads. The overall impact of demand response on the cost and power losses for Case 3 is presented in Figure 21.

Case 4: Cost and Loss Calculations with DR and Power-Sharing
In the last case, demand response and power-sharing are considered. In this case, the network is considered to be more flexible, as the extra amount of energy in microgrids

Case 4: Cost and Loss Calculations with DR and Power-Sharing
In the last case, demand response and power-sharing are considered. In this case, the network is considered to be more flexible, as the extra amount of energy in microgrids using demand response is shared on an optimal basis with other microgrids or Disco; as a result, losses and cost will be reduced. The impact of both DR and power-sharing is visible in the simulations. In Microgrid 1, the impact of DR and power-sharing on the cost and losses is presented in Figure 22. using demand response is shared on an optimal basis with other microgrids or Disco; as a result, losses and cost will be reduced. The impact of both DR and power-sharing is visible in the simulations. In Microgrid 1, the impact of DR and power-sharing on the cost and losses is presented in Figure 22. In Case 4, Microgrid 2's response to both power-sharing and DR is shown in Figure  23. Power-sharing and DR have a nominal role in reducing the cost and power losses. In Case 4, Microgrid 2's response to both power-sharing and DR is shown in Figure 23. Power-sharing and DR have a nominal role in reducing the cost and power losses. In Case 4, Microgrid 2's response to both power-sharing and DR is shown in Figure  23. Power-sharing and DR have a nominal role in reducing the cost and power losses. MG 3, having a commercial load, has a nominal change in power losses and the cost due to the implementation of DR and power-sharing. The impact is shown in Figure 24. Power-sharing has the advantage of sharing extra energy among the microgrids and the main grid, and wastage of energy is prevented. MGs 4 and 5 have residential loads, and the impact of both demand response and power-sharing is shown in Figure 25. The sharing of power among microgrids helps them MG 3, having a commercial load, has a nominal change in power losses and the cost due to the implementation of DR and power-sharing. The impact is shown in Figure 24. Power-sharing has the advantage of sharing extra energy among the microgrids and the main grid, and wastage of energy is prevented. In Case 4, Microgrid 2's response to both power-sharing and DR is shown in Figure  23. Power-sharing and DR have a nominal role in reducing the cost and power losses. MG 3, having a commercial load, has a nominal change in power losses and the cost due to the implementation of DR and power-sharing. The impact is shown in Figure 24. Power-sharing has the advantage of sharing extra energy among the microgrids and the main grid, and wastage of energy is prevented. MGs 4 and 5 have residential loads, and the impact of both demand response and power-sharing is shown in Figure 25. The sharing of power among microgrids helps them MGs 4 and 5 have residential loads, and the impact of both demand response and power-sharing is shown in Figure 25. The sharing of power among microgrids helps them to share energy on an optimal basis for cost optimization, and demand response is used in the microgrids to control power losses and to utilize energy properly.
In MG6, the RTP demand response is used and hence there is no impact of TOU, although power-sharing will take place in MG 6 with other microgrids and the main grid using power-sharing constraints. The impact of power-sharing is shown in Figure 26.
The overall impact of DR (TOU) and power-sharing in Case 4 are presented in Figure 27.
The impact of all the cases on the cost and losses is represented in Figure 28. The figure clearly shows the impact of both demand response and power-sharing on losses and the cost. Case 4, which is our proposed idea, has the lowest cost and minimum power losses, which shows the effectiveness of our proposed idea. to share energy on an optimal basis for cost optimization, and demand response is used in the microgrids to control power losses and to utilize energy properly. In MG6, the RTP demand response is used and hence there is no impact of TOU, although power-sharing will take place in MG 6 with other microgrids and the main grid using power-sharing constraints. The impact of power-sharing is shown in Figure 26.  to share energy on an optimal basis for cost optimization, and demand response is used in the microgrids to control power losses and to utilize energy properly. In MG6, the RTP demand response is used and hence there is no impact of TOU, although power-sharing will take place in MG 6 with other microgrids and the main grid using power-sharing constraints. The impact of power-sharing is shown in Figure 26.  The impact of all the cases on the cost and losses is represented in Figure 28. The figure clearly shows the impact of both demand response and power-sharing on losses and the cost. Case 4, which is our proposed idea, has the lowest cost and minimum power  The impact of all the cases on the cost and losses is represented in Figure 28. The figure clearly shows the impact of both demand response and power-sharing on losses and the cost. Case 4, which is our proposed idea, has the lowest cost and minimum power losses, which shows the effectiveness of our proposed idea.

Conclusions
The impact of demand response and optimal power-sharing in microgrids for cost and power loss optimization using the ABC algorithm in a smart distribution system were analyzed in this work. Residential, industrial, commercial, and academic load profiles were all taken into account. Power-sharing and demand response programs (TOU) for each type of load were adopted. The key aspect of the microgrid-based smart distribution network is fragmentation. Two essential objectives were discussed separately in this article: minimizing the total system's operational cost and losses. The operation cost is lowered when all microgrids are directly linked to the main grid or indirectly through other microgrids. When certain microgrids are linked to the main grid and others are not, the network's minimal loss is available. The second method used in this article was DR programming. As can be observed, DR programs have a favorable impact on distribution network variables such as load factors, and they are important for lowering peak loads and flattening the 24-h load profile. To examine the effects of power-sharing and demand response programs, a power-sharing and DR (TOU) program was implemented for each objective function, and its impact was investigated. It was demonstrated that implementing power-sharing and demand response plans effectively lowered operational

Conclusions
The impact of demand response and optimal power-sharing in microgrids for cost and power loss optimization using the ABC algorithm in a smart distribution system were analyzed in this work. Residential, industrial, commercial, and academic load profiles were all taken into account. Power-sharing and demand response programs (TOU) for each type of load were adopted. The key aspect of the microgrid-based smart distribution network is fragmentation. Two essential objectives were discussed separately in this article: minimizing the total system's operational cost and losses. The operation cost is lowered when all microgrids are directly linked to the main grid or indirectly through other microgrids. When certain microgrids are linked to the main grid and others are not, the network's minimal loss is available. The second method used in this article was DR programming. As can be observed, DR programs have a favorable impact on distribution network variables such as load factors, and they are important for lowering peak loads and flattening the 24-h load profile. To examine the effects of power-sharing and demand response programs, a power-sharing and DR (TOU) program was implemented for each objective function, and its impact was investigated. It was demonstrated that implementing power-sharing and demand response plans effectively lowered operational costs and network losses. The cost and losses of network operation were investigated due to uncertainties in generation, consumption, and customer engagement in the DR program and power-sharing in microgrids. The simulation results show that our proposed idea, namely, the impact of DR and power-sharing in microgrids using the ABC algorithm, had the lowest cost and minimum losses (8.4% and 4%, respectively). Future research should concentrate on power losses and cost optimization in microgrids using new algorithms such as the Jellyfish algorithm, the Golden Eagle algorithm, HHO, and WCO, etc. Additionally, flexible switching strategies for real-time scheduling in microgrids that take other constraints into account are an exciting future study path.

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.

Conflicts of Interest:
The authors declare no conflict of interest.