A list,

Genetic Algorithm (GA) is a part of evolutionary computing. It is a computational model that simulates Darwin’s Genetic selection and natural selection of biological evolution process. It is a method to search for optimal solution by simulating natural evolution process. The algorithm is simple, universal, robust and suitable for parallel processing.

2 Characteristics and Application of Genetic Algorithm Genetic algorithm is a kind of robust search algorithm which can be used for complex system optimization. Compared with traditional optimization algorithm, it has the following characteristics: (1) The encoding of decision variables is taken as the operation object. Traditional optimization algorithms often directly use the actual value of the decision variable itself to optimize the calculation, but genetic algorithm uses a certain form of the decision variable encoding as the operation object. This method of encoding decision variables makes it possible for us to use the concepts of chromosomes and genes in biology for reference in optimization calculation, to imitate the genetic and evolutionary incentives of organisms in nature, and to easily apply genetic operators. (2) Directly use fitness as search information. The traditional optimization algorithm not only needs to use the value of the objective function, but also needs to satisfy the requirement of “the derivative of the objective function must exist” in order to determine the search direction. Genetic algorithm can only use the fitness function value transformed from the objective function value to determine the further search range, without the derivative value of the objective function and other auxiliary information. The objective function value or individual fitness value can be directly used to concentrate the search scope into the search space with higher fitness, so as to improve the search efficiency. (3) Search information of multiple points is used with implicit parallelism. Traditional optimization algorithms usually start from an initial point in the solution space to search the optimal solution iteratively. The search information provided by a single point is not much, so the search efficiency is not high, and there may be local optimal solution and stagnation. Genetic algorithms start the search process for optimal solutions from an initial population consisting of many individuals rather than from a single individual. The operation of selection, crossover and mutation on the initial population produces a new generation of population, which contains a lot of population information. This information can avoid searching some unnecessary points, so as to avoid falling into the local optimal solution and gradually approach the global optimal solution. (4) Use probabilistic search rather than deterministic rules. Traditional optimization algorithms often use deterministic search methods, the transfer of a search point to another search point has a certain direction and transfer relationship, such deterministic search may not reach the optimal shop, limit the scope of application of the algorithm. Genetic algorithm (GA) is a kind of adaptive search technology. Its selection, crossover, mutation and other operations are carried out in a probabilistic way, which increases the flexibility of the search process, and can converge to the optimal solution with a large probability, and has a good global optimization capability. However, crossover probability, mutation probability and other parameters can also affect the search results and search efficiency of the algorithm, so how to choose the parameters of genetic algorithm is a relatively important problem in its application. To sum up, genetic algorithm provides a general framework for solving complex system problems because the overall search strategy and optimal search mode of genetic algorithm do not depend on gradient information or other auxiliary knowledge in calculation, but only require the solution of objective function that affects the search direction and the corresponding fitness function. It is not dependent on the specific domain of the problem and has strong robustness to the type of the problem, so it is widely used in a variety of fields, including: function optimization, combinatorial optimization production scheduling problem, automatic control, robotics, image processing (image restoration, image edge feature extraction……) Artificial life, genetic programming, machine learning.

Simple Genetic Algorithms (SGA) only uses selection operator, crossover operator and mutation operator. It is the basis of other Genetic Algorithms because of its Simple evolution process.

3.1 The basic process of genetic algorithm generates a number of initial populations encoded by a certain length (length is related to the accuracy of the problem to be solved) in a random way; Each individual was evaluated by fitness function, and the individuals with high fitness were selected to participate in genetic operation, while the individuals with low fitness were eliminated. The collection of genetically manipulated individuals (replication, crossover, mutation) forms a new generation of population until the stop criterion (evolutionary algebra GEN>=?) is satisfied. ; The best cashed individual in the offspring is taken as the execution result of the genetic algorithm.Where GEN is the current algebra; M is population size and I is population size.

3.2 Implementation technology of Genetic Algorithm Basic genetic algorithm (SGA) is composed of coding, fitness function, genetic operator (selection, crossover, variation) and operating parameters. 3.2.1 Encoding (1) Binary encoding The length of the string encoded in binary is related to the accuracy of the problem solved. It is necessary to ensure that every individual in the solved space can be coded. Disadvantages: large length (2) Other coding methods gray code, floating point coding, symbol coding, multi-parameter coding, etc. 3.2.2 Fitness function Fitness function should effectively reflect the gap between each chromosome and the optimal solution of the problem chromosome. 3.2.3 Selecting the operator3.2.4 Crossover Operator Crossover operation refers to the exchange of part of genes between two mutually paired chromosomes in a certain way, so as to form two new individuals; Crossover operation is an important feature of genetic algorithm which is different from other evolutionary algorithms and is the main method to generate new individuals. Before crossover, individuals in the group need to be matched, generally adopting the principle of random pairing. Common crossover methods: Single point crossing double point crossing (multi-point crossing, the more points of crossing, the more likely the individual’s structure will be destroyed, Arithmetic crossover 3.2.5 mutation operator Mutation operation in genetic algorithm refers to the replacement of gene values at some loci in the coding string of individual chromosome with other alleles of that loci, thus forming a new individual.

In terms of the ability to generate new individuals in the process of genetic algorithm, crossover operation is the main method to generate new individuals, which determines the global search ability of genetic algorithm. Mutation operation is only an auxiliary method to generate new individuals, but it is also an essential operation step, which determines the local search ability of genetic algorithm. The combination of crossover operator and mutation operator completes the global search and local search of the search space, so that the genetic algorithm can complete the optimization process with good search performance.

3.2.6 Operating Parameters4 Basic principle of genetic algorithm 4.1 Pattern theorem4.2 Building blocks Assume that patterns with low order, short definition length, and fitness values higher than the population average fitness value are called gene blocks or building blocks. Building block hypothesis: individual gene blocks can be spliced together to form individual coding strings with higher fitness through selection, crossover, mutation and other genetic operators. The building block hypothesis illustrates the basic idea of solving all kinds of problems with genetic algorithms, that is, better solutions can be produced by directly joining the building blocks together.

Ii. Source code

%% Clear environment CLC clear tic; %% genetic algorithm parameter MAXGEN=200; % evolution algebra sizepop=40; % population size Pcross =0.6; % cross probability pmutation=0.01; % variance probability lenchrom=ones(1,48); % variable string length bound=[-20 20-20 20-20 20-20 20-20 20-20 - 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20-30, 120 to 30, 120 to 30, 120 to 30, 120 to 30, 120 to 30, 120 to 30, 120 to 30, 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 30 120 Trace =zeros(1,MAXGEN); %% individual initialization gen=1; fprintf('%d\n',gen); individuals=struct('fitness',zeros(1,sizepop), 'chrom',[],'pgrid',[],'Ebat',[]); % population structure bestfitness=[]; % population optimum fitness bestChrom =[]; For I =1:sizepop individuals. Chrom (I,:)=Code(lenchrom,bound); X=individuals. Chrom (I,:); [money pgrid Ebat]=fun(X); individuals.fitness(i)=money; % individual fitness individuals. Pgrid (I,:)=pgrid; individuals.Ebat(i,:)=Ebat; End % Find the best chromosome [bestindex]=min(individuals. Fitness); bestchrom=individuals.chrom(bestindex,:); % bestpgrid=individuals. Pgrid (bestindex,:); BestEbat =individuals.Ebat(bestindex,:) % record the bestfitness and average fitness trace(1)=bestfitness; Function ret = Cross (pcross lenchrom, chrom, sizepop, bound) % % pcorss the crossover operation of the completion of this function input: crossover probability % lenchrom input: Chromosome length % chrom input: chromosome population % sizePOP input: population size % ret output: For I =1:sizepop % Select two chromosomes to cross randomly pick=rand(1,2); While the prod (pick) = = 0 pick = rand (1, 2); end index=ceil(pick.*sizepop); Pick =rand; while pick==0 pick=rand; end if pick>pcross continue; end flag=0; While flag==0 % pick=rand; while pick==0 pick=rand; end pos=ceil(pick.*sum(lenchrom)); % Randomly select the location for crossover, that is, the number of variables selected for crossover. Note: the two chromosomes cross at the same location pick=rand; % cross start v1=chrom(index(1),pos); v2=chrom(index(2),pos); For I =1:sizepop % select a random chromosome to mutate pick=rand; while pick==0 pick=rand; end index=ceil(pick*sizepop); % mutation probability determines whether the cycle is mutated pick=rand; if pick>pmutation continue; end flag=0; While flag==0 % pick=rand; while pick==0 pick=rand; end pos=ceil(pick*sum(lenchrom)); % Randomly select the location of chromosome variation, that is, select the pos variable for variation v= Chrom (I,pos); v1=v-bound(pos,1); v2=bound(pos,2)-v; pick=rand; % variation if pick delta = > 0.5 v2 * (1 - pick ^ ((1 - pop/pop (2) (1)) ^ 2)); chrom(i,pos)=v+delta; else delta=v1*(1-pick^((1-pop(1)/pop(2))^2)); chrom(i,pos)=v-delta; Flag =test(lenchrom,bound,chrom(I,:)); End end ret=chrom; if flag1*flag2==0 flag=0; else flag=1; End function ret=Select(individuals,sizepop) % End function ret=Select(individuals,sizepop) % % individuals input: population information % sizePOP input: population size % opts input: selection method % ret output: Fitness = 1./(individuals. Fitness); sumfitness=sum(individuals.fitness); sumf=individuals.fitness./sumfitness; index=[]; For I =1:sizepop % to sizepop pick=rand; while pick==0 pick=rand; end for j=1:sizepop pick=pick-sumf(j); if pick<0 index=[index j]; break; End end individuals. Chrom =individuals. Chrom (index,:); end end individuals. individuals.fitness=individuals.fitness(index); end ret=chrom;Copy the code

3. Operation results

Fourth, note

Version: 2014 a