function [Rabbit_Energy,Rabbit_Location,CNVG]=HHO(N,T,lb,ub,dim,fobj)
% disp('HHO is now tackling your problem')
% 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,:));
FU=X1>ub;FL=X1<lb;X1=(X1.*(~(FU+FL)))+ub.*FU+lb.*FL;
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);
FU=X2>ub;FL=X2<lb;X2=(X2.*(~(FU+FL)))+ub.*FU+lb.*FL;
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));
FU=X1>ub;FL=X1<lb;X1=(X1.*(~(FU+FL)))+ub.*FU+lb.*FL;
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);
FU=X2>ub;FL=X2<lb;X2=(X2.*(~(FU+FL)))+ub.*FU+lb.*FL;
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
end
% ___________________________________
function o=Levy(d)
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,d)*sigma;v=randn(1,d);step=u./abs(v).^(1/beta);
o=step;
end
神经网络机器学习智能算法画图绘图
- 粉丝: 2824
- 资源: 660
最新资源
- DIN 17178-1986 特殊要求细晶粒结构钢焊接.pdf
- DIN 17174-1985 低温用焊接钢管.pdf
- DIN 17178-1986 中文版 特殊要求细晶粒结构钢焊接圆形钢管 交货技术条件.pdf
- DIN 32676-2001 饮食业、化工业和医药业用配件.不锈钢管夹具接头.焊接式(德文原版).pdf
- DIN 28181-1985 管束式热交换器的焊接钢管.尺寸.尺寸偏差和材料.pdf
- DIN 86037-1-1995 铜镍合金管道的活套法兰和焊接凸肩.第1部分组装.pdf
- DIN 86037-2-1995 铜镍合金管道的活套法兰和焊接凸肩.第2部分焊接凸肩.pdf
- DIN 46234-1980 非焊接接线端.铜导线用无绝缘套管环形连接.pdf
- DIN 86037-3-1995 铜镍合金管道的活套法兰和焊接凸肩.第3部分活套法兰.pdf
- DIN 86088-1996 铜镍合金制管道焊接异型件.三通.pdf
- DIN EN 499-1995 焊料.非合金钢和细粒钢的手动金属电弧焊接用涂剂焊条.分类.pdf
- DIN 86057-1976 管闷头连接件用法兰(套环)的焊接.pdf
- DIN EN 1011-1-2002 中文版 焊接.焊接金属材料的建议.第1部分电弧焊接通则.pdf
- DIN EN 1043-1-1996 金属材料焊接的破坏试验 硬度测试 第1部分:电弧焊接连接件的硬度试验.pdf
- DIN EN 1435-2002 焊缝的无损检验.焊接接头的X光照相检验.pdf
- DIN EN 1708-1-1999 中文版 焊接—钢焊接接头的基本细节 第1部分:承压构件.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈