The background,

Constraints: Multiple logistics centers. The vehicle starts from a logistics center and after completing the distribution task, it can return to the nearest logistics center instead of returning to the original logistics center, which is the open vehicle path. Of course, depending on the distance between the last customer of the vehicle service and all the logistics centers, if it is the shortest distance from the original logistics center, you can also return to the original logistics center. Optimization objective: The sum of fixed use cost (200 yuan/vehicle), vehicle travel time cost (0.3 yuan/minute), vehicle waiting time cost (0.3 yuan/minute), vehicle service time cost (0.3 yuan/minute) is minimum. Constraints :(1) do not exceed the vehicle capacity limit (vehicle capacity is 1000 units), (2) the service must be carried out within the customer time window, (3) the vehicle can arrive at the customer ahead of time, resulting in waiting time. (4) Set the departure time of vehicles from the logistics center as 0, i.e. 0 minute.

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, combinational optimization 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. It is the basis of other Genetic Algorithms because of its Simple evolution process.

3.1 Basic flow of genetic algorithm

A number of initial populations encoded by a certain length (length is related to the accuracy of the problem to be solved) are generated 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) consists of coding, fitness function, genetic operator (selection, crossover, variation) and operation parameters.

3.2.1 coding

(1) Binary coding

The length of the binary-encoded string depends on the precision of the problem being solved. It is necessary to ensure that every individual in the solved space can be coded.

Advantages: coding, decoding simple operation, inheritance, cross easy to achieve

Disadvantages: Large length

(2) Other coding methods

Gray code, floating point coding, symbol coding, multi – parameter coding and so on

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 Selecting the operator



3.2.4 Crossover operator

Crossover operation refers to two mutually paired chromosomes in a way to exchange part of their genes, 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:

A single point of intersection

Double point crossing (multi-point crossing, the more points of crossing, the more likely the individual’s structure will be damaged, generally, the multi-point crossing is not adopted)

Uniform cross

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 Parameters



4 Basic principles of genetic algorithm

4.1 Pattern Theorem



4.2 Building block hypothesis

Patterns with low order, short definition length, and fitness values higher than the population average 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

Function [] = opengAmainForFZH20200706 () Close all clear all tic% % % % % data read [data1, data2, data3, respectively, data4, data5, data6, data7] = textread ('depot2.txt'.'%n%n%n%n%n%n%n'.'delimiter'.', '.'headerlines'.1); Datazx =[data1 data2 data3 data4 data5 data6 data7]; Center data read % % % % % % % % % % [data1, data2, data3, respectively, data4, data5, data6, data7] = textread ('RC201.txt'.'%n%n%n%n%n%n%n'.'delimiter'.', '.'headerlines'.1);
data=[data1 data2 data3 data4 data5 data6 data7];
wjchangdu=size(data,1); %% The length of the call file % changes the service time of each client to5Minutes %for gg=2:wjchangdu
%     data(gg,7) =5;
% end
% data;
%%%%%%%%%%%%%
Gmax=1000; % Number of iterations Size=200; Pm = % scale0.03; % variation probability Pc=0.85; % cross probability maxQ=1000; % Load sudu=60/60; % Vehicle speed km/min fy=0.3; % Unit cost cb=200; % fixed cost khNum=length(data(:,1)); ZxNum =length(datazx(:,1)); % Number of centers cheNum=khNum; % Maximum number of vehicles = number of customers CodeL=khNum*2; % Number of encodings = Sequential order + Center allocation Allocation uses integer codes1It is to belong to1 2Belong to2
juli=zeros(khNum+1,khNum+1); % distance matrix calculationfor i=1:khNum % The distance between customersfor j=i+1:khNum
        juli(i,j)=(sum((data(i,2:3)-data(j,2:3)). ^2)) ^0.5; % from juli (j, I) = juli (I, j); % symmetric end endfor i=1:zxNum
    for j=1:khNum
        julizx(i,j)=(sum((datazx(i,2:3)-data(j,2:3)). ^2)) ^0.5; % distance to center end endfor i=1 :Size
    Pop(i,:)= [randperm(CodeL/2) ceil(rand(1,CodeL/2)*zxNum)]; % initialization is preceded by the order followed by the membership endfor kg=1:Gmax % start loop disp(['Genetic algorithm in progress' num2str(kg) 'suboptimization'])
    
    for i=1: Size % operation % calculated for each individual objective function fi = fical (Pop (I, :), CodeL, data, juli, maxQ, sudu, fy, cb, julizx, zxNum); % call target fit(1,i)=1/fi; End [Val,Ind]= Max (fit); % find the maximum value and its position gBestf=Val; GBestS =Pop(Ind,:); % Global optimal individual % select GA_chose (Pop,fit,Size); Pop=ga_cross(Pop,Size,CodeL,Pc); % mutation operation Pop= GA_mutation (Pop,Size,CodeL,Pm); Bestfi(kg)=gBestf; Pop(Size,:)=gBestS; % end of elite reserve strategy [MB, AP, ZSJ ZJL, waitingtime, qi] = fical (gBestS, CodeL, data, juli, maxQ, sudu, fy, cb, julizx, zxNum); The optimal calculation % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % figure ('color'[1 1 1])% convergence curve1./Bestfi)
xlabel('Evolutionary algebra')
ylabel('Objective function')
 
figure('color'[1 1 1[val,ind]=sort(AP(:,2)); % plot(AP(ind,3)); % arrival time curve plot(data(1:end,5),'r--'% time window start plot(data(1:end,6),'r:'% Time window end xlabel('Customer Number')
ylabel('the time/min')
legend('Start time of Service'.'Earliest required time'.'Latest claim time')
 
yanse={'r'.'b'.'m'};
for i1=1:max(AP(:,5Ind1 =find(AP(:,5)==i1); % Current centerfor i=1:max(AP(ind1,1)% Routing figure for each arranged vehicle ('color'[1 1 1[/ b] [b] [c] [Dfor  j=1:zxNum
            scatter(datazx(j,2),datazx(j,3),'b*')% each center coordinates text(datazx(j,2),datazx(j,3),'Distribution Center' num2str(datazx(j,1))])% endfor j=1:khNum
            scatter(data(j,2),data(j,3),'bo')% each customer coordinates text(data(j,2),data(j,3),num2str(data(j,1End ind=find(AP(ind1,1)==i); % lj=[AP(ind1(ind),2)]; % ind3=find(qi(:,1)==i1 & qi(:,2)==i);
        
        %             plot([datazx(i1,2); data(lj,2)],[datazx(i1,3); data(lj,3)].'r'% path plot([datazx(i1,2); data(lj,2); datazx(qi(ind3,3),2)],[datazx(i1,3); data(lj,3); datazx(qi(ind3,3),3)].'r')% path draw %end
        xlabel('x')Abscissa %ylabel('y')% ordinatetitle(['center' num2str(i1) 'vehicle' num2str(i) The path of 'is'. num2str(lj')])% end end figure('color',[1 1 1]) scatter(datazx(j,2),datazx(j,3),b*Datazx (j,2),datazx(j,3),['Distribution centerNum2str (datazx(j,1))])% End for J =1:khNum scatter(data(j,2),data(j,3),bo') % each client coordinates text (data (j, 2), data (j, 3), num2str (data (j, 1))) % number marked the end for i1 = 1: Max (AP (:, 5)) % ind1 = find every center (AP (:, 5) = = i1); % current center disp(['center' num2str(i1) 'Route arrangement:']) for I = 1: Max (AP (ind1, 1)) % each arrange vehicle path ind = find (AP (ind1, 1) = = I); % Lj =[AP(ind1(ind),2)]; Ind3 =find(qi(:,1)== i1&qi (:,2)== I); disp(['vehicle' num2str(i) 'Route arrangement:' num2str([i1+khNum lj'   qi(ind3,3)+khNum]) ])
        plot([datazx(i1,2); data(lj,2); datazx(i1,2)],[datazx(i1,3); data(lj,3); datazx(qi(ind3,3),3)].'r')% path draw end endxlabel('x')Abscissa %ylabel('y')% ordinatetitle( 'General Route Plan')% Path title annotates TOCdisp([The optimal total cost is:  num2str(1./Bestfi(end))    , the total number of vehicles is:   num2str(length(qi(:,1)))  ', total vehicle distance: '  num2str(zjl) ', total vehicle service time: ' num2str(zsj)  ', total waiting time: num2str(waitingtime)])
end
Copy the code

3. Operation results

Fourth, note

Version: 2014 a