智能优化算法——哈里斯鹰算法（Matlab代码实现）

1 写在前面

2 哈里斯鹰优化数学模型

2.1 位置更新公式

2.2 猎物能量减少的线性递减公式

2.3 软包围

2.4 硬包围

2.5 采取渐进式快速俯冲的软包围策略

2.6 采取渐进式快速俯冲的硬包围策略

3 matlab代码实现

3.1 代码

3.2 结果

2 哈里斯鹰优化数学模型

2.2 猎物能量减少的线性递减公式

When the value of E0 decreases from 0 to -1, the rabbit is physically flagging, whilst when the value of E0 increases from 0 to 1, it means that the rabbit is strengthening. The dynamic escaping energy E has a decreasing trend during the iterations.

2.3 软包围

2.5 采取渐进式快速俯冲的软包围策略

LF(·)为莱维飞行的数学表达式,在已知群的维度D的基础上,更新策略可表达为:

3 matlab代码实现

3.1 代码

``````%%===欢迎关注公众号：电力系统与算法之美===
clear
close all
clc

SearchAgents_no = 30 ; %　种群规模
dim = 10 ; % 粒子维度
Max_iter = 1000 ; %　迭代次数
ub = 5 ;
lb = -5 ;
%% 初始化猎物位置和逃逸能量
Rabbit_Location=zeros(1,dim);
Rabbit_Energy=inf;

%% 初始化种群的位置
Positions= lb + rand(SearchAgents_no,dim).*(ub-lb) ;

Convergence_curve = zeros(Max_iter,1);

%% 开始循环
for t=1:Max_iter
for i=1:size(Positions,1)
FU=Positions(i,:)>ub;FL=Positions(i,:)<lb;Positions(i,:)=(Positions(i,:).*(~(FU+FL)))+ub.*FU+lb.*FL;
fitness=sum(Positions(i,:).^2);
if fitness<Rabbit_Energy
Rabbit_Energy=fitness;
Rabbit_Location=Positions(i,:);
end
end

E1=2*(1-(t/Max_iter));
%% 鹰群的个体位置位置更新
for i=1:size(Positions,1)
E0=2*rand()-1; %-1<E0<1
Escaping_Energy=E1*(E0);

if abs(Escaping_Energy)>=1
%%

q=rand();
rand_Hawk_index = floor(SearchAgents_no*rand()+1);
X_rand = Positions(rand_Hawk_index, :);
if q<0.5
%%
Positions(i,:)=X_rand-rand()*abs(X_rand-2*rand()*Positions(i,:));
elseif q>=0.5

Positions(i,:)=(Rabbit_Location(1,:)-mean(Positions))-rand()*((ub-lb)*rand+lb);
end

elseif abs(Escaping_Energy)<1
%%

%% phase 1

r=rand();

if r>=0.5 && abs(Escaping_Energy)<0.5
Positions(i,:)=(Rabbit_Location)-Escaping_Energy*abs(Rabbit_Location-Positions(i,:));
end

if r>=0.5 && abs(Escaping_Energy)>=0.5
Jump_strength=2*(1-rand());
Positions(i,:)=(Rabbit_Location-Positions(i,:))-Escaping_Energy*abs(Jump_strength*Rabbit_Location-Positions(i,:));
end

%% phase 2
if r<0.5 && abs(Escaping_Energy)>=0.5
Jump_strength=2*(1-rand());
X1=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-Positions(i,:));

if sum(X1.^2)<sum(Positions(i,:).^2)
Positions(i,:)=X1;
else
beta=1.5;
sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta);
u=randn(1,dim)*sigma;v=randn(1,dim);step=u./abs(v).^(1/beta);
o1=0.01*step;
X2=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-Positions(i,:))+rand(1,dim).*o1;
if (sum(X2.^2)<sum(Positions(i,:).^2))% improved move
Positions(i,:)=X2;
end
end
end

if r<0.5 && abs(Escaping_Energy)<0.5
Jump_strength=2*(1-rand());
X1=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-mean(Positions));

if sum(X1.^2)<sum(Positions(i,:).^2)
Positions(i,:)=X1;
else

beta=1.5;
sigma=(gamma(1+beta)*sin(pi*beta/2)/(gamma((1+beta)/2)*beta*2^((beta-1)/2)))^(1/beta);
u=randn(1,dim)*sigma;v=randn(1,dim);step=u./abs(v).^(1/beta);
o2=0.01*step;
X2=Rabbit_Location-Escaping_Energy*abs(Jump_strength*Rabbit_Location-mean(Positions))+rand(1,dim).*o2;
if (sum(X2.^2)<sum(Positions(i,:).^2))% improved move
Positions(i,:)=X2;
end
end
end
%%
end
end

Convergence_curve(t)=Rabbit_Energy;

if mod(t,50)==0
display(['At iteration ', num2str(t), ' the best fitness is ', num2str(Rabbit_Energy)]);
end
end
figure('unit','normalize','Position',[0.3,0.35,0.4,0.35],'color',[1 1 1],'toolbar','none')
subplot(1,2,1);
x = -5:0.1:5;y=x;
L=length(x);
f=zeros(L,L);
for i=1:L
for j=1:L
f(i,j) = x(i)^8+y(j)^8;
end
end
surfc(x,y,f,'LineStyle','none');
xlabel('x_1');
ylabel('x_2');
zlabel('F')
title('Objective space')

subplot(1,2,2);
semilogy(Convergence_curve,'Color','r','linewidth',1.5)
title('Convergence_curve')
xlabel('Iteration');
ylabel('Best score obtained so far');

axis tight
grid on
box on
legend('HHO')
display(['The best solution obtained by HHO is : ', num2str(Rabbit_Location)]);
display(['The best optimal value of the objective funciton found by HHO is : ', num2str(Rabbit_Energy)]);
``````

THE END

)">