An Improved Heap-Based Optimizer for Optimal Design of a Hybrid Microgrid Considering Reliability and Availability Constraints

The hybrid microgrid system is considered one of the best solution methods for many problems, such as the electricity problem in regions without electricity, to minimize pollution and the depletion of fossil sources. This study aims to propose and implement a new algorithm called improved heap-based optimizer (IHBO). The objective of minimizing the microgrid system cost is to reduce the net present cost while respecting the reliability, power availability, and renewable fraction factors of the microgrid system. The results show that the PV/diesel/battery hybrid renewable energy system (HRES) gives the best solution, with a net present cost of MAD 120463, equivalent to the energy cost of MAD 0.1384/kWh. The reliability is about 3.89%, the renewable fraction is about 95%, and the power availability is near to 99%. The optimal size considered is represented as 167.3864 m2 of PV area, which is equivalent to 44.2582 kW and 3.8860 kW of diesel capacity. The study results show that the proposed optimization algorithm of IHBO is better than the artificial electric field algorithm, the grey wolf optimizer, Harris hawks optimization, and the original HBO algorithm. A comparison of the net present cost with a different fuel price is carried out, in which it is observed that the net present cost is reduced even though its quantity used is mediocre.


Introduction
The implementation of hybrid microgrids is necessary due to their advantages. Many projects and studies have proven their essential ecological and economic effects. The literature has assessed the microgrid from all directions, including design, operation, optimization, control, and others. Literature reviews have provided more comprehensive studies. In [1], a comprehensive study on the optimization of microgrid operations has been presented. In [2], a review of AC and DC microgrid protection has been presented. Reference [3] presented a D.C. microgrid protection comprehensive review. Reference [4] presented a review on optimization and control techniques of the hybrid AC/DC microgrid, as well as the integration challenges. Reference [5] presented a comprehensive review of the planning, the operation, and the control of a DC microgrid. Reference [6] presented a review of microgrid sizing, design, and energy management.
The design and operation optimization of microgrids, considered the main objective of this work, has been presented in many papers. Reference [7] presented a design and assessment of the microgrid using a statistical methodology that calculates the effect of energy reliability and variability on microgrid performance. The paper used a REopt platform to explore the cost savings and revenue streams. In [8,9], the microgrid design has been investigated using several algorithms and configurations. In [10], a hybrid • An improved version of the conventional HBO algorithm is proposed with the aim of improving its performance; • The conventional HBO and proposed IHBO algorithms are applied for optimal design of a hybrid microgrid system including RES (photovoltaic panels, wind turbines, and batteries) with diesel generators; • In the designed microgrid, the reliability, availability and the renewable fraction constraints are considered; • The proposed IHBO algorithm's efficiency and performance are evaluated on different benchmark functions, including the statistical measurement; • The impact of the fuel price variation on the project investment is analyzed.
The paper is organized as follows: the introduction occurs in Section 1; the modeling of HRES components is contained in Section 2; Section 3 presents the objective functions and constraints; Section 4 presents the new, improved algorithm, namely IHBO; the results and discussion are presented in Section 5; and the conclusion is presented in Section 6.

PV Panel Modeling
The PV output power is calculated as follows [28,29]: where I represents the irradiation, η pv represents the efficiency of PV, and A pv is the area of PV. The efficiency of PV can be calculated based on reference efficiency (η r ), the efficiency of MPPT (η t ), temperature coefficient (β), ambient temperature (T a ), PV cell reference temperature (T r ) and nominal operating cell temperature (NOCT), as follows:

Wind System Modeling
The wind turbine output power can be calculated following these conditions [30]: where V represents the wind velocity, P r is rated power, v ci is cut-in, v co represents cut-out, and v r is the rated wind. a and b are constant values that expressed as: The rated power of wind turbine can be calculated as: where ρ is the air density, A wind represents the swept area of the wind turbine, and C p is the maximum power coefficient (from 0.25 to 0.45).

Diesel System Modeling
The diesel rated power can be calculated as [31]: where F dg represents the fuel consumption, P dg,out is the output power of the diesel generator, and A g and B g are two constant values represent the fuel linear consumption.

Battery System Modeling
The battery capacity of the battery can be calculated as [31]: where E l is the load demand, AD is the autonomy of the battery which can lead power to the load on rainy days, DOD represents the depth of discharge, and η i and η b represent the inverter and battery efficiency, respectively.

Net Present Cost
The NPC represents an economic factor, which is considered the objective function in this study. The goal of the paper is to minimize the NPC, which is the sum of all costs during the project lifetime. The NPC is calculated as [32,33]: where C represent the capital cost, OM is the operation and maintenance costs, R is the replacement cost, and FC dg is the fuel cost.

LCOE Index
The LCOE represents the price of energy and is a critical factor which is calculated as [31]: where CRF represents the capital recovery factor (obtained by converting the initial cost to annual capital cost), and P load represents the power load. The CRF is calculated as:

LPSP Index
The loss of power supply probability (LPSP) is a technical index that ranges from 0 to 1. It is used to indicate the reliability of the microgrid system. The LPSP is calculated as follows [31]: Sustainability 2021, 13, 10419 5 of 25

Renewable Energy Index
Renewable energy (RF) is calculated to determine the renewable energy percent that is penetrated into the microgrid system. The RF is expressed as [31]: where P re represents the sum of renewable energy powers.

Availability Index
The availability factor (Av) is assumed as an index of the customer's satisfaction; it measures the ability of the microgrid to convert the total energy to load charge. The availability is calculated as [33]: where P bmin represents the battery min state, P b represents the battery power, and u is a fixed value which equals 1 when the load is not satisfied and which equals 0 otherwise.

Constraints
Constraints are introduced to tune the microgrid system factors and help to improve the microgrid service quality. In this work, the constraints proposed are: where LPSP max = 0.05, RF min = 70%, Av min = 90%, and AD min = 1 day. The sizing limit is different from configuration to the others. All other parameters are shown in Table A1.

Heap-Based Optimizer (HBO)
The heap-based optimizer algorithm (HBO) is inspired by the social behavior of human beings [34]. One sort of social interaction between human beings can be observed in organizations where people in teams are arranged in a hierarchy for achieving a specific target; this is known as corporate rank hierarchy (CRH). CRH is presented in Figure 1a. The HBO algorithm is based on CRH in a very distinctive manner. In this regard, the concept of CRH is to arrange the search agents based on their suitability in this hierarchy using a heap tree-based data structure to enact the implementation of priority queues. Figure 1b shows an example of 3 degrees (3-ary) of min-heap. Three types of employees' behaviors were used in the HBO algorithm. These types are: (i) the interaction of subordinates with their immediate head; (ii) the interaction between co-workers; and (iii) the self-contribution of individuals. The mapping of the heap concept is divided into four steps: A. Modeling the corporate rank hierarchy Figure 2 displays the procedure of CRH modeling through a heap data structure, wherein xi is the ith search agent of the population. The curve in the objective space describes the shape of the supposed objective function, and the search agents are drawn on the fitness shape according to their convenience.

B. Mathematically modeling the collaboration with the boss
In a centralized organizational structure, the regulations and policies are enforced from the upper levels, and subordinates must follow their direct manager. This can be mathematically described by updating the agent position of each search as follows:   The mapping of the heap concept is divided into four steps: A. Modeling the corporate rank hierarchy Figure 2 displays the procedure of CRH modeling through a heap data structure, wherein xi is the ith search agent of the population. The curve in the objective space describes the shape of the supposed objective function, and the search agents are drawn on the fitness shape according to their convenience. The mapping of the heap concept is divided into four steps: A. Modeling the corporate rank hierarchy Figure 2 displays the procedure of CRH modeling through a heap data structure, wherein xi is the ith search agent of the population. The curve in the objective space describes the shape of the supposed objective function, and the search agents are drawn on the fitness shape according to their convenience.

B. Mathematically modeling the collaboration with the boss
In a centralized organizational structure, the regulations and policies are enforced from the upper levels, and subordinates must follow their direct manager. This can be mathematically described by updating the agent position of each search as follows:

B. Mathematically modeling the collaboration with the boss
In a centralized organizational structure, the regulations and policies are enforced from the upper levels, and subordinates must follow their direct manager. This can be mathematically described by updating the agent position of each search as follows: where t is the current iteration, k is the kth component of a vector, B denotes the parent node, r is a random number from the range [0, 1], T is the maximum number of iterations, and C represents a user-defined parameter.

C. Mathematically modeling the interaction between the colleagues
Colleagues cooperate and perform official tasks. It is assumed in a heap that the nodes at the same level are colleagues, and each search agent x i updates its location based on its randomly selected colleague S r as follows: D. Self-contribution of an employee to accomplish a task In this phase, the self-contribution of a worker is mapped as follows: The following part explains how exploration can be controlled with this equation.

E. putting all together
The principal challenge is determining the selection probabilities for the three equations to balance exploration and exploitation. The purpose of the roulette wheel is to achieve a balance of possibilities. The roulette wheel is divided into three parts: p 1 , p 2 , and p 3 . The value of p 1 makes a population changes their position, and it is calculated from the following equation: The selection of p 2 is computed from the following equation: Finally, the selection of p 3 is calculated as follows: Accordingly, a general position-updating mechanism of the HBO algorithm is mathematically represented as follows: where p is a random number in the range (0, 1).

Improved Heap-Based Optimizer(IHBO)
In order to enhance the strength of the proposed IHBO algorithm for many highdimensional optimization problems, core aspects of one of the most used meta-heuristic algorithms, PSO, are utilized. The PSO algorithm is introduced by [35]. The velocity equation from the PSO algorithm is used in the proposed IHBO algorithm. This modification leads to the improvement of the ability of the global search and enhances the local search capabilities of the improved algorithm. This core equation is as follows: where C 1 = C 2 = 0.5, as these values gave the best solution in [36]; w = 0.7; r 1 and r 2 are a random number in the range (0, 1); p best is the best solution of an individual population, and g best is the best solution so far. The flow chart of the proposed IHBO algorithm is shown in Figure 3. where = = 0.5, as these values gave the best solution in [36]; = 0.7; and are a random number in the range (0, 1); is the best solution of an individual population, and is the best solution so far. The flow chart of the proposed IHBO algorithm is shown in Figure 3. Calculate the vectors Ƴ, λ according to Eqs. (17), and (18),respectively Compute the vector p1, p2, p3 according to Eqs. (21), (22) and (23)  Performance of the Proposed IHBO Algorithm The proposed IHBO algorithm's efficiency and performance are evaluated on different benchmark functions, including statistical measurements, such as minimum values, mean values, maximum values, and standard deviation (STD) for best solutions obtained by the proposed IHBO algorithm and the other recent optimization algorithms. The results obtained with the proposed IHBO technique is compared with three well-known optimization algorithms, including the sine cosine algorithm (SCA) [37], salp swarm algorithm (SSA) [38], movable damped wave algorithm (MDWA) [39], and the original heap-based optimizer (HBO). Table 1 shows the parameters of all compared algorithms (SSA, MDWA, SCA, IHBO, and HBO). Qualitative metrics on F1, F4, F7, F9, F11, F12, F15, and F18, including 2D views of the functions, search history, average fitness history, and convergence curve, are presented in Figure 4. Performance of the Proposed IHBO Algorithm The proposed IHBO algorithm's efficiency and performance are evaluated on different benchmark functions, including statistical measurements, such as minimum values, mean values, maximum values, and standard deviation (STD) for best solutions obtained by the proposed IHBO algorithm and the other recent optimization algorithms. The results obtained with the proposed IHBO technique is compared with three well-known optimization algorithms, including the sine cosine algorithm (SCA) [37], salp swarm algorithm (SSA) [38], movable damped wave algorithm (MDWA) [39], and the original heap-based optimizer (HBO). Table 1 shows the parameters of all compared algorithms (SSA, MDWA, SCA, IHBO, and HBO). Qualitative metrics on F1, F4, F7, F9, F11, F12, F15, and F18, including 2D views of the functions, search history, average fitness history, and convergence curve, are presented in Figure 4.

Algorithms Parameter Settings
Common settings Population size: nPop = 50 Maximum iterations: Max_iter = 1000 Number of independent runs: 20 SSA c2 = rand ; c3 = rand MDWA amax = 1; amin = 0 SCA A = 2 IHBO sv = 100; degree = 3; w = 0.7; C1 = 0.5; C2 = 0.5; r1 = rand; r2 = rand HBO sv = 100; degree = 3 Tables 2-4 tabulate the statistical results of the proposed IHBO algorithm and other well-known algorithms when applied for unimodal benchmark functions, named F1 to F7, multimodal benchmark functions, named F8 to F13, and composite benchmark functions, named F14 to F23, respectively. The best values, shown in bold, were achieved with the proposed IHBO algorithm, as well as MDWA and SCA, but the proposed IHBO technique achieves the best results for most of the benchmark functions. The convergence curves of all algorithms for the unimodal benchmark functions are shown in Figure 5 while Figure 6 shows the boxplots of each algorithm for these unimodal benchmark functions. Figure 7 displays the convergence characteristics curves of all algorithms for the multi-modal benchmark functions. The boxplots for each algorithm for these types of benchmark functions are presented in Figure 8. The convergence curves of all algorithms for the composite benchmark functions are displayed in Figure 9 while Figure 10 illus-

Algorithms Parameter Settings
Common settings Population size: nPop = 50 Maximum iterations: Max_iter = 1000 Number of independent runs: 20 SSA c 2 = rand; c 3 = rand MDWA amax = 1; amin = 0 SCA A = 2 IHBO sv = 100; degree = 3; w = 0.7; C 1 = 0.5; C 2 = 0.5; r 1 = rand; r 2 = rand HBO sv = 100; degree = 3 Tables 2-4 tabulate the statistical results of the proposed IHBO algorithm and other well-known algorithms when applied for unimodal benchmark functions, named F1 to F7, multimodal benchmark functions, named F8 to F13, and composite benchmark functions, named F14 to F23, respectively. The best values, shown in bold, were achieved with the proposed IHBO algorithm, as well as MDWA and SCA, but the proposed IHBO technique achieves the best results for most of the benchmark functions. The convergence curves of all algorithms for the unimodal benchmark functions are shown in Figure 5 while Figure 6 shows the boxplots of each algorithm for these unimodal benchmark functions. Figure 7 displays the convergence characteristics curves of all algorithms for the multimodal benchmark functions. The boxplots for each algorithm for these types of benchmark functions are presented in Figure 8. The convergence curves of all algorithms for the composite benchmark functions are displayed in Figure 9 while Figure 10 illustrates the boxplots for each algorithm for these benchmark functions. The proposed algorithm reached a stable point for all functions. Also, the boxplots of the proposed IHBO technique are very narrow for most functions compared to the other algorithms. The best values obtained are in bold.  The best values obtained are in bold. The best values obtained are in bold. trates the boxplots for each algorithm for these benchmark functions. The proposed algorithm reached a stable point for all functions. Also, the boxplots of the proposed IHBO technique are very narrow for most functions compared to the other algorithms.

Project Implementation Location
The project was implemented in a small region in the west of Morocco called Terfaya, at coordinating latitude 27.932 and longitude −12.935.

Results and Discussion
In this paper, the Terfaya region of Morocco is selected as the case study to implement an HRES platform based on an improved optimization algorithm called IHBO. The maps for the project location, the load charge, the annual ambient radiation, temperature, wind speed, and pressure are presented in Figures 11-15 Figure 11. Load power. Figure 11. Load power.     The proposed HRES includes two renewable sources (PV and wind turbines), a diesel generator, and a battery storage system. According to the mathematical modeling of the mentioned systems, the PV output can be affected by the solar radiation data; otherwise, the output power of the wind is influenced by the wind speed data. The decision variables in this study are dedicated to the size of the HRES where: x(1) is the PV area ( ,), x(2) is the wind swept area ( ), x(3) represents the battery capacity ( ) and x(4) is the rated power of the diesel generator ( ). In this paper, an analysis of fuel price variation is carried out.

PV/Diesel/Battery HRES
The results of the optimal HRES design for the case study concerning the PV/diesel/battery HRES are summarized in Table 5. The table presents all used algorithms concerning the predefined constraints, including the LPSP, RF, and the availability. The algorithms are arranged as GWO, HBO, AEFA, HHO, and IHBO, with a net present cost of MAD 191,661, MAD 175,321, MAD 169,142, MAD 147,527, and MAD 120,463, respectively. The optimal system needs MAD 120,463, equivalent to an LCOE of MAD 0.13/kWh. The system designed respected the constraints very well, with a reliability (LPSP) of 3%, a renewable fraction of 95%, and power availability of 98%. Table 6 presents the optimal size of each algorithm; the best solution is then obtained by IHBO, with 1,673,864 m 2 and 38,860 kW of diesel generator capacity. Table 7 presents the convergence time of all simulations.
The convergence curve results for all scenarios are presented in Figure 16, in which the IHBO proves its efficacy to reach the optimal solution.  The proposed HRES includes two renewable sources (PV and wind turbines), a diesel generator, and a battery storage system. According to the mathematical modeling of the mentioned systems, the PV output can be affected by the solar radiation data; otherwise, the output power of the wind is influenced by the wind speed data. The decision variables in this study are dedicated to the size of the HRES where: x(1) is the PV area (A pv ,), x(2) is the wind swept area (A wind ), x(3) represents the battery capacity (C BESS ) and x(4) is the rated power of the diesel generator (P dg ). In this paper, an analysis of fuel price variation is carried out. The results of the optimal HRES design for the case study concerning the PV/diesel/ battery HRES are summarized in Table 5. The table presents all used algorithms concerning the predefined constraints, including the LPSP, RF, and the availability. The algorithms are arranged as GWO, HBO, AEFA, HHO, and IHBO, with a net present cost of MAD 191,661, MAD 175,321, MAD 169,142, MAD 147,527, and MAD 120,463, respectively. The optimal system needs MAD 120,463, equivalent to an LCOE of MAD 0.13/kWh. The system designed respected the constraints very well, with a reliability (LPSP) of 3%, a renewable fraction of 95%, and power availability of 98%. Table 6 presents the optimal size of each algorithm; the best solution is then obtained by IHBO, with 1,673,864 m 2 and 38,860 kW of diesel generator capacity. Table 7 presents the convergence time of all simulations.  The convergence curve results for all scenarios are presented in Figure 16, in which the IHBO proves its efficacy to reach the optimal solution. stainability 2021, 13, x FOR PEER REVIEW 20    The second configuration used in this paper concerns the PV/wind/diesel/ba HRES. From Table 8, the results respect the constraints; then, the best algorithms re converge as HBO, GWO, AEFA, HHO, and IHBO, with an investment cost of M 461,233, MAD 226,559, MAD 221,694, MAD 215,371, and MAD 100,337, respectively best cost needs MAD 100,337, equivalent to MAD 0.08/kWh; in this situation, the LP about 4%, the renewable fraction is near 100%, and the power availability is more needs MAD 100,337, equivalent to MAD 0.08/kWh; in this situation, the LPSP is about 4%, the renewable fraction is near 100%, and the power availability is more than 99%. Table 9 presents the size results, which show that the best project needs 261.3031 m 2 of PV area, 102.7114 m 2 of swept area of the wind turbines, 23.2177 kWh of battery, and 1.0762 kW of diesel. Table 10 presents the convergence time of all simulations.  Figure 17 presents the convergence curve of the NPC for the PV/wind/diesel/battery HRES; the curve shows that the IHBO algorithm gives better convergence results.

Impact of Fuel Price Variation
In the paper, if we suppose that the price of fuel is about MAD 0.41/L, then we can compare the total investment cost with the previous study that used the actual price, which is MAD 0.96/L. From Table 11, it is clearly shown that the NPC of the HRES is reduced strongly while it is passed from MAD 120,463. Table 12 presents the optimal HRES size using all optimization algorithms. Figure 18 presents the convergence curve of the NPC for the PV/diesel/battery HRES, with a fuel price of MAD 0.54/L. This figure shows that the IHBO algorithm gives the better convergence results.

Conclusions
This paper proposed a platform to design an HRES microgrid system based on two configurations, PV/diesel/battery, and PV/wind/diesel/battery. The platform is based on modeling, power management, and a cost optimization study using an improved IHBO algorithm. The proposed IHBO algorithm proved its efficacy in finding the optimal solution compared with many algorithms, including AEFA, GWO, HHO, and the original HBO. In the paper, we discussed the case of reducing fuel prices and its impact on the investment cost. The results show that the NPC is highly reduced when the use of diesel is small. Several systems, such as hydrogen storage and biomass systems, can be integrated in the microgrid. Future work will focus on developing configurations considering the degradation of battery characteristics. Constants of the linear consumption of the fuel (L/kW) A pv PV area (m 2 ) A wind Swept area of the wind turbine (m 2 ) C BESS Capacity of BESS (kWh) C p Maximum power coefficient (%) E bmin Min battery energy in discharge (kWh) E l Energy Load (kWh) FC dg Fuel cost (MAD) F dg Fuel consumption (L/h) P dg,out Output power of diesel generator (kW) P dg Rated power of diesel generator (kW) P load Load power (kW) P pv Output power of PV (kW) P re Output power of renewable energy sources (kW) P wind Output wind power (kW) T a Ambient temperature ( • C), T r Photovoltaic cell reference temperature ( • C).