# An Improved Directed Crossover Genetic Algorithm Based on Multilayer Mutation

Authors: Feng Xie; Quansheng Sun; Yinfeng Zhao; Haibo Du
Journal: Journal of Control Science and Engineering
 (2022)

---

## Abstract

In order to solve the shortcomings of traditional genetic algorithms in image matching in terms of computational speed and matching accuracy, this paper proposes a directed crossover genetic matching algorithm (DCGA) based on multilayer variation. The algorithm differs from the traditional genetic algorithm (GA) in which the crossover strategy is improved and a multilayer adaptive variation operator is introduced. The crossover operation selects a certain proportion of spherical individuals from each generation as the evolutionary target, and the rest of the individuals evolve towards it in each dimension; the variation operation stratifies the population and adopts different adaptive variation methods for different layers. Avoiding the shortcomings of traditional genetic algorithms that tend to fall into local extremes, thus alleviating premature convergence, improves the search performance of the algorithm. The algorithm proposed in this paper is compared with the commonly used genetic algorithm by testing the effect of the function and tested practically in template matching. The experimental results show that the improved genetic algorithm has better convergence speed and search accuracy.


---

## Body

## 1. Introduction

Image matching includes template matching, target matching, and dynamic pattern matching, among which template matching is the most common matching method, which is widely used in remote sensing images, medical imaging, computer vision, and many other fields. Traditional matching algorithms adopt an iterative region-dependent matching search strategy, which results in a large amount of time spent on nonoptimal matching points, making it difficult to use in real-time applications. Therefore, some foreign scholars have started to use genetic algorithms to study template matching problems, such as literature [1]. A large amount of practice has shown that traditional genetic algorithms applied to image matching may have the following shortcomings: (1) genetic operations tend to destroy the construction of individuals during recombination, resulting in the algorithm approaching a local optimum or premature maturity; (2) the computational effort of adaptation is large, resulting in the algorithm running at a speed that cannot meet the system’s real-time needs. Therefore, the genetic algorithm needs to be improved when applied to image matching.There are two types of fast image matching algorithms in practice: the sequential similarity detection algorithm [2] (SSDA) and the multiresolution tower structure algorithm [3] (MPSA). The SSDA algorithm guarantees global optimality in image matching, but the SSDA algorithm has a variable matching time per frame with different target positions, which affects its implementation in practical engineering. The MPSA algorithm requires essentially the same matching time per frame, but its algorithm has the possibility of mismatching in principle, especially in low contrast conditions where it is more likely to be lost, and the algorithm trades the matching accuracy loss for speed improvement.Heuristic algorithms are often used to solve optimization problems in real life, and there are three main categories: genetic algorithm, simulated annealing [4], and particle swarm optimization [5]. Compared with the other two algorithms, the genetic algorithm has the characteristics of simple and general, strong robustness, suitable for parallel processing, and high efficiency. Genetic algorithms take all individuals in the population as objects and use randomization techniques to guide an efficient search of an encoded parameter space. As Holland of the University of Michigan proposed [6], more and more researches have been carried out around this algorithm. After years of development, genetic algorithms are widely used in power grid line loss calculation [7], solving the traveling salesman problem [8], circuit design optimization [9], cloud computing resource allocation [10], job shop scheduling [11, 12], and other aspects, the algorithm is often used for the optimal solution of multipeak functions.The main purpose of this paper is to propose a new directional crossover genetic algorithm by improving the crossover strategy and introducing the idea of multilayer adaptive mutation operator, so as to solve the problems of slow convergence and premature convergence of the genetic algorithm. The main contributions of this paper are as follows: (1) Directed crossover operator: directed crossover is an improvement to the crossover operation of traditional genetic algorithms, using the current optimal solution as the evolutionary direction of the target population, which is more responsive to the evolutionary direction of the whole population. Experimental results show that the directed crossover operator has faster convergence and higher search accuracy than the traditional genetic algorithm with a finite parent crossover operator. (2) The introduction of multilayer adaptive mutation operator: at the same time, the hierarchical adaptive mutation operator is proposed, and three kinds of mutation scale are introduced. The algorithm can adjust the variation range according to the convergence, ensuring that the algorithm can still explore the rest of the solution space while converging.


## 2. The Principle of Traditional Genetic Algorithm

In the genetic algorithm,n-dimensional decision vector X=x1,x2,…,xnT is represented by a symbol string X composed of n symbols xii=1,2,…,n: X=x1,x2,…,xn regards each xi as a genetic gene, and all its possible values are called alleles. In this way, X can be regarded as a chromosome composed of n genetic genes. The simplest allele is composed of two integers 0 and 1, and the corresponding chromosome can be represented as a string of binary symbols. The permutation form X formed by this code is the genotype of the individual, and the X value corresponding to it is the phenotype of the individual. Chromosome X is also called individual X. For each individual X, its fitness should be determined according to certain rules. The traditional genetic algorithm encodes the possible solutions of the target problem as chromosomes xi, the target problem is abstracted into a fitness calculation function fxi, and the higher the fitness, the closer the chromosome is to the optimal solution of the problem. Multiple chromosomes constitute a population, and through the steps of crossover, mutation, and selection, the population converges to the optimal solution in multiple iterations.At the beginning of the algorithm, the populationX=x1,x2,…,xn is randomly generated, and the fitness of the population is calculated. Then, enter the selection link, randomly remove a part of the chromosomes according to the fitness, and supplement with the same amount of individuals with high fitness to form a new population. Then, the crossover operator is performed, the crossover probability is set to pc, the parent xi and xj cross to generate the child x¯i and x¯j, and the formula is as follows:(1)x¯i=1−αxi+αxj,x¯j=1−αxj+αxi.Here,α is a random number between (0, 1), which reflects the inheritance degree of the offspring to the parent traits. Then, mutate individual xi to generate xi+1. The mutation formula is as follows:(2)xi+1=xi+xi×randnt≤pm,xi,t>pm,where randn() represents the random number in the interval −1,1, t is the random number between 0,1, and pm represents the probability of mutation.Cyclic execution of crossover, mutation, and selection operators can make the species chromosomes approach the optimal solution gradually, until the evolutionary algebra of the population reaches the specified value or the chromosome with the highest fitness meets the requirements. At this time, the best individual is the target searched by the algorithm. The traditional genetic algorithm is shown in Algorithm1.Algorithm 1: Traditional genetic algorithm.
Input:fxk:fitness function; X:population; xk:parents; x¯k:children; n:numbers of evolutions; N:the predetermined number of iterations;Output: optimal individual X1:
initializeX, n=0 and N;2:
repeat3:
evaluate fitness functionfxi of population xi4:
choose the populationxi with higher fitness5:
select operation toxi according to formula (1)6:
Mutation operation toxi according to formula (2)7:
untiln>N


## 3. Directed Crossover Genetic Algorithm for Multilayer Mutation

Most of the traditional genetic algorithms use the method of limited parental crossover, which is difficult to reflect the overall situation of the population. It has the shortcomings of slow convergence speed and easy to fall into the extreme value, and the mutation operator has a single structure, resulting in poor search ability in the early operation of the algorithm and low search accuracy in the later operation. Low problem: in this paper, the idea of directional crossover is introduced, and the directional crossover operator of the algorithm is improved. At the same time, the hierarchical adaptive mutation operator is optimized, and a directional crossover genetic algorithm based on multilayer mutation is constructed.


### 3.1. Directional Crossing

The crossover process of the traditional genetic algorithm often adopts the crossover of two parents. In order to make the population converge faster, researchers have proposed some methods of multiparent crossover, such as the three-parent crossover operator mentioned in literature [13, 14], from three-parent chromosomes The individual with the greatest fitness is selected as the direction of the crossover. The idea of these crossover operators is to crossover within the local range limited by the parent, and the evolution range is limited. In order to better reflect the evolutionary direction of the population as a whole during the crossover process, this paper introduces the idea of directional crossover and sorts the chromosomes in the population according to the fitness. The greater the fitness, the better the chromosomes. In each iteration, the optimal part of individuals is selected as the common parent of the offspring.Assuming that, after the selection operation, the individuals of thea-th generation population are sorted as Xa=xa1,xa2,…,xan according to their fitness size. For the D-dimensional problem, a single chromosome xai=xa,1i,…,xa,Di, and the population size is n. Let the number of selected excellent chromosomes be s, and the remaining n−s chromosomes of the population are crossed with them, respectively. The formula of the crossover operator is as follows:(3)x¯a,ji=xa,ji+fdfi+fd×xa,jd−xa,ji.In formula (3), x¯a,j represents the j-th dimension chromosome generated by crossover, xa,ji represents the less adaptive chromosome in the a-th generation, xa,jd represents the excellent chromosome in this generation, and fi,fd represent the fitness of individuals xa,ji and xa,jd. In the crossover process, the traits inherited by the offspring are affected by the fitness of the two parents, that is, the outstanding ones in the parents can pass on more imprints to the next generation, which improves the convergence speed. The directional crossover process is shown in Figure 1.Figure 1
Schematic diagram of the directional crossover process.


### 3.2. Hierarchical Adaptive Mutation

In the binary coded traditional genetic algorithm, the mutation operator flips every gene in chromosome with the same mutation probability. In the literature [15], the authors have proved that traditional mutation methods cannot effectively maintain the diversity of alleles at the same locus. In order to solve the shortcomings of traditional mutation operators with single structure and small mutation range, this paper proposes a corresponding hierarchical adaptive mutation operator that adjusts the mutation range based on convergence conditions.Literature [16] proposed the concept of hierarchical mutation and improved the variation operation of traditional genetic algorithms by introducing the concept of hierarchical variation. Literature [17–19] shows that the convergence speed and accuracy of the algorithm can be well optimized by improving the variational operation. In this regard, this paper adopts hierarchical adaptive mutation and divides the population into four layers according to the size of fitness, and the number of chromosomes in each layer is recorded as A, B, C, D. For individuals with different fitness, different mutation methods are applied to achieve the diversification of population search functions. Among them, layer A stores the current optimal chromosomes and does not participate in mutation, which can protect excellent traits.In layer B, individuals with similar fitness order between two generations are selected to represent the evolution direction of the population. Preliminary simulation shows that group B represents individuals with similar fitness to the optimal parent generation in the operation process. The convergence goal is clear, and the intergenerational difference can effectively increase the performance of fine search. The mutation operator is as follows:(4)xa+1,ji=x¯a,ji+randn×x¯a,ji−x¯a−1,ji,where C is the j-th generation generated after mutation; x¯a,ji,x¯a−1,ji are the same dimension of the current generation chromosome and the previous generation chromosome with the same population fitness order, respectively; randn represents the standard normal distribution with the mean value of 0 and variance of 1.In layer C, adaptive mutation strategy was adopted according to the current search range of the population. Because the fitness of the C-layer chromosome occupies a medium position in the population, it has limited role in solving the current exact solution, so it undertakes a large range of search work. The search area adopts an adaptive strategy, adjusting itself according to the current population dispersion. The formulas are as follows:(5)xa+1,ji=x¯a,ji+normrnd0,l,l=k×Xmax−Xmin−x¯a,jmax−x¯a,jminXmax−Xmin,where normrnd0,l represents a random number with a mean of 0 and a variance of 1. Xmin,Xmax,x¯a,jmin,x¯a,jmax, respectively, represent the constraint range solved by the algorithm and the search range of the j-th dimension of the current population. k is the scaling factor. It can be seen from the formula that the variance l is positively correlated with k, and the variation effect of this grouping can be changed by adjusting k. When k is too large, the variation tends to be random, and the convergence rate slows down. If k is too small, the search range is narrow, and the algorithm converges prematurely. Through experiments, the convergence speed and search performance can be balanced when k is between 2,3. It can be seen that when the population convergence degree is high, the standard deviation l becomes larger, and the search range after C-layer variation increases. When the population is dispersed, l is smaller, resulting in rapid convergence of chromosomes. This mutation operator has a feedback control effect on the global convergence.Layer D has the smallest fitness, so it has the largest range of variation and is responsible for completely random search tasks.(6)xa+1i=xai+P×Xmax−Xmin.P∈−0.4,0.4 is random number. Large scale variation occurred in this group of individuals, and the individuals after variation were randomly distributed in half solution space, further expanding the search scope. For this reason, intergenerational detection is set. The algorithm detects the search results every t generation. When the fitness increase of the current optimal solution is found to be small, random initialization is performed on the chromosomes of layers B, C, and D.Algorithm 2: Hierarchical adaptive mutation algorithm.
Input:fx:fitness function; X:crossed population; gen:number of evolutions;Output: mutated population1:
Initialize: the populationX is ranked x1,…,xn according to fitness;2:
if0<x_d<Athen then3:
no mutation;return4:
else iffA<fx_d<fBthen5:
do B-layer mutation operation;return6:
else iffB<fx_d<fCthen7:
do C-layer mutation operation;return8:
elsedo D-layer mutation operation; return9:
end if10:
ifgen can be divided by 5 then11:
iffitnessgen−fitnessgen−t<0.001then12:
initialize layer B,C and D;return13:
end if14:
end if


### 3.3. Algorithm Flow

The algorithm in this paper adopts the termination method of the specified evolutionary algebra, and the overall flow of the improved algorithm is shown in Figure2. Algorithm 2 is the framework of the improved algorithm in this paper.Figure 2
Flowchart of the adaptive directional crossover genetic algorithm.In addition to the crossover operator and mutation operator mentioned in the text, the selection operator is also used in the algorithm to simulate the phenomenon of survival of the fittest in nature. In the selection, this paper adopts the roulette algorithm [20]: assuming that the fitness of individual xi is fxi, and the number of individuals contained in the population is n, the probability of it being retained is expressed as(7)pxi=fxi∑k−1nfxk,and this selection method can ensure that all individuals have a certain probability of being retained, and the greater the fitness, the greater the probability of being retained.


## 3.1. Directional Crossing

The crossover process of the traditional genetic algorithm often adopts the crossover of two parents. In order to make the population converge faster, researchers have proposed some methods of multiparent crossover, such as the three-parent crossover operator mentioned in literature [13, 14], from three-parent chromosomes The individual with the greatest fitness is selected as the direction of the crossover. The idea of these crossover operators is to crossover within the local range limited by the parent, and the evolution range is limited. In order to better reflect the evolutionary direction of the population as a whole during the crossover process, this paper introduces the idea of directional crossover and sorts the chromosomes in the population according to the fitness. The greater the fitness, the better the chromosomes. In each iteration, the optimal part of individuals is selected as the common parent of the offspring.Assuming that, after the selection operation, the individuals of thea-th generation population are sorted as Xa=xa1,xa2,…,xan according to their fitness size. For the D-dimensional problem, a single chromosome xai=xa,1i,…,xa,Di, and the population size is n. Let the number of selected excellent chromosomes be s, and the remaining n−s chromosomes of the population are crossed with them, respectively. The formula of the crossover operator is as follows:(3)x¯a,ji=xa,ji+fdfi+fd×xa,jd−xa,ji.In formula (3), x¯a,j represents the j-th dimension chromosome generated by crossover, xa,ji represents the less adaptive chromosome in the a-th generation, xa,jd represents the excellent chromosome in this generation, and fi,fd represent the fitness of individuals xa,ji and xa,jd. In the crossover process, the traits inherited by the offspring are affected by the fitness of the two parents, that is, the outstanding ones in the parents can pass on more imprints to the next generation, which improves the convergence speed. The directional crossover process is shown in Figure 1.Figure 1
Schematic diagram of the directional crossover process.


## 3.2. Hierarchical Adaptive Mutation

In the binary coded traditional genetic algorithm, the mutation operator flips every gene in chromosome with the same mutation probability. In the literature [15], the authors have proved that traditional mutation methods cannot effectively maintain the diversity of alleles at the same locus. In order to solve the shortcomings of traditional mutation operators with single structure and small mutation range, this paper proposes a corresponding hierarchical adaptive mutation operator that adjusts the mutation range based on convergence conditions.Literature [16] proposed the concept of hierarchical mutation and improved the variation operation of traditional genetic algorithms by introducing the concept of hierarchical variation. Literature [17–19] shows that the convergence speed and accuracy of the algorithm can be well optimized by improving the variational operation. In this regard, this paper adopts hierarchical adaptive mutation and divides the population into four layers according to the size of fitness, and the number of chromosomes in each layer is recorded as A, B, C, D. For individuals with different fitness, different mutation methods are applied to achieve the diversification of population search functions. Among them, layer A stores the current optimal chromosomes and does not participate in mutation, which can protect excellent traits.In layer B, individuals with similar fitness order between two generations are selected to represent the evolution direction of the population. Preliminary simulation shows that group B represents individuals with similar fitness to the optimal parent generation in the operation process. The convergence goal is clear, and the intergenerational difference can effectively increase the performance of fine search. The mutation operator is as follows:(4)xa+1,ji=x¯a,ji+randn×x¯a,ji−x¯a−1,ji,where C is the j-th generation generated after mutation; x¯a,ji,x¯a−1,ji are the same dimension of the current generation chromosome and the previous generation chromosome with the same population fitness order, respectively; randn represents the standard normal distribution with the mean value of 0 and variance of 1.In layer C, adaptive mutation strategy was adopted according to the current search range of the population. Because the fitness of the C-layer chromosome occupies a medium position in the population, it has limited role in solving the current exact solution, so it undertakes a large range of search work. The search area adopts an adaptive strategy, adjusting itself according to the current population dispersion. The formulas are as follows:(5)xa+1,ji=x¯a,ji+normrnd0,l,l=k×Xmax−Xmin−x¯a,jmax−x¯a,jminXmax−Xmin,where normrnd0,l represents a random number with a mean of 0 and a variance of 1. Xmin,Xmax,x¯a,jmin,x¯a,jmax, respectively, represent the constraint range solved by the algorithm and the search range of the j-th dimension of the current population. k is the scaling factor. It can be seen from the formula that the variance l is positively correlated with k, and the variation effect of this grouping can be changed by adjusting k. When k is too large, the variation tends to be random, and the convergence rate slows down. If k is too small, the search range is narrow, and the algorithm converges prematurely. Through experiments, the convergence speed and search performance can be balanced when k is between 2,3. It can be seen that when the population convergence degree is high, the standard deviation l becomes larger, and the search range after C-layer variation increases. When the population is dispersed, l is smaller, resulting in rapid convergence of chromosomes. This mutation operator has a feedback control effect on the global convergence.Layer D has the smallest fitness, so it has the largest range of variation and is responsible for completely random search tasks.(6)xa+1i=xai+P×Xmax−Xmin.P∈−0.4,0.4 is random number. Large scale variation occurred in this group of individuals, and the individuals after variation were randomly distributed in half solution space, further expanding the search scope. For this reason, intergenerational detection is set. The algorithm detects the search results every t generation. When the fitness increase of the current optimal solution is found to be small, random initialization is performed on the chromosomes of layers B, C, and D.Algorithm 2: Hierarchical adaptive mutation algorithm.
Input:fx:fitness function; X:crossed population; gen:number of evolutions;Output: mutated population1:
Initialize: the populationX is ranked x1,…,xn according to fitness;2:
if0<x_d<Athen then3:
no mutation;return4:
else iffA<fx_d<fBthen5:
do B-layer mutation operation;return6:
else iffB<fx_d<fCthen7:
do C-layer mutation operation;return8:
elsedo D-layer mutation operation; return9:
end if10:
ifgen can be divided by 5 then11:
iffitnessgen−fitnessgen−t<0.001then12:
initialize layer B,C and D;return13:
end if14:
end if


## 3.3. Algorithm Flow

The algorithm in this paper adopts the termination method of the specified evolutionary algebra, and the overall flow of the improved algorithm is shown in Figure2. Algorithm 2 is the framework of the improved algorithm in this paper.Figure 2
Flowchart of the adaptive directional crossover genetic algorithm.In addition to the crossover operator and mutation operator mentioned in the text, the selection operator is also used in the algorithm to simulate the phenomenon of survival of the fittest in nature. In the selection, this paper adopts the roulette algorithm [20]: assuming that the fitness of individual xi is fxi, and the number of individuals contained in the population is n, the probability of it being retained is expressed as(7)pxi=fxi∑k−1nfxk,and this selection method can ensure that all individuals have a certain probability of being retained, and the greater the fitness, the greater the probability of being retained.


## 4. Experiments and Results Analysis

In order to verify the effectiveness of the designed directional crossover genetic algorithm based on multilayer mutation, eight tested functions are selected and compared with the three genetic algorithms of IGA [21], IRCGA [22], and TAGA [23], and the accuracy and convergence speed of the search results are compared.


### 4.1. Comparing Examples and Test Functions

In tests, the population size of each algorithm is set to 100, the number of iterations is 100, each algorithm runs independently 20 times, and the search rangexi of the population limit is −10,10. The four algorithms to be tested are as follows:DCGA: the directional cross genetic algorithm is proposed in this paper; the algorithm parameter settings are introduced in Section2: s=5,A=B=20,C=D=30,t=5.IGA is an improved genetic algorithm based on real number coding, which is a classic algorithm that achieves adaptive adjustment during operation by changing the crossover and mutation probability. Mutation parametersr=0.2,b=3; adaptive parameters k1=k2=1,k3=k4=0.5.IRCGA: the improved real-coded genetic algorithm adopts the strategy of adaptively changingpc and pm and performs multiparental crossover, which can theoretically increase the speed of convergence and increase the efficiency of evolution: p1=0.65,p2=0.2,c1=c2=1.5.TAGA: an optimized genetic algorithm proposes the idea of learning from the best individual:pc=0.65,pm=0.2,ai∈−0.5,1.5,c1=c2=1.5.We choose the following eight test functions:Bohachevsky function: it is a unimodal bowl function and slowly converges to the minimum value 0 at [0, 0].(8)f=0.7+x2+2y2−0.3cos3πx−0.4cos4πy.Schaffer function: it is a multimodal function and gets the minimum value−1 at [0, 0].(9)f=−0.5+sinx2+y22−0.51+0.001×x2+y22.Griewank function: it is a multimodal function and gets the minimum value 0 at [0, 0].(10)f=x2+y24000−cosx+1×cosy2+1.DropWave function: it is a multimodal function and gets the minimum value−1 at [0, 0].(11)f=−1+cos12x2+y20.5x2+y2+2.Rastrigin function: it is a multimodal function which has multiple local extremum and gets the minimum value 0 at [0, 0].(12)f=20+x2−10cos2πx+y2−10cos2πy.Sum-squares function: it is a unimodal function and gets the minimum value 0 at [0, 0].(13)f=x2+2y2.Booth function: the function is disc-shaped and converges more slowly and gets the minimum value 0 at [1, 3].(14)f=x+2y−72+2x+y−52.Levy-13 function: this function is a multimodal function with a lot of folds and gets the minimum value 0 at [1, 1].(15)f=sin23πx+x−121+sin23πy+y−121+sin22πy.


### 4.2. Results of Algorithm Experiment and Analysis

This paper takes the error between the searched value and the theoretical maximum value as the main comparison data. For the same test function, each algorithm is run twenty times. The test results are shown in Table1. The convergence of each algorithm under each test function is shown in Figure 3. The minimum mean and minimum standard deviation in each test function are bolded in the figure.Table 1
Algorithm running results error comparison.
AlgorithmsDCGAIGAIRCGATAGATest functionsMeanStd. devMeanStd. devMeanStd. devMeanStd. devSchaffer4.86E−042.12E−034.54E−034.69E−039.45E−031.17E−036.72E−033.09E−03Griewank1.99E−086.51E−089.40E−042.27E−031.93E−033.16E−033.02E−032.38E−03DropWave8.80E−112.85E−104.79E−031.38E−024.94E−022.48E−025.65E−022.05E−02Rastrigin4.86E−091.93E−085.68E−028.04E−024.52E−014.60E−017.45E−011.63E−01Bohachevsky7.85E−082.18E−074.63E−033.98E−32.24E−032.39E−031.99E−011.63E−01SumSquares1.28E−082.40E−082.36E−046.12E−041.38E−041.43E−041.37E−021.22E−02Booth3.66E−076.66E−073.53E−036.77E−031.39E−031.67E−035.32E−025.16E−02Levy-132.01E−072.93E−072.98E−034.01E−035.99E−031.33E−021.10E−027.50E−02Figure 3
Curves of error evolution.Since most of the test functions achieve the minimum value at [0, 0], in order to prevent the special value of 0 from interfering with the running effect of the algorithm, before running, all test functions are shifted by 2.5 unit lengths in each dimension to reflect the randomness of the solution.The local extremum of the multimodal function Schaffer is ring-shaped, and there are continuity equivalent solutions at the folds, which can easily interfere with the algorithm and make the algorithm converge on the extremum ring. It can be seen from the experimental results that the IGA, IRCGA, and TAGA algorithms are all trapped at the extreme value solution of 0.99, while the DCGA algorithm in this article can further jump out of the extreme value and find the most value point.For Griewank, DropWave, Rastrigin, and Levy-13, the extreme point of this kind of multimodal function presents a peak shape around the extreme point, and the genetic operator can jump out of the extreme point. This type of function tests the convergence performance of the algorithm’s crossover operator. It can be seen from the iterative error evolution curve that the new algorithm has the fastest convergence speed in the multimodal function, and the accuracy is much higher than other algorithms. Once a possible solution is found, the algorithm can lock until the mutation operator makes the population find a better target.The unimodal functions Bohachevsky, sum-squares, and booth have a small slope at the peak and a gentle peak, which are suitable for the search accuracy of the detection algorithm. The new algorithm in this paper shows excellent performance for these problems, fast convergence, and small error. The other algorithms slow down their convergence under a flat objective function, resulting in greater error than the DCGA algorithm.It can be seen from Table1 that, for the eight test functions, the errors of the DCGA algorithm are much smaller than that of the control group, and the smaller standard deviation also indicates that the new algorithm is also very stable in multiple runs.


### 4.3. Algorithms Tested in Template Matching

Template matching is to search for the target image position in the original image. When searching, it is necessary to take a subimage from the original image and compare it with the template. If the similarity between the two reaches a certain level, it can be considered that the target position has been found, and the search is over.Assuming that the template isS and the size is M×N pixels, we place the template on the original image and move it. The coordinate i,j in the upper left corner represents the current position. When the template moves, the corresponding subimage T of the same shape is captured in the original image, and the subimage T is used. The Euclidean distance with the template S is the basis for judging the similarity:(16)Di,j=∑m=1M∑n=1NSijm,n−Tm,n2.In formula (16), the smaller the D is, the higher the similarity between S and T is. In order to facilitate comparison, formula (16) is normalized, and the following formula is obtained after processing:(17)Ri,j=∑m=1M∑n=1NSijm,n⋅Tm,n∑m=1M∑n=1NSijm,n2∑m=1M∑n=1NTm,n2.In formula (17), the similarity R represents the matching degree between the subgraph and the template under the corresponding coordinates, and the closer the R is to 1, the higher the matching degree. Considering the similarity calculation formula as a fitness function, the template matching problem can be regarded as a two-dimensional function optimization problem.The template used in the test and the original image are shown in Figure4. The search template is in the white box, the size is 88∗98 pixels, and the size of the original image is 1024∗1024 pixels.Figure 4
Template matching original image.In this paper, the coordinates of the upper left corner pointi,j are used as independent variables. The optimal solution for matching is the pixel point 586,580. We simulate matching algorithm based on DCGA on the MATLAB software platform and compare the results with the runs of SSDA, traditional genetic algorithm (GA), and adaptive genetic algorithm (AGA) [24]. The DCGA algorithm proposed in this paper uses an improved directed crossover operation compared to the AGA algorithm and a hierarchical adaptive variation operator compared to the traditional GA algorithm. The population size and the number of iterations were set to 100, each algorithm was run independently for 50 times, and the similarity between the average searched subgraph and the template and the average number of iterations when convergence was recorded was recorded. The experimental results are shown in Table 2.Table 2
Results of template matching.
AlgorithmsIndicatorsSSDAGAAGADCGAMaximum time (s)18.3058.0395.0621.871Minimum time (s)15.5067.6813.8320.817Average time (s)16.7117.9664.6731.017Correct numbers49454648Average matching accuracy0.9980.7910.8831It can be seen from Table2 that compared with the SSDA algorithm, the genetic algorithm can reduce the image matching time to a greater extent, among which the DAGA algorithm proposed in this paper has the shortest time in image matching. To verify the excellent performance of the DAGA algorithm in terms of global convergence, DAGA is compared with the GA and AGA algorithms. In 50 matching tests, the DCGA-based image matching algorithm achieved 100 percent matching accuracy every time, while the average matching accuracy of the GA and AGA algorithms were 79.1 percent and 88.3 percent, respectively, indicating that the algorithm proposed in this paper has good global convergence.


## 4.1. Comparing Examples and Test Functions

In tests, the population size of each algorithm is set to 100, the number of iterations is 100, each algorithm runs independently 20 times, and the search rangexi of the population limit is −10,10. The four algorithms to be tested are as follows:DCGA: the directional cross genetic algorithm is proposed in this paper; the algorithm parameter settings are introduced in Section2: s=5,A=B=20,C=D=30,t=5.IGA is an improved genetic algorithm based on real number coding, which is a classic algorithm that achieves adaptive adjustment during operation by changing the crossover and mutation probability. Mutation parametersr=0.2,b=3; adaptive parameters k1=k2=1,k3=k4=0.5.IRCGA: the improved real-coded genetic algorithm adopts the strategy of adaptively changingpc and pm and performs multiparental crossover, which can theoretically increase the speed of convergence and increase the efficiency of evolution: p1=0.65,p2=0.2,c1=c2=1.5.TAGA: an optimized genetic algorithm proposes the idea of learning from the best individual:pc=0.65,pm=0.2,ai∈−0.5,1.5,c1=c2=1.5.We choose the following eight test functions:Bohachevsky function: it is a unimodal bowl function and slowly converges to the minimum value 0 at [0, 0].(8)f=0.7+x2+2y2−0.3cos3πx−0.4cos4πy.Schaffer function: it is a multimodal function and gets the minimum value−1 at [0, 0].(9)f=−0.5+sinx2+y22−0.51+0.001×x2+y22.Griewank function: it is a multimodal function and gets the minimum value 0 at [0, 0].(10)f=x2+y24000−cosx+1×cosy2+1.DropWave function: it is a multimodal function and gets the minimum value−1 at [0, 0].(11)f=−1+cos12x2+y20.5x2+y2+2.Rastrigin function: it is a multimodal function which has multiple local extremum and gets the minimum value 0 at [0, 0].(12)f=20+x2−10cos2πx+y2−10cos2πy.Sum-squares function: it is a unimodal function and gets the minimum value 0 at [0, 0].(13)f=x2+2y2.Booth function: the function is disc-shaped and converges more slowly and gets the minimum value 0 at [1, 3].(14)f=x+2y−72+2x+y−52.Levy-13 function: this function is a multimodal function with a lot of folds and gets the minimum value 0 at [1, 1].(15)f=sin23πx+x−121+sin23πy+y−121+sin22πy.


## 4.2. Results of Algorithm Experiment and Analysis

This paper takes the error between the searched value and the theoretical maximum value as the main comparison data. For the same test function, each algorithm is run twenty times. The test results are shown in Table1. The convergence of each algorithm under each test function is shown in Figure 3. The minimum mean and minimum standard deviation in each test function are bolded in the figure.Table 1
Algorithm running results error comparison.
AlgorithmsDCGAIGAIRCGATAGATest functionsMeanStd. devMeanStd. devMeanStd. devMeanStd. devSchaffer4.86E−042.12E−034.54E−034.69E−039.45E−031.17E−036.72E−033.09E−03Griewank1.99E−086.51E−089.40E−042.27E−031.93E−033.16E−033.02E−032.38E−03DropWave8.80E−112.85E−104.79E−031.38E−024.94E−022.48E−025.65E−022.05E−02Rastrigin4.86E−091.93E−085.68E−028.04E−024.52E−014.60E−017.45E−011.63E−01Bohachevsky7.85E−082.18E−074.63E−033.98E−32.24E−032.39E−031.99E−011.63E−01SumSquares1.28E−082.40E−082.36E−046.12E−041.38E−041.43E−041.37E−021.22E−02Booth3.66E−076.66E−073.53E−036.77E−031.39E−031.67E−035.32E−025.16E−02Levy-132.01E−072.93E−072.98E−034.01E−035.99E−031.33E−021.10E−027.50E−02Figure 3
Curves of error evolution.Since most of the test functions achieve the minimum value at [0, 0], in order to prevent the special value of 0 from interfering with the running effect of the algorithm, before running, all test functions are shifted by 2.5 unit lengths in each dimension to reflect the randomness of the solution.The local extremum of the multimodal function Schaffer is ring-shaped, and there are continuity equivalent solutions at the folds, which can easily interfere with the algorithm and make the algorithm converge on the extremum ring. It can be seen from the experimental results that the IGA, IRCGA, and TAGA algorithms are all trapped at the extreme value solution of 0.99, while the DCGA algorithm in this article can further jump out of the extreme value and find the most value point.For Griewank, DropWave, Rastrigin, and Levy-13, the extreme point of this kind of multimodal function presents a peak shape around the extreme point, and the genetic operator can jump out of the extreme point. This type of function tests the convergence performance of the algorithm’s crossover operator. It can be seen from the iterative error evolution curve that the new algorithm has the fastest convergence speed in the multimodal function, and the accuracy is much higher than other algorithms. Once a possible solution is found, the algorithm can lock until the mutation operator makes the population find a better target.The unimodal functions Bohachevsky, sum-squares, and booth have a small slope at the peak and a gentle peak, which are suitable for the search accuracy of the detection algorithm. The new algorithm in this paper shows excellent performance for these problems, fast convergence, and small error. The other algorithms slow down their convergence under a flat objective function, resulting in greater error than the DCGA algorithm.It can be seen from Table1 that, for the eight test functions, the errors of the DCGA algorithm are much smaller than that of the control group, and the smaller standard deviation also indicates that the new algorithm is also very stable in multiple runs.


## 4.3. Algorithms Tested in Template Matching

Template matching is to search for the target image position in the original image. When searching, it is necessary to take a subimage from the original image and compare it with the template. If the similarity between the two reaches a certain level, it can be considered that the target position has been found, and the search is over.Assuming that the template isS and the size is M×N pixels, we place the template on the original image and move it. The coordinate i,j in the upper left corner represents the current position. When the template moves, the corresponding subimage T of the same shape is captured in the original image, and the subimage T is used. The Euclidean distance with the template S is the basis for judging the similarity:(16)Di,j=∑m=1M∑n=1NSijm,n−Tm,n2.In formula (16), the smaller the D is, the higher the similarity between S and T is. In order to facilitate comparison, formula (16) is normalized, and the following formula is obtained after processing:(17)Ri,j=∑m=1M∑n=1NSijm,n⋅Tm,n∑m=1M∑n=1NSijm,n2∑m=1M∑n=1NTm,n2.In formula (17), the similarity R represents the matching degree between the subgraph and the template under the corresponding coordinates, and the closer the R is to 1, the higher the matching degree. Considering the similarity calculation formula as a fitness function, the template matching problem can be regarded as a two-dimensional function optimization problem.The template used in the test and the original image are shown in Figure4. The search template is in the white box, the size is 88∗98 pixels, and the size of the original image is 1024∗1024 pixels.Figure 4
Template matching original image.In this paper, the coordinates of the upper left corner pointi,j are used as independent variables. The optimal solution for matching is the pixel point 586,580. We simulate matching algorithm based on DCGA on the MATLAB software platform and compare the results with the runs of SSDA, traditional genetic algorithm (GA), and adaptive genetic algorithm (AGA) [24]. The DCGA algorithm proposed in this paper uses an improved directed crossover operation compared to the AGA algorithm and a hierarchical adaptive variation operator compared to the traditional GA algorithm. The population size and the number of iterations were set to 100, each algorithm was run independently for 50 times, and the similarity between the average searched subgraph and the template and the average number of iterations when convergence was recorded was recorded. The experimental results are shown in Table 2.Table 2
Results of template matching.
AlgorithmsIndicatorsSSDAGAAGADCGAMaximum time (s)18.3058.0395.0621.871Minimum time (s)15.5067.6813.8320.817Average time (s)16.7117.9664.6731.017Correct numbers49454648Average matching accuracy0.9980.7910.8831It can be seen from Table2 that compared with the SSDA algorithm, the genetic algorithm can reduce the image matching time to a greater extent, among which the DAGA algorithm proposed in this paper has the shortest time in image matching. To verify the excellent performance of the DAGA algorithm in terms of global convergence, DAGA is compared with the GA and AGA algorithms. In 50 matching tests, the DCGA-based image matching algorithm achieved 100 percent matching accuracy every time, while the average matching accuracy of the GA and AGA algorithms were 79.1 percent and 88.3 percent, respectively, indicating that the algorithm proposed in this paper has good global convergence.


## 5. Conclusions

Aiming at the defects of slow convergence speed and premature convergence of traditional genetic algorithm, this paper proposes a multilayer mutation directed crossover genetic algorithm. On the one hand, the algorithm combines the crossover algorithm to improve the directional crossover operator and takes the current optimal solution of the population as the evolutionary goal to better reflect the evolution direction of the population; on the other hand, the algorithm introduces a multilayer adaptive operator to improve the accuracy of the degree of adaptation of different populations. The new algorithm and other comparison algorithms are compared in different dimensions for typical test functions and then compared in the model matching task. The two test results show that the optimization effect, convergence speed, and search ability of the algorithm have been greatly improved.



---

*Source: 4398952-2022-09-19.xml*