Sparrow search algorithm specific steps and formula description:

Building sparrow population:

Where, D represents the dimension of the problem to be optimized, and N represents the number of sparrow population. The fitness function of all sparrow populations can be expressed as follows:

Where, Fx represents the fitness function value.

Sparrows in the sparrow algorithm are divided into two categories: finders and entrants. Finders are responsible for finding food for the whole population and providing foraging directions for entrants. Therefore, the foraging search scope of finders is larger than that of entrants. During each iteration, the discoverer iterates according to Formula (3).

T said the current number of iterations, Xij said of the ith the sparrow population in the first j d location information, alfa said random number of 0 and 1, itermax said the largest number of iterations, Q means a obey the normal distribution of random Numbers, L is a 1 * d and all elements of 1 matrix, R2 belong to early warning value of 0 and 1 is the location of the sparrow population, ST belongs to the safe value of 0.5-1 indicating the position of sparrow population.

When R2<ST, it means that the warning value is less than the safe value. At this time, there is no predator in the foraging environment, and the finder can conduct extensive search operations. When R2>ST, it means that some sparrows in the population have found the predator, and give warning to other sparrows in the population. All sparrows need to fly to the safe area for foraging.

In the process of foraging, part of the entrants will monitor the discoverers all the time. When the discoverers find better food, the entrants will compete with them. If they succeed, they will get the discoverers’ food immediately.

Where, XP represents the optimal location discovered by the discoverer, Xworst represents the global worst location, and A represents the 1* D matrix whose elements are randomly assigned to 1 or -1 and meet the following relations:

L is still a 1 times d matrix with all 1’s. When I >n/2, it indicates that the ith entrant has no food and is hungry. At this time, he/she needs to fly to other places for food so as to obtain more energy.

In the sparrow population, the number of sparrows aware of danger accounts for 10% to 20% of the total number. The positions of these sparrows are randomly generated, and the positions of sparrows aware of danger are constantly updated according to Formula (5).

Where, Xbest represents the current global optimal position, is the random number that follows the standard normal distribution and is used as the step size control parameter, beta is a random number ranging from -1 to 1, Fi represents the fitness value of the current individual sparrow, FG represents the global best fitness value, fw represents the global worst fitness value, Does the one like the left ear read “Il Buzeno”? “One not zeno” means a constant that avoids a zero in the denominator. When FI >fg, sparrows are at the edge of the population and vulnerable to predators. When FI = FG, sparrows in the middle of the population are also in danger and need to be close to other sparrows to reduce the risk of being preyed on.

%____________________________________________________________________________________ % You can simply define your cost in a seperate file and load its handle to fobj % The initial parameters that you need are: %__________________________________________ % fobj = @YourCostFunction % dim = number of your variables % Max_iteration = maximum number of generations % SearchAgents_no = number of search agents % lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n % ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n % If all the variables have equal lower bound you can just % define lb and ub as two single number numbers % To run SSA: [Best_score,Best_pos,SSA_cg_curve]=SSA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj) %__________________________________________ clear all clc SearchAgents_no=30; % Number of search agents Function_name='F1'; % Name of the test function that can be from F1 to F23 ( Max_iteration=1000; % Maximum numbef of iterations % Load details of the selected benchmark function [lb,ub,dim,fobj]=Get_Functions_details(Function_name); [Best_score,Best_pos,SSA_cg_curve]=SSA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj); Figure ('Position',[500 500 660 290]) %Draw search space subplot(1,2,1); func_plot(Function_name); title('Parameter space') xlabel('x_1'); ylabel('x_2'); Zlabel ([Function_name,'(x_1, x_2)']) %Draw objective space subplot(1,2,2); semilogy(SSA_cg_curve,'Color','r') title('Objective space') xlabel('Iteration'); ylabel('Best score obtained so far'); axis tight grid on box on legend('SSA') display(['The best solution obtained by SSA is \m ', num2str(Best_pos)]); display(['The best optimal value of the objective funciton found by SSA is \n ', num2str(Best_score)]);Copy the code

Complete code or simulation consultation QQ1575304183