1 Introduction

Recent advancements in renewable energy sources (RESs) have garnered significant attention from both engineers and academics due to their potential to reduce fossil fuel reliance and mitigate environmental issues [1]. RESs offer notable benefits including reduced power losses, improved power quality, increased reliability, and environmental advantages [2]. However, their integration into distribution networks poses challenges such as increased complexity in control, protection, and operation [3]. The concept of microgrids (MGs) has emerged as a promising solution to address these challenges by combining controllable loads with distributed generation (DG) systems [4]. The development of electric vehicles (EVs) and increased energy efficiency relies on microgrids (MGs), which can function both independently and in conjunction with the main grid. [5,6,7,8]. Despite their advantages, integrating high RES penetration and EVs can lead to issues like power quality degradation, increased system demand, and infrastructure [9] costs. Before proceeding further, Table 1 lists the abbreviations for a better understanding of the paper.

Table 1 List of Abbreviations

Many related studies based on MG energy management using renewable energy may be found in the literature. A few of them are assessed here.

Torkan et al., [10] has developed a multi-objective genetic algorithm (MOGA) to address the MG’s technical and financial issues. Reactive loads, demand response (DR) programs, and uncertainties resulting from renewable energy sources are all taken into account in this stochastic programming.

Kavitha et al., [11] have developed an energy management plan based on Mimosa pudica for the best microgrid scheduling to minimize production overheads while taking into account underlying system limits. Furthermore, the suggested method was developed to control the power balancing between the dispersed resources and utilities using a common communication protocol.

Bukar et al., [12] have introduced a metaheuristic optimization searching method (MOST) and a rule-based algorithm for the size of an autonomous microgrid and energy management (EM), respectively. The energy management scheme’s (EMS) goal was to establish a power supply schedule for each of the microgrid’s several parts.

Merabet et al., [13] have suggested improving the energy management system to reduce the battery storage and energy coasts of a hybrid solar and wind microgrid with grid connectivity.

Hai et al., [14] have investigated in the research the impacts of different weather conditions on the PV unit’s power output and the best time to schedule the MG. In order to do this, solar irradiance measurements were collected on four separate days throughout each of the four seasons. The single-objective optimization framework that was utilized to generate the scheduling problem states that the target function should be to minimize the total operational cost over the scheduling period. The "hybrid whale optimization algorithm and pattern search (HWOA-PS)" optimization method can handle the aforementioned day-ahead scheduling problem, and energy storage systems, as well as non-renewable and renewable producing units, were described.

Sun et al., [15] have presented a system-level optimization technique for engines and motors that uses layered design to address the issue of linking the control algorithm’s parameters with the physical system’s characteristics.

Sun et al., [16] have developed a system-level optimization (SLO) that relies on the collection of road information. The control strategy was categorized into online and offline parts. First, the speed information throughout the entire driving process was obtained by integrating the global positioning system with real-time vehicle map data. Subsequently, the K-means clustering method was employed to classify distinct kinematic segments based on several characteristic parameters.

Sun et al., [17] have suggested a method for energy management that takes power splitting and gear shift control into account. The dynamic programming approach was used to compute a large quantity of gear-switching data for gear shift management under various working situations. In the offline portion, these data are used to train the neural network so that in the online model, it can deliver the proper gear-switching signal on time. This paper primarily chooses an enhanced equivalent fuel consumption minimization method (ECMS) for power-split control, and then iteratively solves the best equivalent factor using the gray wolf optimization technique.

Recent research on microgrid (MG) energy management using renewable energy sources highlights several optimization approaches with distinct strengths and limitations. One method utilizes a multi-objective genetic algorithm (MOGA) to address technical and economic challenges, focusing on minimizing costs and greenhouse gas (GHG) emissions through demand-side management. While effective, its stochastic nature may limit adaptability to changing conditions. Another approach employs a bioinspired scheme based on plant behavior for optimal scheduling and power balancing, though its implementation can be complex. Rule-based algorithms combined with metaheuristic optimization techniques offer effective power delivery solutions but may not fully account for the variability of RES. Advances in energy management systems for hybrid solar and wind microgrids emphasize optimizing battery usage and energy costs, but may struggle with fluctuating electricity prices. Stochastic optimization methods provide robust day-ahead scheduling but may need refinement for broader applicability. System-level optimizations integrating parameter coupling between physical systems and control algorithms offer detailed sensitivity analysis but face challenges in generalizability. Methods focusing on gear shift control and power splitting, using neural networks and optimization algorithms demonstrate advanced control but require comprehensive data integration. By filling these gaps, energy management answers may become even more effective and applicable.

The gravitational search algorithm (GSA) was chosen for this study due to its strong capability to balance exploitation and exploration, which is crucial for optimizing complex microgrid energy management systems. While many existing studies have applied improvements to GSA to address stagnation issues, the proposed method introduces a novel adaptation by focusing on the precise identification of control signals based on power differentials between RESs and load sides. This adaptation enhances the traditional GSA framework by optimizing performance specifically for microgrid applications, addressing constraints like energy consumption and storage levels more effectively. The novelty of this approach lies in its tailored use of GSA to create a cost-efficient solution that outperforms established techniques, such as modified PSO (MPSO) and genetic algorithms (GAs), concerning both cost and performance.

  • Novel application of the gravitational search algorithm (GSA) to optimize energy management in microgrids with re RESs, enhancing performance and efficiency.

  • Achieved a notable reduction in energy management costs, with the proposed method demonstrating a cost of $1.1, outperforming existing optimization techniques.

  • Validated the proposed methodology through detailed MATLAB simulations, showcasing its superior performance compared to established methods.

  • Developed an innovative approach for accurately managing control signals, and optimizing power distribution between the source and load sides.

  • Provided a thorough performance evaluation and statistical analysis, including comparisons with modified particle swarm optimization (MPSO), GA, and PSO, demonstrating the proposed method’s effectiveness across multiple metrics.

This paper’s remaining sections are organized as follows: the configuration of microgrid energy management with the renewable energy system is shown in Part 2. Part 3 provides the proposed method based on the microgrid. In Part 4, results and a discussion are given. The manuscript is finally concluded in Part 5.

2 Configuration of microgrid energy management with renewable energy system

This incorporates sophisticated control algorithms that give priority to renewable energy sources like solar, wind, or hydroelectric electricity while constantly balancing supply and demand. Batteries and other energy storage technologies are frequently used to reduce intermittent power and provide steady power supply. Smart grid technologies improve system resilience and efficiency by enabling adaptive control and real-time monitoring.

Figure 1 depicts the architecture of a microgrid energy management system integrating RESs like solar PV and wind turbines, managed by a proposed controller based on the GSA. The microgrid comprises three feeders: Feeder A is connected to the solar PV system, while Feeder B integrates wind turbines, a battery storage system and a fuel cell, which is managed by a charge controller. Feeder C is linked to the main grid through a transformer at the point of common coupling (PCC). On every feeder, power and voltage (P&V) meters and circuit breakers are installed to monitor and regulate the flow of electricity. The GSA-based controller optimizes the energy management by accurately identifying control signals, considering the power differential between the RESs and the load. A static switch is used to manage the connection between Feeder B and the grid, ensuring stable power flow and system reliability. The battery storage system helps stabilize the output by compensating for fluctuations in renewable energy generation, allowing the microgrid to efficiently manage energy resources while minimizing costs.

Fig. 1
figure 1

Architecture of Proposed Method

2.1 Controller with microgrid

The architecture consists of a range of MG kinds, including PV, WT, FC, and DG, as well as point of common coupling, radial feeders, and delicate loads. The breakers will shield the system from damage in an unexpected disaster [18, 19]. To meet the load requirement and charge the battery, the entire system is utilized. The MGs architecture generated the electrical power. Fuel must be added to the FC and DG energy sources in order for them to produce electricity. The MG setup and the mathematical model were taken into consideration. To fulfill the load requirement and charge the battery, the complete system is used. All of the MGs supply the load and the batteries. The output of MGs is directly delivered to power the battery and satisfy load requirements, which can be mathematically described as follows,

$$\sum\limits_{i = 1}^{n} {P_{gi} } = P_{l} - P_{pv} - P_{wt} - P_{Bat} \,\,\,$$
(1)

here,the power generation is denoted by \(Pgi\), the power demand by \(Pl\), the battery’s output power, expressed in kW, by \(P_{Bat}\), The output power of the solar system by \(P_{PV}\), and the output power of WT by \(Pt\). The following boundaries can be used to limit the generated power.

$$P_{gi}^{\min } \le P_{gi} \le P_{gi}^{\max }$$
(2)

here \(P_{gi}^{\min }\) is the minimum and \(P_{gi}^{\max }\) be the maximum power generated in unit \(i\). Grid and load mode analysis is used to examine the PFM of HRES [20]. The following power balancing equation is conveyed; both the DC-link and the PCC must satisfy it.

$$P_{hres} (t) = P_{wt} (t) + P_{pv} (t) + P_{fc} (t) + P_{bat} (t)$$
(3)

In this instance, the total power of the available RES at time \(t\) is indicated by \(P_{hres} (t)\). The equation above serves as an illustration of the system total power flow concept. The system power balances in the grid and load connected mode are obtained from the previous Eqs. (4) and (5), and with the HRES results, the active power control procedure is complete and the necessary loads \(P_{grid} (t),\) and \(P_{load} (t)\).

$$P_{grid} (t) = P_{load} (t) - P_{hres} (t)$$
(4)
$$P_{load} (t) = P_{hres} (t) + P_{grid} (t)$$
(5)

The following algorithms are used to find \(Q_{grid} (t)\) and \(Q_{load} (t)\), which perform reactive power regulation in grid and load linked mode:

$$Q_{grid} (t) = Q_{load} (t) - Q_{hres} (t)$$
(6)
$$Q_{load} (t) = Q_{hres} (t) + Q_{grid} (t)$$
(7)

When the battery power storage device is charging, it is referred to as the load, and when it is discharging, it is called the source. The amount of power generated by the load through the DC connection may be ascertained using the following equation:

$$P_{DC - link} (t) = C_{DC - link} \frac{{dV_{DC - link} }}{dt}V_{DC - link}$$
(8)
$$P_{DC - link} (t) = P_{hres} (t) - P_{grid} (t)$$
(9)

here the grid power operator at time \(t\) is \(P_{grid} (t)\), the DC-link voltage and capacitance are \(V_{DC - link}\) and \(C_{DC - link}\), and the DC-link resulting power during time \(t\) is \(P_{DC - link} (t)\).

2.2 Modeling of solar PV

Understanding the solar resources available at the microgrids location is essential. This involves assessing solar irradiance levels, weather patterns [21, 22], and seasonal variations to estimate the energy generation potential of the solar photovoltaic system.

The solar photovoltaic panel’s single diode equivalent circuit is displayed. Equation can be used to express the solar PV array’s output current.

$$I_{pv} = I_{pb} N_{p} - I_{o} N_{p} \left( {e^{{\left( {\frac{{V + IR_{s} \left( {\frac{N}{{N_{p} }}} \right)q}}{{n^{*} K^{*} T^{*} N_{s} }}} \right)}} - 1} \right) - \frac{{V + IR_{s} \left( {\frac{N}{{N_{p} }}} \right)}}{{R_{p} \left( {\frac{{N_{s} }}{{N_{p} }}} \right)}}$$
(10)

\(I_{0}\) stands for reverse saturation current, \(I_{ph}\) for photon current, and for an \(I_{pv}\) solar panel output, \(N_{p}\) and \(N_{s}\) stand for the quantity of solar PV modules linked in parallel and series, respectively. Electron charge is represented by \(q\), and the Boltzmann constant by \(k\), the factor of ideality (1 or 2) by n, solar panel surface temperature T, and so on. Reverse saturation current \(I_{0}\) temperature-dependent characteristic.

By addressing these key aspects of energy management, a microgrid powered by solar PV can achieve increased energy efficiency, reliability, and resilience while reducing carbon emissions and dependence on traditional grid infrastructure.

2.3 Modeling of fuel cell

Fuel cells with proton exchange membranes have several advantages, including the ability to run quietly, swiftly, at low temperatures, and with a high energy density despite their tiny size (up to 2 W/cm2). Its efficiency can reach up to 45%. The primary benefit of the PEMFC is its low pollution level, as the hydrogen fuel utilized in FC doesn’t have any negative environmental consequences [23, 24]. Despite the benefits of the FC, there are many drawbacks as well. These include the FC’s unstable output voltage, poor reaction to changes in load, limited lifespan due to increased current ripple, and relatively high cost.

The modeling and simulation of the FC were discussed in eq.

$$A = \frac{RT}{{z\alpha F}}$$
(11)
$$E_{oc} = E_{n} K_{c}$$
(12)
$$i_{o} = \frac{{zFk\left( {P_{{H_{2} }} + P_{{O_{2} }} } \right)}}{RH}e^{{\frac{ - \Delta G}{{RT}}}}$$
(13)

here, \(K_{c}\) represents the voltage constant under normal operating conditions, while \(T\) represents the operating temperature., \(\Delta G\) is the activation barrier’s size, which varies depending on the catalyst and electrode type utilized; \(h\) denotes Planck’s constant, \(z\) stands for the number of electrons in motion; \(k\) represents the Boltzmann’s constant; \(P_{{H_{2} }}\) indicates the hydrogen partial pressure inside the stack and \(P_{{O_{2} }}\) indicates the oxygen partial pressure within the stack.

The following formula is used to get the fuel and air usage factor:

$$U_{{fO_{2} }} = \frac{{n_{{O_{2} }}^{r} }}{{n_{{O_{2} }}^{in} }} = \frac{{6000RTN_{ifc} }}{{2zFP_{air} V_{{imp\left( {air} \right)}} y\% }}$$
(14)
$$U_{{fH_{2} }} = \frac{{n_{{H_{2} }}^{r} }}{{n_{{H_{2} }}^{in} }} = \frac{{6000RTN_{ifc} }}{{zFP_{fuel} V_{{imp\left( {fuel} \right)}} x\% }}$$
(15)

In the case where \(P_{air}\) indicates the air supply pressure in absolute terms and \(P_{fuel}\) denotes absolute supply pressure of fuel; "\(N\)" stands for "number of cells." In Block B, the Nernst voltage is calculated as follows:

$$E_{Nernstt} = 1.229 - \left( {T - 298.15} \right)\frac{ - 44.43}{{zF}} + \frac{ - RT}{{zF}}\ln \left( {P_{{H_{2} }} P_{{O_{2} }}^{\frac{1}{2}} } \right)$$
(16)
$$E_{Nernstt} = 1.229 - \left( {T - 298.15} \right)\frac{ - 44.43}{{zF}} + \frac{ - RT}{{zF}}\ln \left( {\frac{{P_{{H_{2} }} P_{{O_{2} }}^{\frac{1}{2}} }}{{P_{{H_{2} O}} }}} \right)$$
(17)

when \(T > 100^\circ C\),

In block B, the partial pressures for \(H_{2}\), \(O_{2}\), and \(H_{2} O\) are also computed using the following formula:

$$P_{{H_{2} }} = \left( {1 - U_{{fH_{2} }} } \right)x\% P_{fuel}$$
(18)
$$P_{{H_{2} O}} = \left( {W + 2y\% U_{{fO_{2} }} } \right)P_{air}$$
(19)
$$P_{{O_{2} }} = \left( {1 - U_{{fO_{2} }} } \right)y\% P_{air}$$
(20)

here, \(W\) stands for the proportion of water vapor in the oxidant, and \(P_{{H_{2} O}}\) indicates the water vapor’s partial pressure within the stack. The updated values of the open circuit voltage and exchange current Io are \(P_{{H_{2} O}}\), based on the partial pressure and Nernst voltage.

2.4 Modeling of battery

Optimizing the utilization of diverse energy sources within a confined grid system is the aim of microgrid energy management using renewable energy and batteries [25, 26]. Here’s a breakdown of key components and considerations:

These include solar PV panels, WTs, and sometimes hydroelectric or biomass sources. The intermittency of these sources requires sophisticated management to ensure a steady power supply. When renewable energy output is at its lowest, batteries are crucial for storing extra energy produced during peak production periods (such as sunny or windy days). Since lithium-ion batteries have a high energy density and efficiency, they are widely employed. An EMS is the brain of the microgrid, responsible for monitoring energy supply and demand in real-time, forecasting energy production, and maximizing the use of battery storage and RES to satisfy demand while lowering costs and ensuring dependability.

In discharge mode, the following is an illustration of the battery voltage equation:

$$V_{batt} = E_{0} - K\left( {\frac{Q}{Q - it}} \right)i^{*} - K\left( {\frac{Q}{Q - it}} \right)it + Ae^{Bit} \left( {i^{*} > 0} \right)$$
(21)

here, \(E_{0}\) stands for constant voltage in \(V\), and \(K\) for polarization constant in \(Ah^{ - 1}\). In \(A\), \(i^{*}\) indicates the dynamics of low-frequency currents; \(Q\) denotes highest possible capacity of battery.

By effectively integrating renewable energy sources with battery storage and implementing advanced energy management strategies, microgrids can enhance energy resilience, lower greenhouse gas emissions, and support the development of more sustainable energy sources [27].

2.5 Modeling of wind turbine

Managing a microgrid with a wind turbine involves similar principles to those with other renewable energy sources like solar PV. Here’s how energy management with a wind turbine typically works within a microgrid context:

Variable-speed operation is required for the adjustment of blade pitch. The following is the extracted power that a wind turbine produces:

$$Pmw = 0.5\rho AV_{w}^{3} C_{p} \left( {\omega w,\beta w} \right)$$
(22)

here \(V_{w}\), ρ, and \(C_{p}\) stand for wind speed, rotor sweep area, and power factor, respectively, \(C_{p}\) depending on the turbine’s rotatory velocity, the wind speed, and the blade specifications.

By effectively managing energy production from wind turbines and integrating them into microgrid systems, communities can harness clean, renewable energy to enhance energy resilience, mitigate climate change, and lessen dependence on fossil fuels [28, 29].

3 Gravitational search algorithm for optimal microgrid energy management

The GSA is employed to optimize microgrid (MG) configurations by efficiently addressing load requirements and minimizing operational costs. In this context, wind turbines (WTs) and photovoltaic (PV) systems are leveraged for their cost-free generation capabilities, while fuel cells (FCs) and diesel generators (DGs) are utilized to manage power requirements and handle fuel costs. The GSA, inspired by Newton’s laws of motion and gravity, operates by treating potential solutions as search agents, each represented by masses that reflect their performance [30]. These agents are influenced by gravitational forces, which guide them toward optimal solutions. Heavier masses, indicating higher fitness values, attract lighter masses, causing the system to converge on solutions with better performance. The algorithm iteratively adjusts gravitational constants and inertial masses to refine solutions, balancing exploration and exploitation effectively. By using load demand as input, the GSA generates optimal MG configurations, addressing constraints and reducing operational costs. This approach offers a significant advancement over existing optimization methods by providing a more dynamic and effective solution to managing complex microgrid systems. Below is a description of the algorithm’s steps.

Step 1: Initialization.

Set the initial values for power and voltage inputs.

Step 2: Random Generation.

In a matrix, the input parameter appears arbitrarily.

$$X = \,\left[ {\begin{array}{*{20}c} {x_{1,1} } & {x_{1,2} } & {...} & {x_{1,d} } \\ {x_{2,1} } & {x_{2,2} } & {...} & {x_{2,d} } \\ {...} & {...} & {...} & {...} \\ {x_{n,1} } & {x_{n,2} } & {...} & {x_{n,d} } \\ \end{array} } \right]$$
(23)

here, \(X\) indicates the population of the location, \(n\) indicates the count of methods, \(d\) indicates the number of variables.

Step 3: Fitness Calculation.

Using F to find the fitness value

$$F = \alpha .C_{op} + \beta .C_{pen}$$
(24)

where \(C_{op}\) represents the operational cost, which includes expenses related to energy generation, consumption, and storage, \(C_{pen}\) is a penalty term applied when constraints are not fully satisfied, specifically addressing unmet load demand.

The penalty function \(C_{pen}\) is defined as:

$$C_{pen} = \sum\limits_{i = 1}^{N} {\max \left( {0,D_{i} - P_{gen,i} - P_{stor,i} } \right)}$$
(25)

In this equation, \(D_{i}\) denotes the load demand at time \(i\), \(P_{gen,i}\) indicates the power generated at time \(i\), \(P_{stor,i}\) indicates the power supplied by storage systems at time, \(N\) indicates the overall number of time periods.

The term \(\max \left( {0,D_{i} - P_{gen,i} - P_{stor,i} } \right)\) represents the shortfall in meeting the load demand. If \(D_{i}\) exceeds the combined power from generation and storage, the shortfall is penalized.

Optimization of Load Demand:

During the optimization process, the GSA algorithm iteratively adjusts parameters related to energy generation and storage to minimize the fitness function F. By exploring and exploiting potential solutions, the algorithm aims to balance operational cost with the need to meet load demands, as indicated by the penalty term \(C_{pen}\).

The goal is to find optimal values for generation schedules and storage capacities that both minimize cost and ensure that the load demand constraints are met effectively.

Step 4: Constant Gravitational Computation.

The derivation Eq. (26), which uses the iteration, is used to determine the constant gravitational \(G\left( t \right)\).

$$S\left( t \right) = G_{0} \exp \left( { - \alpha \frac{t}{T}} \right)$$
(26)

here, \(T\) stands for the total number of iterations, \(t\) stands for the current time, \(G_{0}\) indicates the gravitational constant selected at random, and \(\alpha\) represents the constant.

Step 5: Update the Inertial Masses.

Subsequent iteration \(t\) updates both the gravitational and inertial masses.

$$mg_{j} \left( t \right) = \frac{{fit_{j} \left( t \right) - worst\left( t \right)}}{best\left( t \right) - worst\left( t \right)}$$
(27)

here \(\,\,fit_{j} \left( t \right)\,\,\) indicates the \(j^{th}\) factor’s fitness.

Below is the mass of the \(j^{th}\) factor.

$$Mg_{j} \left( t \right) = \frac{{mg_{j} \left( t \right)}}{{\sum\nolimits_{i = 1}^{n} {mg_{i} \left( t \right)} }}$$
(28)

Step 6: Total Force Calculation.

The following is the assessment of the overall force applied to the \(j^{th}\) agent at iteration t.

$$F_{j}^{d} \left( t \right) = \sum\nolimits_{i \in kbesti \ne j} {rand_{i} F_{ji}^{d} \left( t \right)}$$
(29)

here, \(rand_{i}\) stands an arbitrary value within the range [0, 1] and the initial K agents consist of those with the highest mass and optimal fitness value.

The force exerted on the \(j^{th}\) mass (\(M_{j} \left( t \right)\)) from the \(i^{th}\) mass (\(M_{i} \left( t \right)\)) is given by the following equation, which is in accordance with the gravitational theory.

$$F_{ji}^{d} \left( t \right) = G\left( t \right)\frac{{M_{j} \left( t \right) \times M_{i} \left( t \right)}}{{R_{ji} \left( t \right) + \in }}\left( {x_{i}^{d} \left( t \right) - x_{j}^{d} \left( t \right)} \right)$$
(30)

here, Euclidian distance between the \(j^{th}\) and \(i^{th}\) agents is indicated by \(R_{ji} \left( t \right)\). and \(\in\) indicates the constant.

Step 7: Acceleration and Velocity Calculation.

The acceleration \(a_{j}^{d} \left( t \right)\) at iteration t and the velocity of the \(j^{th}\) agent at iteration (t + 1) in the \(d^{th}\) dimension are updated using the following equation, which makes use of the laws of motion and gravity.

$$a_{j}^{d} \left( t \right) = \frac{{F_{i}^{d} \left( t \right)}}{{Mg_{j}^{d} \left( t \right)}}$$
(31)
$$v_{j}^{d} \left( {t + 1} \right) = rand_{j} \times v_{j}^{d} \left( t \right) + a_{j}^{d} \left( t \right)$$
(32)

Step 8: Update the best solution.

Next, the following modification was made to the \(j^{th}\) factor’s location in the \(d^{th}\) dimension.

$$x_{j}^{d} \left( {t + 1} \right) = x_{j}^{d} \left( t \right) + v_{j}^{d} \left( {t + 1} \right)$$
(33)

Step 9: Termination.

Check that the stopping requirements are met; if so, the process is finished; if not, go to step3. Figure 2 shows the gravitational search algorithm’s flowchart.

Fig. 2
figure 2

GSA flowchart

4 Results and discussion

The experimental evaluation outcomes of the proposed technique are displayed in this part in comparison to other methods. The proposed method’s performance analysis is compared to the existing approaches, which include PI controller, GA, PSO, and MPSO.

4.1 Performance analysis of the proposed approach

An evaluation of the proposed strategies efficacy is done. By evaluating the proposed method performance and comparing it to the existing in use method, its effectiveness is ascertained.

4.1.1 Case 1: load variation

Figure 1 illustrates the relationship between irradiance and time, showing that the irradiance is maintained constant at 1000 W/m2 despite any load shifts.

Figure 2 provides insights into various power generation and consumption components over time. Subplot 2(a) shows the stability of wind power between 0 and 1 s. The wind power starts at 0 watts, peaks at 3600 watts, and then remains constant after a reduction to its minimum level at 0.5 s. Subplot 2(b) depicts the stability of photovoltaic (PV) power within the same time frame. The PV power ranges from a maximum of 5000 watts to a minimum of 4000 watts, stabilizing between 0.2 and 1 s. In subplot 2(c), the battery power initially rises from 0 watts to a maximum of 1400 watts, then drops to 0 watts, and subsequently increases to 8000 watts at 2.03 s, remaining constant from 0.3 to 1 s. Finally, subplot 2(d) shows the power produced by the proposed method, which increases to 2600 watts within 0.25 s after initially reaching a maximum of 1500 watts. This power then remains steady from 0.3 to 1 s.

Figure 3 presents the power analyses of load, grid, and total power using the Gravitational Search Algorithm (GSA) technique. Subplot 3(a) shows the load power, which peaks at 1.7 watts from 0 to 0.1 s and remains steady between 0.3 and 0.75 s, extending to 2.3 watts and stabilizing from 0.3 to 1 s. Subplot 3(b) depicts grid power, which reaches a maximum of 2 watts between 0.01 and 0.21 s, and remains constant at this level from 0.25 to 1 s. Subplot 3(c) illustrates total power, peaking at 2 watts from 0.01 to 2.5 s and staying constant from 0.25 to 1 s. Figure 4 compares the grid, battery, and total power. In subplot 4(a), grid power starts at a maximum of 1500 watts at 0 s, extends to 6000 watts between 0.01 and 0.25 s, and remains constant at this level from 0.25 to 1 s. Subplot 4(b) shows battery power reaching a maximum of 3500 watts at 0 s and stabilizing between 0.3 and 1 s. In subplot 4(c), total power peaks between 0.4 and 1.9 watts, drops to a minimum of 0.6 watts, and then remains constant until reaching an extended level of 0.8 watts at 0.5 s. Figure 5 analyzes individual power sources and inverter voltage. Subplot 5(a) shows that individual power reaches a maximum of 1400 watts from 0 to 0 s, with a constant level from 0.25 to 1 s using the proposed method with PV, wind, FC, grid, and battery. Subplot 5(b) depicts the inverter voltage, rising to a maximum of 10 watts from 0 to 0.2 s with PI, GA, PSO, and MPSO methods, and then stabilizing from 0.25 to 1 s. Figure 6 compares the fitness of the proposed method with existing techniques (PSO, MPSO, GA, PI). The fitness function ranges from 2.3 to 2.62 watts between 30 and 100 s. The proposed method achieves a fitness value 2% lower than other methods, indicating superior performance in minimizing inaccuracies.

Fig. 3
figure 3

Irradiance vs. Time

Fig. 4
figure 4

Power analyses of (a) Wind (b) PV (c) Battery (d) FC using proposed technique

Fig. 5
figure 5

Power analyses of (a) Load (b) Grid (c) Total power

Fig. 6
figure 6

Power comparison of (a) Grid (b) Battery (c) Total power

4.1.2 Case 2: step irradiation

Figure 7 illustrates the power analysis for wind, battery, photovoltaic (PV), and fuel cell (FC) systems using the proposed method. Subplot 7(a) shows wind power reaching a maximum of 3500 W between 0 and 0.7 s, after which it drops to a minimum and remains constant. Subplot 7(b) depicts PV power, which ranges from 2400 to 4000 W between 0 and 0.75 s. It then decreases to a minimum of 600 W at 0.75 to 0.9 s and stays constant. Subplot 7(c) displays battery power, peaking at 15000 W from 0 to 0.3 s and then remaining constant at 0 W from 0.3 to 1 s. In subplot 7(d), FC power grows to 2600 W at 0.25 s after initially reaching 1500 W, and remains constant from 0.3 to 1 s. Figure 8 provides power analyses of the load, grid, and total power using the Gravitational Search Algorithm (GSA). Subplot 8(a) shows load power reaching its peak of 1.7 W between 0 and 0.2 s, remaining steady from 0.3 to 0.75 s, and then extending to 2.3 W, stabilizing from 0.3 to 1 s. Subplot 8(b) presents grid power, which peaks at 3500 W, then rises to 2000 W between 0.01 and 0.21 s and remains constant from 0.3 to 1 s. Subplot 8(c) illustrates total power, generating a maximum of 1.5 W between 0 and 0.5 s, extending to 2.5 W from 0.01 to 2.5 s, and remaining constant from 0.25 to 1 s. Figure 9 compares the power of grid, battery, and total power. Subplot 9(a) displays grid power, which reaches a maximum of 1600 W at 0 s, extends to 6000 W between 0.01 and 0.25 s, and remains constant from 0.25 to 1 s. Subplot 9(b) presents battery power, peaking at 3500 W at 0 s and remaining constant from 0.3 to 1 s. Subplot 9(c) displays total power, reaching a maximum between 0.4 and 1.9 W, dropping to a minimum of 0.6 W at 1.5 s, and then rising to 0.8 W at 0.5 s before stabilizing.

Fig. 7
figure 7

Comparison analysis of (a) Individual power (b) Inverter voltage

Fig. 8
figure 8

Fitness comparison of proposed with existing techniques

Fig. 9
figure 9

Power analyses of (a) Wind (b) PV (c) Battery (d) FC using proposed technique

Figure 10 provides comparative analyses of individual power and inverter power. Subplot 10(a) displays that individual power reaches a maximum of 1400 W between 0 and 0.25 s, with the proposed technique integrating PV, Wind, FC, Grid, and Battery systems. Between 0.25 and 1 s, this power stays constant. In Subplot 10(b), the inverter voltage increases to a peak of 10 W between 0 and 0.2 s, with the proposed method being compared to PI, GA, PSO, and MPSO techniques. The inverter voltage stays constant from 0.25 to 1 s. Figure 11 presents the fitness comparison of the proposed method against existing techniques (PI, GA, PSO, and MPSO). The fitness function ranges from 2.3 to 2.62 W over a 30 to 100-s period, with the proposed method showing a 2% improvement over the other methods. Figure 12 illustrates irradiance held constant at 1000 W/m2 from 0 to 1 s, despite load variations. Figure 13 details power stability across wind, PV, battery, and FC systems: Subplot 13(a) shows wind power starting at 0 W, peaking at 3600 W, and then maintaining a constant minimum level from 0.5 to 1 s. Subplot 13(b) depicts PV power varying from 2600 to 5000 W, dropping to 4000 W between 0.75 and 0.9 s, and remaining constant from 0.2 to 1 s. Subplot 13(c) illustrates battery power reaching a maximum of 1400 W from 0 to 0.3 s, expanding to 8000 W at 2.03 s, and remaining constant from 0.3 to 1 s. Subplot 13(d) shows the proposed method’s power growing to 2600 W at 0.25 s after an initial maximum of 1500 W and remaining unchanged from 0.1 to 1 s. Figure 14 presents power analyses of load, grid, and total power using the Gravitational Search Algorithm (GSA): Subplot 14(a) shows load power peaking at 3500 W between 0 and 0.1 s, steady from 0.3 to 0.75 s, and increasing to 2.3 W from 0.3 to 1 s. Subplot 14(b) depicts grid power reaching 2 W between 0.5 and 2 s, and remaining steady from 0.25 to 1 s. Subplot 14(c) illustrates total power generating up to 2 W between 0 and 0.5 s, extending to 2.5 W from 0.01 to 2.5 s, and remaining constant from 0.25 to 1 s.

Fig. 10
figure 10

Power analyses of (a) Load (b) Grid (c) Total power

Fig. 11
figure 11

Power comparison of (a) Grid (b) Battery (c) Total power

Fig. 12
figure 12

Comparison analysis of (a) Individual power (b) Inverter voltage

Fig. 13
figure 13

Fitness comparison of proposed with existing techniques

Fig. 14
figure 14

Irradiance vs. Time

In Fig. 15 the Power comparison of Grid, Battery, and Total power are given in subplot 15(a)-(c). In 15(a) illustrated about the grid power. During the time interval of 0s, the power reaches the maximum level at 0-1500w. And at time period 0.01–0.25, the power in extended level and it remain constant at 0.25-1s at the level of 6000w. In subplot 15(b) &(c), the Battery and total power is considered. In 15(b), the power achieves its maximum level at 0-3500w at time interval 0s, and it stays constant at 0.3-1s. In 15(c) from 0.4 to 1.9, the power reaches the maximum level and it remains minimum level at 1.5–0.6w. After that, it stays constant until it reaches the extended level at 0.8w at 0.5s. Figure 16 illustrates the microgrid system’s performance with the GSA across various load conditions. Subplot 16(a) shows load power peaking at 14,000 W and stabilizing at 5,000 W, indicating consistent demand. Subplot 16(b) depicts inverter voltage reaching 35 V within the first 0.2 s and then remaining constant, reflecting effective voltage management. Subplot 16(c) illustrates the total power output of the proposed system, emphasizing its peak performance and stability over time. The plot reveals that the system, optimized using the GSA, maintains a high and consistent power output, crucial for reliably meeting load demands. This stability is significant as it reflects the system’s capability to effectively integrate and manage power from various renewable sources and storage units. The observed performance underscores the GSA’s efficacy in ensuring consistent power delivery and optimizing the energy management strategy. Figure 17 breaks down power contributions from different sources, with Subplot 17(a) showing grid power peaking at 1,500 W and stabilizing at 6,000 W, Subplot 17(b) indicating battery power reaching 3,500 W, and Subplot 17(c) combining these to demonstrate total power availability. Figure 18 compares the performance of individual power sources and inverter voltage stability across different control strategies, highlighting the proposed method’s effectiveness. Figure 19 illustrates the fitness comparison between the proposed and existing methods. The proposed method is contrasted here with other methods that are currently in use, including PI, GA, PSO, and MPSO. The fitness function of PI controller converges at the iteration of 48 and GA converges at 42. The PSO converge the iteration of 40 and MPSO is 33 and the proposed technique converges efficiently than the existing methods. Figure 20 presented a cost comparison of the proposed and existing methods. The cost reduction analysis further highlights the advantages of using GSA over other optimization techniques. The GSA achieves a notable cost reduction, with a total operational cost of $1.1, compared to $2.2 for the GA, $3.2 for PSO, and $4.2 for MPSO. This substantial difference demonstrates the GSA’s superior efficiency in minimizing costs while maintaining system performance. The reduced expenditure is attributed to GSA’s optimized resource allocation and effective reduction of unnecessary operational costs. This performance not only enhances the economic viability of the energy management system but also showcases the GSA’s potential for broader application in optimizing cost-effective energy solutions. Test system parameters are presented in Table 2. Statistical parameters of different optimization approaches is presented in Table 3. Table 4 presents a comparative analysis of different optimization algorithms, focusing on performance metrics such as best, worst, mean, median values, variance, standard deviation, and elapsed time. The proposed method achieves the best performance with the lowest best value of 389.315 and a mean value of 415.800, outperforming MOST, ARO, and HWOA-PS. It also demonstrates superior efficiency with the shortest elapsed time of 192.085 s. The proposed method’s variance (795.807) and standard deviation (0.00047) are significantly lower than those of the other approaches, demonstrating improved consistency and stability of the results. However, its worst value of 469.758 is higher than MOST’s worst value, suggesting some potential for higher worst-case scenarios. Overall, the proposed method excels in both efficiency and reliability.

Fig. 15
figure 15

Power analysis of (a) Wind (b) PV (c) Battery (d) FC using proposed technique

Fig. 16
figure 16

Power analysis of (a) Load (b) Grid (c) Total power

Fig. 17
figure 17

Power comparison of (a) Grid (b) Battery (c) Total power

Fig. 18
figure 18

Comparison analysis of (a) Individual power (b) Inverter voltage

Fig. 19
figure 19

Fitness comparison of proposed with existing techniques

Fig. 20
figure 20

Comparison of proposed with existing techniques

Table 2 Test system parameters
Table 3 Parameter table of GSA
Table 4 Statistical Parameters of Different Optimization Approaches

5 Conclusion

The proposed method effectively demonstrates its utility in managing microgrid (MG) systems that integrate various renewable energy sources (RES) and storage units. By employing the Gravitational Search Algorithm (GSA), the proposed technique addresses key issues in energy management and offers a more efficient solution compared to existing methods. Evaluated using MATLAB, the proposed method outperforms conventional approaches like GA, PSO, and MPSO in terms of performance and cost efficiency. Specifically, the GSA achieves a total operational cost of $1.1, significantly lower than the costs associated with GA ($2.2), PSO ($3.2), and MPSO ($4.2). This substantial cost reduction, combined with the superior convergence efficiency of GSA, highlights its effectiveness in optimizing energy management and improving system performance.

5.1 Limitations of the proposed work

Despite its advantages, the proposed GSA-based method has certain limitations. One key limitation is its reliance on idealized models for renewable energy sources and storage systems, which may not fully capture real-world variability and operational uncertainties. This idealization can affect the algorithm’s performance in practical scenarios where such variability plays a significant role.

5.2 Future extensions

Future studies should concentrate on integrating more accurate and realistic models of m RESs and storage systems in order to overcome these constraints. By integrating real-time data into the optimization process, the adaptability and responsiveness of the energy management system can be enhanced. Such advancements would improve the algorithm’s ability to handle real-world challenges and further refine its effectiveness in diverse operational contexts.