人工鱼群算法源代码Word下载.docx
- 文档编号:22519674
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:9
- 大小:17.55KB
人工鱼群算法源代码Word下载.docx
《人工鱼群算法源代码Word下载.docx》由会员分享,可在线阅读,更多相关《人工鱼群算法源代码Word下载.docx(9页珍藏版)》请在冰豆网上搜索。
%人工鱼数量
fori=1:
N
wwww=[X(i,1),X(i,2)];
d(i)=maxf(wwww);
end
[w,i]=max(d);
maxX=[X(i,1),X(i,2)];
%初始公告板记录
maxY=w;
figurex=[];
figurey=[];
figurez=[];
figurex(numel(figurex)+1)=maxX
(1);
figurey(numel(figurey)+1)=maxX
(2);
figurez(numel(figurez)+1)=maxY;
kkk=0;
while(k<
m)
XX=[X(i,1),X(i,2)];
%人工鱼当前状态Xi
nf=0;
Xc=0;
forj=1:
N%聚群行为开始
XXX=[X(j,1),X(j,2)];
if(norm(XXX-XX)<
Visual)
nf=nf+1;
Xc=Xc+XXX;
Xc=Xc/nf;
if((maxf(Xc))>
maxf(XX))
XXnext1=XX+rand*Step*(Xc-XX)/norm(Xc-XX);
if(XXnext1
(1)>
b1)
XXnext1
(1)=b1;
if(XXnext1
(1)<
a1)
XXnext1
(1)=a1;
if(XXnext1
(2)>
b2)
XXnext1
(2)=b2;
if(XXnext1
(2)<
a2)
XXnext1
(2)=a2;
else
XXnext1=gmjprey(XX,Try_number,Visual,Step);
end%聚群行为结束
%maxX=XX;
%追尾行为开始
%maxY=maxf(XX);
Friend_number
Visual&
maxf(XXX)>
maxY)maxX=XXX;
maxY=maxf(XXX);
if((maxY)>
XXnext2=XX+rand*Step*(maxX-XX)/norm(maxX-XX);
if(XXnext2
(1)>
XXnext2
(1)=b1;
if(XXnext2
(1)<
XXnext2
(1)=a1;
if(XXnext2
(2)>
XXnext2
(2)=b2;
if(XXnext2
(2)<
XXnext2
(2)=a2;
XXnext2=gmjprey(XX,Try_number,Visual,Step);
end%追尾行为结束
if(maxf(XXnext1)>
maxf(XXnext2))
X(i,1)=XXnext1
(1);
X(i,2)=XXnext1
(2);
X(i,1)=XXnext2
(1);
X(i,2)=XXnext2
(2);
end%一次迭代结束
XXXX=[X(i,1),X(i,2)];
ifmaxf(XXXX)>
maxY
maxY=maxf(XXXX);
maxX=XXXX;
figurey(numel(figurey)+1)=maxX
(2);
figurez(numel(figurez)+1)=maxY;
k=k+1;
%进入下一次迭代
maxX
plot3(figurex,figurey,figurez)
function[XXnext]=gmjprey(XX,Try_number,Visual,Step)pp=0;
Try_number
XXj=XX+rand*Step*Visual;
if(maxf(XX)<
maxf(XXj))
XXnext=XX+rand*Step*(XXj-XX)/norm(XXj-XX);
pp=1;
break
if(~pp)
XXnext=XX+rand*Step;
functiony=maxf(QQ)
y=(sin(QQ
(1))/QQ
(1))*(sin(QQ
(2))/QQ
(2));
人工鱼群算法的仿真程序-matlab23
tic;
figure
(1);
holdon;
ezplot('
x*sin(10*pi*;
%%参数设置;
fishnum=50;
%生成50只人工鱼;
MAXGEN=50;
%最多迭代次数;
try_number=100;
%最多试探次数;
visual=1;
%感知距离;
delta=0.618;
%拥挤度因子;
step=0.1;
%步长;
%%初始化鱼群;
lb_ub=[-1,
tic
holdon
x*sin(10*pi*x)+2'
[-1,2]);
%%参数设置
%生成50只人工鱼
%最多迭代次数
%最多试探次数
%感知距离
%拥挤度因子
%步长
%%初始化鱼群
lb_ub=[-1,2,1];
X=AF_init(fishnum,lb_ub);
LBUB=[];
fori=1:
size(lb_ub,1)
LBUB=[LBUB;
repmat(lb_ub(i,1:
2),lb_ub(i,3),1)];
gen=1;
BestY=-1*ones(1,MAXGEN);
%每步中最优的函数值
BestX=-1*ones(1,MAXGEN);
%每步中最优的自变量
besty=-100;
%最优函数值
Y=AF_foodconsistence(X);
whilegen<
=MAXGEN
fprintf(1,'
%d\n'
gen)
fishnum
%%聚群行为
[Xi1,Yi1]=AF_swarm(X,i,visual,step,delta,try_number,LBUB,Y);
%%追尾行为
[Xi2,Yi2]=AF_follow(X,i,visual,step,delta,try_number,LBUB,Y);
ifYi1>
Yi2
X(:
i)=Xi1;
Y(1,i)=Yi1;
i)=Xi2;
Y(1,i)=Yi2;
[Ymax,index]=max(Y);
plot(X(1,index),Ymax,'
.'
'
color'
[gen/MAXGEN,0,0])
ifYmax>
besty
besty=Ymax;
bestx=X(:
index);
BestY(gen)=Ymax;
[BestX(:
gen)]=X(:
else
BestY(gen)=BestY(gen-1);
gen)]=BestX(:
gen-1);
end
gen=gen+1;
plot(bestx
(1),besty,'
ro'
MarkerSize'
100)xlabel('
x'
)
ylabel('
y'
title('
鱼群算法迭代过程中最优坐标移动'
%%优化过程图
figure
plot(1:
MAXGEN,BestY)
xlabel('
迭代次数'
优化值'
鱼群算法迭代过程'
disp(['
最优解X:
'
num2str(bestx,'
%1.5f'
)])disp(['
最优解Y:
num2str(besty,'
)])toc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 人工 鱼群 算法 源代码