A list,

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

2 Characteristics and Applications 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) It takes the coding of decision variables as the operation object. Traditional optimization algorithm often directly uses the actual value of decision variables to carry out optimization calculation, but genetic algorithm uses some form of coding of decision variables as the operation object. This coding processing method of decision variables makes it possible for us to learn from the concepts of chromosome and gene in biology, to imitate the genetic and evolutionary incentives of organisms in nature, and to easily apply genetic operators in optimization calculation. (2) Use fitness as the search information directly. The traditional optimization algorithm not only needs to use the value of the objective function, but also the search process is often constrained by the continuity of the objective function. It may also need to meet the requirement of “the derivative of the objective function must exist” to determine the search direction. Genetic algorithm only uses the fitness function value transformed from the value of the objective function to determine the further search range, without the derivative of the objective function and other auxiliary information. Directly using the value of the objective function or the individual fitness value can also focus the search range to the search space with higher fitness, so as to improve the search efficiency. (3) The search information of multiple points is used, which has implicit parallelism. The traditional optimization algorithm usually starts from an initial point in the solution space and iteratively searches for the optimal solution. A single point provides little search information, so the search efficiency is not high, and may fall into the local optimal solution and stagnation; Genetic algorithms start the search process for the optimal solution from an initial population composed of many individuals, rather than from a single individual. The operation, selection, crossover and variation of the initial population produce a new generation of population, which includes a lot of population information. These 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 searches rather than deterministic rules. Traditional optimization algorithms often use deterministic search methods. The transition from one search point to another has a certain direction and relationship, which may make the search not reach the optimal store and limit the application scope of the algorithm. Genetic algorithm 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, has a good global optimization solving ability. However, parameters such as crossover probability and mutation probability will also affect the search results and search efficiency of the algorithm, so how to select the parameters of genetic algorithm is a relatively important problem in its application. To sum up, because the overall search strategy and optimization search method of genetic algorithm do not rely on gradient information or other auxiliary knowledge, and only need to solve the objective function and the corresponding fitness function that affect the search direction, genetic algorithm provides a general framework for solving complex system problems. It does not depend 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 of production scheduling problems, automatic control, robotics, image processing (image recovery, image edge feature extraction……) Artificial life, genetic programming, machine learning.

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

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

The basic genetic algorithm (SGA) consists of coding, fitness function, genetic operators (selection, crossover, mutation) and operating parameters. 3.2.1 Coding (1) Binary coding The length of binary coding string is related to the accuracy of the problem. You need to make sure that every individual in the space you’re solving for can be coded. Advantages: simple operation of coding and decoding, and easy realization of heredity and crossover Disadvantages: large length (2) Other coding methods: Gray code, floating point number coding, symbol coding, multi-parameter coding, etc. 3.2.2 Fitness function The fitness function should effectively reflect the gap between each chromosome and the optimal solution chromosome of the problem. 3.2.3 Selection operator3.2.4 Crossover operator Crossover operation refers to the formation of two new individuals by the exchange of some genes between two pairs of chromosomes in a certain way. Cross operation is an important characteristic of genetic algorithm which is different from other evolutionary algorithms and is the main method of generating new individuals. Before crossover, individuals in the group need to be paired, and the principle of random pairing is generally adopted. Common ways to cross: Single-point crossover, double-point crossover (multi-point crossover, the more crossover points, the more likely the individual structure is destroyed, Uniform crossover arithmetic crossover 3.2.5 Mutation operator Mutation operation in genetic algorithm is to replace the gene value of some loci in the individual chromosome coding string with other alleles of the locus, thus forming a new individual.

In terms of the ability of generating new individuals in the process of genetic algorithm operation, cross operation is the main method of generating 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 of the optimization problem with good search performance.

3.2.6 Running Parameters4 Basic principles of genetic algorithm 4.1 Pattern theorem4.2 Building Blocks A pattern that assumes low order, short defined length, and fitness value higher than the average fitness value of the population is called a genetic block or building block. Building block hypothesis: individual gene blocks can be spliced together to form individual coding strings with higher fitness through the action of genetic operators such as selection, crossover and mutation. The building block hypothesis illustrates the basic idea of solving various problems with genetic algorithms, that is, better solutions can be produced by building blocks directly joining each other together.

Ii. Source code

%Single Link Inverted Pendulum Control clear all; close all; Global A B C D %Single Link Inverted Pendulum Parameters g=9.8; M = 1.0; M = 0.1; L = 0.5; Fc = 0.0005; Fp = 0.000002; I=1/12*m*L^2; l=1/2*L; t1=m*(M+m)*g*l/[(M+m)*I+M*m*l^2]; t2=-m^2*g*l^2/[(m+M)*I+M*m*l^2]; t3=-m*l/[(M+m)*I+M*m*l^2]; t4=(I+m*l^2)/[(m+M)*I+M*m*l^2]; A = [0,1,0,0; t1, 0, 0, 0,0,0,1; t2, 0, 0]; B=[0;t3;0;t4]; C = [1,0,0,0; 0,0,1,0]; D=[0;0]; e1_1=0; e2_1=0; e3_1=0; e4_1=0; u_1=0; Xk = [- 10/57.3, 0,0.20, 0]; % Initial state ts = 0.02; for k=1:1:1000 time(k)=k*ts; Tspan=[0 ts]; para=u_1; [t,x]=ode45('chap7_12f',Tspan,xk,[],para); z=length(x); xk=x(length(x),:); R1 (k) = 0.0; % Pendulum Angle r2 (k) = 0.0; % Pendulum Angle Rate r3 (k) = 0.0; % the Car Position r4 (k) = 0.0; %Car Position Rate x1(k)=xk(1); x2(k)=xk(2); x3(k)=xk(3); x4(k)=xk(4); e1(k)=r1(k)-x1(k); e2(k)=r2(k)-x2(k); e3(k)=r3(k)-x3(k); e4(k)=r4(k)-x4(k); de1(k)=e1(k)-e1_1; U1 (k) = e1 (k) - 6.2366-43.304 * * de1 (k); de2(k)=e2(k)-e2_1; U2 (k) = e2 (k) - 6.2366-6.2366 * * de2 (k); de3(k)=e3(k)-e3_1; U3 (k) e3 (k) = 6.2366 * 6.2366 * de3 (k); de4(k)=e4(k)-e4_1; U4 (k) = 6.2366 * e4 (k) to 6.2366 * de4 (k); u(k)=u1(k)+u2(k)+u3(k)+u4(k); if u(k)>=10 u(k)=10; elseif u(k)<=-10 u(k)=-10; end e1_1=e1(k); e2_1=e2(k); e3_1=e3(k); e4_1=e4(k); u_1=u(k); end ee1_1=0; ee2_1=0; ee3_1=0; ee4_1=0; uu_1=0; XXK = [- 10/57.3, 0,0.20, 0]; %Initial state for i=1:1:1000 time1(i)=i*ts; Tspan=[0 ts]; para1=uu_1; [tt,xx]=ode45('chap7_12f',Tspan,xxk,[],para1); zz=length(xx); xxk=xx(length(xx),:); Rr1 (I) = 0.0; % Pendulum Angle rr2 (I) = 0.0; % Pendulum Angle Rate rr3 (I) = 0.0; % the Car Position rr4 (I) = 0.0; %Car Position Rate xx1(i)=xxk(1); xx2(i)=xxk(2); xx3(i)=xxk(3); xx4(i)=xxk(4); ee1(i)=rr1(i)-xx1(i); ee2(i)=rr2(i)-xx2(i); ee3(i)=rr3(i)-xx3(i); ee4(i)=rr4(i)-xx4(i); dee1(i)=ee1(i)-ee1_1; uu1(i)=-50*ee1(i)-10*dee1(i); dee2(i)=ee2(i)-ee2_1; uu2(i)=-10*ee2(i)-10*dee2(i); dee3(i)=ee3(i)-ee3_1; uu3(i)=-10*ee3(i)-10*dee3(i); dee4(i)=ee4(i)-ee4_1; uu4(i)=-10*ee4(i)-10*dee4(i); uu(i)=uu1(i)+uu2(i)+uu3(i)+uu4(i); if u(i)>=10 u(i)=10; elseif u(i)<=-10 u(i)=-10; end ee4_1=ee4(i); uu_1=uu(i); end figure(1); plot(time,r1,'r',time,x1,'b'); %Pendulum Angle xlabel('time(s)'); ylabel('Angle'); hold on plot(time1,xx1,'--'); %Pendulum Angle figure(2); plot(time,r2,'r',time,x2,'b'); %Pendulum Angle Rate xlabel('time(s)'); ylabel('Angle rate'); hold on plot(time1,xx2,'--'); figure(3); plot(time,r3,'k',time,x3,'b'); %Car Position xlabel('time(s)'); ylabel('Cart position'); hold on plot(time1,xx3,'--'); figure(4); plot(time,r4,'r',time,x4,'b'); %Car Position Rate xlabel('time(s)'); ylabel('Cart rate'); hold on plot(time1,xx4,'--'); figure(5); plot(time,u,'b'); %Force F change xlabel('time(s)'); ylabel('Force'); hold on plot(time1,uu,'--');Copy the code

Third, the operation result

Fourth, note

Version: 2014 a