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

fobj = TestFunctions (Func_name); 
D=length(Lower);
fitness=zeros(1,N);
BEST=zeros(1,D);
PD=zeros(1,D);
Positions=zeros(N,D);
Positionsnew=zeros(N,D);
Pos=zeros(N,D);
Score=1e+200;
xmin=1.0;
xmax=4.0;

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

for i=1:N
   if (fitness(i)<Score)
     Score=fitness(i);
     BEST=Positions(i,:);
   end
end

Positions = boundary (Positions, Lower,Upper,N,D);    

iter=1;

while(iter <= Maxiter)

    for i=1:N
       for j=1:D
          if(rand<0.5)
              PD(j)=abs(BEST(j)-rand*Positions(i,j));
              Pos(i,j)=BEST(j)+((rand+rand)-(2*rand))/round(xmin+rand*(xmax-xmin))*PD(j);
          else
              PD(j)=abs(BEST(j)-rand*Positions(i,j));
              Pos(i,j)=BEST(j)-((rand+rand)-(2*rand))/round(xmin+rand*(xmax-xmin))*PD(j);
          end
       end
     
       for j=1:D
           Positionsnew(i,j)=(Pos(i,j)+Positions(i,j))/(2.0+rand);
       end    
    end
     
     Positionsnew = boundary (Positionsnew, Lower,Upper,N,D); 
     Positions=update (Positions,Positionsnew,fobj);
    
     for i=1:N
        fitness(i)=fobj(Positions(i,:));
        if (fitness(i)<Score)
            Score=fitness(i);
            BEST=Positions(i,:);
        end
     end
     FuncBEST=fobj(BEST);
    %Positionsnew = boundary (Positionsnew, Lower,Upper,N,D);  
    
   iter=iter+1;
end




endfunction
