Genetic algorithm and particle swarm applied in electric system optimization

This paper aims to present and run a composite model using Genetic Algorithm (GA) and Particle Swarm (PSO), with the assistance of parallel computing methods, to optimize the electrical distribution in a power grid based on an IEEE 14-bus system. The mathematical-computational modeling allows using the objective function to analyze the cost in relation to power or voltage as independent variables, and it is the bridge for the connection between the 2 implemented algorithms. The results presented in this article demonstrate that the methodology was implemented splendidly, in addition to obtaining an excellent computational cost and complying with the physical restrictions of network security, it also achieved global solutions in its optimization.


Introduction
Most of the Brazilian electrical power is generated from hydroelectric systems, thereby the country requires to constantly watch over the rain fallout predicted over the ensuing months and dam enough water as precaution for dry spells.
However, on April of the current year the Electric Sector Monitoring Committee (CMSE), has unveiled that in the period between September 2020 and March 2021, Brazil went through the lowest amount of rain in the last 90 years (BBC, 2021). Because of Development, v. 10, n. 10, e166101018871, 2021 (CC BY 4.0) | ISSN 2525-3409 | DOI: http://dx.doi.org/10.33448/rsd-v10i10.18871 the rainfall reduction, the strategy adopted by the National Electric System Operator (ONS) is to increase the use of power plants, this measure entails a higher cost on the final consumer's bills.
To situations with high quantity of variables and the need of tuning its values, it is often applied Artificial Intelligence (AI) techniques for both precision and efficiency. Mascarenhas et al (2020) use an AI to find the most effective and efficient path to perform the classification of knowledge of Physics Teachers. The strategy is presented as a scientific innovation and highlights a new area of research, which can help educators and scientists in the teaching-learning processes. Chitero et al (2020) developed an interactive graphical interface, based on Artificial Neural Networks, to predict soil recovery rates. This research allows more than a user-friendly environment, it works as a toolbox, helping and facilitating learning for researchers and undergraduate and graduate students, who carry out work in the field of Science of the Ground.
At Pinto et al (2020), the authors presented an intelligent system that allows analyzing generational behaviors more clearly, and by such, enabling the definition of strategies for applying this information in people management. Teles et al (2021) worked with several learning algorithms. The choice was performed after the comparison between the Multilayer Perceptron Neural Network and the Linear Regression. The authors searched for the system that presented the best performance for predicting the diagnosis of the Nasturtium disease. The criteria used were: sensitivity, specificity, accuracy and area under the curve of apprenticeship. The generated models were also compared, using the automatic attribute selection methods: Forward Selection, Backward Elimination and Genetic Algorithm.
The idea of applying evolutionary algorithms to optimize electrical networks, aiming to minimize electrical consumption and cost to users, is no innovation nowadays. The Genetic Algorithm was already used as tool to optimize the economic dispatch on the West Algeria power grid (R. Ouiddir, 2005). GA has also been applied to achieve the optimal balance between the parameters of power grid, such as load, resistance, voltage, and the system operation cost (R. Garg and A. K. Sharma, 2008).
However, with technological advances in the field of electrical engineering, energy distribution systems and domestic electrical networks have become more complex and dynamic, increasing the number of elements connected to the network, and the need for heavier analysis and calculations with the lowest possible computational cost. Following this flow of evolution, some optimization algorithms, although reaching great levels of precision, are demanding more powerful hardware to be able to perform their computation in a timely manner.
In this context, one of the strategies adopted by researchers in that field is to carry out tests with 2 or more algorithms, to compare their results and performance and choose the tool that presents the best balance. In H. Hong et al (2018), the authors describe an analysis about the flood susceptibility assessment using Differential Evolution (DE) and GA models.
The objective of this study is to optimize the economic dispatch in a 14-bus network balancing performance and efficiency, using methods that provide a shorter execution time, without losing quality in the results. To achieve this goal, a methodology that combines the PSO with the GA will be implemented, along with parallel computing techniques.
In Y. Zhou et al (2016), the analysis of the application of Particle Swarm in the optimization of an energy grid is carried out, and they conclude that such algorithm, despite having a low computational cost, still lacks reliability and stability when compared to other more mature algorithms. Based on the Y. Zhou et al work, the idea of carrying out a combination of 2 algorithms that could compensate for each other's failures emerged. The Genetic Algorithm and the Particle Swarm were chosen, combining GA's exploitation skills and the PSO's exploration power (Ghosh, 2019). The mathematical modeling of the problem situation, as well as the details of the methodology's implementation, and the results obtained in this study, are detailed throughout the article.

Methodology
The methodology performed in this article has as reference the guidelines proposed by Pereira et al. (2018), which supports the methodological steps to production of scientific papers. This study also works with a Mathematical-Computational Modeling, applied as the main support to the analysis and optimization of the electrical network, as this approach allows working with relatively high complexity systems, and enables direct implementation, without the need for intermediate abstractions.
Among the steps of modeling in this work, the first part, and most important for the success of this study, is the Mathematical Modeling.

Mathematical Modeling
In the 14-bus system, the electrical distribution must be carefully analyzed and defined, so that errors in the metric do not cause damage to the system, and consequently, to its users. One of the control variables of the system addressed in this study is the Electric Power (P), that is, the total power to supply the system, as shown in Costa et al (2017) Where a, b and c are coefficients, is the power of each bus at the iteration , the latter being an integer between 0 and 14. Following still the parameters developed by Costa et al, the coefficients and intervals are set such as = 2239, = 21.02, = 0.009 and 10 ≤ ≤ 150. Consequently, one can define = 10 and = 150.
The Equation 1 will turn into the objective function in this optimization work, it has great flexibility as it allows to calculate the independent values of each bus, and it can be worked as a function of voltage, inserting it instead of power as independent variable. This possibility comes from the relation (2) Where is the energy, is time, is voltage, is electric current and is the resistance, and the resistance is the real portion of impedance, that is, = , such as shown in relation 3.

= + (3)
Being the impedance in ohms, is the imaginary unity and the reactance value in ohms. Accordingly, one can get the result shown in Equation 4.
Where is the voltage in each bus at the iteration . This modification is extremely important since it allows the connection and conversion between the 2 evolutionary algorithms implemented on the next section.

Computational Modeling
The computational modeling has two main parts, each part being an implemented evolutionary algorithm, the bond of Research, Society and Development, v. 10, n. 10, e166101018871, 2021 (CC BY 4.0) | ISSN 2525-3409 | DOI: http://dx.doi.org/10.33448/rsd-v10i10.18871 the tools forms a robust system with an optimal performance and accuracy projection, to justify the inclusion of such methods each will be explained separately. Following the same order of the steps in the program coded for this work, the first mechanism is the Particle Swarm Optimization (PSO).
The Particle Swarm is a cooperative population metaheuristic algorithm, built to simulate the behavior of animal species that perform activities together, based on a social model described by J. Kennedy and R. Eberhart (1995). The PSO can be theoretically represented as a set of particles that navigates through a space of solutions, the main element of this method is the exchange of information between particles in the population, which allows a collective mobilization towards the optimal solution.
The PSO population is made up of several particles, each particle represents an individual in the population, and everyone has a coordinate value in each of the dimensions in domain space. These particles are represented on the computational dimension by multiple variables, such as [ 1 , 2 , … , ], allowing the particles to be set as vectors, being each particle vector built by their related positions and velocities. The population is started as a group of particles uniformly distributed throughout the search space, with random values within the delimited ranges.
The evaluation function, or fitness function is the mechanism responsible for evaluation the quality of a solution, its parameters are entered into the function in the format ( , ), where is the position of a particle on the iteration , and the result represents the score of this solution, the higher the score, the higher is the probability of this solution to be taken as a global optimum.
One of the main parameters of each particle is its position in the search space, the position of a particle can be defined as Where is the particle's index, and the number of dimensions worked. On this implementation, every particle is a solution to the system, and each solution presents a value for each bus in the grid, so each particle has 14 parameters, that is, a position vector composed of 14 values.
The second essential parameter for the composition of each particle is the velocity, as well as the position the velocity is updated at each iteration of the PSO. The effect of velocity on the system is to update the direction the particle should follow and define how intensely it will move on this new trajectory (Y. Shi and R. Eberhart, 1998). The velocity is updated based on Where is the inertia term, responsible for maintaining the particle in the current direction, being the coefficient responsible for setting the weight of this element. The term 1 • 1 • ( − ) is set as the cognitive term, this one tunes the priority of the best position found by the particle, where 1 is a random value between 0 and 1, 1 is the coefficient of the cognitive term and the best position where the particle was. There is also the social term, set by 2 • 2 • ( − ), it works oppositely to the cognitive term, prioritizing the best position value found by the population, where 2 is a random number between 0 and 1, 2 as coefficient of the social term and as the best position of the swarm.
After updating the particle velocity, the algorithm will apply its effect on the population, then the position of each particle will be changed according to its new velocity and trajectory. The x-position of a particle at each iteration is given by Equation (6).
Another important factor applied to the PSO is the parallel computing process, a method that ensures greater efficiency in the processing of the algorithm. Throughout every iteration, even though the particles are updated based on the positions of the rest of the population, each particle is sequentially calculated based on the values from the previous iteration. Based on this fact, it is possible to process the particles individually and in parallel, without harming the quality of the results, but improving the efficiency of the PSO.
At the end of the PSO, the exported product of the algorithm is a population, in matrix format, optimized for maximizing the power in every bus, which will serve as the main input data in the computational process. The flowchart in Figure 1 illustrates how the PSO works. As shown in Figure 1, the PSO follows a sequence of steps, where the main steps are engaged into a for loop that stops when the stop criterium is met. For this simulation, the criterium chosen to stop the loop is the number of generations, this way the algorithm will be able to perform in a more predictable time interval, depending on the PSO to reach a high precision result on the fitness value would require an unknown processing time, and would affect its purpose to be the fast element on the whole process.
The second main part of the computational composition of this work is the Genetic Algorithm (GA), such tool consists of a search algorithm for global solutions presented by John Holland (1962) and David Goldberg (1989), it aims to replicate the process of biological evolutionism. GA creates a population of possible solutions and performs the necessary crosses formulating generations of better individuals until the stopping criterion is met. This method also performs random changes in individuals, a process called mutation, very important to ensure the random aspect in the search for solutions, this helps the algorithm to prevent the solutions from converging to a local optimal point. The initial population is built of individuals generated at the end of the PSO execution, these individuals occupy the best global positions found in the previous algorithm. The use of these optimal individuals as a starting point in the search for the global optimal drastically reduces the processing time, and consequently the computational cost. 4 and works with the minimization of voltage in every bus, the mathematical modeling presented in the previous section allowed to transcend 2 different units, power and tension, using the same 14 position variables that compose the individuals. However, because they work with different scales, the search interval for variables in relation to voltage was defined as 0.065 ≤ , ≤ 1

The fitness function in GA is defined in Equation
Because this is the range of operable voltages in the buses. The workflow is represented as seen in Figure 2. The Figure 2 allows to notice the structural similarity between GA and PSO, since both encompass their main steps in a loop, yet it shows the difference is their respective steps, while the PSO maintains its population by only updating it over time, the GA rely on the breeding of its individuals and getting their offspring as results. The different behavior and workflow between these algorithms ensure to Genetic Algorithm a higher genetic variability, preserving the diversity of its population, is what makes the GA to require higher computational cost. Costa et al (2020) applied mathematical-modeling on the optimization of Criteria Matrix Analytic Hierarchy Process (CMAHP), through Newton's Method. Costa et al (2021) optimized an integrated electricity and natural gas network using GA in an IEEE 14-bus system, where the evolutionary algorithm is responsible for security-constrained optimal dispatch. As a continuity of that work, this research chose to work with a similar electrical network in the IEEE 14-bus system model, as shown in Figure 3. This system is composed of capacitor banks, transmission lines, generators and loads, the system presents 14 electric buses. Every electric bus is worked as a variable in both optimization algorithms implemented on this study, that is the reason why the fitness value is calculated by a 14 variables function.

Case Study
As demonstrated in the mathematical modeling, this system allows a minimum power of 10MW and a maximum power of 150MW, distributed over the 14 buses that make it up. The voltage in the system is the variable to be minimized based on the optimal power values. The cost of the system is measured and compared based on the fitness values, as these are arbitrary values that represent the score, hence the quality, of the solution found.

Results and Discussion
After configuring the virtual environment according to the presented methodology, and executing the entire computational process, the algorithms have outputted data that will be presented and analyzed in this section of the work.
Following the flow of this paper's methodology, the initial results are exported at the end of the PSO execution, in which the population is optimized to maximize the power in the system.
The PSO algorithm provides a population of optimal solutions to be used as the initial population in GA, one of these solutions is shown in Figure 4. The Figure 4 presents and optimal solution, that is, one of the individuals from the last generation, outputted by the PSO, such algorithm performed greatly by stablishing a population with similar fitness scores, and well balanced position values.
This balanced yet diverse population is the element responsible for delivering to GA a great starting point, removing much of the chaos factor inside of a bioinspired algorithm but not damaging its random factor.
The balance between individuals quoted in the previous paragraph is exhibited in Figure 5, since this figure shows all the whole population in a bar plot format at the end of the iterations executed. According to Figure 5, while performing the sum of the power values on every bus, no combination had total power above 150MW or below 10MW. Still referring to Figure 5, 2 individuals from the last generation were highlighted, the individual 11 and 17, respectively the highest and the lowest scores of the current population, showing there is a reasonable gap between the quality of these solutions, approximately 21.5% between the best and the worst solution. Nevertheless, this population is not the result of the whole process, it is the promising area built by the PSO to smooth GA processing.
Before proceeding to the next step, it is necessary to emphasize the importance of parallel computing in the execution of the PSO. Parallel processing allowed greater utilization of the processor responsible for executing the algorithms, surpassing a maximum utilization of 25% of the processor's capacity, and reaching a wondrous 89% of its maximum capacity. This gain in usability allowed the PSO to run in just 2.09s, which is an excellent processing time if compared to the approximate 10.72s that the algorithm took to finish using sequential classical methods.
Proceeding to the Genetic Algorithm step, the optimization process has as its initial population the data produced by the PSO, so the global solutions found in the Swarm create a search region in which the GA will operate. This conditioning was an important process to ensure a great performance, because instead of looking for optimal points in the entire domain of the function, the algorithm remained close to the promising areas found.
The GA results are given according to their fitness values, which represents the operating cost score in the system, that is, they work with arbitrary values that do not actually represent a currency unit. The first GA result is shown in Figure 6.   The Figure 7 display the best solutions found over the generations, and it is perceptible that, after the generation number 50, the best values have stabilized between 3.14 × 10 4 and 3.16 × 10 4 . Though establishing around an optimal area, as seen in Figure 7, the best solution keeps reaching highs and lows, that occurs because of the mutation step shown in Figure 2, it ensures the population diversity and prevents from premature convergence.
It is important, while analyzing the performance of the GA, to include the genetic variability of individuals as one of the control variables, this element represents the dispersion between the position values of individuals in the population. Genetic variability is calculated using the variance of the respective parameters of everyone in the population. Figure 8 shows a comparison between the variance of the parameters of the first and last generation individuals. When analyzing Figure 8, it is noticeable that the genetic variability among individuals of last generation decreased when compared to the individuals from the initial population, this action is a consequence of the population's convergence towards the global solution. To reach the optimal point, the individuals gather around the same point, losing its diversity. To better analyze this loss of variability, the values shown in Figure 8 are arranged in a discretized way as shown in Table 1. By observing the table data, it is possible to have a numerical understanding of the difference in variance between the first and the last generation. GA was also able to reduce the cost from 32279.2 to 31529.1 according to the fitness values, this change represents an approximate 2.4% decrease in system cost.

Conclusion
The composite model of the PSO with the GA proved to be efficient in achieving satisfactory results, not only for the global optimal values, but mainly in terms of performance gain, these results prove the efficiency and usefulness of the presented method. The results responsible for ensuring this method robustness and performance, also presents a wide horizon of possibilities where this model may be implemented, not only in the engineering field, but in the biological and social fields too.
For future work, it is intended to improve the union of evolutionary algorithms, making the transition between systems less abrupt, to implement different crossing and mutation methods, and to apply this method in more complex systems that require a greater number of variables. Besides improving the evolutionary algorithms, the authors of this work are developing a more sophisticated and powerful composite model, assembling PSO, GA and Neural Networks as technique to achieve better results in the learning development of an AI.