编程语言
首页 > 编程语言> > 【Matlab 013期】【车间调度】基于粒子群的车间调度matlab源码

【Matlab 013期】【车间调度】基于粒子群的车间调度matlab源码

作者:互联网

针对作业车间调度问题,提出一种基于自适应权重和混沌的改进粒子群优化算法。构建以机器加工时间最短为优化目标的多约束作业车间调度模型,采用基于工序排列的编码方式得到粒子参数与工序序列的映射关系;基于自适应权重改进粒子群算法中的惯性系数和加速因子,使得算法可以根据适应度值动态调整参数因子;采用反向学习策略改善种群初始解的质量;引入莱维飞行、变邻域搜索、混沌,增强了算法的搜索能力,避免陷入局部最优解。试验结果表明:改进粒子群算法可以有效地提高粒子利用率,平衡全局搜索与局部搜索能力,改善传统粒子群算法易早熟的缺点,得到更优的解。

function []=FJSP_PSO()
[~, ~, alldata] = xlsread('data2.xlsx');
[row, columns]=size(alldata);
for i=2:row
    for j=1:columns
        if ischar(cell2mat(alldata(i,j)))
            alldata(i,j)={str2num(cell2mat(alldata(i,j)))};
        end
    end
end
 
TaskAmo=alldata{row,1};
SubtaskAmo=row-1;
SubtaskNum=zeros(1,TaskAmo);
MachineAmo=0;
 
for i=1:SubtaskAmo
    MachineAmo=max(MachineAmo,max(alldata{i+1,5}));
end
 
count1=0;
for i=2:row
    if ~isnan(alldata{i,2})
        count1=count1+1;
        SubtaskNum(count1)=alldata{i,2};
    end
end
 
tic
nind=50;
maxgen=20;
w=0.72;
c1=1.79;
c2=1.79;
gen=0;
 
trace=zeros(2,maxgen);
chrom=zeros(nind,2*SubtaskAmo);
X_process=zeros(1,SubtaskAmo);
chrom_operating=zeros(nind,2*SubtaskAmo);
chrom_temp_P=zeros(nind,SubtaskAmo);
chrom_temp_M=zeros(nind,SubtaskAmo);
 
% individual_best=zeros(nind,3);
% population_best=zeros(1,3);
 
 
for r=1:nind
    for i=1:SubtaskAmo
        X_process(i)=alldata{i+1,1};
    end
    
    Queue=randperm(numel(X_process));
    X_process=X_process(Queue);
    
    X_machine=M_generate3(alldata,X_process,TaskAmo,SubtaskAmo,SubtaskNum);
    chrom(r,:)=[X_process,X_machine];
end;
 
[objective,chrom_X_P,chrom_X_M,minP,minM,minfit]=FJSP_objv3(alldata,TaskAmo,SubtaskAmo,SubtaskNum,nind,chrom);
 
individual_best_object=objective;
individual_best_P=chrom_X_P;
individual_best_M=chrom_X_M;
 
population_best_objective=minfit;
population_best_P=minP;
population_best_M=minM;
 
 
while gen<maxgen
    for r=1:nind
        for i=1:SubtaskAmo
            chrom_temp_P(r,i)=w*chrom(r,i)+c1*rand*(individual_best_P(r,i)-chrom(r,i))+c2*rand*(population_best_P(i)-chrom(r,i));
        end
        [~,temp_node]=sort(chrom_temp_P(r,:));
        temp=chrom(r,1:SubtaskAmo);
        chrom(r,1:SubtaskAmo)=temp(temp_node);
        chrom(r,SubtaskAmo+1:2*SubtaskAmo)=M_generate3(alldata,chrom(r,1:SubtaskAmo),TaskAmo,SubtaskAmo,SubtaskNum);
    end
    
    [objective,chrom_X_P,chrom_X_M,minP,minM,minfit]=FJSP_objv3(alldata,TaskAmo,SubtaskAmo,SubtaskNum,nind,chrom);
    
    for r=1:nind
        if objective(r)<individual_best_object(r)
            individual_best_object(r)=objective(r);
            individual_best_P(r,:)=chrom(1:SubtaskAmo);
            individual_best_M(r,:)=chrom(SubtaskAmo+1:2*SubtaskAmo);
        end
    end
    
    if minfit<population_best_objective
        population_best_objective=minfit;
        population_best_P=minP;
        population_best_M=minM;
    end
    
    gen=gen+1;
    
    trace(1,gen)=min(objective);
    trace(2,gen)=sum(objective)/length(objective);  
end
toc
 
population_best_W=W_generate2(alldata,SubtaskAmo,TaskAmo,SubtaskNum,population_best_P,population_best_M);
[T,~,trace1,trace2,trace3,~]=FJSP_ADV_fitness4(population_best_P,population_best_M,population_best_W);
 
minXulie=[population_best_P,population_best_M,population_best_W]
minFitness=population_best_W
 
figure(1);
plot(trace(1,1:gen));
hold on;
plot(trace(2,1:gen),'-.');grid;
 
 
figure(2);
colorset1=rand(1,TaskAmo);
colorset2=rand(1,TaskAmo);
[Trow,Tcol]=size(T);
for i=1:Trow
    for j=1:Tcol
        if trace2(i,j)~=0
            fill([T(i,j),T(i,j)+trace1(i,j),T(i,j)+trace1(i,j),T(i,j)],[1*i-0.3,1*i-0.3,1*i+0.3,1*i+0.3],[trace2(i,j)/TaskAmo,0.9*colorset1(trace2(i,j)),0.8*colorset2(trace2(i,j))]);hold on
            text(T(i,j),i,strcat(num2str(trace2(i,j)),',',num2str(trace3(i,j))));
        end
    end
end
end
        
        
 

在这里插入图片描述
注:完整代码或者代写添加QQ2449341593

标签:SubtaskAmo,车间,调度,源码,zeros,best,chrom,alldata,nind
来源: https://blog.csdn.net/TIQCmatlab/article/details/112059038