遗传算法Matlab源代码(7)

2021-04-06 04:23

完整可以运行的数值优化遗传算法源代码

%NewPop(y1(i+2),xPoints(1):xPoints(2))=OldPop(y1(i+1),xPoints(1):xPoints(2));

temp=[OldPop(y1(i+1),xPoints(2)+1:n) OldPop(y1(i+1),1:xPoints(2))];

for del1i=xPoints(1):xPoints(2)

temp(find(temp==OldPop(y1(i+2),del1i)))=[];

end

NewPop(y1(i+1),(xPoints(2)+1):n)=temp(1:(n-xPoints(2)));

NewPop(y1(i+1),1:(xPoints(1)-1))=temp((n-xPoints(2)+1):end);

temp=[OldPop(y1(i+2),xPoints(2)+1:n) OldPop(y1(i+2),1:xPoints(2))];

for del2i=xPoints(1):xPoints(2)

temp(find(temp==OldPop(y1(i+1),del2i)))=[];

end

NewPop(y1(i+2),(xPoints(2)+1):n)=temp(1:(n-xPoints(2)));

NewPop(y1(i+2),1:(xPoints(1)-1))=temp((n-xPoints(2)+1):end);

end

end

end

NewPop(y2,:)=OldPop(y2,:);

% -二进制串均匀交叉算子

function [children1,children2]=EqualCrossOver(parent1,parent2)

global n children1 children2

hidecode=round(rand(1,n));%随机生成掩码

crossposition=find(hidecode==1);

holdposition=find(hidecode==0);

children1(crossposition)=parent1(crossposition);%掩码为1,父1为子1提供基因

children1(holdposition)=parent2(holdposition);%掩码为0,父2为子1提供基因

children2(crossposition)=parent2(crossposition);%掩码为1,父2为子2提供基因

children2(holdposition)=parent1(holdposition);%掩码为0,父1为子2提供基因

% -二进制串多点交叉算子

function [Children1,Children2]=MultiPointCross(Parent1,Parent2)%交叉点数由变量数决定

global n Children1 Children2 VarNum

Children1=Parent1;

Children2=Parent2;

Points=sort(unidrnd(n,1,2*VarNum));

for i=1:VarNum

Children1(Points(2*i-1):Points(2*i))=Parent2(Points(2*i-1):Points(2*i));

Children2(Points(2*i-1):Points(2*i))=Parent1(Points(2*i-1):Points(2*i));

end

% -- 变异操作 --

function [NewPop]=Mutation(OldPop,fit,pMutation,VarNum,opts)

global m n NewPop

NewPop=OldPop;

r=rand(1,m);

MutIn=find(r<=pMutation);

L=length(MutIn);


遗传算法Matlab源代码(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:经典幻灯片模板

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: