1 / 4
文档名称:

matlab自适应遗传算法.doc

格式:doc   大小:36KB   页数:4页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

matlab自适应遗传算法.doc

上传人:小s 2021/10/25 文件大小:36 KB

下载得到文件列表

matlab自适应遗传算法.doc

相关文档

文档介绍

文档介绍:end
end
function [xv,fv]=AdapGA(fitness,a,b,NP,NG,Pc1,Pc2,Pm1,Pm2,eps) %X ?eeo | o ?' ???•••
L = ceil(log2((b-a)/eps+1));
x = zeros(NP,L);
for i=1:NP
x(i,:) = Initial(L);
fx(i) = fitness(Dec(a,b,x(i,:),L));
end
for k=1:NG
sumfx = sum(fx);
Px = fx/sumfx;
PPx = 0;
PPx(1) = Px(1);
for i=2:NP
PPx(i) = PPx(i-1) + Px(i);
end
for i=1:NP
sita = rand();
for n=1:NP
if sita <= PPx(n)
SelFather = n;
break;
end
end
Selmother = round(rand()*(NP-1))+1;
posCut = round(rand()*(L-2)) + 1;
favg = sumfx/NP;
fmax = max(fx);
Fitness_f = fx(SelFather);
Fitness_m = fx(Selmother);
Fm = max(Fitness_f,Fitness_m);
if Fm>=favg
Pc = Pc1*(fmax - Fm)/(fmax - favg);
else
Pc = Pc2;
end
r1 = rand();
if r1<=Pc
nx(i,1:posCut) = x(SelFather,1:posCut);
nx(i,(posCut+1):L) = x(Selmother,(posCut+1):L);
fmu = fitness(Dec(a,b,nx(i,:),L));
if fmu>=favg
Pm = Pm1*(fmax - fmu)/(fmax - favg);
else
Pm = Pm2;
end
end r2 = rand();
if r2 <= Pm
posMut = round(rand()*(L-1) + 1); nx(i,posMut) = ~nx(