导航:首页 > 源码编译 > 蜂群算法matlab程序

蜂群算法matlab程序

发布时间:2023-02-15 06:43:51

Ⅰ 人工蜂群算法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实现

    阅读全文

    与蜂群算法matlab程序相关的资料

    热点内容
    社交软件app该怎么聊 浏览:23
    pc的启动文件夹 浏览:671
    文件夹压缩过程中点击取消压缩 浏览:215
    顺丰app专享优惠券怎么用 浏览:667
    酷狗音乐分享文件夹 浏览:826
    服务器mgmt旁边的接口是什么 浏览:844
    单片机发光二极管原理图 浏览:50
    在北京当程序员6年 浏览:128
    编译器gcc如何用 浏览:412
    androidbringup 浏览:978
    算法设计与分析英文版 浏览:911
    java程序员加班吗 浏览:142
    编译检查的是什么错误 浏览:405
    加密兔f码生成器免费 浏览:292
    思科路由器命令明文加密 浏览:171
    方舟生存进化服务器如何改名字 浏览:892
    央行数字货币app怎么注册 浏览:431
    51单片机显示时间 浏览:770
    我的世界网易版怎么压缩地图 浏览:682
    qq小程序云服务器和 浏览:740