current position:Home>[job shop scheduling] solve the dual objective flexible job shop scheduling problem based on the improved whale algorithm of MATLAB [including Matlab source code phase 026]

[job shop scheduling] solve the dual objective flexible job shop scheduling problem based on the improved whale algorithm of MATLAB [including Matlab source code phase 026]

2021-08-25 07:42:58 Buddha anger lotus

One 、 brief introduction

 be based on matlab Improved whale algorithm for solving dual objective flexible job shop scheduling problem
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here

Two 、 Partial source code

clear;
clc;

dbstop if error;
M=7;
RouN=[4 3 3 2 5 4];
Jm={[2 4 6],[1 2 4 7],[1 3 5 6],[1 3 5 7],0;
    [2 4 6],[1 3 5],[1 2 4 5 6 7],0,0;
    [1 4],[1 3 4 6],[2 3 7],0,0;
    [5 7],[4 5 6],0,0,0;
    [1 3 5],[2 3 6],[4 5 7],[1 2 5 7],[1 4 6];
    [1 2 3 4 6 7],[3 5],[1 4 6],[2 3 7],0};

T ={[16 16 15],[17 18 14 16],[20 20 18 13],[20 17 13 19],0;
    [17 18 14],[17 18 22],[19 17 21 19 17 19],0,0;
    [18 20],[18 17 23 19],[22 20 17],0,0;
    [16 18],[25 20 21],0,0,0;
    [19 18 16],[12 9 10],[10 13 8],[13 16 14 12],[20 19 22];
    [10 9 11 9 9 10],[17 11],[14 10 9],[13 11 10],0};
    function [PVal,Cost]=caltime(P,M1,T,Jm,M,CO,s,l,dj,RouN)

PNumber=size(Jm,1);
WNumber=size(P,2);
MT=cell(M,1);
TPE=zeros(1,PNumber);
PVal=zeros(2,WNumber);
Cost=0;

for i=1:M
    MT{i,1}=[0;1000000000];
end

for i=1:WNumber
    val=P(1,i);
    a=mod(val,100);
    b=(val-a)/100;
    c=sum(RouN(1:b-1))+a;
    m_number=M1(1,c);
    m=Jm{b,a}(m_number);
    t=T{b,a}(m_number);
    co=CO{b,a}(m_number);
    Cost=co*t*l+t*s;% If so, there is no need for greedy decoding , You can add standby costs 

    k=size(MT{m,1},2);
    
    
    
    for j=1:k
        t1=MT{m,1}(2,j)-MT{m,1}(1,j);%t1 The numerical calculation of MT Of the m individual cell In the cell j Subtract the value of the first row from the second row of the column 
        % It means the idle time of the machine . The value in the previous line indicates the completion time of the previous operation , The value in the next line indicates the start time of the next operation 
        t2=MT{m,1}(2,j)-TPE(1,b); %t2 The meaning of numerical calculation is to express MT Of the m individual cell In the cell j The second row of the column subtracts the completion time of the previous operation of a workpiece 
        % It means the start time and time of the next process of the machine b The difference between the completion time of the last operation of the workpiece is used to judge whether it is on the machine m Top processing b The time of the next process of the workpiece 
        if  t<=min(t1,t2) % Comprehensive judgment of the two , Minimum value , It is used to judge whether the processing time of an operation can be inserted , First processing , If entering if Can be inserted 
            % When it can be inserted 
            PVal(1,i)=max(TPE(1,b),MT{m,1}(1,j));%PVal The first line shows the start processing time of the operation , It is the completion time of the previous operation of a workpiece 
            % And the maximum value of the completion time of the last process on the machine 
            PVal(2,i)=PVal(1,i)+t;%PVal The second line shows the processing completion time of the operation , Equal to the start processing time of the previous reinsertion operation plus the machining time 
            TPE(1,b)=PVal(2,i);% Save the processing completion time of the operation into the operation completion time of the corresponding workpiece 
            
            
            if j<k % Insert... If you can , Put the inserted value in the second row m individual cell In the second line of the unit , Indicates the time when the operation starts processing , The previous value becomes the following 
                MTtemp=MT{m,1}(:,j+1:k);
                MT{m,1}(2,j+1)=MT{m,1}(2,j);
                MT{m,1}(2,j)=PVal(1,i);
                MT{m,1}(1,j+1)=PVal(2,i);
                MT{m,1}=MT{m,1}(:,1:j+1);
                MT{m,1}=[MT{m,1} MTtemp];
            else
                MT{m,1}(2,j+1)=MT{m,1}(2,j);% Add MTcell Number of columns in the array , And the assignment . The meaning of this expression is to put j In the column 2 Row is assigned to j+1 The second row of the column is 1000000
                MT{m,1}(2,j)=PVal(1,i);% Assign the start time of the process just completed on this machine to the j In the column 2 That's ok 
                MT{m,1}(1,j+1)=PVal(2,i);% Assign the end time of the process just completed on this machine to the j+1 In the column 1 That's ok 
                MT{m,1}=MT{m,1}(:,1:j+1);% This is what will be broadened MT Of the m A unit is reassigned to the original unit 
            end
            break;
        end
    end

end

djcost=0;
for q_1=1:M
    mt=MT{q_1,1};
    for q_2=1:size(mt,2)-1
        djtime=MT{m,1}(2,j)-MT{m,1}(1,j);
        djcost=djcost+djtime*dj;
    end
end

Cost=Cost+djcost;
function [MinVal,P,PVal,MVal]=IWOA(M,Jm,T,CO,RouN)

WNumber=sum(RouN);
NIND=50;
b=1;
Ps=0.5;
Wmax=0.9;
Wmin=0.2;
gen=1;
MAXGEN=50;
r1=0.3;
r2=0.7;
trace=zeros(2,MAXGEN);

% Mixed population initialization 
%Chrom=zeros(NIND,2*WNumber);
MS=initial(NIND,Jm,T,RouN,M);
OS=CSH(MS,M,Jm,T,CO,RouN);
%Chrom(:,1:WNumber)=MS(:,:);
%Chrom(:,WNumber+1,2*WNumber)=OS(:,:);


while gen<=MAXGEN
    
    [PVal1,ObjVCh,P1,MVal1]=cal(OS,MS,M,Jm,T,CO,RouN);
    trace(1,gen)=min(ObjVCh);
    trace(2,gen)=mean(ObjVCh);
    
    Position=transback(MS,Jm,M,RouN);
    PX=ROV(Position,OS,RouN);
    
    [~,Best]=min(ObjVCh);
    Xbest=Position(Best(1),:);
    for i=1:NIND
 
        a=(2-(2*gen/MAXGEN))*(1-(gen^3)/(MAXGEN^3));
        A=2*a*r1-a;
        C=2*r2;
        L=2*rand-1;
        
        X=Position(i,:);
        W=Wmax-(Wmax-Wmin)*log(1+gen*1.7183/MAXGEN);
        if rand<Ps
            if abs(A)<1
                D=abs(C*Xbest-X);
                Xt=Xbest-W*A*D;
                Position(i,:)=Xt;
            else
                q=0.3*(1-gen/MAXGEN);
                if rand<q
                    [Xmin,~]=min(X);
                    [Xmax,~]=max(X);
                    Xj=Xmin+rand(Xmax-Xmin);
                    Position(i,unidrnd(WNumber))=Xj;
                end
            end
        else
            DD1=abs(Xbest-X);
            Xt=DD1*exp(b*L)*cos(2*pi*L)*W+Xbest;
            Position(i,:)=Xt;
        end
        
    end
    Position=YH(Position,M);
    [MS,OS]=trans(Position,PX,RouN,Jm,M);
    [PVal2,ObjV,P2,MVal2]=cal(OS,MS,M,Jm,T,CO,RouN);
    
    
    if gen==1
        if min(ObjVCh)<min(ObjV)
            Val1=PVal1;
            Val2=P1;
            Val3=MVal1;
            MinVal=min(ObjVCh);
        else
            Val1=PVal2;
            Val2=P2;
            Val3=MVal2;
            MinVal=min(ObjV);
        end
    end
    if MinVal>trace(1,gen)
        Val1=PVal2;
        Val2=P2;
        Val3=MVal2;
        MinVal=trace(1,gen);
    end
    
    gen=gen+1;
end

PVal=Val1;
P=Val2;
MVal=Val3;
clf;
figure(1);

for i=1:WNumber
    val=P(1,i);
    a=mod(val,100);
    b=(val-a)/100;
    c=sum(RouN(1:b-1))+a;
    m_number=MVal(1,c);
    m=Jm{b,a}(m_number);
    MaHao=m;
    plotRec(PVal(1,i),PVal(2,i),MaHao);
    mPoint1=PVal(1,i);
    mPoint2=PVal(2,i);
    x1=mPoint1;
    y1=MaHao-0.5;
    x2=mPoint2;
    y2=MaHao-0.5;
    x3=mPoint2;
    y3=MaHao;
   

 


      
  • 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.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.

3、 ... and 、 Running results

 Insert picture description here
 Insert picture description here

Four 、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.

copyright notice
author[Buddha anger lotus],Please bring the original link to reprint, thank you.
https://caren.inotgo.com/2021/08/20210825074257092p.html

Random recommended