典型JSP车间调度问题学习10

变异操作的 Matlab 编程实现

 

三种变异操作方式:
互换
逆序:
    涉及函数 fliplr
插入:
     涉及函数: circshift

%变异操作--插入方法
function outChromes=muteChromesInsert(chromes,muteRate) 
 [pop,len]=size(chromes); 
 for i=1:pop 
 nowChrome=chromes(i,:); 
 if rand()<muteRate %判断能否变异
% outPoint=randperm(len,1);
% inPoint=randperm(len,1);
 i 
 points=randperm(len,2) 
 nowChrome 
 if points(1)<points(2) 
 insertChrome=nowChrome(points(1):points(2)-1); 
 newChrome=circshift(insertChrome,-1); 
 chromes(i,points(1):points(2)-1)=newChrome; 
 else
 insertChrome=nowChrome(points(2)-1:points(1)); 
 newChrome=circshift(insertChrome,1); 
 chromes(i,points(2)-1:points(1))=newChrome; 
 end
 chromes(i,:) 
 
 end
 outChromes=chromes; 
 end
 
end
%变异操作--逆序方法
function outChromes=muteChromesInv(chromes,muteRate) 
 [pop,len]=size(chromes); 
 for i=1:pop 
 nowChrome=chromes(i,:); 
 if rand()<muteRate 
% outPoint=randperm(len,1);
% inPoint=randperm(len,1);
 i 
 points=sortrows(randperm(len,2)')' 
 nowChrome 
 newChrome0=nowChrome(points(1):points(2)); 
 newChrome1=fliplr(newChrome0) 
 chromes(i,points(1):points(2))=newChrome1; 
 chromes(i,:) 
 
 end
 outChromes=chromes; 
 end
 
end
JSP 遗传算法集成
%找出当前种群中最优解的染色体编码以及最优解的值
function [nowOptFit,nowOptChrome]=findOptSolution(inChromes,data) 
 %step1:计算每条染色体的适应度值,放到数组中
 pop=size(inChromes,1); 
 fitnesses=zeros(pop,1); 
 for i=1:pop 
 sch=createSchedule(data,inChromes(i,:)); 
 fit=fitness(sch); 
 fitnesses(i)=fit; 
 end
 %对适应度值进行排序
 [fit2,chromeId]=sortrows(fitnesses,1); 
 nowOptFit=fit2(1); %对应最好的适应度值
 nowOptChrome=inChromes(chromeId(1),:); %对应最好的染色体
end

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值