# Archives November 2021

#### Matlab Genetic Algorithm Toolbox

What is the Matlab genetic algorithm toolbox?

Genetic algorithm has the advantages of simple thinking and obvious application effect. Experts and scholars in various fields have conducted in-depth research on it, and used C, C++ and other programming languages ​​to implement algorithms. However, these languages ​​require users to write genetic algorithm programs, which brings certain difficulties to researchers who are not familiar with programming languages. The genetic algorithm toolbox of Matlab can realize the operation of genetic algorithm through a graphical user interface (GUI) . The problem can be quickly defined by writing a small amount of fitness function program and setting the corresponding parameters in the toolbox. Flexible, easy to use, and easy to modify parameters.

This article takes the genetic algorithm toolbox in Matlab7.1 version as an example to introduce the structure and parameter settings of the toolbox. Type “gatool” in the Matlab working window. After the command is run, you can open the Genetic Algorithm Tool box, or find and open the tool box in the Start menu in Matlab. The operation interface is shown in Figure.

The genetic algorithm toolbox is divided into 5 parts from left to right, mainly including defining function handles and variable numbers, running displays (Plots), constraints (Constraints), running commands and results (Run Solver), parameter settings (Options), etc.

(1) When solving actual problems, first determine the fitness function of the problem, and write it as an M file and store it on the working path of Matlab. Fill in the handle of the compiled fitness function in Fitness Function, the format is “@funtname”, and enter the number of variables to be solved in Number of vari.

(2) Constraints include constraints such as Linear inequalities, Linear equalities, and Bounds. For example, boundary constraints limit the minimum and maximum values ​​of variables, and the maximum value constraints of multiple variables can be expressed in matrix form.

(3) Operation display (Plots) displays the operation process of the selected item in image form during operation. For example, after checking Best fitness, the algorithm operation process will display the best function value and average value in each generation of the group; checking Best individual will display the individual corresponding to the best fitness value under the current iteration number.

(4) The run command and result (Run solver) includes operation buttons such as run, pause, stop, etc. The number of iterations and operation status will be displayed during the running process, and the final optimization result will be displayed in the final point after the algorithm stops.

(5) Parameter settings (Options) mainly affect the calculation speed and accuracy of the algorithm, mainly including population (Population), fitness scale (Fitness scaling), selection (Selection), mutation (Mutation), stop condition (Stopping Criteria), Crossover (Crossover) and other parameter settings. The relevant parameters can be selected and set through the drop-down menu.

#### Genetic Algorithm Fitting

What is genetic algorithm fitting?

Genetic Algorithm (Genetic Algorithm, GA) is a global optimization algorithm, which is based on the evolutionary theory of natural selection and genetics to find the optimal solution to the function problem. It is not only suitable for general fitting problems, but also can solve the traditional fitting methods. Deal with non-linear and highly complex data fitting problems.

Therefore, this paper uses genetic algorithm to fit the test data obtained from the lithium-ion power battery cycle life test, and obtain the optimal coefficient and equation between the capacity retention rate and the number of cycles.

Genetic algorithm (GA) simulates the evolutionary process of gene recombination and mutation in the process of biological reproduction. When solving actual problems, the potential solution of the problem (randomly generated) is used as the initial population of the algorithm. The population is used as an individual after binary coding by a computer. These individuals perform operations similar to natural selection, crossover, and mutation in biological evolution, and reproduce according to the rule of survival of the fittest, and finally obtain the optimal individual that meets the convergence condition is the optimization result of the problem.

When the genetic algorithm is used for curve fitting, the algorithm uses group evolution to process multiple individuals at the same time. It does not need to know the derivative of the problem to be sought, does not depend on the complexity of the problem, and the initial population, recombination, mutation and other operations in the genetic algorithm It is performed randomly, which can avoid the local optimum in the optimization process and achieve the global optimum effect, and can effectively solve the optimal estimation problems such as polynomial coefficients.

The main calculation steps of genetic algorithm are:

① Randomly generate an initial population based on actual problems.

②Use the designed fitness function to calculate the fitness of the individual.

③ Perform operations such as selection, crossover, and mutation.

Selection refers to the use of certain methods to select individuals with high adaptability to inherit to the next generation according to the fitness of the individual.
Crossover refers to selecting two individuals with higher probability from the group, and exchanging part of the genes in each pair of individuals.
Commonly used methods such as single-point crossover and multi-point crossover. Variation refers to changing the value of part of the gene position of the individual in the population after crossover with a small probability.

④ Determine whether the convergence conditions are met.

When the set convergence conditions are met, the individual with the greatest fitness is the optimal solution to the problem, otherwise, proceed to steps ③ and ④.

The fitness function is used to measure the fitness of an individual, which is equivalent to the objective function in actual problems. It can only find the minimum value in the Matlab genetic algorithm toolbox. The genetic algorithm controls the operation of the algorithm through the fitness function, uses the size of the individual fitness to determine the probability of an individual being inherited to the next generation, and then changes the group structure. It is the basis for the algorithm’s natural selection and the driving force of evolution. When the genetic algorithm is used to fit the function, the fitness function f(x) that can be selected is as shown in the formula (formula diagram), where Cmax is a sufficiently large positive number, and ER is the objective function.