一、哈里斯鹰算法简介
HHO算法用数学公式来模拟现实中哈里斯鹰在不同机制下捕捉猎物的策略.在HHO中,哈里斯鹰是候选解,猎物随迭代逼近最优解.HHO算法包括两个阶段:全局探索阶段、局部开采阶段。 1 全局探索阶段 在这一阶段中,哈里斯鹰处于等待状态,仔细检查和监控搜索空间[lb,ub]以发现猎物.它根据两种策略在随机的地方寻找猎物,迭代时以概率q进行位置更新,数学表达式为: 式中,Xt+1和Xt分别为哈里斯鹰第t+1次和第t次迭代时的位置,Xrabbit, t表示猎物第t次迭代时的位置,q和r1,r2,r3,r4是区间(0,1)内的随机数字,lb是搜索空间的下界,ub是搜索空间的上界,Xrand, t表示第t次迭代时哈里斯鹰的随机位置,Xm,t表示第t次迭代时哈里斯鹰的平均位置,公式如下: 2 过渡阶段 任何群智能算法的精确运行,需要保持探索和开采之间适当的平衡.HHO通过猎物的能量方程实现从探索到开采的过渡,其模型如下: 式中,E表示猎物逃跑的能量,E0是猎物能量的初始状态,公式为E0=2*rand-1,rand是(0,1)之间的随机数字,T为最大迭代次数,t为当前迭代次数.当|E|≥1时,哈里斯鹰算法将执行全局探索;否则,HHO算法进入局部开采.
3 局部开采阶段
在这一阶段,哈里斯鹰根据前一阶段的检测执行突袭攻击预期猎物,而猎物试图逃离危险.根据猎物的逃跑行为和哈里斯鹰的追逐策略,HHO算法提出了四种可能的策略来模拟攻击行为.用λ表示猎物成功逃脱的概率,当λ<0.5时,猎物逃脱成功;当λ≥0.5时,猎物逃脱失败.用参数E模拟哈里斯鹰软或硬的围攻策略.当|E|≥0.5时,执行软围攻;否则,执行硬围攻. Case1:软围攻.当|E|≥0.5,λ≥0.5时,猎物有足够的能量且以跳跃的方式逃脱围捕,而哈里斯鹰会逐渐消耗猎物的能量,然后选择最佳的位置突袭俯冲逮捕猎物.更新位置的方程如下: 式中,Xt是迭代时猎物与哈里斯鹰的位置之差,J=2(1-r5)表示猎物逃跑过程中的随机跳跃,r5是介于0到1之间的随机数字.
Case2:硬围攻.当|E|<0.5,λ≥0.5时,猎物筋疲力尽,哈里斯鹰选择迅速突袭.位置更新如下: Case3:累速俯冲式软围攻.当|E|≥0.5,λ<0.5时,猎物有足够的能量E逃跑,哈里斯鹰在突袭之前会建立一个软围攻.为了模拟猎物的逃跑模式和跳跃动作,将levy函数LF集成在HHO算法中.更新位置的策略为: 式中,D为问题维度,S为D维随机行向量.
Case4:累速俯冲式硬围攻.当|E|<0.5,λ<0.5时,猎物能量E低,哈里斯鹰在突袭前构建硬围攻捕捉猎物,位置更新如下: HHO算法用猎物能量E和因子λ调节哈里斯鹰和猎物(兔子)之间的四种围捕机制,来实现优化求解问题。
二、部分源代码
clear all %#ok<CLALL>
close all
clc
N=30; % Number of search agents
Function_name='F1'; % Name of the test function
T=500; % Maximum number of iterations
% Load details of the selected benchmark function
[lb,ub,dim,fobj]=Get_Functions_details(Function_name);
[Rabbit_Energy,Rabbit_Location,CNVG]=HHO(N,T,lb,ub,dim,fobj);
%Draw objective space
figure,
hold on
semilogy(CNVG,'Color','b','LineWidth',4);
title('Convergence curve')
xlabel('Iteration');
ylabel('Best fitness obtained so far');
axis tight
grid off
box on
legend('HHO')
display(['The best location of HHO is: ', num2str(Rabbit_Location)]);
display(['The best fitness of HHO is: ', num2str(Rabbit_Energy)]);
function [Rabbit_Energy,Rabbit_Location,CNVG]=HHO(N,T,lb,ub,dim,fobj)
disp('HHO is now tackling your problem')
tic
% initialize the location and Energy of the rabbit
Rabbit_Location=zeros(1,dim);
Rabbit_Energy=inf;
%Initialize the locations of Harris' hawks
X=initialization(N,dim,ub,lb);
CNVG=zeros(1,T);
t=0; % Loop counter
while t<T
for i=1:size(X,1)
% Check boundries
FU=X(i,:)>ub;FL=X(i,:)<lb;X(i,:)=(X(i,:).*(~(FU+FL)))+ub.*FU+lb.*FL;
% fitness of locations
fitness=fobj(X(i,:));
% Update the location of Rabbit
if fitness<Rabbit_Energy
Rabbit_Energy=fitness;
Rabbit_Location=X(i,:);
end
end
E1=2*(1-(t/T)); % factor to show the decreaing energy of rabbit
% Update the location of Harris' hawks
for i=1:size(X,1)
E0=2*rand()-1; %-1<E0<1
Escaping_Energy=E1*(E0); % escaping energy of rabbit
if abs(Escaping_Energy)>=1
%% Exploration:
% Harris' hawks perch randomly based on 2 strategy:
q=rand();
rand_Hawk_index = floor(N*rand()+1);
X_rand = X(rand_Hawk_index, :);
if q<0.5
% perch based on other family members
X(i,:)=X_rand-rand()*abs(X_rand-2*rand()*X(i,:));
elseif q>=0.5
% perch on a random tall tree (random site inside group's home range)
X(i,:)=(Rabbit_Location(1,:)-mean(X))-rand()*((ub-lb)*rand+lb);
end
elseif abs(Escaping_Energy)<1
%% Exploitation:
% Attacking the rabbit using 4 strategies regarding the behavior of the rabbit
%% phase 1: surprise pounce (seven kills)
% surprise pounce (seven kills): multiple, short rapid dives by different hawks
r=rand(); % probablity of each event
if r>=0.5 && abs(Escaping_Energy)<0.5 % Hard besiege
X(i,:)=(Rabbit_Location)-Escaping_Energy*abs(Rabbit_Location-X(i,:));
end
if r>=0.5 && abs(Escaping_Energy)>=0.5 % Soft besiege
Jump_strength=2*(1-rand()); % random jump strength of the rabbit
X(i,:)=(Rabbit_Location-X(i,:))-Escaping_Energy*abs(Jump_strength*Rabbit_Location-X(i,:));
end
%% phase 2: performing team rapid dives (leapfrog movements)
if r<0.5 && abs(Escaping_Energy)>=0.5, % Soft besiege % rabbit try to escape by many zigzag deceptive motions
Jump_strength=2*(1-rand());
X1=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-X(i,:));
if fobj(X1)<fobj(X(i,:)) % improved move?
X(i,:)=X1;
else % hawks perform levy-based short rapid dives around the rabbit
X2=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-X(i,:))+rand(1,dim).*Levy(dim);
if (fobj(X2)<fobj(X(i,:))), % improved move?
X(i,:)=X2;
end
end
end
if r<0.5 && abs(Escaping_Energy)<0.5, % Hard besiege % rabbit try to escape by many zigzag deceptive motions
% hawks try to decrease their average location with the rabbit
Jump_strength=2*(1-rand());
X1=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-mean(X));
if fobj(X1)<fobj(X(i,:)) % improved move?
X(i,:)=X1;
else % Perform levy-based short rapid dives around the rabbit
X2=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-mean(X))+rand(1,dim).*Levy(dim);
if (fobj(X2)<fobj(X(i,:))), % improved move?
X(i,:)=X2;
end
end
end
%%
end
end
t=t+1;
CNVG(t)=Rabbit_Energy;
% Print the progress every 100 iterations
% if mod(t,100)==0
% display(['At iteration ', num2str(t), ' the best fitness is ', num2str(Rabbit_Energy)]);
% end
end
toc
end
三、运行结果
四、matlab版本及参考文献
1 matlab版本 2014a
2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016. [2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
今天的文章【优化算法】哈里斯鹰算法(HHO)【含Matlab源码 1309期】分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/17797.html