function [Top_pred,Top_pred_fit] = Marine_Predators_Algorithm (Func_name,N,Lower,Upper,Maxiter)

fobj = TestFunctions (Func_name); 
D=length(Lower);
Top_pred=zeros(1,D);
Stepsize=zeros(N,D);
fitness=zeros(1,N);
Prey=zeros(N,D);
Prey2=zeros(N,D);
Prey3=zeros(N,D);
Prey_old=zeros(N,D);
fit_old=zeros(1,N);
FADs=0.2;
P=0.5;
Top_pred_fit=1E+200;

for i=1:N
  for j=1:D
    Prey(i,j)=Lower(j)+(Upper(j)-Lower(j))*rand;
  endfor
  fitness(i)=fobj(Prey(i,:));
endfor

  fit_old=fitness;
  Prey_old=Prey;

iter=0;

while(iter < Maxiter)
  
  Prey = boundary (Prey, Lower,Upper,N,D);
  for i=1:N
    fitness(i)=fobj(Prey(i,:));
    if(fitness(i)<Top_pred_fit)
       Top_pred_fit=fitness(i);
       Top_pred=Prey(i,:);
    end
  end
  
  for i=1:N
    if (fit_old(i)<fitness(i))
      fitness(i)=fit_old(i);
      Prey(i,:)=Prey_old(i,:);
    end
  end

  fit_old=fitness;
  Prey_old=Prey;
  
  Elite=repmat(Top_pred,N,1);
  CF=(1-(iter/Maxiter))^(2*iter/Maxiter);
  RB=randn(N,D);
  for i=1:N
    lvy(i,:)=0.05*Levy(D);
  end
  
  for i=1:N
    for j=1:D
        r=rand;
        if (iter<(Maxiter/3))
            Stepsize(i,j)=RB(i,j)*(Elite(i,j)-RB(i,j)*Prey(i,j));
            Prey(i,j)=Prey(i,j)+P*rand*Stepsize(i,j);
        elseif ((iter>=(Maxiter/3)) && (iter<(2*Maxiter/3)))
            if (i > N/2)
              Stepsize(i,j)=RB(i,j)*(RB(i,j)*Elite(i,j)-Prey(i,j));
              Prey(i,j)=Elite(i,j)+P*CF*Stepsize(i,j); 
            else
              Stepsize(i,j)=lvy(i,j)*(Elite(i,j)-lvy(i,j)*Prey(i,j));
              Prey(i,j)=Prey(i,j)+P*rand*Stepsize(i,j); 
            end
        else
            Stepsize(i,j)=lvy(i,j)*(lvy(i,j)*Elite(i,j)-Prey(i,j)); 
            Prey(i,j)=Elite(i,j)+P*CF*Stepsize(i,j);  
        end
    end
 end    

   Prey = boundary (Prey, Lower,Upper,N,D);
  for i=1:N
    fitness(i)=fobj(Prey(i,:));
    if(fitness(i)<Top_pred_fit)
       Top_pred_fit=fitness(i);
       Top_pred=Prey(i,:);
    end
  end
  
  if (iter==0)
    fit_old=fitness;    
    Prey_old=Prey;
  end
  
  for i=1:N
    if (fit_old(i)<fitness(i))
      fitness(i)=fit_old(i);
      Prey(i,:)=Prey_old(i,:);
    end
  end

  fit_old=fitness;
  Prey_old=Prey;
  
   
  
  U=zeros(N,D);
  if rand<FADs
      for i=1:N
        for j=1:D
            r3=rand;
          if r3<FADs
              U(i,j)=1.0;  
              Prey(i,j)=Prey(i,j)+CF*(Lower(j)+rand*(Upper(j)-Lower(j)))*U(i,j);
          end
        end
      end  
  else
      Prey2=Prey(randperm(N),:);
      Prey3=Prey(randperm(N),:);
      
      for i=1:N
        for j=1:D
          r2=rand;
          Stepsize(i,j)=(FADs*(1-r2)+r2)*(Prey2(i,j)-Prey3(i,j));
          Prey(i,j)= Prey(i,j)+Stepsize(i,j);
        end
      end
  end

  iter=iter+1;
end
     
endfunction
