Abstract
The sparrow search algorithm is a new type of swarm intelligence optimization algorithm with better effect, but it still has shortcomings such as easy to fall into local optimality and large randomness. In order to solve these problems, this paper proposes an adaptive spiral flying sparrow search algorithm (ASFSSA), which reduces the probability of getting stuck into local optimum, has stronger optimization ability than other algorithms, and also finds the shortest and more stable path in robot path planning. First, the tent mapping based on random variables is used to initialize the population, which makes the individual position distribution more uniform, enlarges the workspace, and improves the diversity of the population. Then, in the discoverer stage, the adaptive weight strategy is integrated with Levy flight mechanism, and the fusion search method becomes extensive and flexible. Finally, in the follower stage, a variable spiral search strategy is used to make the search scope of the algorithm more detailed and increase the search accuracy. The effectiveness of the improved algorithm ASFSSA is verified by 18 standard test functions. At the same time, ASFSSA is applied to robot path planning. The feasibility and practicability of ASFSSA are verified by comparing the algorithms in the raster map planning routes of two models.
1. Introduction
With the continuous development of scientific research, more and more swarm intelligence optimization algorithms have been proposed. The swarm intelligence optimization algorithm basically abstracts a series of formulas based on the life characteristics or behavior rules of organisms or things and finds high-quality solutions in a certain solution space based on these formulas. Scholars have proposed a series of swarm intelligence optimization algorithms through the behaviors of ant, cat, whale, wolf, and others. Among them, the sparrow search algorithm (SSA) [1], which finds optimal solutions through the sparrow foraging process, is a novel swarm intelligence optimization algorithm proposed by two scholars, Xue and Shen in 2020. This algorithm has fewer population roles and simple principles, and it is easy to understand. Compared with gray wolf optimizer (GWO) [2] and particle swarm optimization (PSO) [3], SSA has higher accuracy, stronger convergence, and better optimization capabilities. Moreover, SSA is now more and more applied in practical engineering. However, SSA also has the common shortcomings of swarm intelligence algorithms, such as easy to get stuck in local and excessive randomness during initialization.
In order to overcome these shortcomings of the swarm intelligence optimization algorithm, scholars have studied the algorithm and successfully applied to practical engineering problems. Lei et al. [4] applied the Levi flight strategy in SSA to avoid local convergence and improve global optimization capabilities. They combine the improved sparrow search algorithm with DV-Hop to enhance the positioning accuracy in WSN. Xin et al. [5] used tent chaotic sequence to initialize the population in turn, and Gaussian mutation operator and tent chaotic disturbance balance the global individual position. A series of strategies increase the population diversity of the algorithm, strengthen the local search ability of the algorithm, and improve the possibility of jumping out of the local area. Tang et al. [6] introduced a cubic mapping strategy to initialize the population, avoiding the decrease of population diversity in the later iterations. The reverse learning strategy and elite particles are added to effectively prevent the algorithm from falling into a local optimum. The sine and cosine optimization algorithm is incorporated into the follower position update to reduce search blind spots and balance algorithm development and search capabilities. Finally, a Gaussian walk strategy is used to help the algorithm leave the stagnant state. The good search ability of the improved algorithm is tested through experiments. Xin et al. [7] also proposed an improved algorithm, adding the flying thoughts in the bird swarm algorithm to the location update of the discoverer and the follower, ensuring global convergence, increasing the diversity of the population, and being able to jump out of the local optimum. In this paper, the improved algorithm is also applied to the multithreshold image segmentation method, which solves the original low segmentation accuracy and slow segmentation speed. Mao et al. [8] used sin-cosine algorithm, nonlinear dynamic learning factor, and Levy flight strategy to improve the algorithm, speed up the convergence speed, and strengthen the local escape ability. Song et al. [9] proposed to introduce the skew tent map-based chaotic method to initialize the population and strengthen the individual quality of the population. After that, the nonlinear decreasing weight and mutation operator strategies were combined in each stage to dynamically change the search space, increase the diversity of the population, and improve the ability to jump out of the local optimum. Wu and others [10] used tent chaotic mapping, adaptive weight control step size, Cauchy mutation, and Gaussian mutation to improve the original algorithm in turn. Such a series of strategies balance the global search and local search capabilities, enhance the local development capabilities of the algorithm, and improve the search accuracy. Finally, the improved algorithm is applied to the mine intelligent ventilation system, which proves the good optimization effect of the improved algorithm. Zhang and Ding [11] initialized the population by logistic mapping. In the discoverer phase and the early warning phase, adaptive parameters are introduced to expand the search range of the discoverer, dynamically adjust the number of early warning individuals, and better help the sparrow individuals find the best position. The mutation operator strategy is added to the global process to increase the population diversity. The whole improved algorithm enhances the global search capability of SSA. Finally, the improved CSSA is applied to the stochastic configuration network. The results show that CSSA has good performance and improves the regression performance of SCN in solving large-scale data problems. Zhang et al. [12] used the sine cosine strategy to change the way the discoverer updates the location, and improve global and local search capabilities of the algorithm. A labor cooperation structure is added to the discoverer stage and the early warning stage, allowing the discoverer and the early warning individual to share their locations to achieve cooperation, so as to converge to the global optimal solution faster and more stably.
Although these improved strategies can better improve the optimization ability of each algorithm, they do not change the search mechanism of each algorithm itself. And they only improved the search ability of the algorithm in the neighborhood space, and the learning rate was not high, resulting in the algorithm still having drawbacks. This means that when faced with high-dimensional complex problems, these algorithms may also be stuck into the local optimal situation. Therefore, based on the research of many scholars, this paper proposes the adaptive spiral flying sparrow search algorithm (ASFSSA).
In the following paper, Section 2 gives an introduction to the overall work and motivation of the algorithm. Section 3 introduces the sparrow search algorithm. Section 4 illustrates the improvements made by the adaptive spiral flying sparrow search algorithm. Section 5 compares and analyzes the improved algorithm with other intelligent algorithms. In Section 6, the improved algorithm is applied to path planning and compared with the other three algorithms in two different grids. Section 7 summarizes this paper.
2. Related Work and Motivation
In order to improve the search speed and convergence accuracy of individual sparrows and reduce the possibility of falling into the local optimum, adaptive weights and Levy flight strategies are used in the discoverer stage. In order to make the individual sparrow search more detailed and get a better position, a variable spiral search strategy is introduced in the follower stage. The higher the quality of the solution, the better the search ability.
To verify the convergence and optimization ability of the proposed algorithm, six algorithms are used to compare the optimization effects of 18 test functions. As can be seen from the experimental results, the adaptive spiral flying sparrow search algorithm has more significant advantages than other algorithms. Finally, for the purpose of verifying the practicability and performance of the algorithm better, the four algorithms are applied to the path planning of the robot. The results show that the path planning of the adaptive spiral flying sparrow search algorithm is relatively stable and the cost is the least, which reduces the constraints of the immature and randomness in the path planning of the previous algorithms.
3. Sparrow Search Algorithm
The sparrow population is divided into two roles, namely, the discoverer and the follower. They have three behaviors: foraging, following, and reconnaissance. The task of the discoverer is to find food and inform the follower of the location of the food. Therefore, the discoverer needs to search in a large area, and the foraging range of the follower is generally small. This is the formula for updating the position of the discoverer:
In formula (1), t and M, respectively, denote the current number of iterations and the maximum number of iterations. Xi,j represents the location of the i-th sparrow, and j is the representative dimension. In the above formula, α and R2 are both a random number from 0 to 1 (not zero), and R2 is an important parameter that controls the individual’s flight behavior. ST (ST ∈ [0.5, 1]) is a safety threshold and an important parameter to measure whether the location of the discoverer is safe. L is a 1 × D matrix with all elements of 1. If R2 < ST, it means that the current location is temporarily safe, there are no predators in the surrounding environment, and the discoverer can search for food in a large area. If ≥ ST, it means that the predator’s trace is found at the current location, and the discoverer needs to go to other safe areas for foraging activities at this time.
The location update of followers is described as follows:
In formula (2), refers to the optimal position occupied by the discoverer in the t + 1-th iteration so far (the t + 1-th iteration has not ended) and represents the worst position occupied by the group in the t-th iteration. A is a 1 × D matrix, and the elements in the matrix are randomly assigned values of 1 or −1, and A+ = AT(AAT)−1. If i > n/2, this means that the current follower is at the edge of the entire population and has no food. At this time, the follower needs to go elsewhere for food. Otherwise, the follower will go after the pace of the discoverer for food.
When being aware of the danger, the sparrow population will make antipredatory behavior:
In formula (3), is the global optimal solution obtained in the t-th iteration. In the above formula, β, K, and ε are all parameters in the formula. β is a random number that obeys the standard normal distribution, and it is used to control the step size. K is an arbitrary random number from -1 to 1, it represents the direction in which the individual sparrow moves, and it is also a step control parameter. ε is a relatively small constant, and its function is to prevent the denominator from being zero. fi represents the fitness value of the i-th individual, and and are the best fitness value and the worst fitness value of the current iteration number, respectively.
If fi > , then this indicates that the individual is at the edge of the population and is easily preyed by natural enemies. If fi = , then this means that the individual is located in the center of the population. At this time, the sparrow needs to be close to other individuals to reduce the probability of being captured.
4. Adaptive Spiral Flying Sparrow Search Algorithm
4.1. Tent Chaotic Mapping Based on Random Variables
Because SSA has the shortcoming of large randomness, it is decided to introduce orderly and uniform tent mapping to improve it. Many scholars have applied tent mapping to solve the optimization problem [13]. However, tent mapping is not very stable. In [7], in order to reduce this influence, tent mapping based on random variables was adopted, which has a good effect. Therefore, in this paper, the tent mapping strategy based on random variables is introduced to improve the initialization of SSA, so that the initialization of the population is more orderly, and the controllability of the algorithm is enhanced. Its specific formula is as follows:
The expression after the Bernoulli transformation is
In formula (5), N is the number of particles in the chaotic sequence.
According to the characteristics of the tent mapping, the sequence flow for generating chaos in the feasible domain is as follows:(1)Randomly generate the initial value z0 in (0, 1), and let i = 1.(2)Perform iteration by using that formula (5) to generate a z sequence, and i is increased by 1.(3)Stop if the number of iterations reaches the maximum, and store the generated z sequence.
4.2. Adaptive Weighting
Weight strategies are common in particle swarm optimization algorithms [14]. Generally, the particle swarm algorithm reduces to some extent the trapping into local optimum by adaptively changing between the set maximum and minimum values. Inspired by this, this paper adds an inertia weight which varies with the number of iterations in the discoverer stage of sparrow optimization. In the initial stage of the algorithm, it weakens the influence of random initialization and balances the Levy flight mechanism below, so as to enhance the local search and global search of the algorithm.
The discoverer guides other individuals in the population to search for food, so the introduction of adaptive weights improves the quality of individual locations, enabling other individuals to converge faster to optimal locations, and overall accelerates the convergence rate. Based on the characteristics of sparrows, the formula for adaptive weights is as follows:
The meaning of formula (6) is that has the property of nonlinear change between [0, 1]. According to the characteristics of cos function, the weight value is smaller at the beginning of the algorithm, but the optimization speed is faster and the later weight value is larger, but the change speed is slower, so the convergence property of the algorithm is balanced. The improved discoverer location is updated as follows:
By introducing adaptive weights to dynamically adjust the position changes of sparrows, different guidance modes for the discoverer at different times make the algorithm search flexible. As the number of iterations increases, the individual sparrows converge toward the optimal position, and a larger weight makes the individual move faster, thus increased the convergence speed of the algorithm.
4.3. Levy Flight Mechanism
In SSA, there are few roles in the population, and the same role update position formula is the same, which will result in multiple individuals in the same optimal position. Too high solution repetition rate will reduce the efficiency of the algorithm, which is not conducive to the optimization of the algorithm. The discoverer has a wide search range and globality, and the adaptive weighting strategy is introduced to effectively improve the convergence effect. However, when facing the high-dimensional complex problems, there is still a probability of falling into local optimum. Therefore, the Levy flight strategy is introduced to improve the randomness of the algorithm solution, thereby enriching the diversity of population positions. This can also effectively improve the operating efficiency of the algorithm.
Levy flight obeys the Levy distribution. Principle [15] and the Levy distribution is shown in Figure 1. It uses a random long- and short-distance mechanism to cover a large area. After adding the Levy flight mechanism, the performance of the proposed algorithm can be improved.

The location update format [16] for joining Levy flight strategy is as follows:
In formula (8), xi(t) represents the position of the i-th individual in the t-th iteration, is an arithmetic symbol representing point-to-point multiplication. l denotes a step length control parameter, which is obtained by this formula: l = 0.01(xi(t) − xp). levy(λ) is a path that obeys the Levy distribution, which represents the introduced Levy flight strategy and satisfies the following: .
Because Levy distribution is very complex, Mantegna algorithm is usually used to simulate it [17, 18]. The formula for calculating the step size is as follows:
Among them, , and is generally 1.5.
The introduction of the Levy flight strategy makes the sparrows more flexible at this stage and can also lead other individuals to find a better location, free from the constraints of local extremes. Therefore, the combination of Levy flight mechanism and adaptive weights balances the search method, and the quality of each solution obtained is improved to a certain extent, which greatly improves the search ability of the algorithm.
4.4. Variable Spiral Search Strategy
Followers update dynamically with the location of the discoverer, which leads to blindness and singularity in the way they search. Inspired by the rotation operation of the whale algorithm [19, 20], a variable spiral location update strategy is introduced to make follower location updates more flexible, develop a variety of search paths for location updates, and balance the global and local search of the algorithm. The spiral search diagram is shown in Figure 2.

In the follower location update process, the helix parameter z cannot be a fixed shape, which results in monotonous search methods and the possibility of falling into local optimum, thus weakens the search ability of the algorithm. The parameter z is designed as an adaptive variable to dynamically adjust the spiral shape of the follower search, which broadens the ability of the follower to explore the unknown region, improves both the search efficiency and the global search performance of the algorithm. The formula for the variable spiral position update strategy is as follows:
The parameter z varies according to the number of iterations and is composed of an exponential function based on e. The size and amplitude of the helix are dynamically adjusted according to the properties of cos function. k is the coefficient of change. According to the optimization characteristics of each function, in order to make the algorithm have a suitable search range, k = 5. L is a uniformly distributed random number of [−1, 1]. With the range of follower position updating is from large to small, more quality solutions are found in the early stage, and late optimization reduces the increase of idle work, which improves the global optimal search performance of the algorithm. At the same time, according to the spiral characteristics, the optimization accuracy of the algorithm is improved to a certain extent.
4.5. Process for Improving Sparrow Search Algorithm
The sparrow search algorithm has better optimization performance than other algorithms, but it still depends on the initial population so that it is easy to fall into a local optimal state. In order to improve these shortcomings, this paper proposes an adaptive spiral flying sparrow search algorithm. Initially, the population was initialized by tent chaotic mapping based on random variables to provide adequate preparation for the discoverer’s optimization. Then, adaptive weights and Levy flight strategies were introduced to make the discoverer’s position update method more extensive and flexible, and then a variable spiral was proposed. The strategy makes the follower’s search more detailed, avoids premature phenomenon, and speeds up the optimization speed of the algorithm.
The specific implementation steps of ASFSSA are as follows: Step 1: initialize the sparrow population parameters, for example, the total population pop, the total number of discoverers pNum, the total number of iterations iter, and the solution accuracy ε. Step 2: use tent mapping to initialize the position of population individuals, and generate pop sparrow individuals. Step 3: use the correlation function to calculate the fitness value fi of each population individual, and find the maximum fitness value and the minimum fitness value . Step 4: sort the population according to the fitness value. Step 5: select the individuals with the top pNum fitness as the discoverer, and the rest are followers, and use formulas (7) and (8) after adding the strategy to update the position of the discoverer. Step 6: use formula (10) to update the positions of pop-pNum followers. Step 7: use formula (3) to update the position of the sparrow that is aware of the danger. Step 8: after one iteration is completed, recalculate the fitness value fi of each individual, and update the maximum fitness value , the minimum fitness value , and the corresponding position. Step 9: judge whether the algorithm has reached the maximum number of iterations or the accuracy of the solution. If it has reached, the optimization result will be output; otherwise, it will return to Step 4.
The specific flowchart is shown in Figure 3.

5. Algorithm Performance Test
To test the optimization capability of the improved algorithm, 18 standard test functions are selected to verify the performance. The test functions are listed in Table 1. The first 10 are unimodal functions, the middle 4 are complex multimodal functions, and the last 4 are fixed-dimension function. In order to increase the experimental convincing, it is necessary to compare the particle swarm algorithm (PSO), gray wolf algorithm (GWO), beetle swarm optimization (BSO), SSA, CSSA, and the proposed algorithm optimization effect. Among them, CSSA is an improved sparrow search algorithm in the literature [5], and BSO [21] is a new algorithm which combines beetle antennae search algorithm (BAS) [22] and PSO, and the research on this algorithm is very popular. The complexity and parameters of all algorithms are shown in Table 2.
The population number of all algorithms is 100; the number of iterations is 200. In PSO, c1 = c2 = 2, = 0.728. The BSO parameter settings are as follows: eta = 0.95, c = 2, k = 0.4, step0 = 0.9, and step1 = 0.2. The upper and lower limits of all algorithms are given in the test function table. The experimental environment is MATLAB 2018b, the Windows 10 operating system, and the running memory is 8G. In order to enhance the experimental persuasion, exclude the influence of accidental events, and count the minimum (min) value, average (aver) value, and standard (std) deviation of each algorithm, which reflect the optimization ability and stability of each algorithm. The comparison table of optimization effect of each algorithm is shown in Table 3, and the convergence of each algorithm function is shown in Figure 4.

(a)

(b)

(c)

(d)

(e)

(f)

(g)

(h)

(i)

(j)

(k)

(l)

(m)

(n)

(o)

(p)

(q)

(r)
From Table 3, we can see that the ASFSSA has the best performance in function optimization, especially in F1–F4, F7–F9, F16, and F18, which can find the optimal value each time. The results of CSSA come later, and PSO and GWO are the worst, especially when the boundary is complex. The BSO has good optimization characteristics in the F10, F11, and F17 functions, but the effect in other algorithms has great shortcomings, and the effect is the worst. It can be seen that BSO has the limitation of the optimization ability. Among these three functions, the optimization effect of ASFSSA is second only to it. Generally speaking, ASFSSA has a good convergence speed and accuracy on unimodal functions, and it has a strong ability to resist local extremes on multimodal functions. Therefore, the introduction of multiple strategies significantly improves the stability and searching ability of the algorithm.
From Figure 4, we can see that ASFSSA has a significant improvement in convergence speed and accuracy. Especially, the ASFSSA has very fast convergence speed and very high convergence precision in the functions of F1–F5, F7–F10, F15-F16 and has obvious ability of resisting local attraction in the functions of F5, F10, and F15. ASFSSA has good convergence effect in F6, F13, F14, and F17 functions, but there a few differences with other algorithms. BSO has better performance in the three functions of F11-F12 and F18, and ASFSSA has the second best performance, but BSO has worse performance in the other functions, and some functions have worse performance than PSO. The convergence effect of other algorithms is insufficient. Thus, it can be seen that the introduction of multistrategy makes the algorithm get rid of the insufficient search mode in the optimization process, open up a more flexible and detailed search, and improve the convergence ability of the algorithm.
5.1. Wilcoxon Rank Sum Test
It is not comprehensive to simply calculate the indexes of the running results of each algorithm. In order to highlight the superiority of the ASFSSA algorithm, it is necessary to carry out the statistical test. In order to reflect the fairness, the Wilcoxon rank sum test [20] is used to verify whether the results of each run of ASFSSA are significantly different from those of other algorithms at the significance level. If , it can be considered that there is a significant difference between the two algorithms; if , it means that the difference between the two algorithms is not obvious; that is, the optimization performance of the two algorithms is equivalent. Table 4 shows the results for ASFSSA and PSO, GWO, BSO, SSA, and CSSA are at a significance level of , where N/A indicates that the performance between the two is similar and not comparable.
As can be seen from Table 3, each algorithm is significantly different from the ASFSSA algorithm, with only a few cases of comparable performance. It can be seen that the introduction of multiple strategies improves the disadvantages of the original algorithm and enhances the optimization ability of the algorithm.
6. Robot Path Planning Based on ASFSSA
To verify the feasibility and practicability of the improved algorithm, this paper takes a classic case of robot route planning to explore it. Each individual sparrow is a viable path in routing. Assuming there are N possible paths, dimension D is determined by the number of connections from the starting point to the destination point. Using the raster method to model the environment, the raster method is to use 1 1 raster to construct the equivalent working environment, and use the raster value to equivalent the obstacles in the location [23, 24]. This effectively equates the working environment of the robot to a plane, similar to the lattice effect, and then determines the feasible and obstacle zones based on the raster values.
The raster number defines 0 as the feasible domain and 1 as the obstacle zone, so the robot can plan its path on the raster with a value of 0. Dimension D is the number of columns in the raster map and the cost function of the path length of the i-th sparrow individual, as shown in the following equation:
In equation (11), j is the j-th dimension of a sparrow individual.
6.1. Experimental Environment Settings
To better verify the practicability and feasibility of the improved algorithm, the improved algorithm is used to route the raster maps of the two models. Compared with CSSA, SSA, and PSO, the number of population is 20 and the number of iterations is 100. Other environmental parameters are consistent with the above.
6.2. Simulation Results and Analysis
The optimal route of each algorithm in the two model graphs is shown in Figures 5 and 6. In order to eliminate the influence of chance, each algorithm is tested for 10 times, and the shortest, average, and worst route of each algorithm are counted. Three indicators are used to measure the stability and feasibility of each algorithm in this experiment. The optimization statistical table of each algorithm is shown in Table 5, and the average route convergence chart is shown in Figure 7.

(a)

(b)

(c)

(d)

(a)

(b)

(c)

(d)

(a)

(b)
As shown in Figures 5 and 6, the ASFSSA route is the simplest and clearest, followed by CSSA, while PSO and SSA are obviously trapped in local optimum. From Table 5, we can see that ASFSSA has the best searching ability and stability in both of raster graphs, and CSSA has better stability. However, from Figure 7, we can see that the convergence of SSA and PSO is insufficient, and the optimization results of SSA and PSO are extremely unstable and poor. Therefore, in the two model diagrams, the introduction of multiple strategies makes the algorithm flexible in the search, greatly improves the search ability of the algorithm, and plans a route with the least cost.
7. Conclusion
The sparrow search algorithm has better performance than other algorithms in optimization, but it is still easy to get stuck in local and rely on population initialization. This paper analyzes these defects and proposes an adaptive spiral flying sparrow search algorithm. Firstly, tent mapping based on random variables is used to initialize the population, which makes the distribution of sparrow individuals uniform and helps the individuals to work better. Secondly, the adaptive weights strategy and Levy flight mechanism are used in the discoverer stage, which makes the discoverer flexible and adaptable in the optimization process and reduces the traditional regular strategy. Finally, the variable spiral search strategy is used in the follower stage, which makes the follower search method more detailed and in-depth, and improves the convergence accuracy of the algorithm. The effectiveness of the improved algorithm is verified by 18 test functions and the comparison of other algorithms. Compared with other algorithms, ASFSSA has significant optimization capabilities. At the same time, the feasibility and practicability of the improved algorithm are verified by the robot path planning study. The path planned by the improved algorithm is clear, and the cost function is the smallest. It can be seen that the introduction of multiple strategies has effectively improved the optimization ability of the basic sparrow search algorithm. However, in some functions, the optimization effect of ASFSSA is second only to the BSO algorithm. In the future research phase, how to improve these optimization effect is the research focus, and it needs to be upgraded to more complex applications.
Data Availability
The data used to support the findings of this study are available from the corresponding author upon request.
Conflicts of Interest
The authors declare that they have no conflicts of interest.
Acknowledgments
This work was financially supported by the Regional Foundation of the National Natural Science Foundation of China (no. 61561024).