[Shop Scheduling] Solve the time-constrained workshop scheduling problem based on matlab genetic algorithm [including Matlab source code 2696]

⛄1. Introduction to Workshop Scheduling

1 Definition of Workshop Scheduling
Workshop scheduling refers to assigning the sequence of processing workshops according to the reasonable demand of product manufacturing, so as to achieve the purpose of rationally utilizing product manufacturing resources and improving enterprise economic benefits. The job shop scheduling problem can be mathematically described as having n parts to be processed on m machines. The conditions that need to be met in the problem include that each process of each part uses each machine no more than once, and each part is processed in a certain order.

2 Traditional Job Shop Scheduling
Example of traditional job shop scheduling
insert image description here
There are several workpieces, each workpiece has several processes, and there are multiple processing machines, but each process can only be processed on one machine. Corresponding to the example in the above table, there are two workpieces, workpiece J1 has three processes, process Q11 can only be processed on M3, and the processing time is 5 hours.
The constraint is that for a workpiece, the relative order of the processes cannot be changed. O11->O12->O13. Each job can only be processed on one machine at a time; there can only be one job on each machine.
The task of scheduling is to arrange the processing sequence of the process. The processing sequence is determined, because only one machine is available for each process, and the processing machine is also determined.
The purpose of scheduling is the shortest total completion time (or other goals). For example, after determining the processing sequence of O21->O22->O11->O23->O12->O13, we can calculate the total processing time according to the constraints of the processing machine.
M2 consumes 6 hours to process O21, and the current processing time of workpiece J2 is 6 hours.
M1 consumes 9 hours to process O22, and the current processing time of workpiece J2 is 6+9=15 hours.
M3 consumes 5 hours to process O11, and the current processing time of workpiece J1 is 5 hours.
M4 takes 7 hours to process O23, and the processing time of workpiece J2 is 15+7=22 hours.
M1 consumes 11 hours to process O12, but it will start to process O12 after M1 finishes processing O22, so the current processing time of workpiece J1 is max(5,9)+11=20 hours.
M5 takes 8 hours to process O13, and the processing time of workpiece J2 is 20+8=28 hours.
The total completion time is max(22,28)=28 hours.

2 Flexible job shop scheduling
Examples of flexible job shop scheduling (refer to Gao Liang’s paper
"Improved Genetic Algorithms for Solving Flexible Job Shop Scheduling Problems" - Chinese Journal of Mechanical Engineering)
insert image description here
Compared with traditional job shop scheduling, flexible job shop scheduling relaxes the constraints on The constraints of processing machines are more in line with the actual production situation. There are multiple optional processing machines for each process, which can be processed by one of the multiple processing machines. For example, in the example in the above table, the O12 process of J1 can choose M2 and M4 processing, and the processing time is 8 hours and 4 hours respectively, but M4 processing is not necessarily selected, and the final total completion time is shorter. Therefore, A scheduling algorithm is required to solve the optimization.

Compared with the traditional job shop, the scheduling task of flexible job scheduling not only needs to determine the processing sequence of the process, but also needs to determine the machine allocation of each process. For example, if the processing sequence of O21->O22->O11->O23->O12->O13 is determined, we cannot process the corresponding processing machines, so we should also determine the corresponding [M1, M3, M5]->[M1 , M2, M3]->[M1, M2, M3, M4, M5]->[M2, M3, M4, M5]->[M2, M4]->[M1, M3, M4, M5] machine combination . The purpose of scheduling is still the shortest total completion time (it can also be other goals, such as the shortest maximum machine load and the shortest total machine load)

⛄ 2. Introduction to Genetic Algorithms

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

2. Characteristics and application of genetic algorithm
Genetic algorithm is a kind of robust search algorithm that can be used for complex system optimization. Compared with traditional optimization algorithm, it has the following characteristics: (1) The encoding
of decision variables is used as the operation object. Traditional optimization algorithms often use the actual value of the decision variable itself for optimization calculation, but the genetic algorithm uses some form of coding of the decision variable as the operation object. This way of encoding decision variables allows us to use concepts such as chromosomes and genes in biology for reference in optimization calculations, to imitate the genetic and evolutionary incentives of organisms in nature, and to easily apply genetic operators.
(2) Directly use fitness as search information. Traditional optimization algorithms not only need to use the value of the objective function, but also the search process is often constrained by the continuity of the objective function, and may also need to meet the requirement that "the derivative of the objective function must exist" to determine the search direction. The genetic algorithm only uses the fitness function value transformed from the objective function value to determine the further search range, without other auxiliary information such as the derivative value of the objective function. Directly using the objective function value or individual fitness value can also concentrate the search range into the search space with higher fitness, thus improving the search efficiency.
(3) Using the search information of multiple points has implicit parallelism. The traditional optimization algorithm is often an iterative search process for the optimal solution starting from an initial point in the solution space. The search information provided by a single point is not much, so the search efficiency is not high, and it may fall into a local optimal solution and stagnate; the genetic algorithm starts the search process of the optimal solution from the initial population composed of many individuals, rather than from a single individual Start searching. Operations such as selection, crossover, and mutation are performed on the initial population to generate a new generation of population, which includes a lot of group information. This information can avoid searching for some unnecessary points, so as to avoid falling into the local optimum and gradually approach the global optimal solution.
(4) Use probabilistic search instead of deterministic rules. Traditional optimization algorithms often use deterministic search methods. The transfer from one search point to another has a definite transfer direction and transfer relationship. This certainty may make the search fail to reach the optimal store, which limits the application of the algorithm. scope. Genetic algorithm is an adaptive search technology. Its selection, crossover, mutation and other operations are carried out in a probabilistic manner, which increases the flexibility of the search process and can converge to the optimal solution with a high probability. 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 choose the parameters of genetic algorithm is a relatively important issue in its application.
In summary, since the overall search strategy and optimal search method of the genetic algorithm do not depend on gradient information or other auxiliary knowledge during calculation, it only needs to solve the objective function and the corresponding fitness function that affect the search direction, so the genetic algorithm provides a 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 types of problems, so it is widely used in various fields, including: function optimization, combinatorial optimization production scheduling problems, automatic control, robotics, image processing (
image restoration, image edge feature extraction...), artificial life, genetic programming, machine learning.

3. Basic flow and implementation technology of genetic
algorithm Simple Genetic Algorithms (SGA) only uses three genetic operators, 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 process of genetic algorithm
Randomly generate several initial populations encoded by a certain length (the length is related to the precision of the problem to be solved);
evaluate each individual through the fitness function, and select individuals with high fitness values ​​to participate in the genetic operation , the individuals with low fitness are eliminated;
the collection of individuals through genetic manipulation (replication, crossover, mutation) forms a new generation of population until the stop criterion is met (evolutionary algebra GEN>=?)
; The result of the execution of the algorithm.
insert image description here
Among them, GEN is the current generation; M is the population size, and i represents the population number.

3.2 Implementation technology of genetic algorithm
The basic genetic algorithm (SGA) is composed of coding, fitness function, genetic operator (selection, crossover, mutation) and operating parameters.
3.2.1 Encoding
(1) Binary encoding
The string length of the binary encoding is related to the accuracy of the problem to be solved. It is necessary to ensure that every individual in the solution space can be encoded.
Advantages: simple encoding and decoding operations, easy implementation of inheritance and crossover
Disadvantages: large length
(2) Other encoding methods
such as Gray code, floating-point number encoding, symbol encoding, multi-parameter encoding, etc.
3.2.2 Fitness
function The fitness function should effectively reflect each The distance between a chromosome and the optimal solution chromosome for the problem.
3.2.3 Selection operator
insert image description here
3.2.4 Crossover operator
Crossover operation refers to exchanging some genes of two paired chromosomes in a certain way to form two new individuals; crossover operation is a genetic algorithm that is different from other evolutionary An important feature of an algorithm is the main method for generating new individuals. Before the crossover, the individuals in the group need to be paired, and the principle of random pairing is generally adopted.
Commonly used crossover methods:
single-point crossover,
double-point crossover (multi-point crossover, the more the number of crossover points, the greater the possibility that the individual structure will be destroyed, and the multi-point crossover method is generally not used) uniform crossover, arithmetic crossover 3.2.5
Variation calculation The mutation operation in the sub- genetic algorithm refers to replacing the gene values ​​at some loci in the individual chromosome coding string with other alleles of the loci to form a new individual.


In terms of the ability to generate new individuals during the operation of the genetic algorithm, the crossover operation is the main method for generating new individuals, which determines the global search ability of the genetic algorithm; while the mutation operation is only an auxiliary method for generating new individuals, but it is also necessary. One less operation step, which determines the local search ability of the genetic algorithm. The combination of the crossover operator and the 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 Operating parameters
insert image description here
4 Basic principles of genetic algorithm
4.1 Pattern theorem
insert image description here
4.2 Building block assumption The pattern
with low order, short defined length, and fitness value higher than the average fitness value of the population is called gene block or building block.
Building block hypothesis: Individual gene blocks can be spliced ​​together through the effects of genetic operators such as selection, crossover, and mutation to form individual coding strings with higher fitness.
The building block hypothesis illustrates the basic idea of ​​using genetic algorithm to solve various problems, that is, better solutions can be produced by directly splicing building blocks together.

⛄3. Part of the source code

clear
clc
close all
%The processing time of the workpiece on the machine
T=[ 1,3,6,7,3,6;
8,5,10,10,10,4;
5,4,8,9,1,7 ;
5,5,5,3,8,9;
9,3,5,4,3,1;
3,3,9,10,4,1;
4,5,6,13,8,8;] ;

%The distribution of workpiece tasks on the machine
Jm=[3,1,2,4,6,5;
2,3,5,6,1,4;
3,4,6,1,2,5;
2,1 ,3,4,5,6;
3,2,5,6,1,4;
2,4,6,1,5,4;
3,2,2,6,1,1;];

%Input related power
Pidle=[4,3,6,5,2,7];
Pcut=[5,4,7,6,3,8];
%Parameter initialization
%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%
NIND=40; %Number of individuals
MAXGEN=200; %Maximum number of generations
GGAP=0.9; %Generation gap
XOVR=0.8; % crossover rate
MUTR=0.6; % mutation rate
[PNumber,MNumber]=size(T); %PNumber number of workpieces %MNumber number of single workpiece process
gen=0; %generation counter
trace=zeros(2, MAXGEN); %search The initial value of the optimal result
WNumber=PNumber*MNumber; % Total number of processes
Chrom=zeros(NIND,WNumber); % Initialization group
%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%

%Calculate the total processing time of each machine without scheduling and sorting
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
TT=zeros(1, MNumber) ;
for w=1:MNumber
pos=find(w==Jm);
TT(1,w)=sum(T(pos));
end

⛄4. Running results

insert image description here
insert image description here

⛄5. Matlab version and references

1 matlab version
2014a

2 References
[1] Li Xuehua, Gao Quanli, Zhao Hui, Yang Hao, Jin Shuai, Xu Guoliang. A Hybrid Genetic Algorithm for Solving Flexible Job Shop Scheduling Problems [J]. Computer Technology and Development. 2022,32(08)

3 Remarks
Introduction This part is taken from the Internet and is for reference only. If there is any infringement, please contact to delete

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/131209789