A list,

Sparrow Search Algorithm (SSA) was proposed in 2020. SSA is mainly inspired by the foraging behavior and anti-predation behavior of sparrows. The algorithm is novel and has the advantages of strong searching ability and fast convergence.

1 Algorithm Principle

To establish the mathematical model of sparrow search algorithm, the main rules are as follows:

(1) Finders usually have high energy reserves and are responsible for searching for areas with rich food in the whole population, providing foraging areas and directions for all entrants. The level of energy reserve in model building depends on the Fitness Value of individual sparrows.

(2) Once the sparrow spots a predator, the individual starts to sing as an alarm signal. When the alarm value is greater than the safe value, the finder will take the participant to another safe area for foraging.

(3) The identity of discoverer and entrant changes dynamically. Each sparrow can be a finder if it can find a better food source, but the proportion of finder and entrant to the population remains the same. In other words, if one sparrow becomes the discoverer, another sparrow must become the participant.

(4) The lower the energy of the participants, the worse their foraging position in the whole population. Some hungry enrollees are more likely to fly elsewhere to feed for more energy.

(5) In the process of foraging, entrants can always search for the discoverer who provides the best food, and then obtain food from the best food or forage around the discoverer. At the same time, some participants may constantly monitor the discoverers and compete for food resources in order to increase their predation rate.

(6) When aware of the danger, sparrows at the edge of the population would quickly move to the safe area to get a better position, while sparrows in the middle of the population would move randomly to get close to other sparrows.

In the simulation experiment, we need to use virtual sparrows to search for food, and the population composed of N sparrows can be expressed as follows:







2 Algorithm Flow

Step1: initialize population, number of iterations, and ratio of predator to entrant.

Step2: calculate the fitness value and sort it.

Step3: Use Equation (3) to update the position of predator.

Step4: Use Formula (4) to update the position of the subscriber.

Step5: Use Formula (5) to update the position of watchman.

Step6: calculate fitness value and update sparrow position.

Step7: if the stop conditions are met, exit and output the results; otherwise, repeat step 2-6;

Ii. Source code

clear all 
clc
rng('default'); %% sets WNS override parameter, %% default input parameter is integer, if you want to define decimal, please multiply by the coefficient to integer and then convert. %% for example range1*1, R =0.03Can be converted to100*100, R =3; % AreaX*AreaY*AreaZ AreaX =100;
AreaY = 100;
AreaZ = 100;
N = 20; % Number of overridden nodes R =15; % Communication radius %% Set sparrow optimization parameter POP =30; % Population count Max_iteration=30; % Set maximum number of iterations lb = ones(1.3*N);
ub = [AreaX.*ones(1,N),AreaY.*ones(1,N),AreaZ.*ones(1,N)];
dim = 3*N; % dimension for3N, N coordinates fobj = @(X)fun(X,N,R,AreaX,AreaY,AreaZ); % fitness function [Best_pos,Best_score,SSA_curve]=SSA(POP,Max_iteration, LB, UB,dim,fobj); Began to optimize _________________________________________________________________________ % % % % % sparrow optimization algorithm %_________________________________________________________________________% function [Best_pos,Best_score,curve]=SSA(pop,Max_iter,lb,ub,dim,fobj) ST =0.6; % Warning value PD =0.7; % of the finder column, the rest is the subscriber SD =0.2; PDNumber = round(pop*PD); SDNumber = round(SD*PD); % number of sparrows aware of dangerif(max(size(ub)) == 1)
   ub = ub.*ones(1,dim);
   lb = lb.*ones(1,dim); End % X0= Initialization (pop,dim,ub,lb); X = X0; % Calculate the initial fitness value fitness = zeros(1,pop);
for i = 1:pop fitness(i) = fobj(X(i,:)); end [fitness, index]= sort(fitness); % order BestF = fitness(1);
WorstF = fitness(end);
GBestF = fitness(1); % global optimal fitness valuefor i = 1:pop
    X(i,:) = X0(index(i),:);
end
curve=zeros(1,Max_iter);
GBestX = X(1, :); % global optimal position X_new = X;for i = 1: Max_iter
    disp(['the first',num2str(i),'Next iteration']);
    BestF = fitness(1);
    WorstF = fitness(end);

    
    R2 = rand(1);
   for j = 1:PDNumber
      if(R2<ST)
          X_new(j,:) = X(j,:).*exp(-j/(rand(1)*Max_iter));
      else
          X_new(j,:) = X(j,:) + randn()*ones(1,dim);
      end     
   end
   for j = PDNumber+1:pop
%        if(j>(pop/2))
        if(j>(pop - PDNumber)/2 + PDNumber)
          X_new(j,:)= randn().*exp((X(end,:) - X(j,:))/j^2);
       else% to produce- 1.1Random number A = ones(1,dim);
          for a = 1:dim
            if(rand()>0.5)
                A(a) = - 1;
            end
          end 
          AA = A'*inv(A*A');     
          X_new(j,:)= X(1, :) +abs(X(j,:) - X(1,:)).*AA';
       end
   end
   Temp = randperm(pop);
   SDchooseIndex = Temp(1:SDNumber); 
   for j = 1:SDNumber
       if(fitness(SDchooseIndex(j))>BestF)
           X_new(SDchooseIndex(j),:) = X(1,:) + randn().*abs(X(SDchooseIndex(j),:) - X(1:)); elseif(fitness(SDchooseIndex(j))== BestF) K =2*rand() - 1;
           X_new(SDchooseIndex(j),:) = X(SDchooseIndex(j),:) + K.*(abs( X(SDchooseIndex(j),:) - X(end,:))./(fitness(SDchooseIndex(j)) - fitness(end) + 10^- 8 -)); End End % Indicates the border controlfor j = 1:pop
       for a = 1: dim
           if(X_new(j,a)>ub)
               X_new(j,a) =ub(a);
           end
           if(X_new(j,a)<lb)
               X_new(j,a) =lb(a); End end end % Update positionfor j = 1:pop
    if(fitness_new(j) < GBestF) GBestF = fitness_new(j); GBestX = X_new(j,:); end end X = X_new; fitness = fitness_new; % sort update [fitness, index]= sort(fitness); % order BestF = fitness(1);
   WorstF = fitness(end);
   for j = 1:pop
      X(j,:) = X(index(j),:);
   end
Copy the code

3. Operation results



Fourth, note

Version: 2014 a