遗传算法Matlab源代码(9)

2021-04-06 04:23

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

NewPop(MutIn(i),k(j))=1;

end

end

i=i+1;

end

end

else%Tsp变异

if opts(2)==1|opts(2)==2|opts(2)==3|opts(2)==4

numMut=ceil(pMutation*m);

r=unidrnd(m,numMut,2);

[LocalMinfit,In]=min(fit(r),[],2);

SelectIn=r((In-1)*numMut+[1:numMut]');

while(i<=numMut)

mPoints=sort(unidrnd(n,1,2));

if mPoints(1)~=mPoints(2)

NewPop(SelectIn(i),1:mPoints(1)-1)=OldPop(SelectIn(i),1:mPoints(1)-1);

NewPop(SelectIn(i),mPoints(1):mPoints(2)-1)=OldPop(SelectIn(i),mPoints(1)+1:mPoints(2)); NewPop(SelectIn(i),mPoints(2))=OldPop(SelectIn(i),mPoints(1));

NewPop(SelectIn(i),mPoints(2)+1:n)=OldPop(SelectIn(i),mPoints(2)+1:n);

else

NewPop(SelectIn(i),:)=OldPop(SelectIn(i),:);

end

i=i+1;

end

else

r=rand(1,m);

MutIn=find(r<=pMutation);

L=length(MutIn);

while i<=L

mPoints=sort(unidrnd(n,1,2));

rIn=randperm(mPoints(2)-mPoints(1)+1);

NewPop(MutIn(i),mPoints(1):mPoints(2))=OldPop(MutIn(i),mPoints(1)+rIn-1);

i=i+1;

end

end

end

% -- 倒位操作 --

function [NewPop]=Inversion(OldPop,pInversion)

global m n NewPop

NewPop=OldPop;

r=rand(1,m);

PopIn=find(r<=pInversion);

len=length(PopIn);

i=1;

if len>=1

while(i<=len)

d=sort(unidrnd(n,1,2));


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

下一篇:经典幻灯片模板

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

马上注册会员

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