Lens Learning Sparrow Search Algorithm

In this paper, a lens learning sparrow search algorithm (LLSSA) is proposed to improve the defects of the new sparrow search algorithm, which is random and easy to fall into local optimum.+e algorithm has achieved good results in function optimization and has planned a safer and less costly path to the three-dimensional UAV path planning. In the discoverer stage, the algorithm introduces the reverse learning strategy based on the lens principle to improve the search range of sparrow individuals and then proposes a variable spiral search strategy to make the follower’s search more detailed and flexible. Finally, it combines the simulated annealing algorithm to judge and obtain the optimal solution. +rough 15 standard test functions, it is verified that the improved algorithm has strong search ability and mining ability. At the same time, the improved algorithm is applied to the path planning of 3D complex terrain, and a clear, simple, and safe route is found, which verifies the effectiveness and practicability of the improved algorithm.


Introduction
In recent decades, swarm intelligence algorithms have been gradually explored by researchers. e main principles of these algorithms are mostly to solve some optimization problems by simulating or revealing some natural phenomena or processes, such as Particle Swarm optimization (PSO) [1], Grey Wolf Optimizer (GWO) [2], Beetle Swarm Optimization (BSO) [3]. e sparrow search algorithm (SSA) is a group of intelligence algorithms proposed by Xue and Shen [4] in 2020 to simulate the feeding process of sparrows. It has few parameters, simple principles, and easy implementation and is superior to other algorithms in many optimization functions. However, for some complex optimization problems, the algorithm has some problems, such as low search accuracy and slow convergence rate. After the sparrow search algorithm was put forward, many scholars studied and applied it carefully and made improvements. Xin et al. [5] proposed a chaotic sparrow search algorithm (CSSA), which uses tent mapping based on random variables to initialize the population, so as to make the individual position of sparrows more evenly distributed and improve the diversity of the population; in the process of optimization, disturbance and mutation mechanism are used to prevent the algorithm from falling into the local extremum state and improve the global search performance of the algorithm. e effectiveness and feasibility of the algorithm are verified by 12 test functions and image segmentation problems. In addition, they also proposed an improved sparrow search algorithm for image segmentation [6]. Bird swarm algorithm (BSA) [7] is used to optimize the sparrow search algorithm. e benchmark function and multithreshold image segmentation based on interclass variance and Kapur's entropy verify that the improved algorithm has strong search ability and development ability. Mao et al. [8] proposed an improved sparrow search algorithm which combined Cauchy mutation and reverse learning. At first, a sin chaotic mechanism with infinite folding times is used to initialize the population, and the global optimal solution of the previous generation is introduced into the position updating formula, which speeds up the information exchange of the algorithm. At the same time, the adaptive weight strategy is introduced to coordinate the local and global search ability. en, the fusion of Cauchy mutation and reverse learning strategy is introduced to make disturbance mutation in the optimal position to produce new solutions with higher quality, which improves the ability of the algorithm to jump out of the local optimum. Eight test functions are used to verify that the algorithm has been greatly improved in global optimization. Liu et al. [9] proposed a modified sparrow search algorithm with application for 3D route planning for UAV. Chaos strategy is introduced to enhance the diversity of the population, and adaptive inertia weight is used to balance the convergence speed and exploration ability of the algorithm. Finally, Cauchy Gauss mutation strategy is used to get rid of the stagnation ability of the later algorithm.
rough the comparison of several algorithms in 3D path planning, the improved sparrow search algorithm has strong search ability and the planned route is relatively safe.
Currently, research on sparrow search algorithm has been proposed successively, but the proposed algorithms lack a global improvement mechanism. Although the mapping mechanism is uniform, it is not stable under the sparrow search algorithm with good global results, and it increases the workload of the population. erefore, a search mechanism with global vision and flexibility is needed to improve the search ability of the sparrow search algorithm. For the above analysis, a lens learning sparrow search algorithm (LLSSA) is proposed. is algorithm uses a reverse learning strategy based on lens learning strategy in the discoverer location update formula to improve the algorithm's vision in the optimal space. A variable spiral search strategy is proposed to enable followers to search in more detail and flexibility. Finally, the current solution is refined by fusing simulated annealing algorithm to find a higher quality solution.
rough 15 standard test functions, the effectiveness of LLSSA is verified, and a distinct, simple, and satisfying route is found in the complex three-dimensional path planning.

Sparrow Search Algorithm
During the food search process, the sparrow population is divided into two roles: discoverer and follower, which conduct behavioral strategies separately. Discoverers are generally 0.2 of the population size and are the guides of the individual population, leading other individuals in the search for things, so the role of the discoverer is crucial in the population.
ey have a wide search range. e location update formula for the discoverer is as follows: In formula (1), h represents the current number of iterations and M is the maximum number of iterations. X i,j denotes the current position of the i-th sparrow in the j-th dimension. α is a random number between 0 and 1. Q is a random number from a normal distribution. L represents a 1 × D matrix with all elements 1. R 2 and ST respectively represent warning and safety values, and R 2 ∈ [0, 1], ST ∈ [0.5, 1]. When R 2 < ST, this indicates that the community environment is in a safe state at this time, no predators are found around, and the discoverers can search for food on a wide scale. When R 2 is greater than or equal to ST, this indicates that the individuals within the cluster have found a predator and issued an alarm so that all individuals of the population will make antipredation behavior and the discoverer will lead the follower to a safe location.
To obtain good quality food, the followers would closely follow the discoverers. Some of these followers oversee the discoverers and those discoverers with high rates of predation for food, thus increasing their own nutrition. e positional update for the followers is described below: In (2), X P is the optimal position currently occupied by the discoverer, and X worst denotes the current worst position. A is a matrix of 1 × D in which an element is only 1 or -1, with A + � A T (AA T ) − 1 . When i > (n/2), it indicates that the sparrow population is aware of danger, at which point they make antipredation behavior, and the mathematical expression is as follows: In (3), X best is the current global optimum. β is the control step size parameter and is a random number obeying a normal distribution with mean 0 and variance 1. K ∈ [− 1, 1] is a random number, and K represents the direction in which the sparrow moves while also controlling the moving step size. f i indicates the fitness value of the current sparrow individuals. f g and f w are the optimal and worst fitness values within the current search scope, respectively. ε is the smallest real number, preventing the occurrence of 0 in the denominator. When f i ≠ f g indicates that the current sparrow is at the boundary of the population and vulnerable to predator attack, the location needs to be adjusted. f i � f g , which indicates that individual sparrow in the interior of the population is aware of the danger and need to be close to other sparrows to avoid the danger.

Inverse Learning Strategy Based on Lens Imaging
It is because of the broad search range and flexible search methods that discoverers can lead the group to find good food. Once the discoverer is trapped in the local optimum, the performance of the overall algorithm will be degraded, so improving the search horizon of the discoverer is particularly important. General learning strategies have achieved good results in some optimization algorithms, but have little effect on the performance of the algorithm, because the general learning strategies carry out reverse solutions in local space, which enriches the diversity of the population, but the search scope is narrow and loses flexibility. In order to improve the searching ability of the discoverer, a reverse learning strategy based on lens imaging [10] is proposed and applied to the individual update position formula of the discoverer. e application of this strategy allows new individuals to be acquired for each iteration, resolving the problems left over from previous general learning strategies. e principle is described as follows.
Definition 2 (base point). Suppose there are several points , and k � 1, 2, . . . , n, and O i is called the base point of X and X ′ when k � i.
Using one-dimensional space as an example, assume that an individual P with a height of h is projected as x P (the globally optimal individual) on the coordinate axis, and a lens with a focal length of f is placed at the base position O (the midpoint of [a, b] in the figure). An image P ′ with a height of h ′ can be obtained through the lens imaging process, and its projection on the coordinate axis is x p ′ . At this time, x p ′ is such that x P gives rise to new individuals through a back learning strategy based on the principles of lens imaging. e diagram is shown in Figure 1.
As shown in Figure 1, the globally optimal individual x P is giving its corresponding reversal point x p ′ , obtained from the principle of lens imaging: Let (h/h ′ ) � k, k be the scaling factor, and the inverse point obtained upon transformation is It follows that when k � 1, Form (6) is called general reverse learning strategy. From the above formulas, it can be seen that general learning strategy is only a specific case of lens imaging learning strategy, and the new individuals obtained by general reverse learning strategy are fixed each time. In high-dimensional complex functions, new individuals with fixed ranges are also likely to fall into local optimum with monotonicity; by adjusting the parameter k, new individuals based on lenses imaging learning strategies are dynamic, which improves population diversity. Extending the formula to D-dimensional space is available: In (7), x j p versus x ′j p are the j-th dimension components of x p versus x p ′ , and a j and b j represent the j-th dimension components at the upper and lower bounds of the decision variable, respectively.

Variable Spiral Search Strategy
While it is convenient for followers to follow the discoverer in updating their location, it is easy for followers to search blindly and singularly. Inspired by the rotation of the whale algorithm, this paper introduces a variable spiral location update strategy, which allows followers to have a variety of search paths to better update the location, while balancing the global and local search of the algorithm. e 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 weakening the search ability of the algorithm.
e parameter z is designed as an adaptive variable to dynamically adjust the spiral shape of follower search, which expands the follower's ability to explore unknown areas, makes the algorithm search more efficient, and improves the algorithm's global search performance. e formula for the variable spiral position update strategy is as follows: e parameter Z changes according to the number of iterations. e change of Z is determined by the exponential function based on e in formula (8), and the size and amplitude of the helix are dynamically adjusted according to the

Simulated Annealing Algorithm
Simulated annealing algorithm, derived from the principle of solid annealing, is a probability-based algorithm and a stochastic global optimization algorithm proposed by Metropolis et al. [11]. e simulated annealing algorithm is a classical algorithm and has been studied extensively. Its principle is not described here. e simulated annealing algorithm combines with the improved sparrow algorithm. e simulated annealing algorithm is used to refine the solution found by the sparrow search algorithm each time. It uses the sudden jump of the simulated annealing to get rid of the interference of local optimum and extracts the solution each time. e algorithm has good judgment ability and improves the quality of each solution and tends to be global.

Lens Learning Sparrow Search Algorithm
Sparrow search algorithm has deficiencies in the case of multidimensional complex functions. erefore, this paper presents a lens learning sparrow search algorithm. is algorithm applies the reverse learning strategy based on the principle of lenses to the discoverer stage of sparrow search, improving the diversity of the population and expanding the search range of individual sparrows. In the follower search phase, a variable spiral search strategy is introduced, which makes the follower search more detailed and flexible. Finally, this algorithm is combined with the simulated annealing algorithm, and the previously found solutions are filtered again to obtain the optimal solution. e algorithm works as follows.
(1) Initialize the population location, number, and number of iterations.
(9) Determine the P i of each particle at the current temperature T, and the formula is as follows: (10) Determine a new global optimal value f g from the current sparrow individual P i . (11) Determine whether the termination condition is met or not; if not, return to step (2). If so, proceed to the next step. (12) Output best position and minimum cost. e specific pseudocode is as follows (Algorithm 1).

Effectiveness Analysis
In order to better see the advantages of the improved strategy, the SPHEREFUNCTION function is taken as an example to analyze the effectiveness of the strategy of the LLSSA algorithm. Let the number of populations and the number of iterations be 50 and 10, respectively, and the individual distribution map after 10 iterations of each algorithm is obtained. e specific distribution maps are shown in Figures 3 and 4.
It can be seen from Figures 3 and 4 that the particles of LLSSA converge faster, most of the individuals are close to the optimal value, and the search range is wider, which is beneficial to jump out of the local optimum, while the particles of SSA converge slower, and the search range is smaller, which is easy to fall into the local optimum state in is shows that LLSSA has flexibility in the optimization mechanism and verifies the effectiveness of the three strategies.

Time Complexity Analysis
For an algorithm, time complexity is an important consideration, and it is also an important means of judging the amount of calculations of an algorithm. Suppose the population size of the algorithm is P, the maximum number of iterations is M, and the dimension of the problem is D. From a macro point of view, the SSA algorithm is the same as other intelligent optimization algorithms, with a time complexity of O (P × M × D), while the LLSSA algorithm does not add extra cycles in the optimization process, so in the entire algorithm, time complexity did not increase.
From a micropoint of view, suppose the ratio of discoverers is r, the calculation time of introducing reverse learning based on the lens principle is t 1 , the calculation time of the variable spiral search strategy is t 2 , and the calculation time of using the simulated annealing algorithm to update the optimal solution is t 3 . It can be seen from the pseudocode Input M: the maximum iterations PD: the number of producers SD: the number of sparrows who perceive the danger R 2 : the alarm value N: the number of sparrows λ: attenuation parameter Initialize a population of N sparrows and define its relevant Output: X best , f g Initialize the population according to equation (5) t � 1; While (t < M) Rank the fitness values and find the current best individual and the current worst individual. (1) For i � 1: PD Using equation (7) and equation (8) update the finder's location; End for For i � (PD + 1) : N Using equation (13) update the follower's location; End for For l � 1 : SD Updating the position of a sparrow individual who is aware of danger according to equation (3); End for Perform simulated annealing Get the current new location; If the new location is better than before, update it. t � t + 1 End while Return: X best , f g ALGORITHM 1: e framework of the LLSSA.   D(r(t1 − t2) + t2)) + t3) compared with the SSA algorithm. However, it has not been improved in the order of magnitude, and the optimization efficiency and accuracy of the algorithm can be effectively improved. erefore, the increased time complexity is significant and worthwhile.

Performance Testing
In order to further verify the feasibility and effectiveness of the improved sparrow search algorithm, this paper selects 15 standard test functions to verify its optimization performance. e specific information is shown in Table 1. In order to ensure the fairness of the experiment, all the algorithms are run on the computer with MATLAB 2018b, Windows 10 operating system, and 8g memory. e number of iterations of each algorithm is 200 and the number of population is 50. e initial temperature is t � 50, λ � 0.75, and the parameters of PSO algorithm are C 1 � C 2 � 2, w � 0.729.
At the same time, in order to exclude the contingency of each algorithm and enhance persuasion, the three indexes of optimal value, average value, and standard deviation of each algorithm's search result are counted, and the three indexes are used to judge the optimization ability and stability of each algorithm.
As can be seen from Table 2, the LLSSA algorithm has the best search performance in F 1-7 , F 10-11 , F 15 and has better search ability than other algorithms. In the F 9 function, BSO is the best. In F 13-14 , BSO can find the best one, but its stability is poor, and the optimization results on other functions are extremely poor. erefore, BSO has some limitations in function optimization. LLSSA achieves good results on many function problems. It is inferior only to BSO in F 9 , which shows that LLSSA has strong optimization ability. Other algorithms have achieved poor optimization results. erefore, the introduction and fusion of simulated annealing make the sparrow search algorithm have strong local judgment ability, balance the local and global search, and improve the search ability of the algorithm.
To describe the convergence of each algorithm in each function, the average convergence of each algorithm in each function is counted, and the specific convergence effect is shown in Figure 5. From Figure 5, it can be clearly seen that LLSSA has excellent convergence performance in F1-5, F8, F11-12, F14 functions, which all have advantages in accuracy and speed. However, among F6-7, F9-10, F15 functions, the convergence accuracy is high and the speed is slow, while it has advantages in other functions, but it is not significant. Generally speaking, LLSSA overcomes the limitations of the original algorithm search mechanism, has a reliable optimization scheme, and has greater advantages in speed and accuracy.
Comparing algorithms based on mean and standard deviation alone is not enough. To be more persuasive, statistical tests are needed to verify that the proposed improved algorithm has significant improvement advantages over other existing algorithms. To determine whether each result of LLSSA is statistically significantly different from the best results of other algorithms, the Wilcoxon rank sum test was used at the 5% significance level. e P values calculated in the Wilcoxon rank sum test between LLSSA and other algorithms are given in Table 3 for all the benchmark functions. When P < 5%, the HO hypothesis can be considered rejected, indicating a significant difference between the two algorithms. When P < 5%, it can be assumed that the HO hypothesis is accepted, indicating that the difference between the two algorithms is not obvious; that is, the optimization performance of the two algorithms is equal.
erefore, an algorithm with equivalent performance in each function is marked as N/A, indicating that it is not applicable. e algorithm differences table is shown in Table 3.
From Table 3, there is a big difference between each algorithm and LLSSA as a whole. Only on the first two unimodal functions, the basic SSA itself can find the optimal value. erefore, there is no significant difference between LLSSA, SSA, and CSSA, but only on the F10 function, the P value is greater than 0.05. e experimental results show that BSO has better optimization ability on this function.

Application and Analysis
e proposal and improvement of an algorithm are ultimately to be implemented in the actual project. Since the development of intelligent optimization algorithms, the improvement of multiple algorithms has been successfully applied to specific applications; for example: literature [12] proposed a novel metaheuristic based on integrating chaotic maps into a Henry gas solubility optimization algorithm, which achieved good results in welding beams and cantilever beams. Reference [13] proposed an adaptive metaheuristic algorithm based on decomposition in order to solve the multitarget complex problem in UAV flight. e above authors have all proposed suitable algorithms in actual problems. erefore, this paper applies the LLSSA algorithm to the UAV path planning of three-dimensional complex terrain to verify the feasibility and practicability of the LLSSA algorithm.
In recent years, the problem of UAV path planning has been widely favored by researchers. UAV path planning is also one of the problems of automatic control. Common path planning methods include genetic algorithm [14], particle swarm and ant colony algorithm [15], artificial potential field method [16], and gray wolf algorithm, but for complex high-dimensional problems such as path planning, the functions of these algorithms are limited. Many factors considered are difficult for each algorithm. For complex path planning problems, the algorithm is very easy to meet the current minimum cost and give up the overall plan, lack of autonomous learning. erefore, researchers have made different improvement measures for the deficiencies of each algorithm to make the optimized path more ideal. Aiming at the problem of path planning in three-dimensional complex       terrain, this paper proposes to integrate the improved sparrow search algorithm with the simulated annealing algorithm, so that the algorithm avoids the local optimal solution in the solving process and finds a clear and simple path with the smallest cost function.

Cost Function Design.
Cost function is an indispensable part of route planning. e more reasonable the cost function is set, the closer it is to the real demand. e cost function designed in this paper is as follows: J cost represents the total cost of the path, and J length , J height , and J smooth represent the total length cost, total height cost, and smoothness cost of the path, respectively. w 1 , w 2 , and w 3 are the corresponding weights. In this paper, w 1 � 0.5, e cost function can be used to evaluate the quality of the generated path, which is the basis of iterative evolution of algorithm population. e performance of cost function determines the efficiency and quality of algorithm implementation, and it is also the performance index of path planning. In order to better evaluate the path quality, this paper constructs the fitness function [17][18][19] by comprehensively considering the height cost, length cost, and smoothness cost of the path. Suppose each path is composed of n points. x, y are the point coordinates of the terrain projected on the horizontal plane, and z is the height corresponding to the point coordinates on the horizontal plane.

Path Length Cost.
Path length is one of the most important indicators to evaluate the quality of a path. e shorter the path is, the less energy and time consumption the UAV will take to fly. e cost of introducing path length is as follows:

High Cost.
e stable flight height of the UAV is also an important part of the UAV track planning process. For most aircraft, the flight height should not change much. Stable flight height helps to reduce the burden on the control system and save more fuel. erefore, the cost of introducing track elevation is

Smoothness Cost.
When an UAV is making a turn, it needs to consume some energy due to the air resistance and at the same time exerts some pressure on the body. e smaller the turning angle, the greater the pressure generated and the more energy consumed, making the flight inefficient. erefore, the smoothness of flight is also a key factor in the cost of flight.
φ j �→ represents the degree of deviation between the previous position and this position, and J smooth describes the cumulative sum of the degree of deviation of the connected nodes in the entire path. It is used to simulate the turbulence during the flight of the UAV. e smaller the turbulence, the higher the safety inside and outside the UAV.

Simulation Experiment and Analysis
In order to verify the feasibility and practicability of the fusion algorithm to optimize the effect of UAV, it is compared with SAPSO, PSO, SSA, and CSSA. e parameters of each algorithm are set as follows: the number of population is 100, the number of iterations is 400, the initial temperature T is 25, λ � 0.99, and the specific experimental model parameters are shown in Table 4. In order to enhance the persuasion of the experiment and reduce the interference of accidental events, each algorithm runs 10 times independently and counts the minimum value, average value, and the worst value of each planned route. e optimal roadmap of each algorithm is shown in Figure 6, the performance index of each algorithm is shown in Table 5, and the average cost function convergence diagram is shown in Figure 7.
As you can see from Figures 6 and 7 and Table 4, the LLSSA and SAPSO algorithms optimize the UAV's path to be the simplest and clearest. e CSSA, SSA, and PSO optimization routes appear to be distorted, obviously falling into a local optimal state. From the performance index table of each algorithm, LLSSA has better convergence accuracy and stability than SAPSO, and other algorithms have poorer stability, with the worst cost value exceeding 50. From the average cost convergence graph, it can be seen that the LLSSA algorithm has extremely fast convergence speed and accuracy. It found a path with the least cost before 50 iterations. e route found by the SSA algorithm is poor, complex, and costly, indicating that the SSA algorithm has limitations in solving such complex multidimensional functions. At the same time, it also shows that in complex path planning problems, the algorithm will meet the current minimum cost and fall into a local optimal state. erefore, a flexible and judging search mechanism is needed to make the algorithm get rid of the constraints of the complex environment.
Similarly, in order to further verify the feasibility and significance of the algorithm on the UAV route, Wilcoxon test as described above is conducted among the algorithms, and the rank sum test results are shown in Table 6.
It can be seen from Table 6 and the above comprehensive situation that the algorithm that introduces the simulated annealing strategy has a greater advantage in route planning. e performance of the PSO algorithm and the CSSA algorithm is equivalent, and the SSA algorithm is the worst. Applicable to SSA algorithm, a flexible search mechanism and judgment strategy should be added to make the improved SSA algorithm stand out.

Conclusion
In this paper, aiming at the problem that the sparrow search algorithm falls into the local optimum and depends on the initial population in the optimization process, the reverse learning strategy based on the lens principle and the variable cosine search strategy are introduced, which are applied to the stage of discoverer and follower, respectively, making the search method more flexible and careful. en the simulated annealing algorithm is fused to extract the optimal solution. rough the test of standard test function, it can be seen that LLSSA has good optimization ability and convergence effect. It is applied to the path planning of UAV in three-dimensional complex terrain. rough the comparison of CSSA, SSA, SAPSO, and PSO optimization UAV route planning, it shows that LLSSA optimization UAV path is the simplest and clearest, and the cost is the least. rough the planning route index table and the average cost function convergence diagram, it shows that LLSSA has good stability, so its application in UAV path planning has high reliability. It can be seen that in the process of sparrow optimization, if the leading discoverer is limited, the whole algorithm will be paralyzed, and the solution found each time is not necessarily reliable. erefore, it is extremely important to effectively improve the discoverer's search mechanism and judgment ability. It can be seen from the above experiments that LLSSA relies on the judgment ability of simulated annealing algorithm in complex terrain path planning problems. Although this method can improve the quality of route optimization, it does not necessarily have a good effect in simple path planning problems, and it increases the calculation time, which is still a challenge in multiple complex environments. In the next step, we apply it to the path planning of multimission UAV.

Data Availability
e data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest
e authors declare that they have no conflicts of interest.