*4.2. Improved Particle Swarm Optimization*

For the particle swarm optimization algorithm, it is susceptible to problems such as falling into the local extremum and poor local search ability. To solve these problems, the particle swarm optimization algorithm is improved. A particle swarm optimization with dynamic adjustment of intrinsic weight is used, and exponential function and random function of beta distribution [28] are used to improve it, achieve the algorithm's global search ability, and reduce the possibility of falling into local extremum.

The inertia weight *ω* is an essential variable among the particle swarm, determining influence degree of particle velocity on the velocity in the next iteration. The capability of global search is strong when *ω* is large, the capability of local search is weak, and it can easily fall into the local optimization state. With the increase in iteration times, the exponential function *<sup>e</sup>* <sup>−</sup>*<sup>k</sup> <sup>k</sup>*max is adopted to increase the global search ability and the later search accuracy.

The improved expression for the inertia weights is

$$
\omega = \omega\_{\text{min}} + (\omega\_{\text{max}} - \omega\_{\text{min}})e^{\frac{-k}{k\_{\text{max}}}} + \sigma \times \text{betard}(p, q) \tag{26}
$$

where: *k*max is the maximum number of iterations; σ is the inertia adjustment factor; *ω*max is the initial inertia weight; *ω*min is the inertia weight of the maximum number of iterations.

In particle swarm optimization, the acceleration factor determines the influence of individual particle experience information and other particle experience information on the optimization trajectory. For the acceleration factor, *c*<sup>1</sup> is the global acceleration factor and *c*<sup>2</sup> is the local acceleration factor [29]. To converge faster, the acceleration factor is improved so that *c*<sup>1</sup> gradually increases and *c*<sup>2</sup> gradually decreases, thus strengthening the convergence ability of particles to the global optimum.

$$\begin{cases} c\_1 = c\_0 \sin^2\left[\frac{\pi}{2}\left(1 - \frac{k}{k\_{\text{max}}}\right)\right] \\ c\_2 = c\_0 \sin^2\left(\frac{\pi}{2}\frac{k}{k\_{\text{max}}}\right) \end{cases} \tag{27}$$

where: *c0* is the initial value.

#### *4.3. Solution Steps*

In solving the problem of optimal system capacity configuration, the paper applies the improved IDW-PSO problem solving and the flow is shown in Figure 4.

**Figure 4.** Solution flow.

#### **5. Model Solving**

This paper uses the improved particle swarm optimization algorithm with dynamically adjusted inertia weight to optimize the configuration of each device's hydrogen-containing hybrid energy storage microgrid capacity. Firstly, the fundamental parameter models of each device unit, including illumination intensity and load parameters, are determined secondly, input parameters, including capacity range, conversion rate, etc. Then, the system's capacity is optimized according to the system's total operating cost. The core of the system optimal analysis method based on IDW-PSO is to determine the optimal capacity allocation under the condition of minimum total system cost, to reduce the loss of power supply probability, reduce the fluctuation of power, preventing instability of the microgrid. A flow diagram of the operation strategy is illustrated in Figure 5:

**Figure 5.** Operation strategy flow chart.


#### **6. Example Analysis**

Taking a wind, solar, and hydrogen microgrid system in Beijing as an example, the capacity of centralized photovoltaic units is 200 KW, and that of centralized wind turbines is 350 KW. Figure 6 shows the data on wind power, photovoltaic power generation, and load consumption on a specific day in this area. Relevant parameters of battery and hydrogen storage of the system are presented in Table 1. The optimization model of the capacity optimization of wind and hydrogen storage system constructed in this paper is solved by MATLAB.

**Figure 6.** Wind–solar load curve.

**Table 1.** Example parameters.


In the whole microgrid system, the equipment at the power generation end includes a wind turbine, photovoltaic equipment, storage battery, and hydrogen energy storage system. According to a defined objective value function and various parameters, wind turbine, photovoltaic unit, and hydrogen energy storage jointly bear the load consumption of the system and keep the power balance in real time. At 5~18 h, due to the sun's rising, the light amplitude appeared and reached the maximum peak at 12 h at noon, when the light incident angle reached the maximum. Because wind turbines are built in places with abundant wind resources, they can generate electricity 24 h a day.

#### *Simulation Results Analysis*

To comprehensively analyze the economic advantages of the energy storage operation of the system according to the improved IDW-PSO algorithm, the effects of system load shortage and power balance on the configuration results are considered, this paper sets the following four schemes for comparative analysis. Scheme 1: Choose the energy storage configuration scheme that is currently widely used. Scheme 2: The battery and hydrogen energy storage is selected as the energy storage schemes of the system for optimal configuration, and the compression factor particle swarm optimization algorithm is used. Scheme 3: Select battery and hydrogen energy storage as the system energy storage scheme for optimal configuration, and use the IDW-PSO algorithm. Scheme 4: Select battery and hydrogen energy storage as the system energy storage scheme to optimize the structure and use the improved IDW-PSO algorithm. The simulation establishes the population scale of 200, and iteration number of 200, acceleration factor initial value is set to 1.65, the battery SOC lower limit is 0.1, the SOC upper limit is 0.9, while a battery SOC initial value is set to 0.5, and a simulation results are as follows:

Upon calculation, the results of the optimized configuration under each scenario are obtained as shown in Figure 7 and Table 2. Scheme 2, Scheme 3, and Scheme 4, respectively, show the differences in iteration times, average time, and total cost caused by different operation results. The above three schemes can all be applied to the capacity optimization arrangement of hydrogen-containing composite power storage system. From a comparative analysis of Figure 7, the improved IDW-PSO algorithm can reduce the number of iterations, speed up the calculation time, and calculate the optimal system operating cost more effectively. The convergence speed and accuracy of the improved IDW-PSO are different from those of IDW-PSO and compressed factor particle swarm optimization, which reduces the local optimal solution, slow divergence speed and efficiency. The algorithms in the present paper have fewer iteration times and operation times. Compared with other algorithms, this algorithm is superior to different algorithms with the capacity optimization configuration scheme, which improves the system economy.

**Figure 7.** Comparison of convergence curves of various algorithms.


**Table 2.** Comparison of economic results of each algorithm.

At this time, see Table 3 for the system capacity optimization configuration scheme through Scheme 1, Scheme 3, and Scheme 4.

**Table 3.** Optimization result.


Table 3 shows that the optimal configuration for the microgrid system in the hybrid energy storage of supercapacitors and storage batteries in Scheme 1 is 2034 storage batteries and 28,956 supercapacitors. In this case, the system loss of power supply probability is 0.0321, and the system's total operating cost is 83,210 yuan. The optimal configuration of the Scheme 3 microgrid system before improvement is 1975 batteries and 127 hydrogen storage batteries; now the system loss of power supply probability is 0.0297, and the comprehensive operating of the system costs 83,590 yuan. The optimal configuration of the improved Scheme 4 microgrid system is 1989 batteries and 106 hydrogen storage batteries. Currently, the system loss of power supply probability is 0.014, and the system's total operating cost is 83,230 yuan. From the comparative analysis of Table 3, in the hybrid energy storage of battery and supercapacitor, the minimum price for Scheme 3 is higher than that of Scheme 1 because the cost of hydrogen energy storage is much higher than that of the supercapacitor, and the operating cost of Scheme 4 is unchanged. The scheme proposed in this paper (Scheme 4) reduces the power shortage by 56.4% in Scheme 1 and 52.9% in Scheme 3 while maintaining the running cost unchanged. Therefore, the scheme used in this paper is superior to other projects, which improves the power shortage problem caused by the system's unbalanced configuration.

From the perspective of solving the problem of the power shortage rate, the scheme in this paper has increased by 1.81% and 1.57%, respectively, compared with Scheme 1 and 3. In this paper, Beijing's average daily electricity consumption in 2022 is 210 degrees. According to this ratio, the scheme in this paper can solve the power shortage of about 3.5 degrees by storing energy. Thermal power plants need about 320 g standard coal for the first generation of electricity, saving 1 kg of typical coal = reducing emissions by 2.493 kg "carbon dioxide" = reducing emission by 0.68 kg "carbon." Then, this scheme can reduce carbon dioxide and carbon emissions by about 1019.13 kg a year in this area. Therefore, the scheme proposed in this paper has great practical significance for promoting carbon neutrality.

For wind–solar hybrid electricity generation, both wind turbines and photovoltaic units have limited capacities, and the adjustment range is relatively small. Hydrogen storage has excellent advantages for power generation because hydrogen storage can perform charging and discharging functions and has a wide range of power adjustments. As can be seen from Figure 8, from 0:00 to 6:00, since the load output is higher than the wind and light energy export power, batteries and hydrogen energy storage are discharged; At 6:00–16:00, because the load output is less than the wind and light output power, the

battery and hydrogen energy storage are charged. From 16:00 to 22:00, the battery and hydrogen energy storage discharge because the load output is greater than the wind and light output power. From 22:00 to 24:00, the battery and hydrogen energy storage charge because the load output is less than the wind and light output power.

Based on the economic and system loss of power supply probability, the system optimizes the capacity allocation scheme for wind, light, and hydrogen storage systems, thus achieving the purpose of shaving peaks and filling valleys and restraining power fluctuation. When the generating power of wind and light is greater than the load output, the hydrogen storage is optimized by the algorithm to realize "peak clipping". When the generating power of wind and light is less than the load output, the hydrogen storage system is discharged through algorithm optimization to realize "valley filling" of the system power.

Figure 8 is a power comparison chart before and after system optimization, which is, respectively, the power comparison in the whole system before and after the optimization of the hydrogen energy storage system. Before the optimal configuration of the hydrogen energy storage system, a variance of the output power of the whole system was 9171.78 kW2. After the optimal configuration, the variance of the whole system's output power is 6582.22 kW2, with an obvious decrease in the fluctuation of the output power. The 0-A region represents the supplementary power region where the fuel cell of the hydrogen energy storage system discharges to supplement wind power and photovoltaic power, thus achieving the function of "valley filling" for the system power. The area A-B region represents the electrolyze in the hydrogen storage system for hydrogen storage, to absorb the force of wind power and photovoltaic, and thus achieve the "peak clipping" effect on the system power. The B—C region is the same as the 0—A region, and the C—D region is the same as the A—B region. Meanwhile, the waste power of the hydrogen energy storage system before configuration is 3.7435 kW, while after configuration, it is 1.8263 kW, which significantly reduces the waste air volume.

**Figure 8.** Power comparison diagram before and after optimization.
