0
点赞
收藏
分享

微信扫一扫

【优化算法】变异策略的改进型花朵授粉算法【含Matlab源码 480期】


一、获取代码方式

获取代码方式1:

完整代码已上传我的资源:​​【优化算法】变异策略的改进型花朵授粉算法【含Matlab源码 480期】​​

获取代码方式2:

通过订阅紫极神光博客​付费专栏​,凭支付凭证,​私信博主​,可获得此代码。

备注:

订阅紫极神光博客​付费专栏​,可免费获得​1​份代码(​有效期​为订阅日起,三天内有效);

二、花朵授粉算法简介

介绍了一种新的元启发式群智能算法——花朵授粉算法(flower pollinate algorithm,FPA)和一种新型的差分进化变异策略——定向变异(targeted mutation,TM)策略。针对FPA存在的收敛速度慢、寻优精度低、易陷入局部最优等问题,提出了一种基于变异策略的改进型花朵授粉算法——MFPA。该算法通过改进TM策略,并应用到FPA的局部搜索过程中,以增强算法的局部开发能力。

【优化算法】变异策略的改进型花朵授粉算法【含Matlab源码 480期】_matlab

【优化算法】变异策略的改进型花朵授粉算法【含Matlab源码 480期】_算法_02

【优化算法】变异策略的改进型花朵授粉算法【含Matlab源码 480期】_matlab_03

三、部分源代码

function [pdd,fmin ] =pso( c1,c2,Vmax,Vmin,popmax,popmin,sizepop,maxgen)
%UNTITLED2 此处显示有关此函数的摘要
% 此处显示详细说明
PLb=-5.12*ones(1,30);
PUb=5.12*ones(1,30);
pop=zeros(sizepop,30);
V=zeros(1,30);
fitnessP=zeros(1,sizepop);
for i=1:sizepop
pop(i,:)=PLb+(PUb-PLb)*rand;
V(i,:)=rands(1,30);
fitnessP(i)=Fun(pop(i,:));
end
[bestfitness bestindex]=min(fitnessP);
zbest=pop(bestindex,:); %全局最佳
gbest=pop; %个体最佳
fitnessgbest=fitnessP; %个体最佳适应度值
fitnesszbest=bestfitness; %全局最佳适应度值
% Ntime11=1 ;
% Ntime=Ntime11-1;
% maxgen=0;
% ptol=0.01;
% while(fitnesszbest>ptol),
for i11=1:maxgen

for j=1:sizepop

%速度更新
V(j,:) = V(j,:) + c1*rand*(gbest(j,:)-pop(j,:)) + c2*rand*(zbest-pop(j,:));
V(j,find(V(j,:)>Vmax))=Vmax;
V(j,find(V(j,:)<Vmin))=Vmin;

%种群更新
pop(j,:)=pop(j,:)+0.2*V(j,:);
pop(j,find(pop(j,:)>popmax))=popmax;
pop(j,find(pop(j,:)<popmin))=popmin;

%自适应变异
pos=unidrnd(30);
if rand>0.95
pop(j,pos)=5.12*rands(1,1);
end

%适应度值
% pop(j,:)=simpleboundsP(pop(j,:),PLb,PUb);
fitnessP(j)=Fun(pop(j,:));

end

for j=1:sizepop
%个体最优更新
if fitnessP(j) < fitnessgbest(j)
gbest(j,:) = pop(j,:);
fitnessgbest(j) = fitnessP(j);
end

%群体最优更新
if fitnessP(j) < fitnesszbest
zbest = pop(j,:);
fitnesszbest = fitnessP(j);
end
% Ntime11=Ntime11+1;




end
% maxgen=maxgen+1;
% if maxgen>10000,
% fitnesszbest=ptol-1;
% end
% if round(i11/30)==i11/30,
pdd(i11)=fitnesszbest;
% end

end
fmin =fitnesszbest;
end
% function sfP=simpleboundsP(sfP,PLb,PUb)
% % Apply the lower bound
% ns_tmpfP=sfP;
% IfP=ns_tmpfP<PLb;
% ns_tmpfP(IfP)=PLb(IfP);
%
% % Apply the upper bounds
% JfP=ns_tmpfP>PUb;
% ns_tmpfP(JfP)=PUb(JfP);
% % Update this new move
% sfP=ns_tmpfP;
% end
% ======================================================== %
% Files of the Matlab programs included in the book: %
% Xin-She Yang, Nature-Inspired Metaheuristic Algorithms, %
% Second Edition, Luniver Press, (2010). www.luniver.com %
% ======================================================== %

% -------------------------------------------------------- %
% Bat-inspired algorithm for continuous optimization (demo)%
% Programmed by Xin-She Yang @Cambridge University 2010 %
% -------------------------------------------------------- %
% Usage: bat_algorithm([20 0.25 0.5]); %

function [pblt,fminbl]=bat_algorithm(nb,A,r,BQmin,BQmax,db,NB)
% Display help
% help bat_algorithm.m

% Default parameters
% if nargin<1, para=[10 0.25 0.5]; end
% nb=para(1); % Population size, typically 10 to 25
% A=para(2); % Loudness (constant or decreasing)
% r=para(3); % Pulse rate (constant or decreasing)
% % This frequency range determines the scalings
% BQmin=0; % Frequency minimum
% BQmax=2; % Frequency maximum
% % Iteration parameters
% % Stop tolerance
% N_iter=0; % Total number of function evaluations
% Dimension of the search variables
% db=5;
% Initial arrays
BLb=-5.12*ones(1,db);
BUb=5.12*ones(1,db);
Q=zeros(nb,1); % Frequency
v=zeros(nb,db); % Velocities
Solb=zeros(nb,db);
Fitnessb=zeros(1,nb);
Sb=zeros(nb,db);
% Initialize the population/solutions
for i=1:nb,
Solb(i,:)=BLb+(BUb-BLb)*rand;
Fitnessb(i)=Fun(Solb(i,:));
end
% Find the current best
[fminb,Ib]=min(Fitnessb);
bestb=Solb(Ib,:);

% ====================================================== %
% Note: As this is a demo, here we did not implement the %
% reduction of loudness and increase of emission rates. %
% Interested readers can do some parametric studies %
% and also implementation various changes of A and r etc %
% ====================================================== %
% btol=0.01;
% NB=0;
% Start the iterations -- Bat Algorithm
% while(fminb>btol),
for tb =1: NB,
% Loop over all bats/solutions
for i=1:nb,
Q(i)=BQmin+(BQmin-BQmax)*rand;
v(i,:)=v(i,:)+(Solb(i,:)-bestb)*Q(i);
Sb(i,:)=Solb(i,:)+v(i,:);
% Pulse rate
if rand>r
Sb(i,:)=bestb+0.01*randn(1,db);
end

% Evaluate new solutions
Sb(i,:)=BsimpleboundsP(Sb(i,:),BLb,BUb);
Fnewb=Fun(Sb(i,:));
% If the solution improves or not too loudness
if (Fnewb<=Fitnessb(i)) & (rand<A) ,
Solb(i,:)=Sb(i,:);
Fitnessb(i)=Fnewb;
end

% Update the current best
if Fnewb<=fminb,
bestb=Sb(i,:);
fminb=Fnewb;
end
end
function [aa,fminf,Ntime ] = fpa(n,p,N_iter,d )
%UNTITLED3 此处显示有关此函数的摘要
% 此处显示详细说明
Lb=-600*ones(1,d);
Ub=600*ones(1,d);
Sol=zeros(n,d);
Fitness=zeros(1,n);
for i=1:n,
Sol(i,:)=Lb+(Ub-Lb)*rand;
Fitness(i)=Fun(Sol(i,:));
end

% Find the current best
[fmin,I]=min(Fitness);
best=Sol(I,:);
S=Sol;
Ntime=1;
Ntime= Ntime-1;
for t=1:N_iter,
% Loop over all bats/solutions
for i=1:n,
% Pollens are carried by insects and thus can move in
% large scale, large distance.
% This L should replace by Levy flights
% Formula: x_i^{t+1}=x_i^t+ L (x_i^t-gbest)
if rand<p,
%% L=rand;
L=Levy(d);

dS=L.*(Sol(i,:)-best);
S(i,:)=Sol(i,:)+dS;

% Check if the simple limits/bounds are OK
S(i,:)=simplebounds(S(i,:),Lb,Ub);

% If not, then local pollenation of neighbor flowers
else
epsilon=rand;
% Find random flowers in the neighbourhood
JK=randperm(n);


% end
% As they are random, the first two entries also random
% If the flower are the same or similar species, then
% they can be pollenated, otherwise, no action.
% Formula: x_i^{t+1}+epsilon*(x_j^t-x_k^t)
%
S(i,:)=S(i,:)+epsilon*(Sol(JK(1))-Sol(JK(2)));
%
% Check if the simple limits/bounds are OK
S(i,:)=simplebounds(S(i,:),Lb,Ub);
end

四、运行结果

【优化算法】变异策略的改进型花朵授粉算法【含Matlab源码 480期】_算法_04

五、matlab版本及参考文献

1 matlab版本

2014a

2 参考文献

[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.

[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.



举报

相关推荐

0 条评论