1 简介
针对花授粉算法存在的收敛速度慢,易陷入局部最优及收敛精度低等缺点,提出了基于三重动态调整的改进花授粉算法.采用动态转换概率切换算法的搜索模式,在全局搜索更新机制中引入新型动态因子,并在局部开发更新机制中引入正余弦步长因子.通过对7个测试函数的仿真实验结果和与FPA,CS,ASCSA等算法相比,表明改进的花授粉算法具有更强的全局搜索能力和跳出局部最优能力.
2 部分代码
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%Flower Pollination Algorithm for Multimodal Optimization (MFPA)
%%This is the line to execute the code:
%%[mem,bestSol,bestFit,optima,FunctionCalls]=FPA([50 0.25 500 2]);
%FitFunc implements the function to be optimized
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [mem,bestSol,bestFit,optima,FunctionCalls]=FPA(para)
% Default parameters
if nargin<1,
para=[50 0.25 500];
end
n=para(1); % Population size
p=para(2); % Probabibility switch
N_iter=para (3); % Number of iterations
phase = 1; %First state
phaseIte= [0.5,0.9,1.01]; %State vector
%Deb Function
d = 1;
Lb = 0;
Ub = 1;
optima = [.1;.3;.5;.7;.9];
% Initialize the population
for i=1:n,
Sol(i,:)=Lb+(Ub-Lb).*rand(1,d);
Fitness(i)=fitFunc(Sol(i,:)); %%Evaluate fitness function
end
% Initialice the memory
[mem,bestSol,bestFit,worstF] = memUpdate(Sol,Fitness, [], zeros(1,d), 100000000, 0, phase,d,Ub,Lb);
S = Sol;
FunctionCalls = 0;
% Main Loop
for ite = 1 : N_iter,
%For each pollen gamete, modify each position acoording
%to local or global pollination
for i = 1 : n,
% Switch probability
if rand>p,
L=Levy(d);
dS=L.*(Sol(i,:)-bestSol);
S(i,:)=Sol(i,:)+dS;
S(i,:)=simplebounds(S(i,:),Lb,Ub);
else
epsilon=rand;
% Find random flowers in the neighbourhood
JK=randperm(n);
% 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
Fitness(i)=fitFunc(S(i,:));
end
%Update the memory
[mem,bestSol,bestFit,worstF] = memUpdate(S,Fitness,mem,bestSol,bestFit,worstF,phase,d,Ub,Lb);
Sol = get_best_nest(S, mem, p);
FunctionCalls = FunctionCalls + n;
if ite/N_iter > phaseIte(phase)
%Next evolutionary process stage
phase = phase + 1;
[m,~]=size(mem);
%Depurate the memory for each stage
mem = cleanMemory(mem);
FunctionCalls = FunctionCalls + m;
end
end
%Plot the solutions (mem) founded by the multimodal framework
x = 0:.01:1;
y = ((sin(5.*pi.*x)).^ 6);
plot(x,y)
hold on
plot(mem(:,1),-mem(:,2),'r*');
3 仿真结果
4 参考文献
[1]洪露, 贺兴时, 杨新社. 基于三重动态调整的花授粉算法[J]. 西安工程大学学报, 2021, 35(2):7.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。完整代码获取关注微信公众号天天matlab