[workshop scheduling] solve the workshop scheduling problem based on Matlab genetic algorithm [including Matlab source code 070]

Buddha anger lotus 2021-08-31 15:38:00 阅读数:330

workshop scheduling solve workshop scheduling

One 、 Introduction to workshop scheduling

1 Job shop scheduling problem description
Job shop scheduling problem (Job Shop Scheduling, JSP) Are some of the most classic NP-hard One of the problems . Its application fields are extremely wide , Involving aircraft carrier scheduling , Airport aircraft dispatch , Port terminal cargo ship dispatching , Automobile processing line, etc .
JSP Problem description : A processing system has M Taiwan machine , Required processing N Homework , among , Homework i The number of operations included is Li. Make , be L Is the total work ordinal number of the task set . among , The processing time of each process has been determined , And each operation must be processed according to the sequence of processes . The task of scheduling is to arrange the processing scheduling and sorting of all jobs , While the constraints are met , Optimize the performance index .
Job shop scheduling needs to consider the following constraints :
Cons1: Each process is processed on the designated machine , And the processing can only be started after the previous process is completed ;
Cons2: At some point 1 This machine can only process 1 Homework ;
Cons3: Each job can only be in 1 On this machine 1 Time ;
Cons4: The process sequence and processing time of each operation are known , It does not change with the change of machining order .
2 Problem instance
An example of job shop scheduling problem is given below , Each process is marked with a pair of values (m,p), among ,m Indicates that the current operation must be performed on the m Processing on a machine ,p It means the first one m The processing time required for this machine to process the current operation .( notes : The machine and job numbers are from 0 Start )
jop0=[(0,3),(1,2),(2,2)]
jop1=[(0,2),(2,1),(1,4)]
jop2=[(1,4),(2,3)]
In this case , Homework jop0 Yes 3 Process : It's the first 1 The process is marked with (0,3), It means the second 1 The next process must be in the 0 Processing on a machine , And we need 3 Unit processing time ; It's the first 2 The process is marked with (1,2), It means the second 2 The next process must be in the 1 Processing on a machine , And we need 2 Unit processing time ; The rest is the same . in general , In this case, there are 8 Process .
A feasible solution to this problem is L=8 An arrangement of the start time of a process , And satisfy the constraints of the problem . The following figure shows a feasible solution ( notes : The solution is not the optimal solution ) An example of :
 Insert picture description here

Two 、 Introduction to genetic algorithm

1 Overview of genetic algorithm
Genetic algorithm (ga) (Genetic Algorithm,GA) It's part of evolutionary computing , It is a computational model that simulates the biological evolution process of Darwin's genetic selection and natural elimination , It is a method to search the optimal solution by simulating the natural evolution process . The algorithm is simple 、 Universal , Strong robustness , 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 the traditional optimization algorithm , It has the following characteristics :
(1) Take the code of decision variable as the operation object . Traditional optimization algorithms often directly use the actual value of decision variables to optimize calculation , But genetic algorithm uses some form of coding of decision variables as the operation object . This coding method for decision variables , So we can learn from the concepts of chromosome and gene in Biology , It can imitate the genetic and evolutionary incentives of organisms in nature , Genetic operators can also be easily applied .
(2) Directly use fitness as search information . The traditional optimization algorithm not only needs to use the value of the objective function , Moreover, the search process is often constrained by the continuity of the objective function , There may be a need to meet “ The derivative of the objective function must exist ” To determine the search direction . The genetic algorithm only uses the fitness function value transformed by the objective function value to determine the further search range , No other auxiliary information such as derivative value of objective function is required . Directly using the objective function value or individual fitness value can also focus the search range into the search space with higher fitness , To improve search efficiency .
(3) Search information using multiple points , With implicit parallelism . The traditional optimization algorithm is often an iterative search process starting from an initial point in the solution space . A single point provides little search information , So the search efficiency is not high , It is also possible to fall into the local optimal solution and stop ; Genetic algorithm starts the search process of the optimal solution from the initial population composed of many individuals , Instead of searching from a single individual . Of the initial population 、 choice 、 cross 、 Mutation and other operations , Produce a new generation of groups , It includes a lot of group information . This information can avoid searching some unnecessary points , So as to avoid falling into local optimization , 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 less than optimal , It limits the application scope of the algorithm . Genetic algorithm is an adaptive search technology , Its choice 、 cross 、 Operations such as mutation are carried out in a probabilistic way , Increases the flexibility of the search process , And it can converge to the optimal solution with a large probability , It has good global optimization ability . but , Crossover probability 、 Mutation probability and other parameters will also affect the search results and search efficiency of the algorithm , Therefore, how to select the parameters of genetic algorithm is an important problem in its application .
Sum up , Because the overall search strategy and optimization search method of genetic algorithm do not depend on gradient information or other auxiliary knowledge , Only the objective function affecting the search direction and the corresponding fitness function need to be solved , Therefore, genetic algorithm provides a general framework for solving complex system problems . It does not depend on the specific area of the problem , Strong robustness to the types of problems , So it is widely used in various fields , Include : Function optimization 、 Combinatorial optimal production scheduling problem 、 Auto-Control
、 Robotics 、 The image processing ( Image restoration 、 Image edge feature extraction …)、 Artificial life 、 Genetic programming 、 machine learning .

3 The basic flow and implementation technology of genetic algorithm
Basic genetic algorithm (Simple Genetic Algorithms,SGA) Use only the selection operator 、 Crossover operator and mutation operator are three genetic operators , Evolution is simple , It is the basis of other genetic algorithms .

3.1 The basic flow of genetic algorithm
Generate a number of randomly determined lengths ( The length is related to the accuracy of the problem to be solved ) The initial population of coding ;
Each individual is evaluated by fitness function , Individuals with high fitness value were selected to participate in genetic operation , Individuals with low fitness are eliminated ;
Genetically manipulated ( Copy 、 cross 、 variation ) A new generation of population is formed by the collection of individuals , Until the stop criteria are met ( Evolution algebra GEN>=?);
The best realized individual in the offspring is taken as the execution result of the genetic algorithm .
 Insert picture description here
among ,GEN Is the current algebra ;M It's population size ,i Represents the number of populations .

3.2 Implementation technology of genetic algorithm
Basic genetic algorithm (SGA) Coded by 、 Fitness function 、 Genetic operators ( choice 、 cross 、 variation ) And operation parameters .
3.2.1 code
(1) Binary code
The length of binary coded string is related to the accuracy of the problem . We need to ensure that every individual in the solution space can be encoded .
advantage : Ed 、 The decoding operation is simple , inheritance 、 Crossover is easy to achieve
shortcoming : The length is large
(2) Other coding methods
Gray code 、 Floating point code 、 Symbolic encoding 、 Multi parameter coding, etc
3.2.2 Fitness function
The fitness function should effectively reflect the gap between each chromosome and the chromosome of the optimal solution of the problem .
3.2.3 Selection operator
 Insert picture description here
3.2.4 Crossover operator
Cross operation refers to the exchange of some genes between two paired chromosomes in some way , And two new individuals ; Crossover operation is an important feature that distinguishes genetic algorithm from other evolutionary algorithms , Is the main way to produce new individuals . Before crossing, individuals in the group need to be paired , Generally, the principle of random pairing is adopted .
Commonly used crossover :
A single point of intersection
Two point intersection ( Multi-point crossover , The more cross points , The more likely the individual's structure is to be destroyed , Generally, multi-point intersection is not adopted )
Uniform cross
Arithmetic crossover
3.2.5 Mutation operator
The mutation operation in genetic algorithm refers to replacing the gene values at some loci in the individual chromosome coding string with other alleles at this locus , So as to form a new individual .

In terms of the ability to generate new individuals in the operation of genetic algorithm , Cross operation is the main method to generate new individuals , It determines the global search ability of genetic algorithm ; Mutation is only an auxiliary method to generate new individuals , But it is also an essential operation step , It 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 , Thus, the genetic algorithm can complete the optimization process of the optimization problem with good search performance .

3.2.6 Operation parameters
 Insert picture description here
4 The basic principle of genetic algorithm
4.1 Pattern theorem

 Insert picture description here
4.2 Building block hypothesis
With low order 、 The definition length is short , The pattern whose fitness value is higher than the average fitness value of the population is called gene block or building block .
Building block hypothesis : Individual gene blocks are selected 、 cross 、 The role of genetic operators such as mutation , Can be spliced together , 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、 ... and 、 Partial source code

%% Clear the environment
clc;clear
%% Download data
load scheduleData Jm T JmNumber
% working procedure Time
%% The basic parameters
NIND=40; % Number of individuals
MAXGEN=50; % Maximum hereditary algebra
GGAP=0.9; % Generation gap
XOVR=0.8; % Cross rate
MUTR=0.6; % Variation rate
gen=0; % Generation counter
%PNumber Number of workpieces MNumber Number of processes
[PNumber MNumber]=size(Jm);
trace=zeros(2, MAXGEN); % The initial value of the optimization result
WNumber=PNumber*MNumber; % Total number of processes
%% initialization
Number=zeros(1,PNumber); % PNumber Number of workpieces
for i=1:PNumber
Number(i)=MNumber; %MNumber Number of processes
end
% Code 2 layer , The first process , Second floor machine
Chrom=zeros(NIND,2*WNumber);
for j=1:NIND
WPNumberTemp=Number;
for i=1:WNumber
% Random production process
val=unidrnd(PNumber);
while WPNumberTemp(val)==0
val=unidrnd(PNumber);
end
% The first layer of code represents the operation
Chrom(j,i)= val;
WPNumberTemp(val)=WPNumberTemp(val)-1;
% The first 2 The layer code represents the machine
Temp=Jm{val,MNumber-WPNumberTemp(val)};
SizeTemp=length(Temp);
% Random production process machine
Chrom(j,i+WNumber)= unidrnd(SizeTemp);
end
end
% Calculate objective function value
[PVal ObjV P S]=cal(Chrom,JmNumber,T,Jm);
%% Circular search
while gen<MAXGEN
% Assign fitness values
FitnV=ranking(ObjV);
% Select operation
SelCh=select('rws', Chrom, FitnV, GGAP);
% Cross operation
SelCh=across(SelCh,XOVR,Jm,T);
% Mutation operation
SelCh=aberranceJm(SelCh,MUTR,Jm,T);
% Calculate the target fitness value
[PVal ObjVSel P S]=cal(SelCh,JmNumber,T,Jm);
% Reinsert the new species group
[Chrom ObjV] =reins(Chrom, SelCh,1, 1, ObjV, ObjVSel);
% The generation counter is incremented
gen=gen+1;
% Save the optimal value
trace(1, gen)=min(ObjV);
trace(2, gen)=mean(ObjV);
% Record the best value
if gen==1
Val1=PVal;
Val2=P;
MinVal=min(ObjV);% Minimum time
STemp=S;
end
% Record The smallest process
if MinVal>trace(1,gen)
Val1=PVal;
Val2=P;
MinVal=trace(1,gen);
STemp=S;
end
end
% Current best value
PVal=Val1; % Process time
P=Val2; % working procedure
S=STemp; % Scheduling genes contain machine genes
%% Describe the change of solution
figure(1)
plot(trace(1,:));
hold on;
plot(trace(2,:),'-.');grid;
legend(' Change of solution ',' Changes in population mean ');
%% Show the optimal solution
figure(2);
MP=S(1,PNumber*MNumber+1:PNumber*MNumber*2);
for i=1:WNumber
val= P(1,i);
a=(mod(val,100)); % working procedure
b=((val-a)/100); % workpiece
Temp=Jm{b,a};
mText=Temp(MP(1,i));
x1=PVal(1,i);
x2=PVal(2,i);
y1=mText-1;
y2=mText;
plotRec(x1,x2,mText);
plotRec(PVal(1,i),PVal(2,i),mText);
hold on;
fill([x1,x2,x2,x1],[y1,y1,y2,y2],[1-1/b,1/b,b/PNumber]);
text((x1+x2)/2,mText-0.25,num2str(P(i)));
end

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.

Four 、 Running results

 Insert picture description here
 Insert picture description here

5、 ... and 、matlab Edition and references

1 matlab edition
2014a

2 reference
[1] Baoziyang , Yu Jizhou , Poplar . Intelligent optimization algorithm and its application MATLAB example ( The first 2 edition )[M]. Electronic industry press ,2016.
[2] Zhang Yan , Wu Shuigen .MATLAB Optimization algorithm source code [M]. tsinghua university press ,2017.

 

版权声明:本文为[Buddha anger lotus]所创,转载请带上原文链接,感谢。 https://car.inotgo.com/2021/08/20210825162444506n.html