1 Introduction

In recent years, population density and technological development, especially in developing countries, have increased global energy demand. Today, electrical power generation is mainly based on exhaustible fossil fuels. Fossil fuels are a source of greenhouse gas emissions that have negative impacts on the environment. Therefore, photovoltaic (PV) solar energy and wind turbines (WT) are the most important renewable energy sources (RES) and are the mainstay of independent microgrids [1].

Recent developments in renewable energy (RE) technology and power electronics have been supported worldwide to ensure the economic availability and sustainability of electrical energy. Despite the high capital cost, wind and solar power plants are being installed all over the world because of their desirable carbon-free contribution to reducing the load demand gap [2,3,4]. Considerable research has been conducted on effectively utilizing RES alongside fossil fuels for energy production [5, 6]. Turkey and other countries have accepted both wind and solar energy as standard sources of green energy [7].

Solar irradiance and wind speed, which are crucial parameters for solar and wind energy generation, can fluctuate significantly on an hourly and daily basis. In a hybrid energy system, this creates massive uncertainty. Although using storage and backup resources eliminates this problem, it raises production costs [8]. As a result, measuring numerical data from wind and solar energy sources, as well as efficient planning, management, and operation of the electric power generation system, can help reduce uncertainties. The basic and most important solution to overcome these uncertainties is the use of systems that contain multiple RES and are called hybrid renewable energy systems (HRES). During the required hours and seasons, using more than one energy source in a hybrid energy system can provide energy production that costs less than energy from a single source. Furthermore, because of the difficult processing steps of the optimization algorithms, the variability of energy sources, and the difficulty of cost calculation, optimizing the size of the HRES to meet the load demand is complex [9].

A considerable body of research has harnessed the capabilities of the HOMER software to identify the most favorable operational conditions for either on-grid or off-grid systems in the realm of HRES [10,11,12,13,14]. Optimization studies based on metaheuristic algorithms are also accessible. In a study by HRES, the effects of HRES on size optimization were investigated with the help of particle swarm optimization (PSO) algorithm preference, taking energy efficiency and climate diversity into account [15]. Fodhil et al. used a PSO-based approach to optimize PV-diesel generator (DG)-battery (Batt) HRES for rural areas. It was emphasized that the PSO algorithm is less expensive than the software HOMER [16]. Maleki and Askarzadeh, who used a harmony search (HS) algorithm for right sizing of hybrid PV-Batt systems, compared their results with a diesel production system with regards to total annual cost and environment [17]. Elnozahy et al. determined the optimal configuration of the power system with PV, WT, Batt and DG hybrid component by comparing their results with genetic algorithm (GA), PSO and HOMER software [18]. Wang et al. proposed a non-dominant sorting algorithm combined with reorder-based genetic operators to determine system reliability, total gas emission (TGE), and life cycle cost for optimal sizing of HRES. They implemented the sizing of HRES using crow search algorithm (CSA) and PSO algorithms [19]. Himri et al. and Malik conducted studies on the implementation of RES in Algeria and Brunei, respectively. The studies analyzed various aspects of renewable resources as potential future energy sources [20, 21]. These studies showed the potential of integrating RES with a diesel generator to reduce energy costs and increase the reliability of power systems. An extensive system will result in high costs, while under sizing the system will result in power shortages to meet the targeted demand. Therefore, considering the above problems, optimal sizing of HRES units is essential in power system design and operation. There are numerous studies in the literature on the optimal sizing of hybrid microgrid systems [22].

For performance analysis, researchers in the literature prefer software tools such as HOGA, HOMER Pro, RAPSIM, and methods based on traditional and metaheuristic optimization algorithms. Software tools, despite their significant drawbacks, necessitate more computation time than existing optimization techniques. However, there are a lot of studies where different researchers propose different traditional and evolutionary algorithms to obtain the optimum size of components used in hybrid systems. A variety of metaheuristic evolutionary algorithms have been introduced to tackle the issue of conventional methods plateauing at local minima. Some of the algorithms that help achieve better working conditions for the systems that are off-grid including PV/WT/DG/Batt components are GA, evolutionary algorithm, PSO, grasshopper optimization algorithm, firefly algorithm, modified discrete bat search algorithm, simulated annealing, gray wolf optimization (GWO), and deep learning methods [23,24,25,26,27,28,29,30]

The essence of this study is the design, optimization, and attainment of the most advantageous technical and economic outcomes for HRES that operate both independently of and in connection with the grid. This is focused within a region that is characterized by a reliable supply of energy demand, relatively low costs, and a less harmful impact on the environment. The output of wind turbines and solar panels is rigorously calculated using meteorological numerical data. By deploying algorithmic techniques such as GWO, cuckoo search (CS), and hybrid gray wolf optimizer cuckoo search (GWOCS) to both grid-connected and off-grid HRES, we aid in minimizing the annual cost of system (ACS), levelized cost of energy (LCOE), and total net present cost (TNPC). This also helps in determining the optimal sizes of the components used, and contrasting the numerical results produced by each algorithm. Furthermore, the influence and outcomes of a hybrid algorithm on both systems are thoroughly examined. The paramount contribution of this paper lies in completely satisfying the electricity load demand in a region rich in natural resources, coupled with the achievement of a TGE value reaching zero.

The remainder of the study is planned as follows.

This article is structured into five distinct sections. Section 2 focuses on elucidating the modeling of the hybrid energy system and its renewable energy (RE) components, setting the stage for deeper understanding. Sect. 3 will present a comprehensive overview of the methodology, encompassing system modeling, strategies for energy management, load demand, and the optimization algorithms along with the overall procedural outline. Section 4 is dedicated to delivering the simulation outcomes and deliberations concerning the HRES, and it delves deeply into the statistical analyses, offering an in-depth understanding of the system's performance and implications. Finally, Sect. 5 will address the principal conclusions and identify potential paths for subsequent inquiries, setting a course for future research.

2 Materials and methods

This section encompasses a broad range of topics, including the appraisal of renewable energy sources, load demand, economic computations, cost optimization, techno-economic limitations, and optimization techniques, as well as the procedural steps for designing a HRES. We also delve into system sizing, component detailing, and modeling. Among the available renewable energy resources, solar and wind power are considered to yield the highest social, economic, and environmental benefits, making their amalgamation a favorable option [31]. Hybrid energy systems often amalgamate resources capable of counterbalancing each other's weaknesses. The potential adoption of solar and wind energy sources could significantly diminish the system's storage capacity requirements. Meeting electricity demands at the lowest possible cost necessitates the meticulous design of both on-grid and off-grid hybrid energy systems. In this study, a micro-energy system undergoes optimization through the hybrid optimization of multiple energy resources (HOMER) software, employed in conjunction with various hybrid algorithms. Figure 1 offers a block diagram that illustrates the research methodology. Here, the required annual profile and hourly climate data are maintained in a database. Initially, the system is designed using the HOMER software, followed by the programming of algorithms related to the optimization process using MATLAB 2022b software. Upon the completion of the optimization process, the results obtained from all algorithms are compared, and evaluations are presented with the aid of technical and economic energy analyses of the system.

Fig. 1
figure 1

Block diagram of the research methodology

2.1 Modeling of hybrid renewable energy system

In this study, the HRES under scrutiny comprises seven main components, of which three are related to direct current (DC) power and four to alternating current (AC) power. The DC components of the hybrid system include a photovoltaic plant, a battery group, and a discharge load, while the household load, diesel generator, wind farm, and grid constitute the AC components. An ınsulated gate bipolar transistor (IGBT)-based high-powered bidirectional converter is responsible for the conversion of AC to DC and vice versa. However, as the dynamics of the converter are associated with high frequencies, they will not be considered in the optimization formulation. The energy management system (EMS) monitors and controls the power sharing among each component of the HRES. Figure 2 illustrates the configuration of the microgrid under study. In Fig. 2, the HRES is structured with separate AC and DC buses, utilizing a single DC/AC inverter to convert the form of electric power. All seven generation elements, along with the load and the DC/AC inverter, continuously relay their component states to the EMS, maintaining bidirectional communication with it. Each device, in turn, receives control signals from the EMS for the optimal operation of the HRES. The hybrid microgrid consists of PV, WT, DG, and Batt. Prior to the optimal sizing of the microgrid, the modeling of the system components is a prerequisite. The parameters of the hybrid system components exert a significant impact on the system's LCOE and reliability. Hence, a detailed mathematical modeling of the system components is extensively discussed in the following subsections [32].

Fig. 2
figure 2

Schematic representation of the suggested PV/WT/DG/Batt components for the hybrid energy system

2.2 Modeling of photovoltaic energy system

In a PV system, the total power generated by each solar panel equals the total power produced by the system. Equation (1), known as the simplified PV model, calculates the power produced by each panel per hour using ambient temperature and solar radiation [33].

$$P_{{pv_{{{\text{out}}}} }} \left( t \right) = P_{{\left( {PV_{{{\text{rated}}}} } \right)}} \times \frac{G}{1000} \times \left[ {1 + K(\left( {T_{{{\text{amb}}}} + \left( {0.0256 \times G} \right)} \right) - T_{{{\text{ref}}}} } \right]$$
(1)

The term \(P_{{pv_{{{\text{out}}}} }} \left( t \right)\) denotes the output power (W) from the PV module, while G signifies the value of solar radiation (W/m2). The nominal PV power under standard conditions is represented by \(P_{{\left( {PV_{{{\text{rated}}}} } \right)}}\). The coefficient of temperature, denoted by, \(K\), is calculated using (3.7 × 10–3 (1/°C)). The reference temperature under standard conditions, \(T_{{{\text{ref}}}}\), is set at 25 °C, and \(T_{{{\text{amb}}}}\) indicates the ambient temperature (°C).

The characteristics of the photovoltaic panel include a rated capacity of 0.345 kW, a temperature coefficient of − 0.390, and an operational temperature of 44 °C. The panel's efficiency rate stands at 17.8%, with a lifecycle spanning 20 years and a capital cost fixed at 650 $/kW. Its replacement cost is also pegged at 650 $/kW, while the yearly expenditure for maintenance and operations totals 50 $/year.

2.3 Modeling of wind energy system

To figure out how much power a wind turbine can produce, it is really important to use the best model you can find. Mostly, how much power you'll get from a wind turbine depends on how windy it is at its location. You can use Eq. (2) from reference [34] to work out the turbine’s power output

$$P_{WT} = \left\{ {\begin{array}{*{20}l} 0 \hfill & {v\left( t \right) \le { }v_{{\text{cut - in}}} { }or{ }v\left( t \right) \ge { }v_{{\text{cut - out}}} } \hfill \\ {P_{r} \frac{{v\left( t \right) - v_{{\text{cut - in}}} }}{{v_{r} - v_{{\text{cut - out}}} }}} \hfill & {v_{{\text{cut - in}}} \le v\left( t \right) \le { }v_{r} } \hfill \\ {P_{r} } \hfill & {v_{r} \le v\left( t \right) \le { }v_{{\text{cut - out}}} } \hfill \\ \end{array} } \right.$$
(2)

\(P_{r}\) is the WT nominal power (kW), \(v\left( t \right)\) is the wind speed (m/s), \(v_{{\text{cut - out}}}\) is the low shear speed of WT (m/s), \(v_{r}\) is the WT nominal speed (m/s), \(v_{{\text{cut - in}}}\) is the high shear speed values of WT (m/s).

$$V_{t} = V_{m} \times \left( {\frac{{H_{t} }}{{H_{m} }}} \right)^{{a_{h} }}$$
(3)

In Eq. (3), \(H_{t}\) is the WT hub height (m), \({{H}}_{{\text{m}}}\) is the WT reference height (m), \(V_{m}\) is the wind speed at WT hub height (m/s), \(V_{t}\) is the speed at reference height (m/s), and \(a_{h}\) is the exponential power law values.

The value of a_h, which is influenced by surface roughness and environmental stability, ranges from 0.05 to 0.5. In the selected locations, a_h is presumed to be 0.14 [35]. A typical wind turbine features a rated power of 1 kW, a tower height of 17 m, a capital cost of $2000/kW, and a replacement cost likewise at $2000/kW. It carries an operation and maintenance cost of $200/year, with a projected service life of 20 years.

2.4 Modeling of battery bank storage

To regulate the ranges and load demand of renewable energy, a storage system is required. When the energy produced by renewable energy sources exceeds the total load demand, batteries are charged. When the load demand exceeds the generated power, however, the batteries are discharged to fill the energy gap. Equations 4 and 5 are used to evaluate the battery's charging and discharging processes, respectively [36].

$$E_{{{\text{ch}}}} \left( t \right) = E_{{{\text{Batt}}}} \left( {t - 1} \right) \times \left( {1 - \sigma } \right) + \left[ {E_{WT} \left( t \right) + E_{PV} \left( t \right) - \frac{{E_{L} \left( t \right)}}{{\eta_{Inv} }}} \right] \times \eta_{BC,} \,\,\,{\text{Charging}}\,\,{\text{mode}}$$
(4)
$$E_{{{\text{dch}}}} \left( t \right) = E_{{{\text{Batt}}}} \left( {t - 1} \right) \times \left( {1 - \sigma } \right) + \left[ {\frac{{E_{L} \left( t \right)}}{{\eta_{Inv} }} - (E_{WT} \left( t \right) + E_{PV} \left( t \right))} \right] \times \eta_{BD,} \,\,{\text{Discharging}}\,\,{\text{mode}}$$
(5)

The variable \(E_{{{\text{Batt}}}} \left( t \right)\) denotes the available capacity of the battery at hour \({\text{t}}\) (expressed in kWh), while \(E_{{{\text{Batt}}}} \left( {t - 1} \right)\) signifies the capacity at the preceding hour (t–1). The symbol σ is representative of the battery's self-discharge rate. Furthermore, \(E_{PV}\) and \(E_{WT}\) correspond to the energy output from the photovoltaic module and the wind turbine at hour t, respectively. The demand load at hour t is denoted by \(E_{L}\).

Efficiencies related to battery charging, discharging, and inverter operation are represented by \(\eta_{BC}\), \(\eta_{BD}\), and \(\eta_{{{\text{Inv}}}}\), respectively. These efficiencies, particularly \(\eta_{BC}\) and \(\eta_{BD}\), are integral to the charging process and are subject to variation depending on the charging current at each stage. For the purposes of this study, the charging efficiency is presumed to be a constant 90%.

Excess energy production from renewable resources is diverted into battery storage systems. Nonetheless, these storage systems have a definitive limit and cannot indefinitely store energy. When the battery is at its maximum capacity, any additional surplus energy has to be discharged. The highest permissible discharge depth (DOD), generally represented as a percentage, signifies the proportion of the battery's total energy that has been expended. This research adopted a DOD of 80%. The least battery capacity was calculated by employing Eq. (6) as indicated in the reference [37].

$$E_{{{\text{Batt}}\_\min }} \left( t \right) = \left( {1 - DOD} \right) \times E_{{{\text{Batt}}\_\max }}$$
(6)

Furthermore, the Batt’s capacity constraint at any given hour is articulated through Eq. (7).

$$E_{{{\text{Batt}}\_{\text{min}}}} \le E_{{{\text{Batt}}}} \left( t \right) \le E_{{{\text{Batt}}\_{\text{max}}}}$$
(7)

Here, DOD maximum permissible depth of Batt discharge (%), \(E_{{{\text{Batt}}\_{\text{max}}}}\) and \(E_{{{\text{Batt}}\_{\text{min}}}}\) are the Battery’s maximum and minimum capacity, respectively.

The particular battery under consideration showcases a voltage of 600 V, and it commands a nominal capacity of 100 kWh coupled with a peak capacity of 167 Ah. Furthermore, it displays a round trip efficiency of 90%. Impressively, its maximum charging current is rated at 167 A, its minimum state of charge is set at 20%, and it can withstand a maximum discharging current of 500 A. Anticipated to remain operational for ten years, this battery holds both a capital cost and a replacement expense of $550.00 per kW.

2.5 Modeling of diesel generator

In a hybrid energy system, a DG is used to balance the lack of sufficient power output from the PV, wind, and battery bank. The efficiency and fuel consumption of diesel generators have to be considered in designing an HRES and are presented in Eq. (8) [38].

$$q\left( t \right) = m \times P_{DG} \left( t \right) + n \times P_{r}$$
(8)

In the equation, \(P_{DG} \left( t \right)\) represents the power output of DG at hour t (kW), \(q\left( t \right)\) represents consumption of fuel (L/h), \(P_{r}\) represents average DG power, while m and n (L/kW) are constants that represent the parameters of standard fuel consumption, which were 0.246 and 0.08415, respectively.

The diesel generator in focus boasts a considerable capacity of 1000 kW, along with a replacement cost estimated at $175 per kW. Its operation and maintenance charges stand at $30 per kWh, with an initial capital outlay of $175 per kW. The cost of fuel is a modest $1 per liter. Anticipated to function for a period of 10 years, this diesel generator constitutes a significant investment in the field of energy generation.

2.6 Inverter

An inverter is a piece of electronic equipment that converts the DC power generated by RESs into AC. Equation 9 can be used to calculate the inverter's input power \((P_{{{\text{inv}}}} )\) [39]. Equation (9) is applicable for determining the input power of the inverter, denoted as \((P_{{{\text{inv}}}} )\) [39].

$$P_{{{\text{inv}}}} \left( t \right) = {\raise0.7ex\hbox{${P_{L} \left( t \right)}$} \!\mathord{\left/ {\vphantom {{P_{L} \left( t \right)} {\eta_{{{\text{inv}}}} }}}\right.\kern-0pt} \!\lower0.7ex\hbox{${\eta_{{{\text{inv}}}} }$}}$$
(9)

here \({ }P_{L} \left( t \right)\) and \(\eta_{{{\text{inv}}}}\) are load power and inverter efficiency, respectively.

This study involves a system converter inverter with a power capacity of 1 kW. The financial considerations include an initial investment and a potential replacement cost, each valued at $300, supplemented by an annual expense of $50 for operations and maintenance. The inverter, known for its impressive efficiency of 95%, is expected to provide reliable performance over a period of 15 years.

2.7 Grid modeling

A grid functions as an apparently limitless energy conduit, proficient at both power production and absorption. When the combined energy output from the PV, WT, and Batt fails to meet the electrical load demand at a specific moment, the energy shortfall is compensated by drawing power from the grid, with the DG acting as a safety net. Equation (10) is utilized to calculate the income generated from returning surplus energy to the grid, as noted in reference [40].

$$R_{{{\text{grid}}}} = \mathop \sum \limits_{t = 1}^{8760} r_{{{\text{feed}}\_{\text{in}}}} \times E_{{{\text{grid}}\_s}} \left( t \right)$$
(10)

here \(r_{{{\text{feed}}\_in}}\) represents the feed-in tariff guarantee rate, which is provided as 0.01 $/kWh and is the actual value. The anticipated power purchase from the grid is computed utilizing Eq. (11).

$$C_{{{\text{grid}}}} = C_{p} \times \mathop \sum \limits_{t = 1}^{8760} E_{{{\text{grid}}\_p}} \left( t \right)$$
(11)

here \(C_{p}\) represents the estimated 1 kW electricity purchase from the grid for the central campus, which is designated as the operating area. This value is provided by the University's Department of Facilities Management at a rate of 0.25 $/kWh, which is the actual value.

2.8 Economic parameters

In conducting the financial analysis, it is critical to account for the influence of sensitive variables on the viability of the hybrid energy system. In this research, the key economic factors were established as a 20% real interest rate, a 17% inflation rate, and a 9% discount rate. The hybrid energy system is anticipated to have a lifespan of 20 years. Actual cost figures for the HRES components, provided by the manufacturers, were utilized in the simulations to derive the results.

2.9 Load analysis of the selected region

For this investigation, the study focused on a university campus. Figure 3 displays the geographic coordinates of the selected region on the campus. Meteorological figures for 2021, including hourly wind velocities, levels of solar irradiance, ambient temperature readings, and full-year load distributions, were sourced from the General Directorate of State Meteorology. The university’s peak hourly load was recorded at roughly 1281.23 kW/year, and the lowest demand noted was 425.84 kW/year. On average, the campus consumed 10,220.26 kWh of electricity daily. Figure 4 outlines the annual load distribution for the case study, covering 8760 h, based on the actual data recorded for the specific area.

Fig. 3
figure 3

The case study location (Turkey) on the world map

Fig. 4
figure 4

Annual load profile for the campus

3 Methodology

Hybrid energy systems facilitate more balanced power production by integrating various renewable energy sources. Nevertheless, the design of these systems is complex due to the dependency of renewable sources' energy output on meteorological data. Therefore, the sizing of the components in hybrid energy systems should be optimized in accordance with energy demands and the output of renewable energy sources. This necessitates accurate sizing and component selection, which ensures maximum efficiency and stability from renewable energy sources and guarantees optimal energy utilization. This is, indeed, the cornerstone of the transition to sustainable energy sources.

Our hybrid energy system model encompasses photovoltaic PVs, WTs, DGs, and a Batt group. The performance and cost of each component have been meticulously modeled. Moreover, we have modeled an EMS to regulate the energy flow within the system.

The subsequent section provides a summary of the adopted approaches to address the research questions. Specifically, the subsections elaborate on the methodology used for HRES sizing, the energy management strategy, the objective function, and optimization algorithms.

3.1 Optimization and sizing of HRES

The intricate process of optimizing and appropriately sizing HRES necessitates a comprehensive analysis of vital parameters. These integral parameters include data on wind speed, ambient temperature, solar radiation, and load demand, which directly influence the performance capability of the renewable energy sources harnessed and ensure the efficient sizing of the system. In order to facilitate this complex task, we employed MATLAB software for organizing real-time values of techno-economic parameters related to HRES components into an exhaustive database. This strategy fostered efficient data management and enabled a more profound analysis.

Visual representations of this data are depicted in Fig. 5a–c, displaying annual data for solar radiation, wind speed, and ambient temperature, respectively. These figures offer a holistic perspective on the operating conditions of the HRES throughout the year, thereby refining the precision of our system optimization. Our methodology for assessing the performance and efficiency of the system incorporates several key criteria and objectives, including the ACS, LCOE, LPSP, and REF. These crucial metrics guide our evaluation process, assisting in identifying areas for improvement and potential enhancements. To capture the dynamic nature of environmental conditions and load demands, the simulation was meticulously carried out in hourly increments over the project's lifespan of 8760 h. This detailed approach ensures the accurate representation of fluctuating conditions in the optimization process.

Fig. 5
figure 5

The weather patterns of the study area. a solar radiation \(({\text{W}}/{\text{m}}^{2} )\), b wind speed (m/s), c ambient temperature (°C)

Our approach leverages the power of MATLAB software to identify the most suitable solutions, based on the established evaluation criteria and constraints. After a comprehensive and in-depth analysis, it was found that the HRES configuration with the smallest ACS, TNPC, and LCOE values proved to be the most favorable solution in the scope of this study. This comprehensive approach underscores the significance of diligent data analysis and systematic system evaluation in achieving effective optimization and accurate sizing of hybrid renewable energy systems.

3.2 Off-Grid and on-grid model energy management strategy

Energy management, viewed as the mathematical representation of a methodology that orchestrates inputs, outputs, goals, and constraints, directs the flow of energy within a hybrid energy system [41]. This study focuses on maximizing the use of renewable energy sources, which has implications for extending battery life, reducing fuel consumption, and enhancing system efficiency.

The optimization of the energy management strategy is integral, as it must align with prevailing conditions and projected energy demands. Consequently, the functioning of the EMS controller is influenced by specific off-grid and on-grid scenarios, dictated by the strategy implemented for the battery charging cycle.

A well-conceived energy management strategy ensures efficient distribution of energy derived from various renewable energy sources, resorting to energy storage solutions when necessary. This approach guarantees a consistent and reliable energy supply to meet demand. Thus, the insights gleaned from this study are set to significantly contribute to the evolution of hybrid energy systems and their respective energy management strategies.

Under the framework of an off-grid energy management system, we can distinguish four unique operational modes:

Case 1: Wind and solar energy sources provide enough energy to meet load demand. Excess energy from these sources will charge the Batt banks (\(E_{{{\text{Batt}}}} \left( t \right) < E_{{{\text{Batt}}\_\max }} \left( t \right)\)).

Case 2: Produced wind and solar energy exceeds the load demand. A discharge charge will be used to waste this excess energy (\(E_{{{\text{Batt}}}} \left( t \right) < E_{{{\text{Batt}}\_\max }} \left( t \right)\)).

Case 3: If the generated by wind and solar energy is insufficient, the available energy stored in the banks will contribute meeting the load demand (\(E_{{{\text{Batt}}}} \left( t \right) > E_{{{\text{Batt}}\_\min }} \left( t \right)\)).

Case 4: If the energy generated by wind and solar energy sources is insufficient to meet load demand and there is no energy available in the battery banks, the diesel generator will kick in for meeting load demand, while also charging Batt banks. As soon as renewable energy sources begin producing power again, the diesel generator will cease to operate (\(E_{{{\text{Batt}}}} \left( t \right) > E_{{{\text{Batt}}\_\min }} \left( t \right)\)).

In the context of an on-grid energy management system, there are four distinct operational scenarios:

Case 1: The wind and solar energy sources generate sufficient energy to fulfill the load demand. Surplus power from these renewable sources proceeds to charge the battery storage units, provided that the stored energy does not exceed the maximum battery capacity (\(E_{{{\text{Batt}}}} \left( t \right) < E_{{{\text{Batt}}\_\max }} \left( t \right)\)).

Case 2: When the energy produced by wind and solar systems surpasses the load demand and the battery units are at maximum capacity (\(E_{{{\text{Batt}}}} \left( t \right) < E_{{{\text{Batt}}\_\max }} \left( t \right)\)), excess energy is expelled through a discharge charge process.

Case 3: In situations where the energy generated from wind and solar resources is inadequate to meet the load demand, the power stored in the battery units is called upon to contribute toward fulfilling this demand, given that the stored energy is above the minimum limit (\(E_{{{\text{Batt}}}} \left( t \right) > E_{{{\text{Batt}}\_\min }} \left( t \right)\)).

Case 4: When both the energy production from wind and solar resources falls short of the load demand, and the battery units are devoid of power, the diesel generator is engaged to meet the load demand. Simultaneously, the generator also charges the battery units. As soon as the renewable energy sources resume power production, the operation of the diesel generator is suspended (\(E_{{{\text{Batt}}}} \left( t \right) > E_{{{\text{Batt}}\_\min }} \left( t \right)\)).

This section expounds on the power flow algorithms of the HRES illustrated in Fig. 6 for off-grid setups, and the energy management scheme is depicted in Fig. 7 for on-grid scenarios. Within the optimal operational strategy, diesel generators and battery banks serve as backup power sources for managing energy demand. The commencement of this energy management strategy begins by interpreting the input data, namely solar power, wind power, and load demand. The process hinges on a comparison between the total energy produced by wind and solar resources and the existing load demand. This comparison provides crucial insights into the use and storage of energy resources.

Fig. 6
figure 6

Power management of the PV/WT/DG/Batt off-grid hybrid energy system

Fig. 7
figure 7

Power management of the PV/WT/DG/Batt on-grid hybrid energy system

In an off-grid system, if the renewable resources produce sufficient energy to meet the load demand, the excess energy is directed to charge the battery banks. Conversely, if the energy production is insufficient, battery banks or diesel generators are brought into operation to meet the shortfall. This strategy guarantees an efficient and effective use of energy resources, enhancing overall energy efficiency. For on-grid systems, if renewable energy production surpasses load demand, the surplus energy is fed into the grid, resulting in a fully charged battery.

3.3 Formulation of the optimization problem

The microgrid system optimization was approached as a multi-criteria problem, generally formulated as depicted in Eq. (12).

$$\begin{aligned} & {\text{Minimize}}\, f\left( x \right) = \left[ {f_{1} \left( x \right),f_{2} \left( x \right), \ldots f_{k} \left( x \right)} \right] \\ & {\text{Subject}}\,{\text{to}}\,\,h\left( x \right) \le 0 \\ & {\text{and}}\,\,g\left( x \right) = 0 \\ \end{aligned}$$
(12)

Within the scope of multi-objective optimization, the following terms are defined:

  • \(x\): This term indicates the vector in the design search space.

  • \(f\left( x \right)\): This represents a vector consisting of objective functions to be optimized.

  • \(f_{{\text{i}}} \left( x \right)\): This is the ith objective function within the collection of objectives.

  • \(h\left( x \right)\) and \(g\left( x \right)\): These symbols are employed to denote the collection of inequality and equality constraints, respectively.

In multi-objective optimization processes, several crucial elements combine to delineate the landscape of potential solutions and the constraints that shape them. The design variable vector \(x\) occupies a central role in this framework, embodying the domain of potential solutions within our search space. Often, this vector is a reflection of the design parameters of the system under scrutiny.

In concert with \(x\), we find \(f\left( x \right)\), a vector that encapsulates the objective functions we aim to optimize. Given the nature of multi-objective optimization, it is not unusual for \(f\left( x \right)\) to comprise a multitude of functions, reflecting the diverse, and occasionally conflicting, objectives inherent to these problems. Each of these functions is specified as \(f_{{\text{i}}} \left( x \right)\), representing the ith objective function.

The boundaries within which our solutions must operate are defined by the constraint functions \(h\left( x \right)\) and \(g\left( x \right)\)\(h\left( x \right)\) represents a series of inequality constraints—necessary conditions the solutions must fulfill. For example, if \(h_{{\text{j}}} \left( x \right)\) is the jth inequality constraint, the solution must ensure that \(h_{{\text{j}}} \left( x \right) \le 0\).

Conversely, \(g\left( x \right)\) defines a set of equality constraints—additional conditions the solution must meet. When \(g_{{\text{k}}} \left( x \right)\) is the kth equality constraint, the solution must satisfy the condition \(g_{{\text{k}}} \left( x \right)\) = 0.

In summary, the primary objective of the optimization problem is to discover an \(x\) that maximizes or minimizes all \(f_{{\text{i}}} \left( x \right)\) while simultaneously complying with all constraints defined by \(h\left( x \right)\) and \(g\left( x \right)\). However, due to the inherent complexity of multi-objective optimization, it is unlikely to find a single \(x\) that optimally satisfies all objectives, often necessitating calculated trade-offs. In such instances, solutions typically manifest as a set of Pareto-optimal points, representing the optimal trade-offs between the competing objectives.

3.4 Objective function

The main objective function for analyzing the hybrid energy system is the ACS. The goal here is to optimize the system to ensure a reliable power supply at the lowest possible cost. The trio of primary factors influencing the optimal configuration includes the quantity of batteries, the power capacity of the WT, and the power output of the PV. The most favorable result, adhering to all other stipulated parameters and limitations, is identified by the lowest ACS value in the techno-economic analysis. The objective function encompasses total capital and replacement expenses, along with operational and maintenance costs. Capital costs for each component also account for installation and construction expenses. Key decision variables consist of ACS, LCOE, TNPC, capacities of PV, WT, DG, Batt, and the inverter. The formulation of the ACS is specified in Eq. (13)

$${\text{Objective}}\,\,{\text{ Function}} = {\text{Min}}\left( {{\text{ACS}},\, {\text{TNPC}},\,{\text{ LCOE}}} \right)\left\{ {R_{WT} , \,R_{PV} , \,R_{BT} ,\,R_{DG} } \right\}$$
(13)
$$C_{t}^{PV} = N_{PV} \left( {C_{C}^{PV} + C_{O\& M}^{PV} \times \left( {\left( {1 + i} \right)^{n} - 1/i\left( {1 + i} \right)^{n} } \right)} \right)$$
(14)
$$C_{t}^{WT} = N_{WT} \left( {C_{C}^{WT} + C_{O\& M}^{WT} \times \left( {\left( {1 + i} \right)^{n} - 1/i\left( {1 + i} \right)^{n} } \right)} \right)$$
(15)
$$C_{t}^{{{\text{Batt}}}} = C_{C}^{{{\text{Batt}}}} + C_{O\& M}^{{{\text{Batt}}}} \times \left( {\frac{{\left( {1 + i} \right)^{n} - 1}}{{i\left( {1 + i} \right)^{n} }}} \right) + C_{R}^{{{\text{Batt}}}} \times \mathop \sum \limits_{j = 1}^{{\left( {\frac{n}{{n_{{{\text{Batt}}}} }} - 1} \right)}} \left( {1 + \frac{1}{{\left( {1 + i} \right)^{{jn_{{{\text{Batt}}}} }} }}} \right)$$
(16)
$$C_{t}^{{{\text{diesel}}}} { } = C_{C}^{{{\text{diesel}}}} + C_{O\& M}^{{{\text{diesel}}}} \times \left( {\frac{{\left( {1 + i} \right)^{n} - 1}}{{i\left( {1 + i} \right)^{n} }}} \right) + C_{R}^{{{\text{diesel}}}} \times \mathop \sum \limits_{j = 1}^{{\left( {\frac{n}{{n_{{{\text{diesel}}}} }} - 1} \right)}} \left( {1 + \frac{1}{{\left( {1 + i} \right)^{{jn_{{{\text{diesel}}}} }} }}} \right)$$
(17)

The LCOE, inherently dependent on the TNPC, comprehensively includes the expenses related to O&M and subsequent replacements [42]. Within this framework, the expenditure components of PV, WT, Batt, and DG are meticulously accounted for. Subsequent formulae are utilized to methodically derive the LCOE, with an objective of achieving its minimization.

The total net current cost value can be calculated as in Eq. (18):

$${\text{TNPC}} = C_{t}^{PV} + C_{t}^{WT} + C_{t}^{{{\text{Batt}}}} + C_{t}^{{{\text{diesel}}}} + C_{C}^{{{\text{Inv}}}} + C_{{{\text{grid}}}} - R_{{{\text{grid}}}}$$
(18)

\(N_{PV}\) and \(N_{WT}\) are the PV and WT numbers, respectively. \({ }C_{C}^{PV}\), \(C_{C}^{WT}\), \(C_{C}^{Batt} { }\), \(C_{C}^{diesel} { }\) and \(C_{C}^{Inv}\) are the PV, WT, Batt, DG and the investment costs of inverter. \(C_{O\& M}^{PV}\), \(C_{O\& M}^{WT}\), \(C_{O\& M}^{{{\text{Batt}}}}\) and \(C_{O\& M}^{{{\text{diesel}}}}\) are the PV, WT, Batt and the O&M of DG. \(C_{R}^{Batt}\) and \(C_{R}^{{{\text{diesel}}}} { }\) are the replacement costs of Batt and DG. i stands for the interest (per year) of the HRES, n represents system’s life cycle, \(n_{{{\text{Batt}}}}\) and \(n_{{{\text{diesel}}}}\) are the lifetimes of Batt and DG. \(R_{{{\text{grid}}}}\), represents the revenue derived from selling excess energy back to the grid, while \(C_{{{\text{grid}}}}\) denotes the expected power purchase from the grid.

The LCOE is an esteemed and extensively utilized indicator for evaluating the economic sustainability of microgrid systems [43]. The precise calculation of LCOE is delineated in Eq. (19).

$${\text{LCOE}} ( /{\text{kWh}}) = \frac{{{\text{TNPC}}}}{{\mathop \sum \nolimits_{t = 1}^{8760} P_{{{\text{load}}}} }} \times {\text{CRF}}$$
(19)

In this context, \(P_{{{\text{load}}}}\) represents the quantum of power consumed each hour. To ascertain the annualized capital cost from the initial outlay, one employs Eq. (20). The term 'CRF' is an abbreviation for the capital recovery factor, integral to this calculation. Furthermore, the temporal span of the HRES project, denoted by 'n' (in years), and the real interest rate, indicated by \(i_{r}\), are pivotal parameters within this framework.

$${\text{CRF}}\left( {i_{r} ,n} \right) = \left[ {i_{r} \times \left( {1 + i_{r} } \right)^{n} } \right]/\left[ {\left( {1 + i_{r} } \right)^{n} - 1} \right]$$
(20)

3.5 Loss of power supply probability (LPSP)

LPSP let us calculate the microgrid system’s reliability. LPSP reliability index indicates the likelihood that the power supply will fail to meet the energy demand. This is caused by a fault in the hybrid energy system or by the low power generation of renewable energy sources. Equation (21) is used to calculate it [44].

$$LPSP\left( \% \right) = {{\left( {\mathop \sum \limits_{0}^{T} P_{{{\text{load}}}} - P_{PV} - P_{WT} - P_{DG} - \left( {E_{{{\text{Bat}} - }} E_{{{\text{Bat}}\_\min }} } \right)} \right)} \mathord{\left/ {\vphantom {{\left( {\mathop \sum \limits_{0}^{T} P_{{{\text{load}}}} - P_{PV} - P_{WT} - P_{DG} - \left( {E_{{{\text{Bat}} - }} E_{{{\text{Bat}}\_\min }} } \right)} \right)} {\mathop \sum \limits_{0}^{T} P_{{{\text{load}}}} }}} \right. \kern-0pt} {\mathop \sum \limits_{0}^{T} P_{{{\text{load}}}} }}$$
(21)

Also, the condition in Eq. (22) was applied in the calculation of system reliability.

$$P\left( t \right)_{{{\text{load}}}} > P\left( t \right)_{{{\text{generation}}}}$$
(22)

LPSP, with a range from 0 to 1, serves as an indicator of energy sufficiency: a value of 0 denotes complete fulfillment of energy demand, whereas 1 signifies a total lack of provision [45]. For this simulation, the LPSP is configured to zero, indicating an expectation of fully meeting the energy demand.

3.6 Renewable energy factor (REF)

A suite of indices is employed to evaluate the contribution of renewable sources within the hybrid system, among which REF is pivotal for diminishing reliance on nonrenewable energy. The REF, indicating the proportion of energy supplied by renewables, is calculable via Eq. (23) when HRES includes a diesel generator:

$$REF\,\left( \% \right) = \left( {1 - P_{DG} /\left( {P_{PV} + P_{WT} } \right)} \right) \times 100$$
(23)

Here, optimizing the system involves maximizing REF by reducing the denominator of the equation. However, it is important to note that REF is inherently capped at 100%. Consequently, during the optimization process, as articulated in Eq. (24), the REF must invariably remain beneath a predetermined threshold (εREF) [46].

$${\text{REF}}\,\left( \% \right) \le \varepsilon_{{{\text{REF}}}}$$
(24)

3.7 Greenhouse gases emission optimization model

Another important factor to consider when designing a hybrid renewable energy system is the emission of greenhouse gases (GHG). As the system emits more greenhouse gases, the negative impact on the environment correspondingly increases. Conversely, fewer emissions mean a lesser environmental footprint. The primary contributors to these emissions within the system are predominantly three types of DG emitting gases [47]: \({\text{CO}}_{2}\), \({\text{SO}}_{2}\) and \({\text{NO}}_{x}\). The TGE of the system is calculated using the formula presented in Eq. (25).

$${\text{TGE}} = \mathop \sum \limits_{t = 1}^{8760} \left( {\left( {a_{{{\text{CO}}_{2} }} + a_{{{\text{SO}}_{2} }} + a_{{{\text{NO}}_{x} }} } \right) \times P_{DG} \left( t \right)} \right)$$
(25)

where TGE is the total greenhouse gases emission and \(a_{{{\text{CO}}_{2} }}\), \(a_{{{\text{SO}}_{2} }} { }\) and \(a_{{{\text{NO}}_{x} }}\) are the emission factor of \({\text{CO}}_{2}\), \({\text{SO}}_{2}\) and \({\text{NO}}_{x}\), respectively.

\(P_{DG} \left( t \right)\) is the rated power of the DG. In the study, emission factors of \({\text{CO}}_{2}\), \({\text{SO}}_{2}\) and \({\text{NO}}_{x}\) have been determined as 697, 0.5, and 0.22, respectively.

3.8 Dump energy evaluation

An additional reduction target in the algorithm explored in this study is dump energy. This discharge occurs when an excess of renewable energy is generated and the battery's state of charge reaches its maximum, leading to undesirable energy waste. To mitigate this, strategies such as bulk energy management and controlled discharge are employed. It is imperative to conduct a thorough examination into methods that can effectively utilize this surplus energy, potentially contributing to reduced energy costs. This study achieves the minimization of discharge energy by employing an efficient hybrid GWOCS-based optimal system design. Equation (26) calculates the total dump energy over the system's lifecycle.

$$D_{{{\text{total}}}} = \mathop \sum \limits_{t = 1}^{8760} D\left( t \right)E_{WT} \left( t \right) + E_{PV} \left( t \right) - \frac{{E_{{{\text{Load}}}} \left( t \right)}}{{\eta_{{{\text{Inv}}}} }}$$
(26)

3.9 Design variables

Design variables are critical in optimization, employed to define system characteristics and performance. For instance, in a solar energy system, parameters such as the number and capacity of panels, the quantity and capacity of batteries, and the efficiency of the inverter are optimized to enhance performance and reduce costs.

The boundaries of these variables are typically determined by physical properties, design constraints, and objectives. Lower and upper limits represent the minimum and maximum values a variable can take. Engineers set these boundaries based on experience, experimental results, and similar problems, while optimization software can also automatically designate the range of constraints. Penalty functions may be employed for values outside the boundaries, mitigating their negative impact on the optimization result.

In this study, our decision variables are solar panel power (\(R_{PV}\)), wind turbine power (\(R_{WT}\)), battery power (\(R_{{{\text{Batt}}}}\)), and diesel generator power (\(R_{DG}\)). Equation (24) specifies the accepted variables’ boundaries for the off-grid system, and Eq. (27) does the same for the on-grid system.

$${\text{Design}}\,\,{\text{Variables}} = \left\{ {\begin{array}{*{20}c} {1 \,{\text{kW}} \le R_{WT} \le 5000 \,{\text{kW}}} \\ {1 \,{\text{kW}} \le R_{PV} \le 5000 \,{\text{kW}}} \\ {1 \,{\text{kW}} \le R_{Batt} \le 5000 \,{\text{kW}}} \\ {1\, {\text{kW}} \le R_{DG} \le 1000 \,{\text{kW}}} \\ \end{array} } \right.$$
(27)

In conclusion, for optimizing both on-grid and off-grid systems, we have utilized the values in Eq. (27) to expedite the convergence of the algorithms toward the optimal solution.

3.10 Simulation and optimization techniques

Optimization is the process of designing or configuring a system or process to achieve the best possible results, generally aimed at maximizing or minimizing a specific objective such as cost, performance, or efficiency. However, in certain circumstances, such as the sizing optimization problem of a HRES, specific constraints can make it difficult or impossible to maximize or minimize the objective. These constraints can arise from a variety of factors such as design, material selection, physical space limitations, production capacity, budget, or time. Optimization constraints are used to impose certain limitations on the system or process to be optimized. In this study, specific constraints, such as a minimum renewable energy ratio (minimum 10%) and a maximum annual cost limit (annual cost = 109), were used when designing a HRES. These constraints enable the optimization algorithm to adjust the design parameters to provide a design that meets the constraints.

In this section, we delve into the simulation and optimization methodologies utilized in sizing both off-grid and on-grid hybrid energy systems, comprised of PV/WT/DG/Batt elements, as per the four distinct scenarios outlined in the study. Initially, the simulation conducted via HOMERPro software is expounded, which is subsequently followed by an in-depth look into the GWO, CS, and the hybrid GWOCS algorithms.

3.10.1 HOMER simulation of HRES

The HOMER software, which stands for hybrid optimization of multiple energy resources, is extensively utilized in sizing and optimization. This software facilitates the execution of a pre-feasibility test for various RE configurations of varying sizes, as well as the execution of various configuration and sensitivity analyses for desired energy systems. Figure 8 presents single-line diagram for HRES, and the simulation results obtained by HOMER are presented in Table 1. According to the optimization results obtained here, the load demand can be met throughout the year with the Scenario 1 PV/battery hybrid energy system, which is one of the three most suitable scenarios. Using a 5785-kW solar panel, 936 batteries, and 1384 kW converter, the LCOE was calculated as $0.185, TNPC as $11.2M, and REF as 100%.

Fig. 8
figure 8

HOMER HRES single-line diagram

Table 1 Optimal sizing results obtained with HOMER under scenarios 1, 2, 3, 4 of the proposed HRES

3.10.2 Gray Wolf optimizer (GWO)

The GWO algorithm is a metaheuristic optimization technique. It is often used in the solution of optimization techniques. This technique models the life and hunting of gray wolves in their communities. The selected gray wolf species are α, β, δ ve ω. The alpha group is a dominant species as the wolf group follows its rules. Beta group refers to the secondary wolves that help Alpha in decision making. Omega represents the lowest-ranking gray wolves. If a wolf does not belong to any of the above species, it is referred to as delta. The hunting process consists of finding/tracking the prey, then encircling/guarding the prey, and finally attacking the prey. The major advantages of the GWO algorithm are that it is simpler, more flexible, and free of derivations. The first step in the GWO optimization procedure is to generate a random gray wolf population. Iterations can be used to estimate the likely location of prey by α, β ve δ wolves to represent the optimal solution. Gray wolves update their locations based on their distance from the prey [48].

Wolves have different fitness levels in the GWO algorithm. Wolves are ranked from best to worst alpha, beta, and delta. This gives a set of three wolf-level keys. Other wolves make up the omega group. When gray wolves go out to hunt, they first follow the prey, then approach it and continue to surround and harass until the prey stops. In the last step, they attack the prey.

3.10.2.1 Encircling prey

Gray wolves encircle and enclose their prey while hunting. The following equations were used to model the behavior of wolves encircling the prey:

$$\vec{D} = \left| {\vec{C}.\vec{X}_{P} \left( t \right) - \vec{X}\left( t \right)} \right|$$
(28)
$$\vec{X}\left( {t + 1} \right) = \vec{X}_{P} \left( t \right) - \vec{A}\vec{D}$$
(29)

here \({ }\vec{D}\) is the distance between the preys, \(\vec{X}_{P}\) is the prey location vector, t is the current iteration, \(\vec{A}\) and \(\vec{C}\) represent the vector of coefficients, and X represents the gray wolf location vector. \(\vec{A}\) and \(\overrightarrow {C }\) vectors are calculated as:

$$\vec{A} = 2\vec{a}\vec{r}_{1} - \vec{a}$$
(30)
$$\vec{C} = 2\vec{r}_{2}$$
(31)

here the components of \(\vec{a}{ }\) are linearly reduced from 0 to 2 throughout iteration and \(r_{1} ,r_{2}\) are random vectors in the range \(\left[ {0,1} \right]\).

3.10.2.2 Hunting

In gray wolves, alpha leads the hunt. Beta and delta sometimes join alpha as well. However, there is no information about the prey. In the software, prey is searched for at specific intervals in space. When hunting, it is presumed that alpha, beta and delta know the location of the prey better than others. Therefore, three of the optimal solutions are stored. The GWO algorithm recalculates the positions of these dominant wolves after each run. The positions of the other wolves are also taken into account. The updating of the representative positions can be formulated as follows [49].

$$\vec{D}_{a} = \left| {\vec{C}_{1} \vec{X}_{a} - \vec{X}} \right|, \vec{D}_{\beta } = \left| {\vec{C}_{2} \vec{X}_{\beta } - \vec{X}} \right|,\vec{D}_{\delta } = \left| {\vec{C}_{3} \vec{X}_{\delta } - \vec{X}} \right|$$
(32)
$$\vec{X}_{1} = \vec{X}_{a} - \vec{A}_{1} \vec{D}_{a} , \overrightarrow { X}_{2} = \vec{X}_{\beta } - \vec{A}_{2} \vec{D}_{\beta } , \vec{X}_{3} = \vec{X}_{\delta } - \vec{A}_{3} \vec{D}_{\delta }$$
(33)
$$\vec{X}\left( {t + 1} \right) = \frac{{\vec{X}_{1} + \vec{X}_{2} + \vec{X}_{3} }}{3}$$
(34)
3.10.2.3 Seeking and attacking prey

As mentioned above, when the stopping location is reached, the gray wolves attack the prey, ending the hunt. For mathematical modeling of closeness to prey, the value of \(\vec{\alpha }\) should be reduced. Also, the amplitude oscillation of A is reduced by \(\vec{\alpha }\). In other saying, \(\vec{A}\) is a random value between \(\left[ { - 2\vec{\alpha },2\vec{\alpha }} \right]\), where \(\vec{\alpha }\) will reduce from 2 to 0 throughout the iterations. While \(\vec{A}\) is random values in distance between [− 1, 1], the next location of a search factor can be anywhere between the location of the prey and the current location. The gray wolf seeks for prey, principally taking into consideration the locations of alpha, beta, and delta. The wolves branch out and move away in search of prey and then unite to attack. For mathematical modeling of going away, \(\vec{A}\) with random values greater than 1 or less than -1 was used so that it helps the search factor to branch out from prey. The mathematical expression of a gray wolf attacking its prey was shown by Eq. (35). Here, t represents the number of times the algorithm is run between zero and the maximal number of iterations (Max) [50].

$$A = 2 - 2\left( {\frac{t}{{{\text{Max}}}}} \right)$$
(35)

The code of the GWO algorithm is shown in Fig. 9.

Fig. 9
figure 9

GWO algorithm pseudo-code

3.10.3 Cuckoo search algorithm (CS)

The CS algorithm is a novel evolutionary algorithm suitable for continuous nonlinear optimization problems, developed by Xin-She Yang and Suash Deb, inspired by the breeding behavior of cuckoos [51]. The special lifestyles of the birds and their characteristic properties in ovulation and reproduction have been the main motivation for the development of the algorithm. Cuckoos have interesting aggressive breeding strategies; for example, they put their eggs in the nests of other birds and can discard other eggs in the nest to increase the likelihood of their own eggs hatching. If the nester notices that the bird has eggs in its nest that do not belong to it, it either expends the foreign eggs from the nest or leaves its own nest and builds a new nest elsewhere.

As delineated by Eq. (34), the algorithm of GWO implements a process of updating the loci of individuals exhibiting a superior measure of fitness values through the method of trend search. This subset of individuals is identified as a pivotal cohort within the system. This operational model, unfortunately, hampers the algorithm's competence in effectively executing a global search. Furthermore, it manifests an increased propensity toward being entrapped in local optima, a tendency which becomes more pronounced in scenarios dealing with an extensive volume of datasets. Contrarily, the CS algorithm, equipped with the mechanism of a random walk intertwined with Levy flights, embarks on the task of updating nest positions. The trajectory of the search operation could exhibit variations in length—it could either exceed or fall short of its predecessor, with the probabilities of these outcomes being nearly equal. The course of direction in this model remains predominantly arbitrary. Such a configuration paves the way for enhanced fluidity in translocating from one sector of the search space to an alternate one in subsequent operations.

The CS algorithm is based on three simplified basic rules:

  • Each cuckoo makes one egg at a time and lays it in a randomly selected nest.

  • The best nests with high-quality eggs are transported to the next generations.

  • Thirdly, both the count of bird nests and the likelihood of locating eggs remain constant. In the event that the host bird detects an intruder's egg, the host bird departs from the nest and proceeds to construct a fresh one.

In each nest, every egg opposes a solution, and the algorithm is further streamlined to allow only one egg per nest. As a result, distinctions between the egg, the nest, or the cuckoo are eliminated, as each nest encapsulates an egg, which inherently symbolizes a cuckoo. The CS algorithm leverages both global and local random walk strategies, guided by the \(p_{a} { }\) transition parameter. The local random walk can be articulated as follows:

Within the context of the CS operation, a population, delineated as \(E^{k} \left( {X_{1}^{k} ,X_{2}^{k} , \ldots ,X_{N}^{k} } \right)\), of \(N\) individuals evolves from an initial point (\(k = 0)\) toward a cumulative total of iterations (gen). Each individual \(X_{i}^{k}\) (where \(i\) belongs to the set \(\left[ {1, \ldots ,N} \right]\)) is an n-dimensional vector, with the dimensions \(\left( {X_{i,1}^{k} ,X_{,2}^{k} , \ldots ,X_{i,N}^{k} } \right)\) each representing a decision variable within the optimization problem to be resolved. The performance of each individual, \(X_{i}^{k}\) (termed as a candidate solution), is gauged using an objective function, \(f(X_{i}^{k} )\), where the final outcome epitomizes \(X_{i}^{k}\)’s fitness value.

The employment of levy flights to generate new candidate solutions represents one of the most innovative features of the CS algorithm. A new candidate solution, \(X_{i}^{k}\) (where i belongs to the set [1,…,N]) is conceived by perturbing the current \(X_{i}^{k}\) with a positional change denoted as \(c_{i}\). To extract \(c_{i}\), a symmetric Levy distribution engenders a random step, \(s_{i }\). Mantegna's algorithm is utilized to generate \(s_{i }\) [52].

$$s_{i} = \frac{{\vec{u}{ }}}{{\left| {\vec{v}{ }} \right|^{1/\beta } }}$$
(36)

where \(\vec{u} = \left\{ {u_{1} ,u_{2} , \ldots ,u_{n} } \right\}\) and \(\vec{v} = \left\{ {v_{1} ,v_{2} , \ldots ,v_{n} } \right\}\) both n-dimensional vectors with a dimension of 3/2. Each component of \(\vec{u}\) and \(\vec{v}\) is calculated using the normal distributions described below [53]:

$$u\sim N\left( {0,\,\sigma_{u}^{2} } \right),\,v\sim N\left( {0,\,\sigma_{v}^{2} } \right)$$
(37)
$$\sigma_{u} = \frac{{\Gamma \left( {1 + \beta } \right) \times \sin \left( {\pi \times \frac{\beta }{2}} \right)}}{{\Gamma \left( {\frac{{\left( {1 + \beta } \right)}}{2}} \right) \times \beta \times 2^{)\beta - 1)/2} }},\,\,\sigma_{v} = 1$$
(38)

The gamma distribution is represented by \({\Gamma }\) (.). Once \(s_{i}\) has been determined, the necessary positional adjustment, \(c_{i}\), is calculated as follows:

$$c_{i} = 0.01 \times s_{i} \oplus (X_{i}^{k} - X^{{{\text{best}}}} ){ }$$
(39)

The operator \(\oplus\) signifies element-wise multiplication and \(X^{{{\text{best}}}}\) represents the most optimum solution observed up until this point with respect to its fitness value. Finally, by employing Eq. 40, we determine the subsequent candidate solution, which is represented as \(X_{i}^{k + 1} .\)

$$X_{i}^{k + 1} = X_{i}^{k} + c_{i} { }$$
(40)

Consequently, the CS algorithm is capable of exploring the solution space proficiently due to its ability to adjust its steps according to the detection of small distances and occasional long-distance strides. Over time, the stride length tends to be considerably extended, leading to more efficient exploration [54].

The code of the CS algorithm is shown in Fig. 10.

Fig. 10
figure 10

CS algorithm pseudo-code

3.10.4 Hybrid Gray Wolf optimization-cuckoo search algorithm (GWOCS)

The practice of amalgamating two or more algorithms has recently garnered attention as a promising approach to deriving superior solutions for optimization problems. The assimilation of various renowned optimization techniques into these hybrid optimized algorithms has amplified their efficiency in addressing pertinent issues.

The GWO algorithm mirrors the hunting tactics and leadership hierarchy typical of gray wolves. These creatures ordinarily inhabit groups in wilderness settings, with the groups comprising four distinct species of wolves. The leadership role is vested in the alpha (α) wolf, which occupies the apex of the hierarchical pyramid. Even if the alpha is not the physically strongest, it must be the most effective leader, responsible for crucial group decisions like predatory strategies and food allocation. The beta (β) wolf, situated on the second tier of the hierarchy, functions as an assistant to the alpha, aiding in group management. It needs only to respect the alpha to command others. The delta (δ) wolf, positioned on the third tier, is required to adhere to the directives of both the alpha and beta. They replace the alpha and beta once their prime years have passed, and they are demoted to the delta rank. The omega (ω) wolf, located at the base of the pyramid, must yield to the rest of the group.

In this study, we introduce an innovative hybrid optimization algorithm, named the GWCSO. This algorithm seamlessly combines the strengths of the GWO and the CS and is adeptly used for the efficient optimization of both on-grid and off-grid HRES. The aim is to determine optimal component sizes to both reduce system costs and meet load demands. The GWO algorithm, inspired by the coordinated hunting behavior of gray wolves, is renowned for its ability to exploit local optima [55]. This feature has been utilized to identify the optimal sizes of various components in the system. Despite its advantages, the GWO often faces the challenge of limited global search capabilities, which increases its susceptibility to being trapped in local optima. To address this challenge, the study incorporates aspects of the CS algorithm. The CS, inspired by the brood parasitism of cuckoo birds, leverages a direction-independent and path-agnostic approach for global search. This ability enhances the algorithm's transition capabilities across various solution regions, helping overcome the local optima challenge associated with GWO. The hybrid GWCSO algorithm is devised by ingeniously embedding the position updating functionality of the CS algorithm within the framework of GWO. This modification influences the positions, velocities, and convergence accuracies of the gray wolf agents, bolstering the search efficacy of the algorithm [56].

As a result, this innovative hybrid algorithm, GWCSO, demonstrates a potent ability to swiftly tackle optimization problems. The blend of local search capabilities from GWO and global exploration of CS presents a powerful tool for solving the complex optimization problems of off-grid HRES, enabling efficient extraction of sizing units for solar PVs, WTs, Batts, and DGs.

Additionally, within the context of the on-grid HRES model, we observed that the CS algorithm procured more optimal results in comparison to the GWOCS algorithm. As with all types of algorithms, the notion that hybrid algorithms consistently deliver precise results is not always valid. Hybrid algorithms are primarily designed to integrate the best attributes of multiple methods, aiming to furnish more efficient or effective solutions. However, this integration doesn't always ensure improved outcomes. The performance of a hybrid algorithm depends on several factors, including the nature of the problem it addresses, the design of the algorithm itself, its objectives, and the proficiency and experience of the individual deploying it. In some specific scenarios, such as optimization issues, a hybrid algorithm's performance might align with or even surpass that of its constituent algorithms. Conversely, in other situations, the intricacies of combined algorithms might negatively affect their performance. Thus, it becomes crucial to perform exhaustive testing and trials to verify whether a hybrid algorithm is more effective than other existing algorithms in solving a particular problem. As such, while hybrid algorithms do not always guarantee superior results, when designed and implemented correctly, they usually outperform other approaches. In the process of optimizing the HRES for this study, the objective function of the off-grid model involved three distinct parameters. In contrast, the on-grid model used four unique parameters for optimization. It's normal for algorithms to yield varying or comparable results based on the complexity and dimension of the problem.

The pseudocode for the integration of the GWO with the CS algorithm can be seen in Fig. 11, while Fig. 12 presents the flowchart illustrating this integration.

Fig. 11
figure 11

Hybrid GWOCS algorithm pseudo-code

Fig. 12
figure 12

Flowchart of optimal design procedure using hybrid GWOCS algorithm

4 The results and discussion

Using the methodology described in Sect. 2, we describe the evaluation of optimization results of a PV-WT-DG-Batt system to meet the university campus's electrical load demand. Four different scenarios were implemented in the study for the proposed off-grid HRES. The difference between these scenarios is that they are made up of different HRES components. The following are the definitions for the first, second, third, and fourth scenarios:

  • Scenario1 This scenario is executed considering only solar panels and battery storage, denoted as PV and Batt.

  • Scenario2 Executed with a combination of wind turbines, solar panels, and battery storage, identified as PV, WT, and Batt, being the sole components.

  • Scenario3 Conducted with an integration of solar panels, diesel generators, and battery storage, represented as PV, DG, and Batt.

  • Scenario4 Implemented with a comprehensive mix of solar panels, wind turbines, diesel generators, and battery storage, referred to as PV, WT, DG, and Batt.

Economic optimization is sought with GWO, CS, and hybrid GWOCS algorithms using an objective function based on keeping the annual cost of HRES at the lowest level. All hybrid system and RES parameters and data, such as solar energy, wind energy, temperature, load values, Batt's charging depth as well as battery dimensions, type, and size, were recorded in our database, and the software was developed in the MATLAB environment. Furthermore, in order to provide practical solutions in a short period of time, algorithm designs were created first, taking into account all price details such as the total cost of all components, maintenance and operating costs, work area coordinates, project life, number, and prices. The proposed system's GWOCS algorithm meets the total energy demand in Scenario 1, which consists only of PV and Batt components. Tables 2, 3, 4, and 5 show the results of hybrid energy system optimization for various scenarios. PV-battery (Scenario 1), PV-WT-Batt (Scenario 2), and PV-DG-Batt (Scenario 3) are all applicable schemes. The PV-Batt hybrid system, consisting of 3641.896 kW PV arrays and 4767.595 kW battery units, is the most economically viable option for the university campus. The TNPC is $10899774.295 with an ACS of $671570.577 and a LCOE of $0.1800267/kWh. Furthermore, the proposed system uses 100% renewable energy. It produces no annual emissions. The annual total gas emission of the hybrid system in Scenario 3 is 3638986.6 kg/year, and it is 2388426.10 kg/year in Scenario 4. As a result, the PV-Batt hybrid system is the most cost-effective system with the lowest CO2 emissions.

Table 2 Sizing and cost of optimum off-grid HRES obtained using GWO, CS, GWOCS algorithms in different scenarios
Table 3 Energy and cost of optimum off-grid HRES using GWO, CS, GWOCS algorithms in different scenario1 and scenario2
Table 4 Energy and cost of optimum off-grid HRES using GWO, CS, GWOCS algorithms in different scenario3 and scenario4
Table 5 Energy and cost of optimum on-grid HRES using GWO, CS, GWOCS algorithms

To demonstrate its reliability and validity, the hybrid GWOCS used in solving the optimal size problem of the grid-independent HRES is compared to two other metaheuristic algorithms, namely GWO and CS. The most appropriate ACS and LCOE values were obtained with the GWOCS algorithm in Scenario 1, as shown in Table 2. As a result, any decrease in the objective function is significant. This provides more information about the ideal size. HRES generates an additional 1723177.348 kWh of energy in addition to meeting load demand. This energy is used in campus irrigation systems, among other things. It is used in a variety of unloading loads.

The monthly average energy balance for the grid-connected and off-grid HRES over a year is depicted in Fig. 13a, b. An investigation of the HRES showed that the solar and wind powers are consistent with the available solar and wind resources. In January–February–November–December, when PV panels produce less power, the batteries were activated to meet the load demand. During the other months, a better amount of energy was produced from the sun due to better natural resources. However, in the summer months, the use of the battery bank was reduced, meaning less power was drawn from the batteries. It can also be observed that there was excess energy. The excess energy of 1723177.348 kWh produced can be used in watering systems within the campus or sold to the grid. In consequence of optimization, the HRES, which is conceived for the same working space and interconnected with the grid, has been transacting excess energy back to the grid. The LCOE, standing at a unit energy expenditure of 0.1275 ($/kWh), perpetually suffices the load requested throughout the annum. Table 4 elucidates the findings procured for the grid-connected HRES. As discernible in Fig. 13b, the grid-connected system's energy balance manifests a reliance on the grid to compensate for the deficiency encountered in fulfilling the load demand during the months of January, February, November, and December.

Fig. 13
figure 13

Share of energy from different HES components

To verify the optimal performance of the proposed system over the course of a year, two distinct weeks were selected where load demand was at its peak and its lowest. The weekly chart, which spans from the 3360th to 3527th hour (May 19–26th) when the load demand is low, is presented in Fig. 14. Figure 14a, b exhibit the optimization results for off-grid and on-grid HRES, respectively. Charts for the period of high load demand, from the 336th to 503rd hour (January 14th–21st), are provided in Fig. 15, with Fig. 15a representing the off-grid HRES and Fig. 15b displaying the on-grid system. In Fig. 14a, the high solar energy production in May brings the state of charge (SOC) of the battery close to its maximum, whereas in Fig. 15a, lower solar energy production in January results in a drop in the SOC to its minimum levels. Figures 14b and 15b illustrate the procurement of energy from the grid when necessary. From this, a detailed understanding of the battery's status in relation to other components at different times of the year can be obtained.

Fig. 14
figure 14

HRES Energy balance analysis: a off-grid, b on-grid (3rd week of May)

Fig. 15
figure 15

HRES Energy balance analysis: a off-grid, b on-grid (2nd week of January)

SOC is an important parameter in a system where energy storage elements are used. The performance and lifespan of a battery are of vital importance for the efficiency of hybrid energy systems. Therefore, the battery management system should accurately monitor and optimize the battery's SOC. The SOC is a measure of how much of the battery's accessible capacity has been used. A battery that is completely drained or fully charged can shorten its lifespan and reduce its performance. Figure 16a shows the average SOC of the battery for the off-grid HRES. The SOC percentages were 66.87% in January, 26.55% in February, 35.64% in March, 69.62% in April, 85.73% in November, 46.62% in December, and 100% in the remaining months. Figure 16b displays the average SOC graph for the grid-connected HRES. Here, the SOC percentages are 24.9% in January, 32.18% in February, 66.21% in March, 76.81% in April, 84.66% in May, 91.72% in June, 89.64% in July, 91.64% in August, 78.62% in September, 49.63% in October, 24.5% in November, and 22.43% in December.

Fig. 16
figure 16

Average monthly Battery state of charge (%): a off-grid, b on-grid

Figure 17a, b, respectively, depicts the annual hourly dynamics of battery charging and discharging within HRES components, for both off-grid and grid-connected scenarios. In these graphs, 'Batout' represents the instances where energy is drawn from the battery, signifying the energy provided by the battery storage system to meet the load demand. Conversely, 'Batin' denotes the charging of the battery or the surplus renewable energy fed into the storage system once the load demand has been satisfied.

Fig. 17
figure 17

Annual battery energy balance (kWh): a off-grid, b on-grid

The weekly energy values of load, battery discharge, wind and solar energy are shown in Fig. 18. Here you can see how the load is covered by different sources, battery discharge, wind power and solar power. Figure 18b is shown with an additional Batt charging line compared to Fig. 18a. When there is enough solar energy, we can see that the Battery is charged at that moment and the Battery is charged with the extra energy produced by RES at a certain time in Fig. 18b. As a result of the HRES optimization, all system components are monitored over weekly or yearly charts on an annual hourly basis for 8760 h. Figure 19 portrays a weekly chart that embodies the energy balance analysis of HRES within the temporal interval of 2017–2184 h. Each of the three charts displayed in Fig. 19 elucidates instances of battery depletion, electricity demand being catered to by RES and power procured from the grid, as well as moments of surplus energy being transacted back to the grid.

Fig. 18
figure 18

Off-Grid HRES optimization balance. a Load, battery discharge, and wind and solar power, b load, battery charge, wind power and battery discharge, and solar energy (2017–2184 h)

Fig. 19
figure 19

On-grid HRES optimization balance (2017–2184 h)

Figure 20 depicts a comparison of load demand and renewable energy production. Additional graphs highlight that the energy demand in the off-grid HRES is mainly satisfied by solar power and battery storage. In the case of the on-grid HRES, load demand is met using solar power, battery storage, and additional power drawn from the grid when battery reserves are depleted. It's noteworthy that a substantial part of the load demand is fulfilled by solar energy, leading to the inference that the DG has not been engaged at any point. In contrast, Fig. 21 displays the cumulative amount of energy both sold to and purchased from the grid over the span of a year. This graph tracks the total supply and demand trajectory of grid energy throughout the year, providing numerical values such as the 1383.8 MWh of energy sold and 821.2 MWh of energy purchased. Both of these graphical representations impart a comprehensive understanding of the energy demand and supply patterns.

Fig. 20
figure 20

Annual profile of renewable energy generation and load demand

Fig. 21
figure 21

Comparison of the energy balance of purchased from and sold to the grid in an HRES

Within the context of the on-grid system, the proposed system strategically employs solar, wind, battery storage, a diesel generator, and the electrical grid in a sequence for the procurement or disposition of requisite or surplus energy, thereby accommodating the comprehensive energy demand. Figure 22 illustrates the monthly average energy equilibrium extending over an annual period. The cumulative energy engendered by wind, solar, battery (both ingress and egress), diesel generator, and the grid (inclusive of both sale and acquisition) is exhibited on a monthly basis for an entire year. Conversely, in the event that the power generated solely by solar and wind energy does not suffice to meet the demand, a battery storage system is deployed to offset the existing power deficit, ensuring demand is duly met. Subsequently, in circumstances where an excess of solar and wind energy remains post meeting the load demand, an assessment must be conducted to determine whether the entirety of the residual energy can be conserved within the battery; if feasible, the remnant energy ought to be stored within the battery. As an alternate strategy, any surplus energy post battery charging is sold back to the grid. Owing to heightened solar radiation and temperature levels, the most substantial energy sales occur during the months of June, July, and August, wherein the PV units manifest their maximal power output.

Fig. 22
figure 22

The monthly average energy balance analysis of the HRES over the course of one year (8760 h): a off-grid, b on-grid

Figure 23a, b presents the convergence comparison curves for the off-grid and on-grid HRES, respectively, illustrating how the algorithms employed in the optimization process approach the optimal and highest-quality solution. The slope or structure of these graphs indicates the swiftness with which the algorithm approaches the optimal solution based on the iterations in optimization. In the optimization of the off-grid system, it is evident that the Hybrid GWOCS algorithm performs calculations expeditiously, nearing the optimal value post the 10th iteration, and captures the optimal solution. In contrast, the optimization results for the on-grid system were noticeably superior when the CS algorithm was utilized. This demonstrates that all the algorithms can be applied effectively in the optimization of hybrid renewable energy systems. The principal factor that significantly influences the performance of these algorithms is the nature of the objective functions being optimized. In the on-grid system, multiple objective functions (ACS, TNPC, and LCOE) were optimized, whereas in the off-grid scenario, only a single-objective function (ACS) was optimized. This discrepancy underscores the variations in the performance of the different algorithms in use. The complexity of multi-objective optimization problems is generally greater than that of single-objective problems. However, there could be scenarios where an algorithm can approach a single-objective problem (as in the off-grid case) more efficiently.

Fig. 23
figure 23

The comparison of the convergence curves for the GWOCS, GWO, and CS algorithms: a off-grid, b on-grid

4.1 Statistical analysis of the algorithms

Statistical methods are vital for extracting meaningful insights from complex datasets. These methods help uncover hidden patterns, trends, and relationships that might otherwise remain unnoticed. In this study, we implemented a comprehensive array of statistical tests to compare the performance of five distinct algorithms thoroughly. Our primary goal was to detect significant performance discrepancies among the algorithms and confirm the statistical significance of these differences. This step is crucial to ensure that our conclusions are robust and not merely the result of random data fluctuations [57].

Specifically, we conducted a detailed comparative analysis of the efficacy of various optimization algorithms, including GWOCS, GWO, and CS. We assessed their efficiency and robustness by calculating the average of the results from each run, setting a consistent standard for success evaluation. The means and standard deviations were computed using Eqs. (41) and (42), respectively. Moreover, we analyzed stability to gauge performance consistency under varying initial conditions and across multiple iterations, employing standard deviation as a measurement metric.

$$\mu_{{{\text{algorithm}}}} = \frac{1}{n}\mathop \sum \limits_{i = 1}^{n} x_{i}^{{{\text{algorithm}}}}$$
(41)
$$\sigma_{{{\text{algortihm}}}} = \sqrt {\frac{1}{n}\mathop \sum \limits_{i = 1}^{n} \left( {x_{i}^{{{\text{algorithm}}}} - \mu_{{{\text{algorithm}}}} } \right)^{2} }$$
(42)

In this study, we define \(\mu_{{{\text{algorithm}}}}\) as the mean effectiveness of a specific optimization algorithm, where '\(n\)' represents the total count of iterations, and \(x_{i}^{{{\text{algorithm}}}}\) denotes the outcome of the ith iteration. We focus our analysis on several optimization algorithms, including GWOCS, GWO, and CS, meticulously calculating the average efficacy (\(\mu_{{{\text{algorithm}}}}\)) over multiple iterations. Table 6 presents an extensive compilation of data, detailing the mean, standard deviation, minimum, and maximum results from each algorithm.

Table 6 Average, standard deviation, minimum, and maximum results of the algorithms

Our methodology emphasizes a structured approach, examining the precision and robustness of the model across 40 iterations. We scrutinize the model’s performance, noting the consistency and variability in results, to provide a comprehensive understanding of each algorithm's effectiveness. This structured statistical approach allows us to measure not just the average outcomes but also the range and consistency, providing a holistic view of the model's reliability and the algorithms' performance.

In off-grid scenarios, a reassessment of the GWOCS algorithm’s performance, according to Table 6, is warranted. GWOCS demonstrates a commendable average ACS, outperforming both GWO and CS by incurring lower costs. This indicates GWOCS's superior cost efficiency in these specific conditions. Moreover, GWOCS maintains a relatively low standard deviation under off-grid conditions, signifying consistent and reliable results. In contrast, GWO exhibits a higher average ACS and the largest standard deviation among the three, suggesting potential unpredictability and significant cost variations. CS, while offering competitive average ACS and lower standard deviation than GWO, doesn't quite match the cost-effectiveness and consistency of GWOCS. Therefore, for off-grid scenarios, GWOCS stands out for its economic efficiency and consistent performance.

In on-grid conditions, the CS algorithm emerges as a strong performer. It achieves the lowest average ACS, denoting the most cost-effective solution for these conditions. Its low standard deviation further underscores consistent and reliable performance. The narrow range between its minimum and maximum values suggests predictability and robustness, making CS a preferred choice for optimizing on-grid energy systems. However, the final selection of an algorithm should always be aligned with specific application needs and conditions.

Figures 24a (on-grid) and b (off-grid) visually depicts the distinct performance patterns of GWOCS, GWO, and CS. In Fig. 24a, CS displays remarkable consistency, evidenced by the narrowest interquartile range and minimal outliers, highlighting its robust and predictable performance in on-grid conditions. Conversely, Fig. 24b shows GWOCS excelling in off-grid scenarios with a higher median and a comparably narrow interquartile range, indicating its superior and stable performance. These observations suggest that while the CS algorithm may be more suited to on-grid applications, GWOCS appears to be tailored for off-grid environments, with each algorithm exhibiting strengths in its respective optimal operating condition.

Fig. 24
figure 24

Comparative performance distribution of the GWOCS, GWO, and CS algorithms: a on-grid and b off-grid

Upon examining Figs. 25a, b, we can decipher the performance metrics distribution for GWOCS, GWO, and CS algorithms through their respective histograms. In Fig. 25a, the GWOCS histogram exhibits a tight clustering of values around the mean, indicative of consistent outcomes. The distribution is left-skewed, meaning most trials yield performance above the average, a sign of a generally reliable algorithm. GWO's histogram, in contrast, reveals a broader spread of results, reflecting its greater variability in performance. However, its more symmetrical distribution around the mean suggests a balance of outcomes above and below the average. CS presents a wide distribution, with the highest frequency of outcomes still near the mean, indicating that while its performance can vary widely, it typically hovers around the average.

Fig. 25
figure 25

Probability distribution of the results for the GWOCS, GWO, and CS algorithms: a on-grid and b off-grid

In Fig. 25b, the distribution for GWOCS is markedly concentrated around the mean, with a rapid decline in frequency as one moves away from this central value. This pattern reflects a robust algorithm where performance predictably hovers around a central tendency. GWO, while still displaying a wide range of outcomes, shows a noticeable concentration of values near the mean, suggesting a fair degree of predictability despite its variability. CS, with the widest variance, has a less pronounced peak, indicating that while it has a significant number of trials achieving near-mean performance, its outcomes are the least consistent among the three.

These histograms provide crucial insights into the algorithms’ reliability and predictability under various conditions. GWOCS stands out for its repeatability and tight performance range, making it a potentially reliable choice where consistency is key. GWO, with moderate variability, might be suited for scenarios where some degree of unpredictability is acceptable or even beneficial. CS, with its broad range of outcomes, could be preferred in situations where the system needs to be robust against a wide variety of scenarios, even if it means a less consistent performance.

Understanding these distributions is vital for practical applications. The trade-offs between consistency, variability, and the likelihood of extreme outcomes must be carefully considered against the specific needs and constraints of the task at hand. This detailed histogram analysis, therefore, provides valuable guidance for algorithm selection in real-world scenarios.

4.1.1 Cohen's d test analysis

In this study performed, we measured the mean differences between two separate entities using the Cohen’s d metric for effect size. This metric quantifies the magnitude of the difference between two groups and is expressed mathematically in Eq. (43), as referenced in [58]:

$$d = \frac{{M_{1} - M_{2} }}{{SD_{{{\text{pooled}}}} }}$$
(43)

To calculate Cohen’s d, one subtracts the mean (\(M_{1}\)) of the first group from the mean (\(M_{2}\)) of the second group and divides the result by the pooled standard deviation (\(SD_{{{\text{pooled}}}}\)). The pooled standard deviation is a measure that combines the standard deviations of the two groups (\(SD_{1}\) and \(SD_{2}\)) and considers their respective sample sizes (\(n_{1}\) and \(n_{2}\)). The formula for calculating the pooled standard deviation is provided in reference [59].

According to Cohen’s classification from 1988, as cited in [60], effect sizes can be interpreted as small (0.20), medium (0.50), or large (0.80) based on the d value. This classification aids researchers in understanding the practical significance of the observed differences. For instance, a small effect size might indicate a subtle difference between groups that, while statistically significant, may not have practical implications. Conversely, a large effect size suggests a more substantial difference that could be of significant interest in practical applications or further research.

Understanding the effect size is crucial in this study as it helps to quantify the magnitude of the observed differences and provides insights into their practical significance. By employing Cohen’s d, we can offer a more nuanced interpretation of the data, moving beyond merely noting whether differences exist or not.

Additionally, the calculation of Cohen’s d involves the pooled standard deviation, which is computed as shown in Eq. (44):

$$SD_{{{\text{pooled}}}} = \sqrt {\frac{{\left( {n_{1} - 1} \right) \times SD_{1}^{2} + \left( {n_{2} - 1} \right) \times SD_{2}^{2} }}{{n_{1} + n_{2} - 2}}}$$
(44)

In the analysis presented in Table 7, the performances of the GWOCS, GWO, and CS algorithms are compared using Cohen's d effect size. This statistical method provides a quantitative measure of the variance in performance between the algorithms, ensuring an objective assessment.

Table 7 Average, standard deviation, minimum, and maximum results of the algorithms

In the initial simulation study, each algorithm underwent comparative analysis over 100 iterations. For the statistical analysis, with the intent to alleviate computational burden, we incrementally increased the iteration count from the 1st through the 40th in both on-grid and off-grid optimization scenarios. This procedure was uniformly applied to all three algorithms, culminating in a total of 240 executions. Our methodological approach in this empirical investigation facilitated the identification of pronounced performance disparities among the algorithms. The Cohen’s d results, as presented in our results section, affirmed the superior performance of the GWOCS algorithm in off-grid environments (d = − 0.28468 with GWO, d = − 0.29339 with CS) and the CS algorithm in on-grid environments (d = 0.20069 with GWOCS, d = 0.020114 with GWO). These effect sizes suggest small to moderate performance differences. These findings align with the fitness curves depicted in our study, which suggest that GWOCS and CS are particularly well-suited to their respective operational conditions. Despite the limited number of iterations, the robustness of these trends was evident and supported our premise that conducting a high number of iterations, while beneficial for comprehensive pattern recognition, is not strictly necessary to establish reliable algorithmic performance trends. The data derived from this study serve as a strong argument for the strategic deployment of these algorithms, endorsing GWOCS for scenarios lacking grid infrastructure and CS for scenarios with available grid connectivity.

4.1.2 Wilcoxon rank-sum test

The Wilcoxon rank-sum test, also known as the Mann–Whitney U test, is primarily used for assessing the distributions of two independent samples, as cited in [61]. This nonparametric test serves as an alternative to the t-test and is particularly beneficial when the data do not follow a normal distribution. It is a valuable tool for statistically verifying whether there is a significant difference in the medians of two distinct groups. The test's significance is typically determined by the p-value it yields. Generally, a p-value less than 0.05 is considered to suggest a statistically meaningful difference between the medians of the groups [62]. The fundamental equation used in the Mann–Whitney U test, or the Wilcoxon rank-sum test, is denoted in Eq. (45):

$$U = n_{1} \times n_{2} + \frac{{n_{1} \times \left( {n_{1} + 1} \right)}}{2} - R_{1}$$
(45)

In the analysis conducted, the number of observations in the first and second groups is denoted by \(n_{1}\) and \(n_{2}\), respectively. The cumulative ranks of the first group are indicated by \(R_{1}\). This equation is critical for assessing the disparities between the two groups. The \(U\) statistic plays a significant role in this context, reflecting the degree of difference in the distributions of the groups. Typically, a smaller \(U\) value is indicative of a more substantial disparity between the groups [63].

It is important to understand that employing this equation and interpreting its results requires an in-depth knowledge of statistical techniques. The interpretations made from such statistical tests are contingent upon the nature of the data, the size of the sample, and other pertinent aspects.

Table 8 presents the Wilcoxon rank-sum test results for pairwise comparisons among various algorithms, providing insightful perspectives on their relative performance. Notably, the test results indicate significant disparities in several comparisons.

Table 8 Wilcoxon rank-sum test results

In our investigation, the Wilcoxon rank-sum test was employed to statistically discern performance differences between the algorithms, as delineated in Table 8. For on-grid scenarios, the GWOCS-GWO comparison yielded a p-value of 9.386391 \(\times 10^{ - 1}\), indicating no significant difference in their performance and suggesting similar median ranks. Conversely, both the GWOCS-CS and GWO-CS comparisons manifested highly significant p-values of 1.306156 \(\times 10^{ - 5}\) and 3.975383 \(\times 10^{ - 6}\), respectively. These results signify substantial performance disparities, particularly underscoring the superior median performance of CS in on-grid environments.

In off-grid conditions, the p-values for GWOCS-GWO (0.4079309), GWOCS-CS (0.2144911), and GWO-CS (0.6912264) were all above the conventional alpha level of 0.05, denoting no statistically significant differences in performance. This implies a relative homogeneity in the median performance ranks of these algorithms when operating off-grid, suggesting that no algorithm distinctly outperforms the others under these conditions.

These statistical insights from the Wilcoxon rank-sum test provide a rigorous, nonparametric analysis of the algorithms’ performance, reinforcing our understanding from previous analyses. The findings elucidate the context-dependent performance efficacy, pivotal for guiding the selection of algorithms in practical applications where on-grid and off-grid scenarios present distinct operational challenges.

4.1.3 Correlation matrix analysis of algorithm performance

The primary aim of conducting a correlation matrix analysis is to determine the level of agreement or discrepancy in the performance of different algorithms, utilizing this information for enhanced strategic algorithm selection [64]. Within the matrix, the diagonal represents each algorithm's self-correlation, invariably marked with a value of 1; thus, these figures are omitted from the analysis.

The intensity and shade depicted in the matrix convey the strength of the relationships between the algorithms [65]. Remarkably, the matrix showcases a range of correlations, from strong to weak, illustrating various degrees of concordance or discordance in the performance of the algorithms. This detailed correlation study not only sheds light on the relative advantages and disadvantages of each algorithm but also indicates potential pairings or collective strategies that could leverage these interrelations to enhance optimization results. The in-depth insights gained provide a more intricate understanding of algorithm behavior and can profoundly influence the strategic choice and implementation of these techniques in complex optimization scenarios.

The correlation matrices in Fig. 26a, b represent the relationships between the performance results of the GWOCS, GWO, and CS algorithms under two distinct conditions: on-grid and off-grid.

Fig. 26
figure 26

Probability distribution of the results for the GWOCS, GWO, and CS algorithms: a on-grid and b off-grid

The analysis presented in Fig. 26a demonstrates a strong positive correlation between the performances of GWOCS and GWO under on-grid conditions, with a correlation coefficient determined to be 0.9339. This high correlation suggests that these two algorithms' performances are closely linked under similar conditions, with improvements in one algorithm's performance positively influencing the performance of the other. Although the correlation between GWOCS and CS is lower, at 0.6382, it still indicates a significant correlation between the results obtained from these algorithms. The 0.741 correlation between GWO and CS indicates a robust relationship between their performances, suggesting that improvements in one algorithm are likely to be mirrored by the other.

In the off-grid scenario, as examined in Fig. 26b, the correlation coefficients between the algorithms are significantly lower compared to the on-grid conditions. The correlation coefficient of 0.3185 between GWOCS and GWO implies that off-grid conditions may have different impacts on the performance of these algorithms. The correlation coefficients of 0.2229 between GWOCS and CS and 0.1399 between GWO and CS suggest that these algorithms might exhibit independent and variable performances under off-grid conditions. This variation underscores the necessity of careful consideration of specific circumstances and requirements when selecting algorithms for off-grid scenarios.

These statistical insights from the Wilcoxon rank-sum test provide a rigorous, nonparametric analysis of the algorithms’ performance, reinforcing our understanding from previous analyses. The findings elucidate the context-dependent performance efficacy, which is pivotal for guiding the selection of algorithms in practical applications where on-grid and off-grid scenarios present distinct operational challenges.

5 Conclusions

In this study, we implemented GWOCS, GWO, and CS metaheuristic algorithms to establish an optimization model for both on-grid and off-grid hybrid energy systems, constituted of PV, WT, diesel generator, and battery components. In each model presented, the main energy source is renewable energy, with battery banks serving as intermediary energy sources, and diesel generators and the grid acting as secondary energy sources. For the off-grid model, a single-objective function, ACS, was utilized, while in the on-grid model, ACS, LCOE, and TNPC were employed. The primary goal of this optimization has been to meet the university campus’s energy needs fully, minimize total annual costs, and identify the optimal capacities for PV panels, wind turbines, batteries, and diesel generators. Both the on-grid and off-grid models were compared technically and economically, and it was confirmed that the on-grid model was the more effective of the two.

In this study, we implemented the hybrid GWOCS metaheuristic algorithm to optimize an off-grid HRES. The optimization resulted in an ACS of $671570.577, a LCOE of $0.180026, a TNPC of $10,899,774, and a REF of 100%. The algorithm’s performance, as evidenced by convergence curves, demonstrated its superior convergence rate relative to other tested algorithms. The CS algorithm was employed for the optimization of the on-grid system, meeting the current demand with a 2963.827 kW solar panel array, a battery storage system with a capacity of 201.8896 kW, and drawing 821.2 MWh energy from the grid. The HRES's TNPC value is 4815520.2794 USD, the ACS value is 475782.8240 USD, and the LCOE value is 0.12754 USD/kWh. Throughout the year, an excess energy of 1383.8 MWh produced from RES is sold back to the grid, thus generating income.

In our comprehensive statistical analysis, meticulous attention was paid to the distinct performance characteristics exhibited by the GWOCS, GWO, and CS algorithms in various scenarios. This in-depth analysis significantly highlights the performance differences between the algorithms, bringing to the forefront the unique strengths of each. Notably, the CS algorithm has demonstrated superior efficiency in grid-connected HRES environments, delivering optimal results and reinforcing its suitability for such settings. Conversely, in off-grid HRES situations, the GWOCS algorithm has showcased its adaptability and resilience under isolated and variable conditions by exhibiting higher performance. These outcomes underscore the critical importance of contextual factors in the selection of algorithms. It is concluded that employing the CS algorithm for grid-connected systems and GWOCS for off-grid systems is more appropriate in terms of performance and reliability in practical applications. This study makes a significant contribution to the nuanced understanding of algorithmic effectiveness in varying energy system environments.

The HRES proposed fulfills the load demand at all times of the year with a 100% renewable energy factor, and due to the diesel generator not being operated at any point during the year, the total gas emission value is null. This result of optimization has demonstrated that the load is entirely met at the university campus, the cost is comparatively low, and there is minimal environmental damage.

Even though the inherent variability of RES such as solar and wind energy might prevent their selection in all optimal systems, the steady energy source provided by the grid, batteries, and diesel generators deem them indispensable power generators for all optimal systems. The state of energy sources and loads collectively manage the optimal architecture of the HRES; while the load defines the total energy demands to be supplied, the configuration of the producer apparatus distributing this energy depends on the conditions of the energy sources. Furthermore, the ratio between energy sources and storage devices is determined by both the conditions of energy sources and loads.

In conclusion, the methodology delineated in this study can provide an efficient framework for the design and evaluation of HRES. Moreover, when considering local resource conditions and load data, this comprehensive research can be utilized to estimate the performance of any system in a different city and pinpoint the most suitable system for the specified location. In future research, given that the load used is akin to the type of load stated in this study (university campus, commercial building, hospital, etc.), and the community is of a comparable size, it can be directly applied when data on load and climate conditions are accessible.