 function [BEST1, BESTVAL] = African_Vultures_Optimization1(fx,Lower,Upper,Maxiter,p1,p2,p3,alpha,beta,gammma)
## N number of independent variables
## Lower: Lower limits (xmin) of independent variables
## Upper: Upper limits (xmax) of independent variables
## Maxiter: Maximum number of iterations
## p1,p2,p3 Constant algorithm parameters 
## alpha,beta,gamma Constant algorithm parameters 

 N=length(Lower);
fobj = fx;
D=length(Lower);
X=zeros(N,D);
fitness=zeros(1,N);
XCUR=zeros(N,D);
BEST1=zeros(1,D);
BEST2=zeros(1,D);
RAND_VUL=zeros(1,D);
 
A=zeros(1,D);
B=zeros(1,D);
s1=zeros(1,D);
s2=zeros(1,D);
lvy=zeros(1,D);

 
prob=[alpha,beta];


%% Population initialization
for i=1:N
  for j=1:D
    X(i,j)=Lower(j)+(Upper(j)-Lower(j))*rand;
  endfor
endfor
 


iter=1;

while(iter <= Maxiter)

       X = sortX (X,fobj,N,D);
       BEST1=X(1,1:D);
       BEST2=X(2,1:D);
       a=(-2+4*rand) * ((sin( (pi/2)*(iter/Maxiter))^gammma)+cos(pi/2 *(iter/Maxiter))-1.0);
       P1=(2*rand+1)*(1-(iter/Maxiter))+a;
           for i=1:N
                XCUR=X(i,:);
                F=P1*(-1+rand*2);
                indexx=find(prob);
                
                if (indexx==0)
                    RAND_VUL=BEST1;
                endif
                
                if (indexx==1)
                   RAND_VUL=BEST2;       
                endif
            
                if (abs(F)>=1)
                    if(rand<p1)
                       XCUR=RAND_VUL-(abs((2*rand).*RAND_VUL-XCUR)).*F;
                    else
                       XCUR=RAND_VUL-(F)+rand.*((Upper-Lower).*rand+Lower);
                    endif
          
                elseif (abs(F)<1)
               
                    if (abs(F)<0.5)
                       if(rand<p2)
                          A=BEST1- ((BEST1.*XCUR)./(BEST1-XCUR.*XCUR)).*F;
                          B=BEST2- ((BEST2.*XCUR)./(BEST2-XCUR.*XCUR)).*F;
                          XCUR=(A+B)./2;
                       else
                          lvy=Levy(D);
                          XCUR=RAND_VUL-abs(RAND_VUL-XCUR).*F.*lvy;
                       endif
                    endif
                    if (abs(F)>=0.5)
                       if(rand<p3)
                           XCUR=(abs((2.*rand).*RAND_VUL-XCUR)).*(F+rand)-(RAND_VUL-XCUR);
                       else
                           s1=RAND_VUL.* (rand.*XCUR./(2*pi)).*cos(XCUR);
                           s2=RAND_VUL.* (rand.*XCUR./(2*pi)).*sin(XCUR);
                           XCUR=RAND_VUL-(s1+s2);
                       endif
                    endif 
                endif
                X(i,:)=XCUR;
           endfor
        
       
         
         X=boundary(X,Lower,Upper,N,D);
         
         BESTVAL=fobj(BEST1);
         iter=iter+1;
endwhile         
         
 
 
endfunction
