欢迎来到天天文库
浏览记录
ID:55257578
大小:14.06 KB
页数:7页
时间:2020-05-07
《人工鱼群算法源代码.docx》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、人工鱼群算法源代码%人工鱼群算法;formatlong;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)%人工鱼群算法formatlongVisual=2.5;Step=0.3;N=50;Try_number=50;a1=-10;b1=1
2、0;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=[X1X2];%人工鱼数量fori=1:Nwwww=[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=[];fi
3、gurex(numel(figurex)+1)=maxX(1);figurey(numel(figurey)+1)=maxX(2);figurez(numel(figurez)+1)=maxY;kkk=0;while(k4、axf(Xc))>maxf(XX))XXnext1=XX+rand*Step*(Xc-XX)/norm(Xc-XX);if(XXnext1(1)>b1)XXnext1(1)=b1;endif(XXnext1(1)b2)XXnext1(2)=b2;endif(XXnext1(2)5、b1)XXnext1(1)=b1;endif(XXnext1(1)b2)XXnext1(2)=b2;endif(XXnext1(2)maxY)maxX=XXX;maxY=m6、axf(XXX);endendif((maxY)>maxf(XX))XXnext2=XX+rand*Step*(maxX-XX)/norm(maxX-XX);if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)b2)XXnext2(2)=b2;endif(XXnext2(2)7、Step);if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)b2)XXnext2(2)=b2;endif(XXnext2(2)maxf(XXnext2))X(i,1)=XXnext1(1);X(i,2)=XXnext1(2);elseX(i,1)=XXnext2(1);X(i,2)=XXnext2(8、2);endend%一次迭代结束fori=1:NXXXX=[X(i,1),X(i,2)];ifmaxf(XXXX)>maxYmaxY=maxf(XXXX);maxX=XXXX;figurex(numel(figurex)+1)=maxX(1);figurey(numel(figurey)+1)=maxX(2);figurez(numel(figurez)+1)=maxY;endendk=k+1;%进入下一次迭代e
4、axf(Xc))>maxf(XX))XXnext1=XX+rand*Step*(Xc-XX)/norm(Xc-XX);if(XXnext1(1)>b1)XXnext1(1)=b1;endif(XXnext1(1)b2)XXnext1(2)=b2;endif(XXnext1(2)
5、b1)XXnext1(1)=b1;endif(XXnext1(1)b2)XXnext1(2)=b2;endif(XXnext1(2)maxY)maxX=XXX;maxY=m
6、axf(XXX);endendif((maxY)>maxf(XX))XXnext2=XX+rand*Step*(maxX-XX)/norm(maxX-XX);if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)b2)XXnext2(2)=b2;endif(XXnext2(2)7、Step);if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)b2)XXnext2(2)=b2;endif(XXnext2(2)maxf(XXnext2))X(i,1)=XXnext1(1);X(i,2)=XXnext1(2);elseX(i,1)=XXnext2(1);X(i,2)=XXnext2(8、2);endend%一次迭代结束fori=1:NXXXX=[X(i,1),X(i,2)];ifmaxf(XXXX)>maxYmaxY=maxf(XXXX);maxX=XXXX;figurex(numel(figurex)+1)=maxX(1);figurey(numel(figurey)+1)=maxX(2);figurez(numel(figurez)+1)=maxY;endendk=k+1;%进入下一次迭代e
7、Step);if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)b2)XXnext2(2)=b2;endif(XXnext2(2)maxf(XXnext2))X(i,1)=XXnext1(1);X(i,2)=XXnext1(2);elseX(i,1)=XXnext2(1);X(i,2)=XXnext2(
8、2);endend%一次迭代结束fori=1:NXXXX=[X(i,1),X(i,2)];ifmaxf(XXXX)>maxYmaxY=maxf(XXXX);maxX=XXXX;figurex(numel(figurex)+1)=maxX(1);figurey(numel(figurey)+1)=maxX(2);figurez(numel(figurez)+1)=maxY;endendk=k+1;%进入下一次迭代e
此文档下载收益归作者所有