人工魚群算法源代碼(共7頁)_第1頁
人工魚群算法源代碼(共7頁)_第2頁
人工魚群算法源代碼(共7頁)_第3頁
人工魚群算法源代碼(共7頁)_第4頁
人工魚群算法源代碼(共7頁)_第5頁
已閱讀5頁,還剩2頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上人工魚群算法源代碼%人工魚群算法;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)%人工魚群算法format longVisual=2.5;Step=0.3;N=50;Try_number=50;a1=-10;b1=10;a2=-10;b2=10;d=;h=1e-1;Friend_

2、number=50;k=0;m=50;X1=rand(N,1)*(b1-a1)+a1;X2=rand(N,1)*(b2-a2)+a2;X=X1 X2;%人工魚數(shù)量for i=1:Nwwww=X(i,1),X(i,2);d(i)=maxf(wwww);endw,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

3、)=maxY;kkk=0;while(k<m)for i=1:NXX=X(i,1),X(i,2);%人工魚當前狀態(tài)Xinf=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;endendXc=Xc/nf;if(maxf(Xc)>maxf(XX)XXnext1=XX+rand*Step*(Xc-XX)/norm(Xc-XX); if(XXnext1(1)>b1)XXnext1(1)=b1;endif(XXnext1(1)<a1)XXnext1(1)=a

4、1;endif(XXnext1(2)>b2)XXnext1(2)=b2;endif(XXnext1(2)<a2)XXnext1(2)=a2;endelseXXnext1=gmjprey(XX,Try_number,Visual,Step); if(XXnext1(1)>b1)XXnext1(1)=b1;endif(XXnext1(1)<a1)XXnext1(1)=a1;endif(XXnext1(2)>b2)XXnext1(2)=b2;endif(XXnext1(2)<a2)XXnext1(2)=a2;endend%聚群行為結(jié)束%maxX=XX;%追尾行為開

5、始%maxY=maxf(XX);for j=1:Friend_numberXXX=X(j,1),X(j,2);if(norm(XXX-XX)<Visual & maxf(XXX)>maxY) maxX=XXX;maxY=maxf(XXX);endendif(maxY)>maxf(XX)XXnext2=XX+rand*Step*(maxX-XX)/norm(maxX-XX); if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)<a1)XXnext2(1)=a1;endif(XXnext2(2)>b2)XXne

6、xt2(2)=b2;endif(XXnext2(2)<a2)XXnext2(2)=a2;endelseXXnext2 =gmjprey(XX,Try_number,Visual,Step); if(XXnext2(1)>b1)XXnext2(1)=b1;endif(XXnext2(1)<a1)XXnext2(1)=a1;endif(XXnext2(2)>b2)XXnext2(2)=b2;endif(XXnext2(2)<a2)XXnext2(2)=a2;endend%追尾行為結(jié)束if(maxf(XXnext1)>maxf(XXnext2)X(i,1)=XXn

7、ext1(1);X(i,2)=XXnext1(2);elseX(i,1)=XXnext2(1);X(i,2)=XXnext2(2);endend %一次迭代結(jié)束for i=1:NXXXX=X(i,1),X(i,2);if maxf(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; %進入下一次迭代endmaxXmaxYplot3(figure

8、x,figurey,figurez)function XXnext = gmjprey(XX,Try_number,Visual,Step) pp=0;for j=1:Try_numberXXj=XX+rand*Step*Visual;if(maxf(XX)<maxf(XXj)XXnext=XX+rand*Step*(XXj-XX)/norm(XXj-XX); pp=1;breakendendif(pp)XXnext=XX+rand*Step;endfunction y = maxf(QQ)y=(sin(QQ(1)/QQ(1)*(sin(QQ(2)/QQ(2);人工魚群算法的仿真程序-m

9、atlab23tic;figure(1);holdon;ezplot('x*sin(10*pi*;%參數(shù)設(shè)置;fishnum=50;%生成50只人工魚;MAXGEN=50;%最多迭代次數(shù);try_number=100;%最多試探次數(shù);visual=1;%感知距離;delta=0.618;%擁擠度因子;step=0.1;%步長;%初始化魚群;lb_ub=-1,ticfigure(1);hold onezplot('x*sin(10*pi*x)+2',-1,2);% 參數(shù)設(shè)置fishnum=50; %生成50只人工魚MAXGEN=50; %最多迭代次數(shù)try_number=

10、100;%最多試探次數(shù)visual=1; %感知距離delta=0.618; %擁擠度因子step=0.1; %步長% 初始化魚群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);endgen=1;BestY=-1*ones(1,MAXGEN); %每步中最優(yōu)的函數(shù)值BestX=-1*ones(1,MAXGEN); %每步中最優(yōu)的自變量besty=-100; %最優(yōu)函數(shù)值Y=AF_foodconsistence(X);while

11、gen<=MAXGENfprintf(1,'%dn',gen)fori=1: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); if Yi1>Yi2X(:,i)=Xi1;Y(1,i)=Yi1;elseX(:,i)=Xi2;Y(1,i)=Yi2;endendYmax,index=max(Y);figure(1);plot(X(1,index),Ym

12、ax,'.','color',gen/MAXGEN,0,0)ifYmax>bestybesty=Ymax;bestx=X(:,index);BestY(gen)=Ymax;BestX(:,gen)=X(:,index); elseBestY(gen)=BestY(gen-1);BestX(:,gen)=BestX(:,gen-1); endgen=gen+1;endplot(bestx(1),besty,'ro','MarkerSize',100) xlabel('x')ylabel('y')title('魚群算法迭代過程中最優(yōu)坐標移動')% 優(yōu)化過程圖figureplot(1:MAXG

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論