function [BEST, fitnessBest] = Manta_Ray_Optimization_Algorithm (fobj,Lower,Upper,Maxiter)

D=length(Lower);
N=length(Lower);
 X=zeros(N,D);
XNEW=zeros(N,D);
fitness=zeros(1,N); 
fitnessnew=zeros(1,N);
BEST=zeros(1,D);
 

S=2;
fitnessBest=1e+200;


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

for i=1:N
   if (fitness(i)<fitnessBest)
       fitnessBest=fitness(i);
       BEST=X(i,:);
   end
end

iter=1;

while(iter <= Maxiter)
    
    if (rand<0.5)
       beta=2*exp(rand*((Maxiter-iter+1)/Maxiter))*(sin(2*pi*rand));
       if ((iter/Maxiter)>rand)
           XNEW(1,:)=BEST+rand(1,D).*(BEST-X(1,:))+beta*(BEST-X(1,:));
       else 
           RANDX=rand(1,D).*(Upper-Lower)+Lower;
           XNEW(1,:)=RANDX+rand(1,D).*(RANDX-X(1,:))+beta*(RANDX-X(1,:));
       end    
    else
       alpha=2*rand(1,D).*(-log(rand(1,D))).^0.5; 
       XNEW(1,:)=X(1,:)+rand(1,D).*(BEST-X(1,:))+alpha.*(BEST-X(1,:));
    end
    
    for i=2:N
        if (rand < 0.5)
           beta=2*exp(rand*((Maxiter-iter+1)/Maxiter))*(sin(2*pi*rand));  
              if ((iter/Maxiter)>rand)
                 XNEW(i,:)=BEST+rand(1,D).*(X(i-1,:)-X(i,:))+beta*(BEST-X(i,:));
              else
                 RANDX=rand(1,D).*(Upper-Lower)+Lower;
                 XNEW(i,:)=RANDX+rand(1,D).*(X(i-1,:)-X(i,:))+beta*(RANDX-X(i,:)); 
              end
        else     
            alpha=2*rand(1,D).*(-log(rand(1,D))).^0.5;           
            XNEW(i,:)=X(i,:)+rand(1,D).*(X(i-1,:)-X(i,:))+alpha.*(BEST-X(i,:));    
        end        
    end
    
    XNEW=boundary(XNEW, Lower,Upper,N,D); 
    
    for i=1:N
        fitnessnew(i)=fobj(XNEW(i,:));
        if (fitnessnew(i)<fitness(i))
            fitness(i)=fitnessnew(i);
            X(i,:)=XNEW(i,:);
        end             
    end

    for i=1:N
        XNEW(i,:)=X(i,:)+S.*(rand.*BEST-rand.*X(i,:));
    end
                 
        XNEW=boundary(XNEW, Lower,Upper,N,D); 
    
    for i=1:N
        fitnessnew(i)=fobj(XNEW(i,:));
        if (fitnessnew(i)<fitness(i))
            fitness(i)=fitnessnew(i);
            X(i,:)=XNEW(i,:);
        end             
    end
             
    for i=1:N
        if (fitness(i)<fitnessBest)
           fitnessBest=fitness(i);
           BEST=X(i,:);            
        end
    end   
    iter=iter+1;
end

   




endfunction
