Ⅰ 人工蜂群演算法matlab蜂群種群大小怎麼設定
%/* ABC algorithm coded using MATLAB language */
%/* Artificial Bee Colony (ABC) is one of the most recently defined algorithms by Dervis Karaboga in 2005, motivated by the intelligent behavior of honey bees. */
%/* Referance Papers*/
%/*D. Karaboga, AN IDEA BASED ON HONEY BEE SWARM FOR NUMERICAL OPTIMIZATION,TECHNICAL REPORT-TR06, Erciyes University, Engineering Faculty, Computer Engineering Department 2005.*/
%/*D. Karaboga, B. Basturk, A powerful and Efficient Algorithm for Numerical Function Optimization: Artificial Bee Colony (ABC) Algorithm, Journal of Global Optimization, Volume:39, Issue:3,pp:459-171, November 2007,ISSN:0925-5001 , doi: 10.1007/s10898-007-9149-x */
%/*D. Karaboga, B. Basturk, On The Performance Of Artificial Bee Colony (ABC) Algorithm, Applied Soft Computing,Volume 8, Issue 1, January 2008, Pages 687-697. */
%/*D. Karaboga, B. Akay, A Comparative Study of Artificial Bee Colony Algorithm, Applied Mathematics and Computation, 214, 108-132, 2009. */
%/*Copyright ?2009 Erciyes University, Intelligent Systems Research Group, The Dept. of Computer Engineering*/
%/*Contact:
%Dervis Karaboga ([email protected] )
%Bahriye Basturk Akay ([email protected])
%*/
clear all
close all
clc
%/* Control Parameters of ABC algorithm*/
NP=20; %/* The number of colony size (employed bees+onlooker bees)*/
FoodNumber=NP/2; %/*The number of food sources equals the half of the colony size*/
limit=100; %/*A food source which could not be improved through "limit" trials is abandoned by its employed bee*/
maxCycle=2500; %/*The number of cycles for foraging {a stopping criteria}*/
%/* Problem specific variables*/
objfun='Sphere'; %cost function to be optimized
D=100; %/*The number of parameters of the problem to be optimized*/
ub=ones(1,D)*100; %/*lower bounds of the parameters. */
lb=ones(1,D)*(-100);%/*upper bound of the parameters.*/
runtime=1;%/*Algorithm can be run many times in order to see its robustness*/
%Foods [FoodNumber][D]; /*Foods is the population of food sources. Each row of Foods matrix is a vector holding D parameters to be optimized. The number of rows of Foods matrix equals to the FoodNumber*/
%ObjVal[FoodNumber]; /*f is a vector holding objective function values associated with food sources */
%Fitness[FoodNumber]; /*fitness is a vector holding fitness (quality) values associated with food sources*/
%trial[FoodNumber]; /*trial is a vector holding trial numbers through which solutions can not be improved*/
%prob[FoodNumber]; /*prob is a vector holding probabilities of food sources (solutions) to be chosen*/
%solution [D]; /*New solution (neighbour) proced by v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) j is a randomly chosen parameter and k is a randomlu chosen solution different from i*/
%ObjValSol; /*Objective function value of new solution*/
%FitnessSol; /*Fitness value of new solution*/
%neighbour, param2change; /*param2change corrresponds to j, neighbour corresponds to k in equation v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij})*/
%GlobalMin; /*Optimum solution obtained by ABC algorithm*/
%GlobalParams[D]; /*Parameters of the optimum solution*/
%GlobalMins[runtime]; /*GlobalMins holds the GlobalMin of each run in multiple runs*/
GlobalMins=zeros(1,runtime);
for r=1:runtime
% /*All food sources are initialized */
%/*Variables are initialized in the range [lb,ub]. If each parameter has different range, use arrays lb[j], ub[j] instead of lb and ub */
Range = repmat((ub-lb),[FoodNumber 1]);
Lower = repmat(lb, [FoodNumber 1]);
Foods = rand(FoodNumber,D) .* Range + Lower;
ObjVal=feval(objfun,Foods);
Fitness=calculateFitness(ObjVal);
%reset trial counters
trial=zeros(1,FoodNumber);
%/*The best food source is memorized*/
BestInd=find(ObjVal==min(ObjVal));
BestInd=BestInd(end);
GlobalMin=ObjVal(BestInd);
GlobalParams=Foods(BestInd,:);
iter=1;
while ((iter <= maxCycle)),
%%%%%%%%% EMPLOYED BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%
for i=1:(FoodNumber)
%/*The parameter to be changed is determined randomly*/
Param2Change=fix(rand*D)+1;
%/*A randomly chosen solution is used in procing a mutant solution of the solution i*/
neighbour=fix(rand*(FoodNumber))+1;
%/*Randomly selected solution must be different from the solution i*/
while(neighbour==i)
neighbour=fix(rand*(FoodNumber))+1;
end;
sol=Foods(i,:);
% /*v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) */
sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
% /*if generated parameter value is out of boundaries, it is shifted onto the boundaries*/
ind=find(sol<lb);
sol(ind)=lb(ind);
ind=find(sol>ub);
sol(ind)=ub(ind);
%evaluate new solution
ObjValSol=feval(objfun,sol);
FitnessSol=calculateFitness(ObjValSol);
% /*a greedy selection is applied between the current solution i and its mutant*/
if (FitnessSol>Fitness(i)) %/*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/
Foods(i,:)=sol;
Fitness(i)=FitnessSol;
ObjVal(i)=ObjValSol;
trial(i)=0;
else
trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%% CalculateProbabilities %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%/* A food source is chosen with the probability which is proportioal to its quality*/
%/*Different schemes can be used to calculate the probability values*/
%/*For example prob(i)=fitness(i)/sum(fitness)*/
%/*or in a way used in the metot below prob(i)=a*fitness(i)/max(fitness)+b*/
%/*probability values are calculated by using fitness values and normalized by dividing maximum fitness value*/
prob=(0.9.*Fitness./max(Fitness))+0.1;
%%%%%%%%%%%%%%%%%%%%%%%% ONLOOKER BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i=1;
t=0;
while(t<FoodNumber)
if(rand<prob(i))
t=t+1;
%/*The parameter to be changed is determined randomly*/
Param2Change=fix(rand*D)+1;
%/*A randomly chosen solution is used in procing a mutant solution of the solution i*/
neighbour=fix(rand*(FoodNumber))+1;
%/*Randomly selected solution must be different from the solution i*/
while(neighbour==i)
neighbour=fix(rand*(FoodNumber))+1;
end;
sol=Foods(i,:);
% /*v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) */
sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
% /*if generated parameter value is out of boundaries, it is shifted onto the boundaries*/
ind=find(sol<lb);
sol(ind)=lb(ind);
ind=find(sol>ub);
sol(ind)=ub(ind);
%evaluate new solution
ObjValSol=feval(objfun,sol);
FitnessSol=calculateFitness(ObjValSol);
% /*a greedy selection is applied between the current solution i and its mutant*/
if (FitnessSol>Fitness(i)) %/*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/
Foods(i,:)=sol;
Fitness(i)=FitnessSol;
ObjVal(i)=ObjValSol;
trial(i)=0;
else
trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
end;
end;
i=i+1;
if (i==(FoodNumber)+1)
i=1;
end;
end;
%/*The best food source is memorized*/
ind=find(ObjVal==min(ObjVal));
ind=ind(end);
if (ObjVal(ind)<GlobalMin)
GlobalMin=ObjVal(ind);
GlobalParams=Foods(ind,:);
end;
%%%%%%%%%%%% SCOUT BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%/*determine the food sources whose trial counter exceeds the "limit" value.
%In Basic ABC, only one scout is allowed to occur in each cycle*/
ind=find(trial==max(trial));
ind=ind(end);
if (trial(ind)>limit)
Bas(ind)=0;
sol=(ub-lb).*rand(1,D)+lb;
ObjValSol=feval(objfun,sol);
FitnessSol=calculateFitness(ObjValSol);
Foods(ind,:)=sol;
Fitness(ind)=FitnessSol;
ObjVal(ind)=ObjValSol;
end;
fprintf('Ýter=%d ObjVal=%g\n',iter,GlobalMin);
iter=iter+1;
end % End of ABC
GlobalMins(r)=GlobalMin;
end; %end of runs
save all
Ⅱ 智能優化演算法:人工蜂群演算法
@[toc]
摘要:人工蜂群演算法(artificial bee colony,ABC)是由土耳其學者Karaboga 於 2005 年提出,它是模擬蜜蜂的采蜜行為來解決生活中一些多維和多模的優化問題,它最初應用於數值優化問題,自提出以來受到了眾多學者極大的關注,並廣泛應用到神經網路、數據挖掘、工程應用、圖像識別等多個領域。
在 ABC 演算法里,用蜜源的位置來表示解,用蜜源的花粉數量表示解的適應值。所有的蜜蜂劃分為僱傭蜂、跟隨蜂、探索蜂三組。僱傭蜂和跟隨蜂各占蜂群總數的一半。僱傭蜂負責最初的尋找蜜源並采蜜分享信息,跟隨蜂負責呆在蜂巢里根據僱傭蜂提供的信息去采蜜,探索蜂在原有蜜源被拋棄後負責隨機尋找新的蜜源來替換原有的蜜源。與其他群智能演算法一樣,ABC 演算法是迭代的。對蜂群和蜜源的初始化後,反復執行三個過程,即僱傭蜂、跟隨蜂、探索蜂階段,來尋找問題的最優解。每個階段描述如下:
對 ABC 演算法的參數進行初始化,這些參數有蜜源數 、蜜源確定被拋棄的次數 、迭代終止次數。在標准 ABC 演算法里,蜜源的數目 與僱傭蜂數相等,也與跟隨蜂數相等。產生某個蜜源的公式為:
其中: 代表第 個蜜源 的第 維度值, 取值於 , 取值於 ; 和 分別代表第 維的最小值和最大值。初始化蜜源就是對每個蜜源的所有維度通過以上公式賦一個在取值范圍內的隨機值,從而隨機生成 個最初蜜源。
在僱傭蜂階段,僱傭蜂用以下公式來尋找新蜜源:
其中: 代表鄰域蜜源, 取值於 ,且 不等於 ; 是取值在[-1,1]的隨機數,通過式(2)得到新蜜源後,利用貪婪演算法,比較新舊蜜源適應值,選擇優者。
僱傭蜂階段結束,跟隨蜂階段開始。在該階段,僱傭蜂在舞蹈區分享蜜源信息。跟隨蜂分析這些信息,採用輪盤賭策略來選擇蜜源跟蹤開采,以保證適應值更高的蜜源開採的概率更大。跟隨蜂開采過程與僱傭蜂一樣,利用式(2)找尋新蜜源,並留下更優適應者。
蜜源擁有參數 ,當蜜源更新被保留時, 為 0;反之, 加 1。從而 能統計出一個蜜源沒有被更新的次數。
如果一個蜜源經過多次開采沒被更新,也就是 值過高,超過了預定閾值 ,那麼需拋棄這個蜜源,啟動探索蜂階段。這體現了 ABC 里自組織的負反饋和波動屬性 。在該階段里,探索蜂利用式(3)隨機尋找新的蜜源來代替被拋棄蜜源。
人工蜂群演算法流程
step1.初始化演算法參數,生成蜜蜂初始位置
step2.僱傭蜂計算適應度值,比較並保存最優值
step3.跟隨蜂選擇僱傭蜂更新蜜源位置,計算適應度值,保存最佳值
step4.若有偵察蜂出現,則重新生成初始位置並執行更新選優,否則繼續執行step5
step5.若迭代次數小於預設的迭代次數,則轉到step2;否則輸出最優解
[1]何堯,劉建華,楊榮華.人工蜂群演算法研究綜述[J].計算機應用研究,2018,35(05):1281-1286.
https://mianbaoo.com/o/bread/aJWVkps=
https://mianbaoo.com/o/bread/YZWalJxr
Ⅲ Matlab如何將不等式約束引入蜂群演算法中
優化變數的生成中需要范圍 在這里加入
Ⅳ Matlab程序問題,高分求錯誤原因,小弟感激不盡
那個代碼不完整,裡面用到的Distance和Min函數都沒有定義,而從函數的輸入輸出參數和作用看,並不是系統自帶的distance和min函數。
最好的辦法的是你再找一找,看有沒有更完整的代碼,如果找不到,我幫你補了這兩個函數,程序可以運行,但我不確定是不是符合演算法的本意。
我補的那兩個函數放家裡了,要是你找不到更好的解決辦法,可以追問,我回家後貼出代碼。
Ⅳ 有沒有人有多目標人工蜂群演算法的MATLAB代碼。發我一份 不勝感激!!
http://emuch.net/bbs/attachment.php?tid=3808850&aid=11221&pay=yes
裡面有多個文件
其中之一
%/* ABC algorithm coded using MATLAB language */
%/* Artificial Bee Colony (ABC) is one of the most recently defined algorithms by Dervis Karaboga in 2005, motivated by the intelligent behavior of honey bees. */
%/* Referance Papers*/
%/*D. Karaboga, AN IDEA BASED ON HONEY BEE SWARM FOR NUMERICAL OPTIMIZATION,TECHNICAL REPORT-TR06, Erciyes University, Engineering Faculty, Computer Engineering Department 2005.*/
%/*D. Karaboga, B. Basturk, A powerful and Efficient Algorithm for Numerical Function Optimization: Artificial Bee Colony (ABC) Algorithm, Journal of Global Optimization, Volume:39, Issue:3,pp:459-171, November 2007,ISSN:0925-5001 , doi: 10.1007/s10898-007-9149-x */
%/*D. Karaboga, B. Basturk, On The Performance Of Artificial Bee Colony (ABC) Algorithm, Applied Soft Computing,Volume 8, Issue 1, January 2008, Pages 687-697. */
%/*D. Karaboga, B. Akay, A Comparative Study of Artificial Bee Colony Algorithm, Applied Mathematics and Computation, 214, 108-132, 2009. */
%/*Copyright ?2009 Erciyes University, Intelligent Systems Research Group, The Dept. of Computer Engineering*/
%/*Contact:
%Dervis Karaboga ([email protected] )
%Bahriye Basturk Akay ([email protected])
%*/
clear all
close all
clc
%/* Control Parameters of ABC algorithm*/
NP=20; %/* The number of colony size (employed bees+onlooker bees)*/
FoodNumber=NP/2; %/*The number of food sources equals the half of the colony size*/
limit=100; %/*A food source which could not be improved through "limit" trials is abandoned by its employed bee*/
maxCycle=2500; %/*The number of cycles for foraging {a stopping criteria}*/
%/* Problem specific variables*/
objfun='Sphere'; %cost function to be optimized
D=100; %/*The number of parameters of the problem to be optimized*/
ub=ones(1,D)*100; %/*lower bounds of the parameters. */
lb=ones(1,D)*(-100);%/*upper bound of the parameters.*/
runtime=1;%/*Algorithm can be run many times in order to see its robustness*/
%Foods [FoodNumber][D]; /*Foods is the population of food sources. Each row of Foods matrix is a vector holding D parameters to be optimized. The number of rows of Foods matrix equals to the FoodNumber*/
%ObjVal[FoodNumber]; /*f is a vector holding objective function values associated with food sources */
%Fitness[FoodNumber]; /*fitness is a vector holding fitness (quality) values associated with food sources*/
%trial[FoodNumber]; /*trial is a vector holding trial numbers through which solutions can not be improved*/
%prob[FoodNumber]; /*prob is a vector holding probabilities of food sources (solutions) to be chosen*/
%solution [D]; /*New solution (neighbour) proced by v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) j is a randomly chosen parameter and k is a randomlu chosen solution different from i*/
%ObjValSol; /*Objective function value of new solution*/
%FitnessSol; /*Fitness value of new solution*/
%neighbour, param2change; /*param2change corrresponds to j, neighbour corresponds to k in equation v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij})*/
%GlobalMin; /*Optimum solution obtained by ABC algorithm*/
%GlobalParams[D]; /*Parameters of the optimum solution*/
%GlobalMins[runtime]; /*GlobalMins holds the GlobalMin of each run in multiple runs*/
GlobalMins=zeros(1,runtime);
for r=1:runtime
% /*All food sources are initialized */
%/*Variables are initialized in the range [lb,ub]. If each parameter has different range, use arrays lb[j], ub[j] instead of lb and ub */
Range = repmat((ub-lb),[FoodNumber 1]);
Lower = repmat(lb, [FoodNumber 1]);
Foods = rand(FoodNumber,D) .* Range + Lower;
ObjVal=feval(objfun,Foods);
Fitness=calculateFitness(ObjVal);
%reset trial counters
trial=zeros(1,FoodNumber);
%/*The best food source is memorized*/
BestInd=find(ObjVal==min(ObjVal));
BestInd=BestInd(end);
GlobalMin=ObjVal(BestInd);
GlobalParams=Foods(BestInd,:);
iter=1;
while ((iter <= maxCycle)),
%%%%%%%%% EMPLOYED BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%
for i=1:(FoodNumber)
%/*The parameter to be changed is determined randomly*/
Param2Change=fix(rand*D)+1;
%/*A randomly chosen solution is used in procing a mutant solution of the solution i*/
neighbour=fix(rand*(FoodNumber))+1;
%/*Randomly selected solution must be different from the solution i*/
while(neighbour==i)
neighbour=fix(rand*(FoodNumber))+1;
end;
sol=Foods(i,:);
% /*v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) */
sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
% /*if generated parameter value is out of boundaries, it is shifted onto the boundaries*/
ind=find(sol<lb);
sol(ind)=lb(ind);
ind=find(sol>ub);
sol(ind)=ub(ind);
%evaluate new solution
ObjValSol=feval(objfun,sol);
FitnessSol=calculateFitness(ObjValSol);
% /*a greedy selection is applied between the current solution i and its mutant*/
if (FitnessSol>Fitness(i)) %/*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/
Foods(i,:)=sol;
Fitness(i)=FitnessSol;
ObjVal(i)=ObjValSol;
trial(i)=0;
else
trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%% CalculateProbabilities %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%/* A food source is chosen with the probability which is proportioal to its quality*/
%/*Different schemes can be used to calculate the probability values*/
%/*For example prob(i)=fitness(i)/sum(fitness)*/
%/*or in a way used in the metot below prob(i)=a*fitness(i)/max(fitness)+b*/
%/*probability values are calculated by using fitness values and normalized by dividing maximum fitness value*/
prob=(0.9.*Fitness./max(Fitness))+0.1;
%%%%%%%%%%%%%%%%%%%%%%%% ONLOOKER BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
i=1;
t=0;
while(t<FoodNumber)
if(rand<prob(i))
t=t+1;
%/*The parameter to be changed is determined randomly*/
Param2Change=fix(rand*D)+1;
%/*A randomly chosen solution is used in procing a mutant solution of the solution i*/
neighbour=fix(rand*(FoodNumber))+1;
%/*Randomly selected solution must be different from the solution i*/
while(neighbour==i)
neighbour=fix(rand*(FoodNumber))+1;
end;
sol=Foods(i,:);
% /*v_{ij}=x_{ij}+\phi_{ij}*(x_{kj}-x_{ij}) */
sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2;
% /*if generated parameter value is out of boundaries, it is shifted onto the boundaries*/
ind=find(sol<lb);
sol(ind)=lb(ind);
ind=find(sol>ub);
sol(ind)=ub(ind);
%evaluate new solution
ObjValSol=feval(objfun,sol);
FitnessSol=calculateFitness(ObjValSol);
% /*a greedy selection is applied between the current solution i and its mutant*/
if (FitnessSol>Fitness(i)) %/*If the mutant solution is better than the current solution i, replace the solution with the mutant and reset the trial counter of solution i*/
Foods(i,:)=sol;
Fitness(i)=FitnessSol;
ObjVal(i)=ObjValSol;
trial(i)=0;
else
trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
end;
end;
i=i+1;
if (i==(FoodNumber)+1)
i=1;
end;
end;
%/*The best food source is memorized*/
ind=find(ObjVal==min(ObjVal));
ind=ind(end);
if (ObjVal(ind)<GlobalMin)
GlobalMin=ObjVal(ind);
GlobalParams=Foods(ind,:);
end;
%%%%%%%%%%%% SCOUT BEE PHASE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%/*determine the food sources whose trial counter exceeds the "limit" value.
%In Basic ABC, only one scout is allowed to occur in each cycle*/
ind=find(trial==max(trial));
ind=ind(end);
if (trial(ind)>limit)
Bas(ind)=0;
sol=(ub-lb).*rand(1,D)+lb;
ObjValSol=feval(objfun,sol);
FitnessSol=calculateFitness(ObjValSol);
Foods(ind,:)=sol;
Fitness(ind)=FitnessSol;
ObjVal(ind)=ObjValSol;
end;
fprintf('Ýter=%d ObjVal=%g\n',iter,GlobalMin);
iter=iter+1;
end % End of ABC
GlobalMins(r)=GlobalMin;
end; %end of runs
save all
Ⅵ 求 人工蜂群演算法用於無線感測器網路路由協議的模擬代碼
我有個基於tinyos的nesc 語言的代碼模擬,不知道你需要不,另外好像這個蟻群演算法好像沒有太大的研究意義。PS.這個不是我的電話號碼
Ⅶ 優化演算法筆記(八)人工蜂群演算法
(以下描述,均不是學術用語,僅供大家快樂的閱讀)
工蜂群演算法(Artificial Bee Colony Algorithm,ABC)是一種模仿蜜蜂采蜜機理而產生的群智能優化演算法。其原理相對復雜,但實現較為簡單,在許多領域中都有研究和應用。
人工蜂群演算法中,每一個蜜源的位置代表了待求問題的一個可行解。蜂群分為采蜜蜂、觀察蜂和偵查蜂。采蜜蜂與蜜源對應,一個采蜜蜂對應一個蜜源。觀察蜂則會根據采蜜蜂分享的蜜源相關信息選擇跟隨哪個采蜜蜂去相應的蜜源,同時該觀察蜂將轉變為偵查蜂。偵查蜂則自由的搜索新的蜜源。每一個蜜源都有開採的限制次數,當一個蜜源被采蜜多次而達到開采限制次數時,在該蜜源采蜜的采蜜蜂將轉變為偵查蜂。每個偵查蜂將隨機尋找一個新蜜源進行開采,並轉變成為采蜜蜂。
下面是我的實現方式(我的答案):
1. 三種蜜蜂之間可以相互轉化。
采蜜蜂->觀察蜂:有觀察蜂在采蜜過程中發現了比當前采蜜蜂更好的蜜源,則采蜜蜂放棄當前蜜源轉而變成觀察蜂跟隨優質蜜源,同時該觀察蜂轉變為采蜜蜂。
采蜜蜂->觀察蜂:當該采蜜蜂所發現的蜜源被開采完後,它會轉變為觀察蜂去跟隨其他采蜜蜂。
采蜜蜂->偵查蜂:當所有的采蜜蜂發現的蜜源都被開采完後,采蜜蜂將會變為偵查蜂,觀察蜂也會變成偵查蜂,因為大家都無蜜可采。
偵查蜂->采蜜蜂、觀察蜂:偵查蜂隨機搜索蜜源,選擇較好的數個蜜源位置的蜜蜂為采蜜蜂,其他蜜蜂為觀察蜂。
2.蜜源的數量上限
蜜源的數量上限等於采蜜蜂的數量上限。初始化時所有蜜蜂都是偵查蜂,在這些偵查蜂所搜索到的蜜源中選出數個較優的蜜源,發現這些蜜源的偵查蜂變為采蜜蜂,其他蜜蜂變為觀察蜂。直到所有的蜜源都被開采完之前,蜜源的數量不會增加,因為這個過程中沒有產生偵查蜂。所有的蜜源都被開采完後,所有的蜜蜂再次全部轉化為偵查蜂,新的一輪蜜源搜索開始。也可以在一個蜜源開采完時馬上產生一個新的蜜源補充,保證在整個開采過程中蜜源數量恆定不變。
蜜源的開采實際上就是觀察蜂跟隨采蜜蜂飛向蜜源的過程。得到的下一代的位置公式如下:
表示第i只觀察蜂在第t代時隨機選擇第r只採蜜蜂飛行一段距離,其中R為(-1,1)的隨機數。
一隻觀察蜂在一次迭代過程中只能選擇一隻采蜜蜂跟隨,它需要從眾多的采蜜蜂中選擇一隻來進行跟隨。觀察蜂選擇的策略很簡單,隨機跟隨一隻采蜜蜂,該采蜜蜂發現的蜜源越優,則選擇它的概率越大。
是不是很像輪盤賭,對,這就是輪盤賭,同時我們也可以稍作修改,比如將勤勞的小蜜蜂改為懶惰的小蜜蜂,小蜜蜂會根據蜜源的優劣和距離以及開采程度等因素綜合來選擇跟隨哪只採蜜蜂(雖然影響不大,但聊勝於無)。
忘記了輪盤賭的小夥伴可以看一下 優化演算法筆記(六)遺傳演算法 。
下面是我的人工蜂群演算法流程圖
又到了實驗環節,參數實驗較多,全部給出將會佔用太多篇幅,僅將結果進行匯總展示。
實驗1:參數如下
上圖分別為采蜜蜂上限為10%總數和50%總數的情況,可以看出當采蜜蜂上限為10%總群數時,種群收斂的速度較快,但是到最後有一個點死活不動,這是因為該點作為一個蜜源,但由於適應度值太差,使用輪盤賭被選擇到的概率太小從而沒有得到更佳的蜜源位置,而因未開采完,采蜜蜂又不能放棄該蜜源。
看了看采蜜蜂上限為50%總群數時的圖,發現也有幾個點不動的狀態,可以看出,這時不動的點的數量明顯多於上限為10%總數的圖,原因很簡單,采蜜蜂太多,「先富」的人太多,而「後富」的人較少,沒有帶動「後富者」的「先富者」也得不到發展。
看看結果
嗯,感覺結果並沒有什麼差別,可能由於問題較簡單,迭代次數較少,無法體現出采蜜蜂數對於結果的影響,也可能由於蜜源的搜索次數為60較大,總群一共只能對最多20*50/60=16個蜜源進行搜索。我們將最大迭代次數調大至200代再看看結果
當最大迭代次數為200時,人工蜂群演算法的結果如上圖,我們可以明顯的看出,隨著采蜜蜂上限的上升,演算法結果的精度在不斷的下降,這也印證了之前的結果,由於蜜源搜索次數較大(即搜索深度較深)采蜜蜂數量越多(搜索廣度越多),結果的精度越低。不過影響也不算太大,下面我們再來看看蜜源最大開采次數對結果的影響。
實驗2:參數如下
上圖分別是蜜源開采限度為1,20和4000的實驗。
當蜜源開采上限為1時,即一個蜜源只能被開采一次,即此時的人工蜂群演算法只有偵查蜂隨機搜索的過程,沒有觀察蜂跟隨采蜜蜂的過程,可以看出圖中的蜜蜂一直在不斷的隨機出現在新位置不會向某個點收斂。
當蜜源開采上限為20時,我們可以看到此時種群中的蜜蜂都會向一個點飛行。在一段時間內,有數個點一動不動,這些點可能就是采蜜蜂發現的位置不怎麼好的蜜源,但是在幾次迭代之後,它們仍會被觀察蜂開采,從而更新位置,蜜源開采上限越高,它們停頓的代數也會越長。在所有蜜蜂都收斂於一個點之後,我們可以看到仍會不斷的出現其他的隨機點,這些點是偵查蜂進行隨機搜索產生的新的蜜源位置,這些是人工蜂群演算法跳出局部最優能力的體現。
當蜜源開采上限為4000時,即不會出現偵查蜂的搜索過程,觀察蜂只會開采初始化時出現的蜜源而不會采蜜蜂不會有新的蜜源產生,可以看出在蜂群收斂後沒有出現新的蜜源位置。
看看最終結果,我們發現,當蜜源開采上線大於1時的結果提升,但是好像開采上限為5時結果明顯好於開采次數上限為其他的結果,而且隨著開采次數不斷上升,結果在不斷的變差。為什麼會出現這樣的結果呢?原因可能還是因為問題較為簡單,在5次開採的限度內,觀察蜂已經能找到更好的蜜源進行開采,當問題較為復雜時,我們無法知曉開采發現新蜜源的難度,蜜源開采上限應該取一個相對較大的值。當蜜源開采限度為4000時,即一個蜜源不可能被開采完(開采次數為20(種群數)*200(迭代次數)),搜索的深度有了但是其結果反而不如開采限度為幾次幾十次來的好,而且這樣不會有偵查蜂隨機搜索的過程,失去了跳出局部最優的能力。
我們應該如何選擇蜜源的最大開采次數限制呢?其實,沒有最佳的開采次數限制,當適應度函數較為簡單時,開采次數較小時能得到比較好的結果,但是適應度函數較復雜時,經過試驗,得出的結果遠差於開采次數較大時。當然,前面就說過,適應度函數是一個黑盒模型,我們無法判斷問題的難易。那麼我們應該選擇一個適中的值,個人的選擇是種群數的0.5倍到總群數的2倍作為蜜源的最大開采次數,這樣可以保證極端情況下,1-2個迭代周期內小蜜蜂們能將一個蜜源開采完。
人工蜂群演算法算是一個困擾我比較長時間的演算法,幾年時間里,我根據文獻實現的人工蜂群演算法都有數十種,只能說人工蜂群演算法的描述太過模糊,或者說太過抽象,研究者怎麼實現都說的通。但是通過實現多次之後發現雖然實現細節大不相同,但效果相差不多,所以我們可以認為人工蜂群演算法的穩定性比較強,只要實現其主要思想即可,細節對於結果的影響不太大。
對於人工蜂群演算法影響最大的因素還是蜜源的開采次數限制,開采次數限制越大,對同一蜜源的開發力度越大,但是分配給其他蜜源的搜索力度會相對減少,也會降低蜂群演算法的跳出局部最優能力。可以動態修改蜜源的開采次數限制來實現對演算法的改進,不過效果不顯著。
其次對於人工蜂群演算法影響是三類蜜蜂的搜索行為,我們可以重新設計蜂群的搜索方式來對演算法進行改進,比如采蜜蜂在開采蜜源時是隨機飛向其他蜜源,而觀察蜂向所選的蜜源靠近。這樣改進有一定效果但是在高維問題上效果仍不明顯。
以下指標純屬個人yy,僅供參考
目錄
上一篇 優化演算法筆記(七)差分進化演算法
下一篇 優化演算法筆記(九)杜鵑搜索演算法
優化演算法matlab實現(八)人工蜂群演算法matlab實現
Ⅷ java人工蜂群演算法求解TSP問題
一、人工蜂群演算法的介紹
人工蜂群演算法(Artificial Bee Colony, ABC)是由Karaboga於2005年提出的一種新穎的基於群智能的全局優化演算法,其直觀背景來源於蜂群的采蜜行為,蜜蜂根據各自的分工進行不同的活動,並實現蜂群信息的共享和交流,從而找到問題的最優解。人工蜂群演算法屬於群智能演算法的一種。
二、人工蜂群演算法的原理
1、原理
標準的ABC演算法通過模擬實際蜜蜂的采蜜機制將人工蜂群分為3類: 采蜜蜂、觀察蜂和偵察蜂。整個蜂群的目標是尋找花蜜量最大的蜜源。在標準的ABC演算法中,采蜜蜂利用先前的蜜源信息尋找新的蜜源並與觀察蜂分享蜜源信息;觀察蜂在蜂房中等待並依據采蜜蜂分享的信息尋找新的蜜源;偵查蜂的任務是尋找一個新的有價值的蜜源,它們在蜂房附近隨機地尋找蜜源。
假設問題的解空間是。
代碼:
[cpp]view plain
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<cmath>
#include<fstream>
#include<iomanip>
usingnamespacestd;
constintNP=40;//種群的規模,采蜜蜂+觀察蜂
constintFoodNumber=NP/2;//食物的數量,為采蜜蜂的數量
constintlimit=20;//限度,超過這個限度沒有更新采蜜蜂變成偵查蜂
constintmaxCycle=10000;//停止條件
/*****函數的特定參數*****/
constintD=2;//函數的參數個數
constdoublelb=-100;//函數的下界
constdoubleub=100;//函數的上界
doubleresult[maxCycle]={0};
/*****種群的定義****/
structBeeGroup
{
doublecode[D];//函數的維數
doubletrueFit;//記錄真實的最小值
doublefitness;
doublerfitness;//相對適應值比例
inttrail;//表示實驗的次數,用於與limit作比較
}Bee[FoodNumber];
BeeGroupNectarSource[FoodNumber];//蜜源,注意:一切的修改都是針對蜜源而言的
BeeGroupEmployedBee[FoodNumber];//采蜜蜂
BeeGroupOnLooker[FoodNumber];//觀察蜂
BeeGroupBestSource;//記錄最好蜜源
/*****函數的聲明*****/
doublerandom(double,double);//產生區間上的隨機數
voidinitilize();//初始化參數
doublecalculationTruefit(BeeGroup);//計算真實的函數值
doublecalculationFitness(double);//計算適應值
voidCalculateProbabilities();//計算輪盤賭的概率
voidevalueSource();//評價蜜源
voidsendEmployedBees();
voidsendOnlookerBees();
voidsendScoutBees();
voidMemorizeBestSource();
/*******主函數*******/
intmain()
{
ofstreamoutput;
output.open("dataABC.txt");
srand((unsigned)time(NULL));
initilize();//初始化
MemorizeBestSource();//保存最好的蜜源
//主要的循環
intgen=0;
while(gen<maxCycle)
{
sendEmployedBees();
CalculateProbabilities();
sendOnlookerBees();
MemorizeBestSource();
sendScoutBees();
MemorizeBestSource();
output<<setprecision(30)<<BestSource.trueFit<<endl;
gen++;
}
output.close();
cout<<"運行結束!!"<<endl;
return0;
}
/*****函數的實現****/
doublerandom(doublestart,doubleend)//隨機產生區間內的隨機數
{
returnstart+(end-start)*rand()/(RAND_MAX+1.0);
}
voidinitilize()//初始化參數
{
inti,j;
for(i=0;i<FoodNumber;i++)
{
for(j=0;j<D;j++)
{
NectarSource[i].code[j]=random(lb,ub);
EmployedBee[i].code[j]=NectarSource[i].code[j];
OnLooker[i].code[j]=NectarSource[i].code[j];
BestSource.code[j]=NectarSource[0].code[j];
}
/****蜜源的初始化*****/
NectarSource[i].trueFit=calculationTruefit(NectarSource[i]);
NectarSource[i].fitness=calculationFitness(NectarSource[i].trueFit);
NectarSource[i].rfitness=0;
NectarSource[i].trail=0;
/****采蜜蜂的初始化*****/
EmployedBee[i].trueFit=NectarSource[i].trueFit;
EmployedBee[i].fitness=NectarSource[i].fitness;
EmployedBee[i].rfitness=NectarSource[i].rfitness;
EmployedBee[i].trail=NectarSource[i].trail;
/****觀察蜂的初始化****/
OnLooker[i].trueFit=NectarSource[i].trueFit;
OnLooker[i].fitness=NectarSource[i].fitness;
OnLooker[i].rfitness=NectarSource[i].rfitness;
OnLooker[i].trail=NectarSource[i].trail;
}
/*****最優蜜源的初始化*****/
BestSource.trueFit=NectarSource[0].trueFit;
BestSource.fitness=NectarSource[0].fitness;
BestSource.rfitness=NectarSource[0].rfitness;
BestSource.trail=NectarSource[0].trail;
}
doublecalculationTruefit(BeeGroupbee)//計算真實的函數值
{
doubletruefit=0;
/******測試函數1******/
truefit=0.5+(sin(sqrt(bee.code[0]*bee.code[0]+bee.code[1]*bee.code[1]))*sin(sqrt(bee.code[0]*bee.code[0]+bee.code[1]*bee.code[1]))-0.5)
/((1+0.001*(bee.code[0]*bee.code[0]+bee.code[1]*bee.code[1]))*(1+0.001*(bee.code[0]*bee.code[0]+bee.code[1]*bee.code[1])));
returntruefit;
}
doublecalculationFitness(doubletruefit)//計算適應值
{
doublefitnessResult=0;
if(truefit>=0)
{
fitnessResult=1/(truefit+1);
}else
{
fitnessResult=1+abs(truefit);
}
returnfitnessResult;
}
voidsendEmployedBees()//修改采蜜蜂的函數
{
inti,j,k;
intparam2change;//需要改變的維數
doubleRij;//[-1,1]之間的隨機數
for(i=0;i<FoodNumber;i++)
{
param2change=(int)random(0,D);//隨機選取需要改變的維數
/******選取不等於i的k********/
while(1)
{
k=(int)random(0,FoodNumber);
if(k!=i)
{
break;
}
}
for(j=0;j<D;j++)
{
EmployedBee[i].code[j]=NectarSource[i].code[j];
}
/*******采蜜蜂去更新信息*******/
Rij=random(-1,1);
EmployedBee[i].code[param2change]=NectarSource[i].code[param2change]+Rij*(NectarSource[i].code[param2change]-NectarSource[k].code[param2change]);
/*******判斷是否越界********/
if(EmployedBee[i].code[param2change]>ub)
{
EmployedBee[i].code[param2change]=ub;
}
if(EmployedBee[i].code[param2change]<lb)
{
EmployedBee[i].code[param2change]=lb;
}
EmployedBee[i].trueFit=calculationTruefit(EmployedBee[i]);
EmployedBee[i].fitness=calculationFitness(EmployedBee[i].trueFit);
/******貪婪選擇策略*******/
if(EmployedBee[i].trueFit<NectarSource[i].trueFit)
{
for(j=0;j<D;j++)
{
NectarSource[i].code[j]=EmployedBee[i].code[j];
}
NectarSource[i].trail=0;
NectarSource[i].trueFit=EmployedBee[i].trueFit;
NectarSource[i].fitness=EmployedBee[i].fitness;
}else
{
NectarSource[i].trail++;
}
}
}
voidCalculateProbabilities()//計算輪盤賭的選擇概率
{
inti;
doublemaxfit;
maxfit=NectarSource[0].fitness;
for(i=1;i<FoodNumber;i++)
{
if(NectarSource[i].fitness>maxfit)
maxfit=NectarSource[i].fitness;
}
for(i=0;i<FoodNumber;i++)
{
NectarSource[i].rfitness=(0.9*(NectarSource[i].fitness/maxfit))+0.1;
}
}
voidsendOnlookerBees()//采蜜蜂與觀察蜂交流信息,觀察蜂更改信息
{
inti,j,t,k;
doubleR_choosed;//被選中的概率
intparam2change;//需要被改變的維數
doubleRij;//[-1,1]之間的隨機數
i=0;
t=0;
while(t<FoodNumber)
{
R_choosed=random(0,1);
if(R_choosed<NectarSource[i].rfitness)//根據被選擇的概率選擇
{
t++;
param2change=(int)random(0,D);
/******選取不等於i的k********/
while(1)
{
k=(int)random(0,FoodNumber);
if(k!=i)
{
break;
}
}
for(j=0;j<D;j++)
{
OnLooker[i].code[j]=NectarSource[i].code[j];
}
/****更新******/
Rij=random(-1,1);
OnLooker[i].code[param2change]=NectarSource[i].code[param2change]+Rij*(NectarSource[i].code[param2change]-NectarSource[k].code[param2change]);
/*******判斷是否越界*******/
if(OnLooker[i].code[param2change]<lb)
{
OnLooker[i].code[param2change]=lb;
}
if(OnLooker[i].code[param2change]>ub)
{
OnLooker[i].code[param2change]=ub;
}
OnLooker[i].trueFit=calculationTruefit(OnLooker[i]);
OnLooker[i].fitness=calculationFitness(OnLooker[i].trueFit);
/****貪婪選擇策略******/
if(OnLooker[i].trueFit<NectarSource[i].trueFit)
{
for(j=0;j<D;j++)
{
NectarSource[i].code[j]=OnLooker[i].code[j];
}
NectarSource[i].trail=0;
NectarSource[i].trueFit=OnLooker[i].trueFit;
NectarSource[i].fitness=OnLooker[i].fitness;
}else
{
NectarSource[i].trail++;
}
}
i++;
if(i==FoodNumber)
{
i=0;
}
}
}
Ⅸ 人工蜂群演算法的matlab的編程詳細代碼,最好有基於人工蜂群演算法的人工神經網路的編程代碼
蟻群演算法(ant colony optimization, ACO),又稱螞蟻演算法,是一種用來在圖中尋找優化路徑的機率型演算法。它由Marco Dorigo於1992年在他的博士論文中提出,其靈感來源於螞蟻在尋找食物過程中發現路徑的行為。蟻群演算法是一種模擬進化演算法,初步的研究表明該演算法具有許多優良的性質。針對PID控制器參數優化設計問題,將蟻群演算法設計的結果與遺傳演算法設計的結果進行了比較,數值模擬結果表明,蟻群演算法具有一種新的模擬進化優化方法的有效性和應用價值。
參考下蟻群訓練BP網路的代碼。
Ⅹ 優化演算法筆記(七)差分進化演算法
(以下描述,均不是學術用語,僅供大家快樂的閱讀)
差分進化演算法(Differential Evolution Algorithm,DE)是一種基於群體的進化演算法,它模擬了群體中的個體的合作與競爭的過程。演算法原理簡單,控制參數少,只有交叉概率和縮放比例因子,魯棒性強,易於實現。
差分進化演算法中,每一個個體的基因表示待求問題的一個候選解。每次迭代將先進行變異操作,選擇一個或多個個體的基因作為基,然後選擇不同的個體的差分來構成差分基因,最後將作為基的基因與差分基因相加來得出新的個體。交叉操作將新的個體將於父代的對應個體交叉,然後進行選擇操作,比較交叉後的個體與父代的對應個體,選擇較優的個體保留至下一代。在迭代完成之後將選擇種群中最優個體的基因作為解。
差分進化演算法可以算是我所使用過的優化演算法中大魔王級別的演算法,雖然它每個方面都沒有強到離譜,但是綜合起來的效果好於大多數演算法。它就像一個每個科目都能考到90分(百分制)的學生,雖然沒門課都不是最優秀的,但是論綜合,論總分,它有極大的概率是第一名。
在我研究優化演算法的小路上,我的目標就是找到一個能打敗大魔王或是能在大多數方面壓制魔王的演算法。
這次的主角就選魔王軍吧(或者蟻王軍,為了與蟻群演算法區別還是叫魔王軍吧),個體則稱之為魔王兵。
魔王兵的能力取決於它們的基因,它們可以根據環境或者需要改變自己的基因使得自己更加強大,更方便的處理問題,問題的維度與基因維度相同。
表示第i個魔王兵在進化了第t次後的基因,該個體有D位基因。
與遺傳演算法同為進化演算法的差分進化演算法,它們的操作(運算元)也都非常相似的,都是交叉,變異和選擇,流程也幾乎一樣(遺傳演算法先交叉後變異,差分進化演算法先變異後交叉)。
說到差分進化演算法中的變異,我就想到一句論語 「三人行,必有我師焉。擇其善者而從之,其不善者而改之。」 ,其實這句論語已經向我們說明了差分進化演算法的整個流程:
「三人行,必有我師焉」——變異,交叉。
「擇其善者而從之,其不善者而改之」——選擇。
差分進化演算法中,當一個魔王兵變異時,它會先找來3個小夥伴,當然是隨機找來3個小夥伴,避免同化。在一個小夥伴的基因上加上另外兩個小夥伴基因之差作為自己的目標基因。其變異公式如下:
表示第i個魔王兵找到了編號為r1、r2和r3的三個魔王兵,當然了i、r1、r2、r3為互不相同的整數,F為縮放比例因子,通常 ,一般取F=0.5。 為第i個魔王兵交叉後的目標基因圖紙,不過這是個半成品,再經過交叉後,目標基因圖紙才算完成。
其實現在我們已經有了5個基因圖紙了 ,接下來將進行交叉操作。由於變異操作,差分進化演算法的種群中個體數至少為4,即魔王軍中至少有4個小兵。
交叉操作中,魔王兵i會將目標基因圖紙 進行加工得到 ,加工過程如下:
其中 。 為交叉概率,其值越大,發生交叉的概率越大,一般取 。 為{1,2,…,D}中的隨機整數,其作用是保證交叉操作中至少有一維基因來自變異操作產生的基因,不能讓交叉操作的努力白費。
從公式上可以看出交叉操作實際上是從變異操作得出的基因圖紙上選擇至少一位基因來替換自己的等位基因,得到最終的基因圖紙。
選擇操作相對簡單,魔王兵i拿到了最終的基因圖紙 ,大喊一聲,進化吧,魔王兵i的基因改變了。它拿出了能力測量器fitness function,如果發現自己變強了,那麼就將基因 保留到下一代,否則它選擇放棄進化,讓自己還原成 。
實驗又來啦,還是那個實驗 ,簡單、易算、好畫圖。
實驗1 :參數如下
圖中可以看出在第20代時,群體已經非常集中了,在來看看最終得出的結果。
這結果真是好到令人發指,惡魔在心中低語「把其他的優化演算法都丟掉吧」。不過別往心裡去,任何演算法都有優缺點,天下沒有免費的午餐,要想獲得某種能力必須付出至少相應的代價。
實驗2:
將交叉率CR設為0,即每次交叉只選擇保留一位變異基因。
看看了看圖,感覺跟實驗1中相比沒有什麼變化,那我們再來看看結果。
結果總體來說比實驗1好了一個數量級。為什麼呢?個人感覺應該是每次只改變一位基因的局部搜索能力比改變多位基因更強。下面我們將交叉率CR設為1來看看是否是這樣。
實驗3:
將交叉率CR設為1,即每次交叉只選擇保留一位原有基因。
實驗3的圖與實驗1和實驗2相比好像也沒什麼差別,只是收斂速度好像快了那麼一點點。再來看看結果。
發現結果比實驗2的結果還要好?那說明了實驗2我得出的結論是可能是錯誤的,交叉率在該問題上對差分進化演算法的影響不大,它們結果的差異可能只是運氣的差異,畢竟是概率演算法。
實驗4:
將變異放縮因子設為0,即變異只與一個個體有關。
收斂速度依然很快,不過怎麼感覺結果不對,而且個體收斂的路徑好像遺傳演算法,當F=0,時,差分進化演算法退化為了沒有變異、選擇操作的遺傳演算法,結果一定不會太好。
果然如此。下面我們再看看F=2時的實驗。
實驗5:
將變異放縮因子設為2。
實驗5的圖可以明顯看出,群體的收斂速度要慢了許多,到第50代時,種群還未完全收斂於一點,那麼在50代時其結果也不會很好,畢竟演算法還未收斂就停止進化了。
結果不算很好但也算相對穩定。
通過上面5個實驗,我們大致了解了差分進化演算法的兩個參數的作用。
交叉率CR,影響基因取自變異基因的比例,由於至少要保留一位自己的基因和變異的基因導致CR在該問題上對演算法性能的影響不大(這個問題比較簡單,維度較低,影響不大)。
變異放縮因子F,影響群體的收斂速度,F越大收斂速度越慢,F絕對值越小收斂速度越快,當F=0是群體之間只會交換基因,不會變異基因。
差分進化演算法大魔王已經如此強大了,那麼還有什麼可以改進的呢?當然有下面一一道來。
方案1 .將3人行修改為5人行,以及推廣到2n+1人行。
實驗6:
將3人行修改為5人行,變異公式如下:
五人行的實驗圖看起來好像與之前並沒有太大的變化,我們再來看看結果。
結果沒有明顯提升,反而感覺比之前的結果差了。反思一下五人行的優缺點,優點,取值范圍更大,缺點,情況太多,減慢搜索速度。
可以看出演算法的收斂速度比之前的變慢了一點,再看看結果。
比之前差。
差分進化演算法的學習在此也告一段落。差分進化演算法很強大,也很簡單、簡潔,演算法的描述都充滿了美感,不愧是大魔王。不過這里並不是結束,這只是個開始,終將找到打敗大魔王的方法,讓新的魔王誕生。
由於差分進化演算法足夠強,而文中實驗的問題較為簡單導致演算法的改進甚至越改越差(其實我也不知道改的如何,需要大量實驗驗證)。在遙遠的將來,也會有更加復雜的問題來檢驗魔王的能力,總之,後會無期。
以下指標純屬個人yy,僅供參考
目錄
上一篇 優化演算法筆記(六)遺傳演算法
下一篇 優化演算法筆記(八)人工蜂群演算法
優化演算法matlab實現(七)差分進化演算法matlab實現