日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

萤火虫算法_智能优化算法萤火虫算法

發布時間:2024/9/19 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 萤火虫算法_智能优化算法萤火虫算法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天介紹的算法是螢火蟲算法(Firefly Algorithm,簡稱FA),也是一種仿生優化算法。從算法名字就知道了,該算法的思想來源于螢火蟲,具體是螢火蟲的閃爍行為。下面是展開對算法相關內容的介紹。

01

原理部分

為了便于算法的設計,作者給出了三條理想化的設計假設[1],分別為:

1.螢火蟲不分性別,這樣一個螢火蟲將會吸引到所有其他的螢火蟲;

2.吸引力與它們的亮度成正比,對于任何兩個螢火蟲,不那么明亮的螢火蟲被吸引,因此移動到更亮的一個,然而,亮度又隨著其距離的增加而減少;

3.如果沒有比一個給定的螢火蟲更亮的螢火蟲,它會隨機移動。

下面是算法的一個偽代碼:

結合這個偽代碼,對算法中的一些參數進行介紹:

02

實現代碼

fa.m

clc;clear;close all;%% Problem DefinitionCostFunction=@(x) Sphere(x); % Cost FunctionnVar=5; % Number of Decision VariablesVarSize=[1 nVar]; % Decision Variables Matrix SizeVarMin=-10; % Decision Variables Lower BoundVarMax= 10; % Decision Variables Upper Bound%% Firefly Algorithm ParametersMaxIt=1000; % Maximum Number of IterationsnPop=25; % Number of Fireflies (Swarm Size)gamma=1; % Light Absorption Coefficientbeta0=2; % Attraction Coefficient Base Valuealpha=0.2; % Mutation Coefficientalpha_damp=0.98; % Mutation Coefficient Damping Ratiodelta=0.05*(VarMax-VarMin); % Uniform Mutation Rangem=2;if isscalar(VarMin) && isscalar(VarMax) dmax = (VarMax-VarMin)*sqrt(nVar);else dmax = norm(VarMax-VarMin);end%% Initialization% Empty Firefly Structurefirefly.Position=[];firefly.Cost=[];% Initialize Population Arraypop=repmat(firefly,nPop,1);% Initialize Best Solution Ever FoundBestSol.Cost=inf;% Create Initial Firefliesfor i=1:nPop pop(i).Position=unifrnd(VarMin,VarMax,VarSize); pop(i).Cost=CostFunction(pop(i).Position); if pop(i).Cost<=BestSol.Cost BestSol=pop(i); endend% Array to Hold Best Cost ValuesBestCost=zeros(MaxIt,1);%% Firefly Algorithm Main Loopfor it=1:MaxIt newpop=repmat(firefly,nPop,1); for i=1:nPop newpop(i).Cost = inf; for j=1:nPop if pop(j).Cost < pop(i).Cost rij=norm(pop(i).Position-pop(j).Position)/dmax; beta=beta0*exp(-gamma*rij^m); e=delta*unifrnd(-1,+1,VarSize); %e=delta*randn(VarSize); newsol.Position = pop(i).Position ... + beta*rand(VarSize).*(pop(j).Position-pop(i).Position) ... + alpha*e; newsol.Position=max(newsol.Position,VarMin); newsol.Position=min(newsol.Position,VarMax); newsol.Cost=CostFunction(newsol.Position); if newsol.Cost <= newpop(i).Cost newpop(i) = newsol; if newpop(i).Cost<=BestSol.Cost BestSol=newpop(i); end end end end end % Merge pop=[pop newpop]; %#ok % Sort [~, SortOrder]=sort([pop.Cost]); pop=pop(SortOrder); % Truncate pop=pop(1:nPop); % Store Best Cost Ever Found BestCost(it)=BestSol.Cost; % Show Iteration Information disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]); % Damp Mutation Coefficient alpha = alpha*alpha_damp; end%% Resultsfigure;%plot(BestCost,'LineWidth',2);semilogy(BestCost,'LineWidth',2);xlabel('Iteration');ylabel('Best Cost');grid on;Sphere.mfunction z=Sphere(x) z=sum(x.^2);end

03

結語

? ?以上就是對螢火蟲算法的簡單介紹,具體內容可參考原論文。在公眾號內回復螢火蟲算法即可獲得原論文。

[1]?Yang?X?S.?Firefly?algorithms?for?multimodal?optimization[C]//International?symposium?on?stochastic?algorithms.?Springer,?Berlin,?Heidelberg,?2009:?169-178.?

[2]https://ww2.mathworks.cn/matlabcentral/fileexchange/52900-firefly-algorithm-fa

總結

以上是生活随笔為你收集整理的萤火虫算法_智能优化算法萤火虫算法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。