function [XPREY,fopt] = Honey_Badger_Algorithm (Func_name,N,Lower,Upper,Maxiter)
fobj = TestFunctions (Func_name); 
D=length(Lower); 
beta=6;
C=2;
X=zeros(N,D);
XNEW=zeros(N,D);
XPREY=zeros(1,D);
I=zeros(1,N);
fitness=zeros(1,N);
dist=zeros(1,N);
S=zeros(1,N);

for i=1:N
  for j=1:D
    % Initialize the spatial positions of  N sized D dimensional whale population 
    X(i,j)=Lower(j)+(Upper(j)-Lower(j))*rand; 
  endfor
  % Calculating the fitness value of each whale individual in the population
  fitness(i)=fobj(X(i,:)); 
endfor
   
[fopt,mindex]=min(fitness);
XPREY=X(mindex,:);

iter=1;

   while (iter < Maxiter)
     alpha=C*exp(-iter/Maxiter);
     
     for i=1:N-1
       dist(i)=(norm((X(i,:)-XPREY+eps))).^2;
       S(i)=( norm((X(i,:)-X(i+1,:)+eps))).^2;
     endfor
     dist(N)=( norm((X(N,:)-XPREY+eps))).^2;
     S(N)=( norm((X(N,:)-X(1,:)+eps))).^2;
     
     for i=1:N
       I(i)=rand*S(i)/(4*pi*dist(i));
     end
     
     for i=1:N
         
         if rand<0.5
           F=1;
         else
           F=-1;
         end
         
         for j=1:D
           di=(XPREY(j)-X(i,j));
           if rand < 0.5
              XNEW(i,j)=XPREY(j)+F*beta*I(i)*XPREY(j) + F*rand*alpha*di*abs(cos(2*pi*rand)*(1-cos(2*pi*rand)));
           else
              XNEW(i,j)=XPREY(j)+F*rand*alpha*di;
           end
         end
     end

     XNEW = boundary (XNEW,Lower,Upper,N,D);     
     for i=1:N
        fitnessnew=fobj(XNEW(i,:));
        if fitnessnew < fitness(i)
            fitness(i)=fitnessnew;
            X(i,:)=XNEW(i,:);
        end
     end
  
     X = boundary (X,Lower,Upper,N,D);  
     [foptnew, mindex2]=min(fitness);
     
     if (foptnew < fopt)
         fopt = foptnew;
         XPREY=X(mindex2,:);
     end
     
     iter = iter + 1;
   end
endfunction
