1 Mathematical Model

(1) Explanations and assumptions about the model

1) Known quantities in the model include: location coordinates of each demand point, quantity of material demand at each demand point, arrival time requirements of materials at each demand point, the shortest driving distance between distribution center and each demand point, and the shortest transportation distance between each demand point.

2) The field investigation found that the materials to be distributed can be mixed on the same material rack, and the quantity of materials required by each demand point is smaller than the stock of the material warehouse.

3) Ignore external factors unfavorable to production, such as crowded queues encountered by vehicles in the distribution process, that is to say, the whole assembly workshop runs normally. At the same time, the type, speed and load capacity of the vehicles used in the distribution process are the same, and the distribution vehicles run at a uniform speed in the workshop.

4) Due to the different consumption rates of materials at each production station, in order to better conduct the research, the consumption rates of materials at each demand point should be consistent with the corresponding planned production beat, and the reproduction status of unqualified products should be ignored.

(2) Several constraints on the model

In the modeling process, the following constraints should be taken into account.

1) On each distribution path, the sum of material demands at all demand points shall not exceed the maximum loading capacity of unit distribution vehicles

2) There is only one vehicle on each distribution path for material delivery, and no other vehicles can be used for delivery. Moreover, delivery vehicles only arrive at each demand point on each path once.

3) All the distribution vehicles go out of afa by the same distribution center for material distribution activities. After the distribution activities, the vehicles must return to the original distribution center, and there is no loading situation during the distribution process.

4) For two adjacent demand points on the same distribution path, the moment when the vehicle arrives at the previous demand point shall not exceed the moment when it arrives at the later demand point.





2 Genetic Algorithm

Genetic algorithm (ga)

• Genetic Algorithm (GA) is an evolutionary Algorithm whose basic principle is to imitate the evolutionary law of “natural selection and survival of the fittest” in biology. It was first proposed by Professor J. Holland of University of Michigan in 1967. • Genetic algorithms start with a population that represents the set of possible potential solutions to a problem. A population consists of a number of individuals encoded by a gene. Therefore, the first step is to achieve the mapping from phenotype to genotype, that is, coding. After the generation of the initial population, according to the principle of survival of the fittest and survival of the fittest, generation by generation evolution produces better and better approximate solutions. In each generation, individuals are selected according to their fitness in the problem domain. By virtue of genetic operators of natural genetics, a population representing the new solution set is generated. This process leads to the evolution of the population like natural evolution, in which the population in the later generation is more adaptable to the environment than the previous generation, and the optimal individual in the last generation is through decoding, which can be regarded as the approximate optimal solution of the problem.

• Genetic algorithms have three basic operations: Selection, Crossover and Mutation. • (1) Choice. The purpose of selection is to select good individuals from the current population so that they have a chance to father the next generation. According to the fitness value of each individual, according to certain rules or methods, some excellent individuals from the previous generation of population were selected and passed on to the next generation of population. Selection is based on the probability that highly adaptable individuals will contribute one or more offspring to the next generation. • (2) cross. A new generation of individuals can be obtained through crossover operation, and the new individuals combine the characteristics of the parent individuals. Individuals in the population are randomly paired, and for each individual, some chromosomes between them are exchanged with crossover probability. • (3) variation. To change the value of one or more loci to the other alleles with the probability of variation for each individual in the population. As in biology, variation is rare and provides opportunities for the creation of new individuals.

The basic steps of genetic algorithm:

1) Coding: GA first represents the solution data of the solution space as the genotype string structure data of the genetic space before searching, and the different combinations of these string structure data constitute the different points. 2) Generation of initial group: N initial string structure data are randomly generated, and each string structure data is called an individual, and N individuals constitute a group. GA starts to evolve with these N string structure data as the initial point. 3) Fitness evaluation: fitness indicates the advantages and disadvantages of an individual or solution. The definition of adaptive function is also different.

4) Selection: The purpose of selection is to select good individuals from the current population so that they have a chance to reproduce as fathers for the next generation. Genetic algorithm embodies this idea through the selection process, the principle of selection is that adaptable individuals have a high probability of contributing one or more offspring to the next generation. Selection embodies Darwinian principle of survival of the fittest. 5) Crossover: crossover operation is the most important genetic operation in genetic algorithm. A new generation of individuals can be obtained through crossover operation, and the new individuals combine the characteristics of their parents. Crossover embodies the idea of information exchange. 6) Variation: firstly, an individual is randomly selected in the population, and the value of a certain string in the string structure data is randomly changed with a certain probability for the selected individual. As in biology, the probability of variation in GA is very low, and the value is usually very small.

Genetic Algorithm Toolbox:

• MATLAB embedded genetic algorithm toolbox: Gadst • Sheffield Genetic algorithm toolbox: Gatbx • UnC Genetic algorithm toolbox: GAOT

Initializega function:

The ga functions:

Optimization of initial weights and thresholds of BP neural network by genetic algorithm:

The simulation results







Optimized data









Complete code or simulation consulting to add QQ1575304183

Matlab code display

Clear CLC close all tic %% % shuju= importData ('cc101.txt'); load('cc101'); shuju=c101; % bl=importdata('103.txt'); bl=0; cap=800; % maximum vehicle loading %% extracted data information E=shuju(1,5); % start time of distribution center time window L=shuju(1,6); % End time of distribution center time window zuobiao=shuju(:,2:3); % vertexs= vertexs./1000; customer=zuobiao(2:end,:); Cusnum =size(customer,1); % number of customers v_num=6; % Max value =shuju(2:end,4); A =shuju(2:end,5); % customer time window start time [a[I],b[I]] b=shuju(2:end,6); % customer time window end time [a[I],b[I]] s=shuju(2:end,7); % Customer point service time h=pdist(zuobiao); % dist=load('dist1.mat'); % dist=struct2cell(dist); % dist=cell2mat(dist); % dist=dist./1000; Dist =squareform(h); C [I][j]=dist[I][j] %% genetic algorithm parameter setting alpha=100000; % penalty function coefficient belta=900 for capacity constraint violation; % Penalty function coefficient belta2=60 for violating the time window constraint; Chesu = 0.667; NIND=100; % population size MAXGEN=50; % iteration times Pc=0.9; % cross probability Pm=0.05; % variation probability GGAP=0.9; % Generation gap N= Cusnum +v_num-1; % chromosome length = number of customers + maximum number of vehicles -1 % N= Cusnum; Init (Cusnum, A,demands,cap); Chrom=InitPopCW(NIND,N,cusnum,init_vc); %% Output route and total distance of random solution disp(' a random value in the initial population :') [VC,NV,TD,violate_num,violate_cus]=decode(Chrom(1,:),cusnum,cap,demands,a,b,L,s,dist,chesu,bl); % disp(' disp: ',num2str(TD)]); Disp (' number of vehicles used: ',num2str(TD),',num2str(TD),', violate_num (violate_num),', number of customers violated: ',num2str(violate_cus)]); Disp (' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ') % % optimization gen = 1; figure; hold on; Box on xlim([0,MAXGEN]) title(' optimized process ') xlabel(' algebra ') ylabel(' optimal value ') ObjV=calObj(Chrom,cusnum,cap,demands,a,b,L,s,dist,alpha,belta,belta2,chesu,bl); % preObjV=min(ObjV); While gen < = MAXGEN calculation fitness ObjV % % = calObj (Chrom, cusnum, cap, demands, a, b, m, s, dist, alpha, belta, belta2, chesu, bl); % Calculate population objective function value line([gen-1,gen],[preObjV,min(ObjV)]); Pause (0.0001)% preObjV=min(ObjV); FitnV=Fitness(ObjV); % % choose SelCh = Select (Chrom, FitnV, GGAP); SelCh=Recombin(SelCh,Pc); % % variable SelCh = Mutate (SelCh, Pm); % % local search operations SelCh = LocalSearch (SelCh cusnum, cap, demands, a, b, L, s, dist, alpha, belta, belta2, chesu, bl); %% Chrom=Reins(Chrom,SelCh,ObjV); %% delete the duplicate individuals in the population, and complement the deleted individuals Chrom=deal_Repeat(Chrom); % % to print the current optimal solution ObjV = calObj (Chrom, cusnum, cap, demands, a, b, L, s, dist, alpha, belta, belta2, chesu, bl); % Calculate population objective function value [minObjV,minInd]=min(ObjV); Disp ([' ',num2str(gen),' ']) [bestVC,bestNV,bestTD,best_vionum,best_viocus]=decode(Chrom(minInd(1),:),cusnum,cap,demands,a,b,L,s,dist,chesu,bl); Disp ([' number of vehicles used: ',num2str(bestNV),',num2str(bestNV),',num2str(best_vionum),', number of customers violated the constraint: ',num2str(best_vionum),', ',num2str(best_viocus)]); Fprintf ('\n') %% Number of iterations gen=gen+1; End % % of the optimal solution roadmap ObjV = calObj (Chrom, cusnum, cap, demands, a, b, m, s, dist, alpha, belta, belta2, chesu, bl); % Calculate population objective function value [minObjV,minInd]=min(ObjV); Disp (' best solution :') bestChrom=Chrom(minInd(1),:); [bestVC,bestNV,bestTD,best_vionum,best_viocus]=decode(bestChrom,cusnum,cap,demands,a,b,L,s,dist,chesu,bl); Disp ([' number of vehicles used: ',num2str(bestNV),',num2str(bestNV),',num2str(best_vionum),', number of customers violated the constraint: ',num2str(best_vionum),', ',num2str(best_viocus)]); Disp (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ') % % determine the optimal solution meets the time window constraints and capacity constraints, 0 means in violation of the constraints, 1 to satisfy all constraints flag = Judge (bestVC, cap, demands, a, b, L, s, dist, chesu, bl); DEL=Judge_Del(bestVC, Cusnum); init_v=vehicle_load(bestVC,demands); Draw_Best (bestVC,zuobiao);Copy the code