# MATLAB代做-python代做-FPGA代做- 人工鱼群算法

### 时间：2019-5-10 17:31:22 点击：

核心提示：MATLAB代做-python代做-FPGA代做- 人工鱼群算法...
%人工鱼群算法
format long
Visual=2.5;
Step=0.3;
N=50;
Try_number=50;
a1=-10;
b1=10;
a2=-10;
b2=10;
d=[];
h=1e-1;
Friend_number=50;
k=0;
m=50;
X1=rand(N,1)*(b1-a1)+a1;
X2=rand(N,1)*(b2-a2)+a2;
X=[X1 X2];%人工鱼数量
for i=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)
for i=1:N
XX=[X(i,1),X(i,2)];%人工鱼当前状态Xi
nf=0;
Xc=0;
for j=1:N  %聚群行为开始
XXX=[X(j,1),X(j,2)];
if(norm(XXX-XX)<Visual)
nf=nf+1;
Xc=Xc+XXX;
end
end
Xc=Xc/nf;
if((maxf(Xc))>maxf(XX))
XXnext1=XX+rand*Step*(Xc-XX)/norm(Xc-XX);
if(XXnext1(1)>b1)
XXnext1(1)=b1;
end
if(XXnext1(1)<a1)
XXnext1(1)=a1;
end
if(XXnext1(2)>b2)
XXnext1(2)=b2;
end
if(XXnext1(2)<a2)
XXnext1(2)=a2;
end
else
XXnext1=gmjprey(XX,Try_number,Visual,Step);
if(XXnext1(1)>b1)
XXnext1(1)=b1;
end
if(XXnext1(1)<a1)
XXnext1(1)=a1;
end
if(XXnext1(2)>b2)
XXnext1(2)=b2;
end
if(XXnext1(2)<a2)
XXnext1(2)=a2;
end
end%聚群行为结束
%maxX=XX;%追尾行为开始
%maxY=maxf(XX);
for j=1:Friend_number
XXX=[X(j,1),X(j,2)];
if(norm(XXX-XX)<Visual & maxf(XXX)>maxY)
maxX=XXX;
maxY=maxf(XXX);
end
end
if((maxY)>maxf(XX))
XXnext2=XX+rand*Step*(maxX-XX)/norm(maxX-XX);
if(XXnext2(1)>b1)
XXnext2(1)=b1;
end
if(XXnext2(1)<a1)
XXnext2(1)=a1;
end
if(XXnext2(2)>b2)
XXnext2(2)=b2;
end
if(XXnext2(2)<a2)
XXnext2(2)=a2;
end
else
XXnext2 =gmjprey(XX,Try_number,Visual,Step);
if(XXnext2(1)>b1)
XXnext2(1)=b1;
end
if(XXnext2(1)<a1)
XXnext2(1)=a1;
end
if(XXnext2(2)>b2)
XXnext2(2)=b2;
end
if(XXnext2(2)<a2)
XXnext2(2)=a2;
end
end%追尾行为结束
if(maxf(XXnext1)>maxf(XXnext2))
X(i,1)=XXnext1(1);
X(i,2)=XXnext1(2);
else
X(i,1)=XXnext2(1);
X(i,2)=XXnext2(2);
end
end %一次迭代结束
for i=1:N
XXXX=[X(i,1),X(i,2)];
if maxf(XXXX)>maxY
maxY=maxf(XXXX);
maxX=XXXX;
figurex(numel(figurex)+1)=maxX(1);
figurey(numel(figurey)+1)=maxX(2);
figurez(numel(figurez)+1)=maxY;
end
end
k=k+1; %进入下一次迭代
end
maxX
maxY
plot3(figurex,figurey,figurez)

QQ ：1224848052

• 百度搜索
• 查阅资料过程中
• 论坛发现
• 百度贴吧发现
• 朋友介绍
• 大名：
• 内容：