function [BEST, FuncBEST] = Butterfly_Optimization_Algorithm (Func_name,N,Lower,Upper,Maxiter)

fobj = TestFunctions (Func_name); 
D=length(Lower);
fitness=zeros(1,N);
BEST=zeros(1,D);
X=zeros(N,D);
XNEW=zeros(N,D);

p=0.8;
power_exp=0.01;
sensory_modality=0.01;

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

[minval,mindex]=min(fitness);
BEST=X(mindex,:);
XNEW=X;

iter=1;

  while(iter <= Maxiter)
      
       for i=1:N
         
          FNEW=fobj(XNEW(i,:));
          FP=sensory_modality*(FNEW^power_exp);
          
          if (rand > 0.8)
               XNEW(i,:)=X(i,:)+(rand.*rand.*BEST - X(i,:)).*FP;
          else
               epsi=rand;
               randind=randperm(N);
               XNEW(i,:)= X(i,:)+(epsi.*epsi.*X(randind(1),:)- X(randind(2),:))*FP;
          end
          
          for j=1:D
              if ((Lower(j)>XNEW(i,j))|| (Upper(j)<XNEW(i,j)))
                  XNEW(i,j)=Lower(j)+(Upper(j)-Lower(j))*rand;
              end
          end
          
          FNEW=fobj(XNEW(i,:));
         
          if (FNEW <= fitness(i))
              X(i,:)=XNEW(i,:);
              fitness(i)=FNEW;
          end
      
          if ( FNEW <= minval )
              BEST=XNEW(i,:);
              minval=FNEW;
          end
       end
          sensory_modality = sensory_modality + (0.025 / (sensory_modality * iter)); 
          FuncBEST=fobj(BEST);
       iter = iter +1 ;   
    
  end
    
  

endfunction
