ANovel SparrowParticle SwarmAlgorithm ( SPSA ) forUnmanned Aerial Vehicle Path Planning

Unmanned aerial vehicle (UAV) has been widely used in various fields, andmeeting practical high-quality flight paths is one of the crucial functions ofUAV.Many algorithmshave the problemof too fast convergence and premature inUAVpath planning.+is study proposed a sparrow particle swarm algorithm for UAV path planning, the SPSA.+e algorithm selects a suitable model for path initialization, changes the discoverer position update, and reinforces the influence of start-end line on path search, which can significantly reduce blind search.+e number of target points reached is increased by adaptive variable speed escapes in areas of deadlock. In this case, the planned trajectory will fluctuate, and adaptive oscillation optimization can effectively reduce the fluctuation of the path. Finally, the optimal path is simplified, and the path nodes are interpolatedwith cubic splines to improve the smoothness of the path,which improves the smoothness of theUAVflight trajectory andmakes it more suitable for use as the UAV real flight trajectory. By comparison, it can be concluded that the improved SPSA has good convergence speed and better search results and can avoid local optimality.


Introduction
Unmanned aerial vehicle (UAV) has been widely used in various fields, such as transportation, rescue, and military, with the continuous progress of technology. Compared with ground robot path planning, the path planning of UAV in 3D environment increases the complexity of trajectory calculation as the spatial dimension rises. UAVs are affected by buildings, weather, and their energy consumption during flight, so how to plan a safer, more efficient, and faster path is an ongoing hot research problem. Traditional algorithms such as the A * algorithm [1], artificial potential field method [2,3], and RRT [4] have been used for path planning, but most of them still suffer from high computational complexity and local convergence.
A heuristic algorithm is a new solution algorithm obtained by imitating various natural phenomena and summarizing and refining that natural phenomenon. e heuristic algorithm can solve some problems that ordinary methods cannot solve. e UAV path planning problem is a multivariate problem in the real environment to find the optimal solution. Many scholars have studied this problem with heuristic algorithms [5][6][7][8][9][10][11] to find suitable solutions. Duan [12] et al. used the maximum-minimum adaptive ant colony optimization algorithm to replan the UAV collaborative path in dynamic and uncertain environments, determine the time for the UAV to reach the conflict point, and then determine the flight trajectory and speed of the UAV to avoid static threats and popup threats. Shiri et al. [13] proposed a neural network-assisted online control algorithm for remote UAV paths that enable UAV to make control decisions locally in harsh communication environments, thereby reducing travel time. Qu [14] et al. proposed a reinforcement learning algorithm based on the grey wolf algorithm that adaptively switches selection by controlling the performance accumulated by individual four operations of exploration, exploitation, geometric adjustment, and optimal adjustment, which has better results than other improved grey wolf algorithms. Duan [15] et al. proposed a UAV path planning based on an improved water droplet algorithm, which considers the effects of ice accumulation, Richardson number, meteorological changes, and different flight altitudes on UAV path planning. ey used the virtual potential field method to adjust the flight direction of the UAV to perform static path planning and dynamic path planning for the UAV. Liu [16] et al. proposed an evolutionary algorithm based on the evolutionary algorithm for UAV path planning, which changes the t distribution algorithm to effectively solve the high computational complexity and low efficiency in UAV dynamic path planning. e sparrow search algorithm [17] is a new heuristic algorithm proposed by Jiankai Xue in 2020, and it is a group intelligence algorithm that imitates sparrow predation. e algorithm has the characteristics of fast convergence and meritseeking solid ability. e sparrow search algorithm has been widely used in the field of control engineering, for example, tracking the maximum power point [18], network configuration [19], and path planning field [20]. Liu [21] proposed a modified sparrow search algorithm (CASSA) to balance the convergence speed and searchability. e algorithm improved the efficiency of path planning by the Corsi-Gaussian variation strategy and adaptive inertia weights. Ouyang [22] proposed the learning sparrow search algorithm (LSSA) to improve stability and security. is algorithm solves the shortcomings of strong randomness and easy to fall into local optimum. Abdulhammed [23] applied the sparrow search algorithm to the load balancing problem of cloud computing by separately provisioning different tasks to shorten the server response time and reduce power consumption. e algorithm shows that the advantages of fast convergence and good searchability of the sparrow search algorithm are highly applicable in solving engineering problems.
Particle swarm algorithm [24] is an algorithm proposed by James Kennedy and Russell Eberhart, which has the characteristics of fast convergence and simple structure. Many scholars have applied it to various optimization scenarios [25][26][27][28][29][30] and achieved good results. Li [31] proposed an SLPSO algorithm for solving collision hazards, insufficiently smooth paths, and long planning paths of mobile robots in path planning, and the experimental results showed that the algorithm is effective and feasible. Phung [32] proposed an improved discrete particle swarm algorithm (DPSO) to be used in UAV path planning to improve the algorithm's performance through qualitative initialization, random variation, and edge swapping by taking advantage of parallel computing. Foo [33] proposed a particle swarm algorithmbased 3D UAV path planning that considers the fuel consumption of the UAV, flies over specified obstacles, and leaps over specified reconnaissance targets. abit [34] proposed a multi-robot particle swarm optimization algorithm for multi-UAV path planning in unknown situations. e robot decides the direction of movement based on the information collected by sensors and combines probabilistic windows to obtain current information and previous robot experience to select the path with better fitness.
In the field of human-machine path planning, the current UAV still suffers from the problem of locally optimal solutions, making it difficult to search for globally optimal paths. A novel SPSA is proposed for this problem, which guides the subsequent path search through path initialization. e discoverer position update rule is improved to enhance the search near the start-end line. Adaptive variable speed escape search is used to improve the search efficiency of paths when obstacles are encountered. Adopting adaptive oscillation optimization reduces path fluctuations and improves path smoothing. Finally, the path smoothness is improved by simplifying the nodes and smoothing process, which is more suitable for path planning in the real environment. It is also verified that the SPSA has a shorter convergence path and lower energy consumption than other algorithms. e structure of this study is as follows: Section 2 establishes the environment model that matches the actual situation. Section 3 describes the specific implementation of the sparrow search algorithm and the particle swarm algorithm. Section 4 describes the specific implementation of the SPSA. Section 5 draws the corresponding structure and flow chart for the structure of the SPSA. Section 6 analyzes the experimental results for the algorithm complexity analysis and experimental results. Section 7 concludes the SPSA.

Environment Modelling
In the actual complex environment, the UAV will encounter multiple threats such as obstacles and trees in reaching the target set from the start point, and sometimes, it also needs to consider the climate, the energy of the UAV, and other factors. e main problem of UAV path planning is the path optimization problem considering multiple disturbance factors. By building a mathematical model, the optimal flight path is calculated.

Environmental Model Building.
e movement of the UAV is less restricted by the terrain and can reach the target point quickly in a complex environment, but the trajectory of the UAV's movement is in a three-dimensional environment.
e three-dimensional environment is more complicated than the two-dimensional environment. e amount of calculation will also be tremendous. To reduce the time of UAV path calculation, the establishment of a suitable model has an important influence on the calculation of the optimal path. is study adopts the modelling method in the literature [35]. Each time the position is selected, it will move forward by one unit in the x-axis direction, simplifying the three-dimensional path problem into a two-dimensional path planning problem.
Assuming that the velocity of the UAV flight is variable and disregarding the effect of the structure of the UAV on the flight, the square tall building in the real environment is equated to a square obstacle, and the cylindrical building is equated to a cylindrical obstacle, as shown in Figure 1.

Adaptability Calculation.
e trajectory of the UAV flight is usually close to the line between the start point and the endpoint (start-end line) when avoiding obstacles, while the path should be as smooth as possible. e distance and the safety of UAV from the obstacles are considered in the literature [14]. However, the computational effort also increases with the increase in obstacles, which is not conducive to finding the globally optimal path. Considering the energy loss of UAV, a new fitness calculation is proposed as follows: 2 Scientific Programming e fitness value of UAV flight E is the total energy required for UAV path planning. E path is the energy consumed for all planned paths assuming that the UAV flies at a constant speed. E turning indicates the additional energy consumed for UAV flight turning. E climb indicates the energy is required for UAV climbing and landing. E climb represents the energy consumption for climbing and landing. It is assumed that the energy of the UAV flight consists of three parts, and one part is the energy of uniform flight, and it is assumed that the energy consumption of this part is proportional to the distance flown. e second part is that when turning, there will be additional turning energy loss in addition to the first part of energy. When the turning angle is larger, as the speed remains the same centripetal force is needed to do work, more energy is needed to maintain a constant speed and complete the flight turning. Similarly, more work is required to move the aircraft in the vertical direction, assuming that the energy required by the UAV is proportional to the distance travelled in the vertical direction. Each part of the solution equation is as follows: |Δz|. (2) Here, x s , y s , and z s denote the coordinates of x, y, and z axes of the nodes, respectively, μ 0 denotes the turning angle coefficient, and θ denotes the angle between two adjacent line segments. When the angle is larger, the trajectory is smoother, and the fuel cost is lower. When the turn is smaller, the UAV needs to slow down, steer, and accelerate the process, which will consume more fuel. |Δz| denotes the variation on the z-axis between two adjacent nodes, where k 0 , k 1 , and k 2 are scale factors. e fitness is performed by cubic spline interpolation, and the summation is performed for each slice of the fitness, which is similar to the energy consumption in the real situation.
As the UAV flight in the actual situation of variable speed flight needs to adjust the route to avoid trees, buildings, and other obstacles, UAV flight steering requires more energy E turning , while for the flight trajectory without substantial height oscillation, the flight altitude constantly changes will also consume more energy. In general, the optimal adaptation in UAV flight corresponds to a smooth and smooth flight trajectory.

Basic Theoretical Algorithms
e choice of the algorithm has an essential impact on path planning. A suitable algorithm can improve the convergence of the optimal path and avoid local optima.
is section describes the specific implementation of the involved sparrow search algorithm and particle swarm algorithm.

Basic Sparrow Search Algorithm.
e sparrow search algorithm is a novel bionic algorithm with fast convergence and merit-seeking solid ability. Sparrows are divided into producers and scroungers. e identities of producers and scroungers can be interchanged, but the weight remains the same in the population. e producer with good adaptation in the sparrow search algorithm will get food first. e producers' positions are updated by the following equation Scientific Programming Here, t denotes the current iteration, i denotes the serial number of the current scrounger, j denotes the dimension, α is a random number, and iter max denotes the maximum number of iterations. r 2 and ST denote the warning value and safety value, which are constants, Q is a random number, and L is a 1 × d matrix, and each element is 1. When R 2 < ST, it means there are no predators around the foraging environment, and the scrounger can conduct an extensive search. If R 2 ≥ ST, it means that some sparrows in the population found the predator and alerted other sparrows, and then, the sparrows needed to fly to other places for foraging. e scrounger will watch the scrounger, and if it perceives that the scrounger has found better food, it will leave its present position to grab the food, and if it wins, it gets the scrounger's food. e scrounger's position is updated as follows: Here, P t+1 i,j denotes the optimal position of the next iteration, P t worst is the worst position in the current iteration, and n is the number of scroungers, where A denotes a 1 × d matrix where each element is randomly assigned to 1 or -1, and A + � A T (AA T ) −1 . When i > n/2, the less adapted scroungers need to fly elsewhere in search of food.
Sparrows aware of the danger account for 10% to 20% of the total population. e locations of these sparrows are updated as follows: Here, P t best is the current global best position, β and K are random numbers, f g and f w are the current global best and worst fitness values, and ε is a constant to avoid the denominator being zero. e presence of obstacles in the environment of UAV path planning can interfere with the sparrow search algorithm to search the optimal and worst paths, resulting in the presence of unsearchable target points and loss of good search routes. Since the absolute value of each element in A + is the same, the presence of obstacles in the planned path loses the number of individuals.

Basic Particle Swarm Algorithm.
e particle swarm algorithm is an algorithm that is studied by imitating the predatory behaviour of a flock of birds. e particle swarm algorithm uses massless particles to simulate the birds in a flock, and the particles have velocity and position properties. e optimal solution obtained by each particle searching for a single individual in space is used as the individual's extremum, and the extremum of all individuals is used as the optimal global solution. All particles in the swarm adjust their velocity and position according to the current individual extreme value and the optimal global solution.
e particle swarm algorithm first initializes the position of the particle itself and adjusts its position by iteration. In each iteration, the particle adjusts its speed by the extreme individual value and the optimal global solution, thus changing its position. e particle swarm algorithm velocity and position updates are shown in equations (6) and (7) as follows: Here, V ij denotes the velocity in j-dimensional space of the particle with index i, P l best ij denotes the position in j-dimension corresponding to the particle with index i obtaining the local extremum, and P g best j denotes the position in j-dimension corresponding to the optimal global solution obtained by all particles. Rand is a random number from 0 to 1, and c1 and c2 are learning factors. e corresponding pseudocode for the basic particle swarm algorithm 1 is shown below.

Path Initialization.
UAV path planning is a pathfinding optimization that considers multiple environmental constraints and the UAV's dynamics. e selection of the next adjacent path node is affected by obstacles and the current node position constraints, and from safety considerations, the UAV cannot cross obstacles from the current node to the next node. e path initialization of the sparrow particle swarm algorithm has an essential impact on the convergence of the subsequent sparrow search algorithm. A good path initialization can effectively improve the search efficiency and prevent the path from generating large oscillations that do not conform to the characteristics of the smooth movement of the UAV in the real environment, for which a path initialization method is proposed.
Assuming a variable speed of the UAV, the UAV should tend to fly to the target point if the target point is known. As shown in Figure 2, P a denotes the current position and P Target denotes the position of the target point. X a denotes the x-axis coordinates corresponding to the current position, and P a+1 is the next point to be determined, and it is the orange point in Figure 2. P t is the centre of the following available coordinate range determined from the current 4 Scientific Programming point P a and the coordinates of the target point. P t is calculated according to the following equation: Here, m is the difference between the horizontal coordinate X a+m of the target point and the horizontal coordinate X a of the current point P a . P a+1 is chosen by the following formula: Here, round denotes rounding. rand is a random value from 0 to 1. Δh denotes half of the square length of the range of selectable coordinate points.
During the initialization process, each time the individual confirms the following position based on the current point and the target point, this improved method can avoid too much difference between two adjacent nodes during the UAV movement, interfering with the subsequent convergence.

Improving the Producer Location Update Formula.
e traditional sparrow search algorithm with better pathfinding capability can lead to stagnant search in an environment with more obstacles, thus losing more individuals. e intelligence body has weaker search capability in an environment with more obstacles, leading to local convergence of the path search. e current speed of the particle swarm algorithm is affected by the globally optimal path, assuming that there are no obstacles between the start point and the target point. e optimal path is start-end line. If there is an obstacle, the shortest path should be closer to the start-end line. Using the start-end line as an idealized global optimal path increases the influence of this optimal global path on the producer and enhances the producer's ability to find the optimal solution in the start-end line and enhance the ability to search near the start-end line by changing the producer's function.
Here, P ST is the corresponding coordinate position on the start-end line. rand is a random number from 0 to 1. By increasing the difference between the current path and the start-end line, the searchability around the start-end line is strengthened to avoid falling into the local optimum.

Initialize
Set the basic parameters For each particle i Initialize velocity and position of particles Calculate fitness f i and set p Best i � f i End For g Best � f i For each iteration For each particle Update the position and velocity using by (6) and (7) Calculate the fitness f i

Adaptive Variable Speed Escape Search.
In the sparrow search algorithm, when i > n/2, it indicates that the sparrow needs to fly to other places to find food for more energy, since each element in A + has the same absolute value and is a number from 0 to 1 (excluding 0 and 1). Since the values of formula (4) running to P t+1 i,j , P t+1 P , A + , and L have been fixed, when the next node is unreachable due to obstacles, even if the search is carried out again, it still cannot reach the next node, which is the same as the last one, and at this time, the path search is stalled. For this stagnation, the adaptive variable speed escape exploration is inspired by the particle swarm algorithm.
When the scrounger flies to other places in search of food, if the next node is unreachable, the scrounger searches at the lowest speed and searches ten times, and if a moveable node cannot be found, the speed of movement is increased. If there is a moveable node, the search stops, and the point is taken as the current point. Every ten searches are no moveable point, and then, the speed increases by one until it reaches the maximum search speed. If it still cannot find a moveable node, then the search ends.
Here, V cur denotes the current velocity, increasing from the lowest velocity, since the globally optimal path corresponds to the smallest possible distance between two adjacent points. e pseudocode for the variable speed escape search Algorithm 2 is shown below.

Adaptive Oscillation Optimization.
Since there are random numbers in the selection of paths and significant differences between other paths and the current path, it leads to the planning with oscillation. e oscillation of the drone trajectory will interfere with the judgment of the optimal path adaptation value and easily fall into local minima. e oscillating trajectory will also consume more energy of the UAV and is not suitable as the actual UAV flight trajectory.
For addressing this problem, an adaptive oscillation optimization method is proposed to optimize the planned original path with adaptive oscillation to reduce the trajectory oscillation of the UAV. To reduce the path oscillation at certain points, the overall trajectory trend is judged by its multiple adjacent points to reduce the path oscillation better. e trajectory optimization equation is as follows: Here, round means rounding the value. N P is the number of adjacent nodes that will have an impact on the current position (including the node itself ), the maximum value of N P is 5, and the minimum value is 3. Initially, the value of N P is 5. e optimization of the current position is influenced by the position of the previous node, this node, and the next three nodes. If the optimized position P i,j ′ has obstacles, then the value of N P is subtracted by 1 and re-optimized. If N P is less than 3, no position optimization is performed for the current point. As shown in Figure 3, the original trajectory is blue, and the path after adaptive oscillation optimization is red, which shows that the smooth trajectory has better smoothness.

Simplification of Path Nodes and Smoothing.
e paths after adaptive oscillation optimization have lower oscillation compared with the original paths. e UAV should move in a straight line or smoothly as much as possible in the actual environment. To make the path more realistic, the SPSA finally converges and simplifies the optimal path nodes found to facilitate the subsequent smoothing process with the third spline interpolation.
In Figure 4(a), a simplified diagram of the nodes is shown, where the black line represents the planned path and the blue line represents the simplified path nodes. Point A can reach points B, C, and D, and cannot reach points E and F. Assuming that the UAV reaches point F from point A, which subsequent nodes can be reached from point A is first determined. e corresponding vector is (1, 1, 1, 0, 0), where 1 represents that it can be reached safely and 0 means that it cannot be reached safely, and there are obstacles in the linear path. e last one among these nodes sorted to represent the node that can be reached is D, and it is taken as the current node. When the current node is D, judging the subsequent nodes is continued, assuming that point D can reach point E and point F, the corresponding path vector is (1, 1), and then F is selected as the next node.
is method can effectively avoid the situation that the path is not streamlined enough due to path oscillation, etc. For example, point A′ in Figure 4(b) can reach points B′, C′, D′, and F′, corresponding to the vectors (1, 1, 1, 0, 1). Due to the presence of obstacles, point A′ cannot reach point E′, so directly choose F′ as the next node. Points A′, D′, and F′ form a triangle in space, by the triangle. e sum of line segment A′D′ and line segment D′F′ is greater than A′F′ by the law, from which it can be concluded that this optimization method can minimize the path. e triple spline interpolation function can improve the path's smoothness and reduce the path's twists and turns, and the path is more consistent with the flight path of the UAV as a real environment. e simplified path can be smoothed better by the cubic spline interpolation function, which reduces the turn amplitude in the path and saves the energy consumption of the UAV.

Structure of the Sparrow Particle Swarm
Algorithm. e pseudocode of the sparrow particle swarm algorithm Algorithm 3 is shown below.

Flow chart of the Sparrow Particle Swarm Algorithm.
e sparrow particle swarm algorithm flow chart is shown in Figure 5. 6 Scientific Programming

Experimental Simulation and Result Analysis
To verify the feasibility of the sparrow particle swarm algorithm for path planning, experimental simulations are conducted in three different environments with increasing complexity, and each algorithm is simulated 30 times in each case. e equipment parameters of this simulation experiment are as follows: CPU is Intel(R) Xeon(R) E5-2450H @ 2.10 GHz; graphic card is GTX 1050 Ti; memory space is 32G; and simulation software is MATLAB 2020b.
To verify the performance of the algorithms, we need to avoid the effect of path initialization and perform the same path initialization for all the compared algorithms. In the Update the position by equation (4) Initialize the velocity V cur of individual: V cur � V min Set T � 0 While the position can not reach Update the position by equation (12

End While End For End For
Optimize adaptive oscillation using equation (13) Update position of all individuals Calculate and sort fitness values End For Perform node optimization on the optimal path and smooth optimization Return results Terminate ALGORITHM 3: Sparrow particle swarm algorithm (SPSA) pseudocode. 8 Scientific Programming initialization phase and the algorithm iteration phase: the initialization phase is executed only once and the algorithm iteration phase is executed according to the iteration cycle. e dimension to be calculated for each individual is D, the number of individuals is N, the maximum number of iterations is M, the range of movement in the y-axis and z-axis directions selected during initialization is A and B, respectively, and SD is the proportion of sparrows found to be in danger. e structure of the sparrow search algorithm for path planning in three-dimensional space is O (N × D × A × B + M × N × D), where the complexity of the initialized path is O (N × D × A × B). e computational complexity of the path iterative search optimization is O (M × N × D).
e SPSA increases some computational complexity due to the enhanced ability to optimize the search path, and the complexity of the adaptive oscillation Start Initialize the path usIng Eq. (10), Eq. (11) and Eq. (12) Optimize adaptive oscillation using Eq.
Whether to reach the number of iterations Update the next node of the producer using Eq. Update the next node of the scrounger using Eq. (6) Search for the next position by adaptive escape using Eq. (14) Whether all scroungers complete the search Whether all individuals that find dangers complete the search Update the next node of the individuals that find dangers using Eq.
Optimize adaptive oscillation using Eq.   . It shows that the SPSA also has a fast convergence rate.

Analysis of Experimental Results.
To verify the effect of the simplified node on the path, the experimental results are shown in Figure 6. e red line is the trajectory curve of the path without the simplified node after three times of spline interpolation, and the blue line is the curve after three times    of spline interpolation after the simplified node. It can be seen that there is almost no oscillation in the x-axis and y-axis directions, and there is oscillation in the z-axis direction for the nodes of the un-simplified path, which shows that the simplified path is more suitable as the flight path of the UAV.
It can be seen in Figures 7-9 that the SPSA has better convergence than other algorithms. e SSA has better smoothness than the paths planned by CSO, DE, GWO, and PSO algorithms, which all show different degrees of oscillation, and the altitude of the flight trajectory keeps changing with less smoothness. Oscillation optimizes and simplifies the nodes, improves the smoothness of the trajectory, and is more suitable for smooth operation as a UAV. e fitness values of SPSA in Figures 10-12 can converge to the optimal value faster than other algorithms. For the presence of different obstacles in the UAV-specific constrained    Scientific Programming environment, increasing the influence of the start-end line on the producer strengthens the searchability of the individuals near the start-end line, leading to a path that can converge quickly. e SPSA has significantly better results in the first iteration due to the start-end line guidance, which makes the path shorter than other algorithms. For the stability of the actual UAV flight path, the adaptive oscillation optimization makes it possible that there is no excessive distance difference between two adjacent path nodes, making the path length much shorter and achieving better results than other algorithms. e exploration of the optimal path is avoided by oscillatory optimization to avoid missing the optimal path. Figures 13-15 show that the SPSA is highly robust in different environments.
From the mean, worst, optimal, and standard deviation of different algorithms in Table 2, we can see that the CSO algorithm has the worst convergence effect in path planning. Because in the CSO algorithm, there are differences in the routes between each individual, the smooth paths may be affected by other paths leading to oscillations instead of easy convergence. DE algorithm, PSO algorithm, and SSA have better convergence effect as the iteration increases, and the iterative oscillation of the path makes it difficult to converge  to a better path. By comparison, the SPSA has better convergence stability and the lowest fitness value due to the directional nature of the path search, which strengthens the ability of individuals to search near the start-end line. e smoothness of the paths is improved by continuously optimizing the paths and avoiding the oscillating paths from interfering with the convergence of subsequent paths.

Conclusions
e traditional SSA algorithm is suitable for the optimization search algorithm performed in an unconstrained environment. In the real environment, various environmental factors will affect the SSA algorithm planning path, resulting in poor convergence of the algorithm and loss of more individuals. To address this situation, strengthening the search efficiency and improving the path smoothing are the main problems that need to be solved for UAV path planning. In this study, we combine the sparrow search algorithm and particle swarm algorithm to propose the SPSA, and the main contributions of this study are as follows: (1) Path initialization has a guiding role in the convergence of the subsequent algorithm. e next node's range is calculated according to the spatial geometry, and then, the node that can be moved within the range is randomly selected as the next node. is method avoids the interference of the initialization path trajectory oscillation on the convergence of the subsequent algorithm and can ensure the search capability of the algorithm.
(2) Position update of the producer. e start-end line as the globally optimal path, combined with the particle swarm algorithm, improves the position update of the producer in the sparrow particle swarm algorithm, strengthening the searchability of the algorithm near the start-end line. (3) e searchability of discovering dangerous individuals. Due to the existence of A^+ in the position update formula of the sparrow found to be dangerous in the algorithm, the path may not reach the target point and lose the searched individuals. Inspired by the particle swarm algorithm, a variable speed escape search method is proposed to improve the sparrow search algorithm when the next node is unreachable, improve the path's exploration ability, and reduce the loss of the searched individuals. (4) Adaptive oscillation optimization. For the randomness on path selection resulting in oscillation, an adaptive oscillation optimization method is proposed to reduce the interference of path oscillation to the subsequent path search and improve the smoothness of the path. (5) Simplify node and smoothing processing. Node optimization can reduce the path turning points and improve the smoothness of the path, making the path suitable as the actual flight trajectory of the UAV.
rough simulation experiments, it can be concluded that the sparrow particle swarm algorithm has better convergence and stronger searchability in complex environments, and the smoothed path is suitable as the flight path of the UAV.

Data Availability
e data used to support the findings of this study are included within the article.

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