[Shop Floor Scheduling] Solving matlab source code for Shop Floor Scheduling based on genetic algorithm

Job Shop Scheduling Problem Description

Job Shop Scheduling (JSP) is one of the most classical NP-hard problems.It has a wide range of applications, including carrier dispatch, airport aircraft dispatch, port and dock cargo ship dispatch, automobile processing pipeline, and so on.

JSP Problem Description: A processing system has M machines and requires N jobs to be processed, where Job i contains the number of operations Li.L is the total number of operations in the task set.Among them, the processing time of each operation has been determined, and each operation must be processed in the order of operation sequence.The task of scheduling is to arrange the scheduling order of all jobs, satisfy the constraints and optimize the performance indicators.

Job Shop Scheduling needs to consider the following constraints:

Cons1: Each process is processed on the specified machine and must be completed in the previous process before processing can start.

Cons2: Only one job can be processed by one machine at a time;

Cons3: Each job can only be processed once on one machine;

Cons4: The order and processing time of each job are known and do not change with the processing order.

Examples of problems

An example of a job shop scheduling problem is given below, where each operation is labeled with a pair of values (m,p), where m indicates that the current operation must be processed on the m-th machine and P indicates the processing time required for the m-th machine to process the current operation. (Note: Machine and job numbers start at 0)
jop0=[(0,3),(1,2),(2,2)]
jop1=[(0,2),(2,1),(1,4)]
jop2=[(1,4),(2,3)]
In this example, job jop0 has three processes: its first operation is labeled (0,3), which indicates that the first process must be processed on machine 0 and requires 3 units of processing time;The second process is labeled (1,2), which indicates that the second process must be processed on the first machine and requires 2 units of processing time.The rest is the same.Overall, there are eight operations in this instance.
A possible solution to this problem is an arrangement of L=8 operation start times that satisfies the constraints of the problem.The following figure gives an example of a possible solution (note: the solution is not optimal):

%% Empty environment
clc;clear
 
%% Download Data
load scheduleData Jm T JmNumber
%Operation time
 
%% Basic parameters
NIND=40;        %Number of Individuals
MAXGEN=50;      %Maximum Genetic Algebra
GGAP=0.9;       %Generation gap
XOVR=0.8;       %Crossing rate
MUTR=0.6;       %Variability rate
gen=0;          %Generation Counter
%PNumber Number of Workpieces MNumber  Number of operations
[PNumber MNumber]=size(Jm);
trace=zeros(2, MAXGEN);      %Initial value of search result
WNumber=PNumber*MNumber;     %Total number of operations
 
%% Initialization
Number=zeros(1,PNumber);     % PNumber Number of Workpieces
for i=1:PNumber
    Number(i)=MNumber;         %MNumber Number of operations
end
 
% Layer 2 Code, Layer 1 Operation, Layer 2 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 level of code represents the operation
        Chrom(j,i)= val;
        WPNumberTemp(val)=WPNumberTemp(val)-1;
        
        %Layer 2 code represents machine
        Temp=Jm{val,MNumber-WPNumberTemp(val)};
        SizeTemp=length(Temp);
        %Random production process machine
        Chrom(j,i+WNumber)= unidrnd(SizeTemp);
        
    end
end
 
%Calculate the value of the objective function
[PVal ObjV P S]=cal(Chrom,JmNumber,T,Jm);
 
%% Circular Search
while gen<MAXGEN
    
    %Allocation of fitness values
    FitnV=ranking(ObjV);
    %Select Operation
    SelCh=select('rws', Chrom, FitnV, GGAP);
    %Cross operation
    SelCh=across(SelCh,XOVR,Jm,T);
    %Variation operation
    SelCh=aberranceJm(SelCh,MUTR,Jm,T);
    
    %Calculating target fitness values
    [PVal ObjVSel P S]=cal(SelCh,JmNumber,T,Jm);
    %Reinsert New Population
    [Chrom ObjV] =reins(Chrom, SelCh,1, 1, ObjV, ObjVSel);
    %Generation Counter Increase
    gen=gen+1;
    
    %Save 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 work
    if MinVal>trace(1,gen)
        Val1=PVal;
        Val2=P;
        MinVal=trace(1,gen);
        STemp=S;
    end
    
end
 
% Current Best Value
PVal=Val1; %Operation time
P=Val2;  %working procedure
S=STemp; %Dispatcher Gene Contains Machine Gene
 
%% Describe changes in solution
figure(1)
plot(trace(1,:));
hold on;
plot(trace(2,:),'-.');grid;
legend('Changes in the solution','Changes in population mean');
 
%% Show 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

 

Tags: MATLAB Algorithm

Posted on Mon, 06 Sep 2021 23:04:37 -0400 by thenewperson