function [fbst, xbst, performance] = hho( objective, d, lmt, n, T, S)
%Harris hawks optimization algorithm
% inputs:
% objective - function handle, the objective function
% d - scalar, dimension of the optimization problem
% lmt - d-by-2 matrix, lower and upper constraints of the decision varable
% n - scalar, swarm size
% T - scalar, maximum iteration
% S - scalar, times of independent runs
% data: 2021-05-09
% author: elkman, github.com/ElkmanY/
%% Levy flight
beta = 1.5;
sigma = ( gamma(1+beta)*sin(pi*beta/2)/gamma((1+beta)/2)*beta*2^((beta-1)/2) ).^(1/beta);
Levy = @(x) 0.01*normrnd(0,1,d,x)*sigma./abs(normrnd(0,1,d,x)).^(1/beta);
%% algorithm procedure
tic;
for s = 1:S
%% Initialization
X = lmt(:,1) + (lmt(:,2) - lmt(:,1)).*rand(d,n);
for t = 1:T
F = objective(X);
[f_rabbit(s,t), i_rabbit] = min(F);
x_rabbit(:,t,s) = X(:,i_rabbit);
xr = x_rabbit(:,t,s);
J = 2*(1-rand(d,1));
E0 = 2*rand(1,n)-1;
E(t,:) = 2*E0*(1-t/T);
absE = abs(E(t));
p1 = absE>=1; %eq(1)
r = rand(1,n);
p2 = (r>=0.5) & (absE>=0.5) & (absE<1); %eq(4)
p3 = (r>=0.5) & (absE<0.5); %eq(6)
p4 = (r<0.5) & (absE>=0.5) & (absE<1); %eq(10)
p5 = (r<0.5) & (absE<0.5); %eq(11)
%% update locations
rh = randi([1,n],1,n);
flag1 = rand(1,n)>=0.5;
Y = xr - E(t,:).*abs( J.*xr - X );
Z = Y + rand(d,n).*Levy(n);
flag2 = (objective(Y)<objective(Z)) & (objective(Y)<F);
flag3 = (objective(Y)>objective(Z)) & (objective(Z)<F);
flag4 = (~flag2) & (~flag3);
X_ = p1.*( (X(:,rh) - rand(1,n).*abs( X(:,rh) - 2*rand(1,n).*X )).*flag1 +...
((X(:,rh) - mean(X)) - rand(1,n).*( lmt(:,1) + (lmt(:,2) - lmt(:,1)).*rand(d,n) )).*(~flag1) )...
+ p2.*( xr - X - E(t,:).*abs( J.*xr - X ) )...
+ p3.*( xr - E(t,:).*abs( xr - X ) )...
+ p4.*( Y.*flag2 + Z.*flag3 + ( lmt(:,1) + (lmt(:,2) - lmt(:,1)).*rand(d,n) ).*flag4 )...
+ p5.*( Y.*flag2 + Z.*flag3 + ( lmt(:,1) + (lmt(:,2) - lmt(:,1)).*rand(d,n) ).*flag4 );
X_(:,i_rabbit) = xr;
X = X_;
end
end
%% Êä³ö-outputs
performance = [min(f_rabbit(:,T));mean(f_rabbit(:,T));std(f_rabbit(:,T))];
timecost = toc;
[fbst, ibst] = min(f_rabbit(:,T));
xbst = x_rabbit(:,T,ibst);
%% »æͼ-plot data
% Convergence Curve
figure('Name','Convergence Curve');
box on
semilogy(1:T,mean(f_rabbit,1),'b','LineWidth',1.5);
xlabel('Iteration','FontName','Aril');
ylabel('Fitness/Score','FontName','Aril');
title('Convergence Curve','FontName','Aril');
if d == 2
% Trajectory of Global Optimal
figure('Name','Trajectory of Global Optimal');
x1 = linspace(lmt(1,1),lmt(1,2));
x2 = linspace(lmt(2,1),lmt(2,2));
[X1,X2] = meshgrid(x1,x2);
V = reshape(objective([X1(:),X2(:)]'),[size(X1,1),size(X1,1)]);
contour(X1,X2,log10(V),100); % notice log10(V)
hold on
plot(x_rabbit(1,:,1),x_rabbit(2,:,1),'r-x','LineWidth',1);
hold off
xlabel('\it{x}_1','FontName','Time New Roman');
ylabel('\it{x}_2','FontName','Time New Roman');
title('Trajectory of Global Optimal','FontName','Aril');
end
end
基于哈里斯鹰HHO的优化算法matlab仿真.zip
版权申诉
33 浏览量
2022-11-01
22:19:27
上传
评论
收藏 706KB ZIP 举报
天天Matlab科研工作室
- 粉丝: 3w+
- 资源: 7258
最新资源
- 基于JavaScript讲解的数据结构和算法
- python计算机视觉python-computer-vision.rar
- VB+ACCESS计算机等级考试管理系统(源代码+系统+答辩PPT).zip
- python密码python-ciphers.rar
- 2c60fbb3dt9ad50ed8864298eea1484b.MP4
- 基于yolov8+dlib实现视觉识别的安全驾驶监测系统部署到jetson NX平台源码+模型.zip
- Qt框架+OpenCV+动态爱心+编程教学+520
- 基于opencv+yolov8实现目标追踪及驻留时长统计源码.zip
- 水稻病害基于Yolov8算法优化目标检测识别与AI辅助决策python源码+模型+使用说明.zip
- 海尔618算价表_七海5.20_16.00xlsx(1)(2).xlsx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈