[Shop Floor Scheduling] matlab Source Code for Product Automatic Sorting Problem Based on Genetic Algorithms

1. Model Introduction 1.1 Genetic Algorithms ...
1. Model Introduction
2.2. Process of algorithm
2. Partial Codes
3. Simulation results
4. References

1. Model Introduction

1.1 Genetic Algorithms

Genetic AlgorithmsGenetic algorithm is a heuristic search algorithm inspired by Darwin's evolutionary theory and based on the process of biological evolution. Its main feature is that it operates directly on the structural objects, so unlike other algorithms for solving optimal solutions, there is no derivation and function continuity restriction for genetic algorithm. It uses a probabilistic optimization method and does not needDetermined rules automatically capture and direct the optimized search space and adjust the search direction adaptively.

The above is a relatively abstract summary of genetic algorithms. In order to explain the general principles of genetic algorithms in a more specific way, we first introduce some biological concepts:

(1) Population: A group formed by individuals of different organisms whose evolution takes place as a group, such a group is called a population;

(2) Individuals: individual organisms that make up a population;

(3) Genes: DNA fragments with genetic information, which can be generally interpreted as a piece of information that determines the individual's characteristics;

(4) Phenotypes: according to the external manifestations of individuals genetically formed;

Adaptability: The more adaptable an individual is to the living environment, the greater the probability that he or she will survive and reproduce.

Inheritance: Through the reproductive process, the offspring will acquire a part of the genes from both parents to form their own new genes. In this process, gene replication and crossover will occur, and gene mutation will occur at a lower probability.

Natural selection: natural selection through competition, the natural elimination mechanism of the survival of the fittest. Specifically, individuals with a high degree of environmental adaptability have more opportunities to participate in reproduction and more offspring will be generated. Individuals with a low degree of adaptability have fewer opportunities to participate in reproduction and fewer offspring will be generated.

_Evolution: The process in which a population adapts to its living environment through intergenerational propagation, in which the biological characteristics are continuously improved based on the criterion of suitability to the external environment.

Understanding the meaning of these terms, we can further talk about the process of biological evolution. Because natural selection exists objectively, that is, organisms can only change themselves to adapt to the environment, then in the process of natural selection, individuals with low fitness will be eliminated, individuals with high fitness will be retained, and parents with high fitness will have a higher probability of reproduction.Higher offspring, so after generation after generation, highly adaptable individuals account for a larger proportion of the population and the population has evolved.

Now we are going to use the process of biological evolution to solve the problem of finding the optimal solution. For this reason, the idea of genetic algorithm is to simulate the problem to be solved into a process of biological evolution and find the optimal solution through evolution. Take the problem of finding the maximum value of multimodal function in our topic as an example:

Consider the possible solution (x, y) as an individual; use the function value f(x, y) of the multimodal function as the fitness of the individual; code (x, y) as the gene of the individual; constantly screen the individual based on fitness; and use genetic operators (such as replication, crossover, variation, etc.)Continuously produce the next generation. Continuously iterate so as to complete the evolution. Finally, according to the number of iterations set, the last generation population can be obtained, in which the individual fitness is higher, and the maximum of the multimodal function has a greater probability to exist in this group solution. If the individual with the highest fitness in the population is used as the solution to the problem, then the solution has a higher overview.Rate is the best solution we want to find.

After all, the text is not as well understood as the chart, so let's look at the picture (the following image links this topic to natural inheritance):

From the above description, it is not difficult to see that genetic algorithm can not guarantee the best solution, but can only find the best solution with a certain probability. But when using genetic algorithm, we can not care about how to find the best solution, but simply deny some individuals who do not perform well. This advantage is also one of the reasons why genetic algorithm can be widely used..

2.2. Process of algorithm

With the explanations above, it is clear how to simulate natural evolution to find the optimal solution of the multimodal function. Here I will list the main steps of the genetic algorithm and analyze them one by one:

Step 1: Randomly generate a population as the first generation solution to the problem (usually, the first generation solution may be quite different from the optimal solution, which is tolerable, as long as the first generation solution is guaranteed to be randomly generated to ensure the diversity of individual genes);

Step 2: Find an appropriate encoding scheme to code individuals in the population. You can choose common encoding schemes such as floating point or binary encoding (it should be noted that different encoding schemes directly affect the implementation details of subsequent genetic operators).

The third step is to calculate the fitness of each individual in the population using the function value of the multimodal function as the fitness of the individual (the calculated fitness will provide the basis for subsequent individual selection).

Step 4: Select parents and mothers to participate in reproduction according to their fitness level. The principle of selection is that individuals with higher fitness are more likely to be selected (thereby eliminating individuals with lower fitness);

Step 5: Perform genetic operations on the selected parent and mother, i.e. copy the parent and mother's genes, and use operators such as crossover and mutation to produce offspring (mutation increases the diversity of genes, thus increasing the probability of finding the best solution, while retaining the best genes to a greater extent);

Step 6: According to certain criteria, decide whether to continue the algorithm or find the most suitable individual among all descendants to return to and end the program as solution (criteria can be set threshold of solution, specified iteration number, etc.).

2. Partial Codes

%----Principal Function ------ % Function: Program.m % Description: Automatic Sorting of Products Using Genetic Algorithms % Input: None % Output: None % Return: None % Referred: SHL.m % SHL Model % Ini_Pop % Initial Population Generation Function % Decoding.m % Decoding function % Fitness.m % Fitness function % Selection.m % Selection function % Crossover.m % Crossover function % Mutation.m % Variogram % Exchange.m % Interpopulation gene exchange function % Draw.m % Drawing Functions % Variable: Num_Work % Assembly Line Work Number % Num_Pop1 % Initial Population 1 Number % Num_Pop2 % Two Numbers of Initial Population % Num_Exc % Number of Exchange Genes % Pro_C1 % Initial Population 1 Cross Probability % Pro_C2 % Initial Population 2 Crossing Probability % Pro_M1 % Initial Population 1 Variation Probability % Pro_M2 % Initial Population 2 Variation Probability % Num_Gene % Propagation algebra % Time % Time per station % Matrix % Priority Relationship Matrix % Pop1 % Initial Population 1 % Pop2 % Initial Population 2 % Pop11 % Iterative Population 1 % Dec_Pop1 % Decoded Population 1 % Fit_Pop1 % Population 1 Fitness % Sel_Pop1 % Selected Population 1 % Cro_Pop1 % Crossed Population 1 % Mut_Pop1 % Population 1 after mutation % Pop12 % Population 1 Optimal Reservation(Used for interspecific crossover) % Pop21 % Iterative Population 2 % Dec_Pop2 % Decoded Population 2 % Fit_Pop2 % Population 2 Fitness % Sel_Pop2 % Selected Population 2 % Cro_Pop2 % Crossed Population 2 % Mut_Pop2 % Population 2 after mutation % Pop22 % Population 1 Optimal Reservation(Used for interspecific crossover) % Pop00 % Optimal genes for each iteration % Dec_Pop00 % Optimal gene decoding results for each iteration % Others: None clc % empty Workspace, Command Window and Figure clear close all %Time=[2.80 9.52 3.26 3.61 4.18 6.34 6.12 2.07 3.14 2.17 5.24 3.31 2.13 5.04 9.87 2.75 3.19 5.64 3.39 14.55 1.09 5.02 1.21 3.48 6.72 1.98 3.91 5.57 5.14 7.94 3.12 5.36 2.88 1.38 4.23 3.61 3.74 2.88 4.58 2.97 5.73 5.94 4.51 1.52 5.31 2.22 4.49 4.28 3.61 8.32 7.13 4.08]; % Matrix=[0 1 1 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0 0]; % set(gcf,'outerposition',get(0,'screensize')); % Maximize Display Image % Parameter Initialization Num_Work=3; % Number of assembly line workstations Num_Pop1=100; % Initial Population 1 Number Num_Pop2=100; % Two Numbers of Initial Population Num_Exc=5; % Number of Exchange Genes Pro_C1=0.8; % Initial Population 1 Cross Probability Pro_C2=0.2; % Initial Population 2 Crossing Probability Pro_M1=0.2; % Initial Population 1 Variation Probability Pro_M2=0.05; % Initial Population 2 Variation Probability Num_Gene=100; % Propagation algebra %[Time,Matrix]=SHL(); % Time and Priority Matrix of Work Positions % Produce initial population Pop1=Ini_Pop(Matrix,Num_Pop1); % Initial Population 1 Pop2=Ini_Pop(Matrix,Num_Pop2); % Initial Population 2 % Iterative calculation of genetic algorithm Pop11=Pop1; Pop21=Pop2; for i=1:1:Num_Gene % Population 1 Iteration Dec_Pop1=Decoding(Pop11,Time,Num_Work); % decoding Fit_Pop1=Fitness(Dec_Pop1,Num_Work,Time,Pop11); % Find Fitness Sel_Pop1=Selection(Fit_Pop1,Num_Pop1,Pop11); % Choice Cro_Pop1=Crossover(Sel_Pop1,Pro_C1); % overlapping Mut_Pop1=Mutation(Cro_Pop1,Pro_M1,Matrix); % variation Pop12=Mut_Pop1; % Optimal Reservation Dec_Pop12=Decoding(Pop12,Time,Num_Work); Fit_Pop12=Fitness(Dec_Pop12,Num_Work,Time,Pop12); [a1 b1]=max(Fit_Pop1); % Replace the worst genes with the best [a2 b2]=min(Fit_Pop12); Pop12(b2,:)=Pop11(b1,:); %Population 2 iteration Dec_Pop2=Decoding(Pop21,Time,Num_Work); % decoding Fit_Pop2=Fitness(Dec_Pop2,Num_Work,Time,Pop21); % Find Fitness Sel_Pop2=Selection(Fit_Pop2,Num_Pop2,Pop21); % Choice Cro_Pop2=Crossover(Sel_Pop2,Pro_C2); % overlapping Mut_Pop2=Mutation(Cro_Pop2,Pro_M2,Matrix); % variation Pop22=Mut_Pop2; % Optimal Reservation Dec_Pop22=Decoding(Pop22,Time,Num_Work); Fit_Pop22=Fitness(Dec_Pop22,Num_Work,Time,Pop22); [a3 b3]=max(Fit_Pop2); [a4 b4]=min(Fit_Pop22); Pop22(b4,:)=Pop21(b3,:); % Population 1 crosses Population 2 [Pop11,Pop21]=Exchange(Pop12,Pop22,Num_Exc,Time,Num_Work); %Find the best results for each iteration,And draw the display Dec_Pop01=Decoding(Pop11,Time,Num_Work); Fit_Pop01=Fitness(Dec_Pop01,Num_Work,Time,Pop11); [a01 b01]=max(Fit_Pop01); Dec_Pop02=Decoding(Pop21,Time,Num_Work); Fit_Pop02=Fitness(Dec_Pop02,Num_Work,Time,Pop21); [a02 b02]=max(Fit_Pop02); if a01>a02 Pop00=Pop11(b01,:); Dec_Pop00=Decoding(Pop11(b01,:),Time,Num_Work); else Pop00=Pop21(b02,:); Dec_Pop00=Decoding(Pop21(b02,:),Time,Num_Work); end Draw(Pop00,Dec_Pop00,i,Time); % Drawing Functions pause(0.0010); % Delay Functions if (max(Dec_Pop00)==52) % Determine if the iteration is complete msgbox({'Iteration Completion,Number of iterations is',num2str(i)}) break; end end %Calculate final results after iteration Dec_Pop1=Decoding(Pop11,Time,Num_Work); Fit_Pop1=Fitness(Dec_Pop1,Num_Work,Time,Pop11); [a1 b1]=max(Fit_Pop1); Dec_Pop2=Decoding(Pop21,Time,Num_Work); Fit_Pop2=Fitness(Dec_Pop2,Num_Work,Time,Pop21); [a2 b2]=max(Fit_Pop2); if a1>a2 Pop=Pop11(b1,:); Dec_Pop=Decoding(Pop11(b1,:),Time,Num_Work); else Pop=Pop21(b2,:); Dec_Pop=Decoding(Pop21(b2,:),Time,Num_Work); end Draw(Pop,Dec_Pop,i,Time); save data % Save results

3. Simulation results

4. References

[1] Zhang Pengbin.Study on Product Sequencing of Mixed Flow Assembly Line in Nanhua Electric Machinery Plant [D].Anhui University of Technology.

10 September 2021, 12:05 | Views: 4175

Add new comment

For adding a comment, please log in
or create account

0 comments