# Three-Dimensional DV-Hop Localization Algorithm Based on Hop Size Correction and Improved Sparrow Search

Authors: Pingzhang Gou; Zhaoyang Yu; Xinyue Hu; Kai Miao
Journal: Wireless Communications and Mobile Computing
 (2022)

---

## Abstract

Acquiring precise localization information of sensor nodes is very important in wireless sensor networks. The 3DDV-hop localization algorithm suffers from large localization errors and high energy consumption. In order to improve positioning accuracy and reduce energy consumption, a 3DDV-hop node localization algorithm (3D-HCSSA) based on hop size correction and improved sparrow search optimization is proposed. The algorithm redefines the amendment factor and reduces the cumulative error caused by the hop counts in the traditional algorithm. A maximum distance similar link method based on a similar path search is proposed to find the most similar known node path pair from the target node to the noncoplanar known node link and correct the hop size between multihop counts. The sparrow search algorithm is improved by using thek-means clustering and sine cosine search strategy, which solves the problem that the traditional sparrow algorithm is easy to fall into the local optimum, accelerates the convergence speed, corrects the position deviation of the target node, and improves the positioning accuracy. Experiments demonstrate that the 3D-HCSSA algorithm can improve positioning accuracy and reduce energy consumption. Compared with the 3DDV-hop algorithm, 3D-GAIDV-hop algorithm, and HCLSO-3D algorithm, the 3D-HCSSA positioning accuracy is significantly improved.


---

## Body

## 1. Introduction

Wireless sensor networks (WSNs) is a multihop counts wireless network that incorporates nodes to sense, collect, and process target node information, enabling access to objective physical information, extending information acquisition capabilities, and providing the most direct and accurate information in next-generation wireless networks [1]. In next-generation technology, Non-orthogonal Multiple Access (NOMA) allocates different power to known nodes (a node whose own position is known) and target nodes which have different residual energy in WSNs, saving the known node energy consumption problem by using the Successive Interference Cancellation (SIC) technique. Therefore, this technique can be extended to be used in next-generation networks for larger-scale scenarios [2]. Localization information is one of the basic elements of sensor network monitoring data and in many cases is the basis of the application. Monitoring data without localization information is often worthless, for example, monitoring events such as forest fires and the presence of enemy vehicles on the battlefield, all of which need to determine the specific localization of the event, to achieve the localization, and to track the monitoring target. Therefore, the estimation of target node location is a key issue in wireless sensor networks [3]. It is a challenging work about how to design a localization algorithm with low hardware requirements and low communication and computing overhead. Researchers have proposed some WSNs localization algorithms, which can be broadly classified into two categories: range-based and range-free algorithms [4]. The range-based algorithm calculates the localization of target nodes by measuring the distance or angle information between nodes. Although the effect is more accurate, it requires complex and expensive hardware equipment [5]. The main algorithms based on the range-based approach are the Time of Arrival (TOA) method [6, 7], Time Difference of Arrival (TDOA) method [8], and Angle of Arrival (AOA) method [9]. The localization method based on the range-free approach does not need distance and angle information but only carries out node localization according to some information such as network connectivity. Without additional complex equipment, the positioning accuracy is lower than that of the algorithm based on the range-based method. The typical localization methods based on the range-free algorithm include the centroid algorithm [10], approximate triangle interior point test algorithm [11, 12], and DV-hop localization algorithm [13].The DV-hop localization algorithm was proposed by Dragoş et al. [14]. It is a localization method of WSNs that directly measures the distance among nodes without additional hardware equipment [15]. In terms of implementation, the DV-hop localization algorithm only relies on the connectivity of the whole network, so the implementation of the DV-hop localization algorithm is relatively simple and less costly to set up the network. However, cumulative errors occur during the hop size estimation stage, resulting in large errors between the expected and actual distances between the known node and the target node. In the localization stage, there is also a certain error between the actual position and the expected position of the target node. In the DV-hop localization algorithm, a swarm intelligence optimization algorithm is usually used to reduce the localization error of target nodes. Nowadays, swarm intelligence algorithms are commonly used in DV-hop localization algorithms to optimize algorithms to reduce the target node localization error; classical swarm intelligence algorithms such as particle swarm optimization algorithm (PSO) [16], genetic algorithm [17], ant colony optimization algorithm [18], grey wolf optimization algorithm [19], and bacterial foraging optimization algorithm [20]; and some novel optimization algorithms proposed in recent years, such as the sparrow search algorithm [21], the squirrel search algorithm [22], and the butterfly optimization algorithm [23]. Particle swarm optimization is a common algorithm used by researchers to optimize the DV-hop localization algorithm. In Kanwar and Kumar [24] by adjusting a few particle parameters and extending the target node to the selected known node, the objective function of the particle swarm optimization algorithm is established to provide better positioning accuracy in resource-constrained environment through iteration. However, the increase in parameters will lead to the complexity of the operation and increase the complexity of the algorithm. Singh and Sharma [25] first found the feasibility region of each target node and determined the initial position velocity of the particle in the feasibility region. Secondly, update the particles in the estimation of the particle fitness function. Finally, the optimal position of target nodes can be determined after the iteration is completed by setting the number of iterations. Singh and Sharma [26] used the PSO algorithm to further correct the proposed two-dimensional hyperbolic algorithm to determine the localization of target nodes. Firstly, find out the survival area of each target node and determine the initial position and velocity of the particles in the feasible area; secondly, estimate the fitness of each particle; and finally, obtain the optimal solution through iteration, which is the optimal position of the target node. However, this algorithm does not optimize the PSO algorithm, which will result in slow convergence; the algorithm is easy to fall into a local optimum during the solution process; and the algorithm complexity and space complexity will also increase. In Zhang et al. [27], the PSO algorithm is used to further correct the proposed two-dimensional hyperbolic algorithm to determine the localization of unknown nodes. Firstly, find out the survival region of each unknown node, and determine the initial position and velocity of particles in the feasible region; secondly, the fitness of each particle is estimated; and finally, the optimal solution obtained through iteration is the optimal localization of unknown nodes. The algorithm improves the positioning accuracy but increases the number of operations during the iterative process, which leads to an increase in the complexity of the algorithm. Fang et al. [28] used the exponentially decreasing function to improve the inertia weights because the inertia weight values in the PSO algorithm affect the network optimization speed effect, and the improved PSO algorithm can correct the position of the target node more effectively, thus improving the positioning accuracy. However, the method only optimizes the algorithm itself, but not the global optimization of the algorithm, so the algorithm is prone to problems such as local optimization.Other swarm intelligence algorithms optimize DV-hop localization algorithms. Cai et al. [29] proposed weight convergence analysis of the DV-hop localization algorithm based on the genetic algorithm (MW-GADV-hop). Since the traditional weight model does not analyze the convergence and ignores the relationship between weight and error, this algorithm establishes a weight model based on error variation and proves the convergence of the model, which improves the positioning accuracy. However, some results in the weight model with error variation do not converge to 1/4 communication radius, so the convergence of the model is insufficient, which will eventually affect the positioning accuracy. Kanwar and Kumar [30] proposed a DV-hop based range-free localization algorithm for WSNs using runner-root optimization (RRADV-hop). The rotary root algorithm is used to determine the fitness function, and the one with the smallest value of the fitness function through iteration is the corrected target node coordinate. The rotation root optimization algorithm is not initialized, leading to slow convergence of the algorithm and affecting the positioning accuracy. Mohanta and Das [31] proposed a class topper optimization-based improved localization algorithm in a wireless sensor network (CTODV-hop). A two-dimensional hyperbolic algorithm is used to calculate the target node localization, and by the class topper optimization approach, the efficiency and reliability of the algorithm are improved, the localization error is reduced, and the complexity of the algorithm is decreased. Jacob et al. [32] proposed a modified search and rescue optimization-based node localization technique in WSNs (MSRODV-hop). By the MSRO-NLT method, the problem of solving the target node coordinates is transformed into the problem of solving the minimum in mathematics; this method reduces the number of iterations of the algorithm. However, the algorithm only optimizes the local optimum and does not solve the problem of fast convergence, and it is difficult to cover all solution sets completely.We combine the above studies, a 3DDV-hop localization algorithm based on hop size correction and improved sparrow search is proposed, which further reduces the hop size and localization error and improves the positioning accuracy. The main work of this article is as follows:(1)
The maximum distance similar link method is proposed. Based on the traditional similar path search algorithm, a pair of known node paths most similar to the link from the target node to a specific noncoplanar known node is found, and the multihop size between the known node and the target node is modified, which reduces the hop size calculation overhead and improves the positioning accuracy of the algorithm(2)
TheK-means clustering algorithm is introduced to solve the problem that the traditional sparrow search algorithm is easy to fall into the local optimum when initializing. In the optimization scrounger position update stage, in order to avoid the poor effect of the scrounger position update stage in finding the optimal, the positive cosine search strategy is introduced to enhance the convergence of the sparrow search algorithm and improve the convergence accuracy. The fitness function is redesigned so that the fitness value can correct the target node position deviation after iterationThe remainder of this article is summarized as follows. The second part summarizes the related work. The third part states the 3DDV-hop localization algorithm, the traditional sparrow search algorithm, and the improved sparrow search algorithm. The fourth part mentions the localization algorithm of 3D-HCSSA. The fifth part analyzes the experimental results. The sixth part draws conclusions.


## 2. Related Work

The 3DDV-hop algorithm mainly locates nodes by network connectivity and topology structure. It has low requirements on hardware devices and simple calculation, but nodes are distributed in different areas, resulting in different node densities. The average hop size of target nodes depends on one known node in the whole region. When there are too many known nodes in the region, the hop size of nodes will be wasted, and one known node cannot reflect the network environment of WSNs. If the known node is close to the target node and there is an error in the average hop size itself, the error will be directly transmitted to the target node; then, the error accuracy within the whole network decreases.In the 3DDV-hop localization algorithm, various optimization algorithms and improvement methods can reduce the node localization error. Gou et al. [33] proposed a three-dimensional localization algorithm (HCLSO-3D) based on hop correction and lion swarm optimization in WSNs. The fitness function values of each type of lion are rearranged in ascending order, and the position of the lion with the smallest fitness value is the optimal position of the target node. The position of the lion king with the lowest fitness value was the optimal localization of the target node. However, this article only improves the fitness function and does not initialize the lion swarm algorithm, which leads to problems such as local optimization and slow convergence speed. Kaushik et al. [34] proposed an improved 3DDV-hop localization algorithm (I3D-DVLAIN) based on neighbouring node information. By adopting a new method of solving the equations, subtract the last distance equation from all the other distance equations and then divide the equations by the maximum distance equation. Therefore, the error propagation is reduced, and the mathematical analysis of error propagation proves that the method can effectively improve the positioning accuracy. Due to the large number of parameters and related equations in the operation of this method, the calculation difficulty and algorithm complexity are increased during the calculation. In Kanwar and Kumar [35] firstly, the localization of the target node is corrected by the hyperbolic method. Then, the optimal target node localization was obtained by iterating through single-objective and multiobjective functions, respectively, which improved the robustness of the algorithm. However, there are many function variables and complex process in the iterative process, which increases the algorithm overhead. Cheng et al. [36] introduced that the ratio of the number of common neighbour nodes belonging to two nodes that are neighbour nodes to each other to the number of all neighbour nodes of the two nodes is used to replace the volume ratio of the area where the corresponding nodes are located, reversely solve the relation between the continuous hop count and the node ratio, and use the parameter-corrected relationship to calculate the continuous hop count, thereby reducing the distance estimation error, improving the positioning accuracy, but also increasing the algorithm complexity. Cai et al. [37] proposed a multiobjective three-dimensional DV-hop localization algorithm (N2-3DDV-hop) based on NSGA-II. Firstly, a multitarget model and NSGA-II were added to analyze the limitations of the traditional single-target localization model. Secondly, a multiobjective localization model is proposed in combination with the NSGA-II algorithm, and the target node coordinates are derived by iterating according to the model. Due to the large number of parameters and related equations in the algorithm, the calculation difficulty and algorithm complexity are increased. Sharma and Kumar [38] proposed using the genetic algorithm to improve the range-free localization of three-dimensional WSNs (3D-GAIDV-hop). Firstly, the genetic algorithm is introduced to accelerate the convergence speed. Secondly, the fitness function is redesigned; the optimal position of the target node coordinates is the one with the smallest adaptation value by iteration. The minimum fitness value is the optimal localization of the target node coordinate, and the positioning accuracy is improved. However, there is the problem that the algorithm is difficult to cover all solution sets.Based on the above research, this article is mainly aimed at the inaccurate problem of hop count division, hop size setting, and target node coordinate calculation of the 3DDV-hop localization algorithm and proposes a 3DDV-hop localization algorithm based on hop size correction and improved sparrow search. With the HCSSA localization algorithm (3D-DV-hop based on hop size correction and improved sparrow search algorithm), this article divides the optimal hop count by redefining the amendment factor and proposes the maximum distance similar link method to correct the multihop size between nodes.K-means clustering and sine-cosine search strategy are introduced to improve the traditional sparrow search algorithm to correct the coordinate deviation of target nodes. In conclusion, the 3D-HCSSA localization algorithm improves the node positioning accuracy and reduces the algorithm energy consumption.


## 3. 3DDV-Hop Localization Algorithm and Sparrow Search Algorithm

### 3.1. 3DDV-Hop Localization Algorithm

The 3DDV-hop (three-dimensional distance vector-hop) localization algorithm is a distributed localization algorithm based on the range-free approach [39]. The algorithm consists of three phases.Step 1.
Calculate the minimum hop count of the target node and each known node. The known node floods its information group to the neighbour node, including the localization information of the known node and the hop count with an initial value of zero. By receiving the minimum counts of hop for each known node, ignoring the group from the same known node with a larger count of hop, the hop count is automatically added by 1 and finally forwarded to the neighbour nodes.Step 2.
Calculate the distance between the target node and the known node. The known nodes calculate the average hop size by each known node based on the minimum counts of hop of other known nodes recorded in Step1, and broadcast the average hop size information in the network to estimate the average hop size:
(1)AveHopsizeI=∑I≠JxI−XJ′2+yI−YJ′2+zI−ZJ′2∑I≠JhIJ,where xI,yI,zI,XJ′,YJ′,ZJ′ are the coordinates of known nodes I and J, respectively; hIJ is the hop count between the two known nodes; and AveHopsizeI is the average hop size of known node I. Each known node uses equation (1) to estimate the average actual distance per hop based on the localization information and the number of hop counts away from other known nodes recorded in the first phase.
The distance from the known node to the target node is given by the following equation:(2)HSIu=AveHopsizeI×HopIu,where HopIu is the hop count between the known node I and the target node u.Step 3.
Calculate the coordinates of target nodes. After deriving the expected distances between four and more target nodes to the known node in a three-dimensional space, the coordinates of the target nodes are calculated by the great likelihood estimation method.


### 3.2. Sparrow Search Algorithm

The sparrow search algorithm (SSA) is a swarm intelligence optimization algorithm inspired by sparrow foraging and antipredation behaviour proposed by Xue and Shin [21] in 2020. There are two roles in SSA: producer and scrounger. Producers forage and provide guidance, while the scrounger obtains food through the producer. In order to better obtain quality food, members of the population monitor each other’s behaviour, and in order to increase their own predation rate, scroungers compete for food with the high intake sparrows. The localization of the sparrow population can be expressed as
(3)Π=Π1,1Π1,2⋯⋯Π1,dΠ2,1Π2,2⋯⋯Π2,d⋮⋮⋮⋮⋮Πn,1Πn,2⋯⋯Πn,d,where n represents the number of the sparrow population and d is the optimal dimension.The fitness of each sparrow is(4)FitnessΠ=ςΠ1,ςΠ2⋯ςΠnT,where ςΠ1,ςΠ2⋯ςΠn are the fitness values of each sparrow, respectively.Define producer updated localization:(5)xi,jt+1=xi,jt∙exp−iα∙itermax,ifR2<ST,xi,jt+Q∙L,ifR2≥ST,where t represents the current iteration number and itermax represents a constant of the maximum iteration number. xi,j represents the position information of the ith sparrow in dimension j. α∈0,1 is a random number. R2∈0,1 and ST∈0.5,1 represent the warning value and the safe value, respectively. Q is a random number. L represents a 1×d matrix. When R2<ST, it represents that there are no predators around the foraging environment at this time, and the producer can perform extensive search operations. When R2≥ST, indicating the detection of a predator and alerting members, all sparrows fled to a safe place before foraging.The updated localization of the scrounger is defined as follows:(6)xi,jt+1=Q∙expxworstt−xi,jti2,ifi>n2,xpt+1+xi,jt−xpt+1∙A+∙L,otherwise,where Xp is the producer optimal localization and Xworst is the global worst position. A represents a matrix of 1×d, where the elements have random values of −1 or 1, and A+=ATAAT−1. i>n/2 represents that the ith scrounger with a low fitness value has not obtained food, is in a hungry state, and needs to forage for food in order to forage for more food in other places.SSA has strong local search ability and fast convergence speed but weak global search ability and weak operation of jumping out of the local optimum. Therefore, this article initializes the initial coordinates of known nodes and target nodes and proposes a method to further optimize the SSA when figuring out the target node coordinates.


### 3.3. Improved Sparrow Search Algorithm

This article improves the sparrow search algorithm by introducingK-means clustering and sine-cosine search strategy, using mathematical methods and clustering algorithm to optimize the sparrow search algorithm, solving the problem that the sparrow population is prone to fall into the local optimum when initializing, and improving the convergence accuracy and optimization effect of the traditional SSA. The improved SSA is applied to the third phase of the 3DDV-hop localization algorithm calculating target node coordinates. Through simulation experiments, the improved SSA accelerates the convergence speed and solves the problem that the algorithm is easy to fall into the local optimum and corrects the deviation of target node coordinates. In summary, the improved SSA can solve the problem of position deviation when calculating the target node coordinates and improve the positioning accuracy.


#### 3.3.1.K-means Clustering Initialization

Since the SSA uses the random distribution principle in population initialization, the principle suffers from the problem that the sparrow population initialization cannot completely cover the solution space and there are coverage voids, which makes it difficult to traverse various cases of the solution set in the population and leads to the problem that the algorithm is prone to fall into the local optimum under complex multipeaked functions. Therefore, in this article, theK-means clustering method is used to solve the deficiency that the algorithm is prone to fall into the local optimum when the population is initialized [40].By choosing a similarity measurement method, the two-sample producer and scrounger are divided separately. Among them, the producer represents the known node coordinate, and the scrounger represents the target node coordinate. This partitioning makes the data within the same category as similar as possible. Using the Euclidean distance as the measurement standard, the samples with similar distances are divided into different class clusters until the set of the two samples initially divided is obtained. The mean value of each class cluster sample was taken as the centre of the next cluster, and the distance between the remaining samples and the new cluster centre was calculated and classified. Iterate repeatedly until the clustering criterion function converges or reaches the number of iterations and finally improves the global search ability of SSA.w=Θ,Ξ is divided into two clusters: w1,w2, where wi=Θi,ΞiT, c1,c2 are the two initial clustering centers, and the methods used in the clustering process are as follows:Euclidean distance between samplesΘ, Ξ:
(7)dΘ,Ξ=Θ−ΞTΘ−Ξ.Average distance from sampleΘ to all samples:
(8)m=1n∑dΘ,Ξ.Sample variance:(9)var=1n−1∑dΘ,Ξ−m2.Average distance of data set samples:(10)d=2nn−1∑∑dΘ,Ξ.Sum of squares of error:(11)S=∑i=12∑Θ−ci2.Assuming a population size of100, Figures 1 and 2 are the populations initialized by random distribution and K-means clustering, respectively. After the comparison between Figures 1 and 2, it is obvious that the population distribution of the latter is more uniform than that of the former, which fully covers the knowledge space. Therefore, the algorithm has better ergodicity and improves the global search ability.Figure 1
Randomly distributed initial population.Figure 2
K-means cluster initialization population.


#### 3.3.2. Sine-Cosine Search Strategy

The sine and cosine search strategy was proposed by Mirjalili in 2016 [41], and its main idea is to enhance the convergence of the algorithm by iteratively continuously optimizing the solution set of the objective function through the mathematical method sine and cosine function properties for the local and global search of the population. In the SSA, the scrounger position update is mainly influenced by the discoverer, which leads to the disadvantage of poor algorithm search effect, and in order to improve the convergence accuracy and search effect, this article uses an improved sine and cosine search strategy to optimize the producer position [41].The improved sine and cosine search strategy expression can be expressed as(12)ϕϱ+1=ϕϱ+r1∙sinr2∙Dr3<0.5,ϕϱ+r1∙cosr2∙Dr3≥0.5,where r2,r3 are random factors and the corresponding value ranges are 0,360° and 0,1, respectively. Among them, r2 determines the moving distance in the iterative process, r3 is the random weight coefficient assigned to the current optimal solution to enhance (when r3>1) or weaken (when r3<1) the influence of the optimal solution on the defined distance, and r1 represents the control factor, which is a linear decreasing function that controls the fluctuation amplitude of the sine and cosine function and also determines the movement direction of the iteration. If r1<1, the next solution will move from the current solution to the region of the optimal solution; if r1>1, it will move in the reverse direction. The expression of the control factor is as follows:
(13)r1=ε1−tT,where ε is a constant and T represents the maximum number of iterations.The process of seeking optimization of the sine-cosine optimization algorithm mainly includes two phases: global search and local search. As the number of iterationst increases, r1 demonstrates a linear decreasing trend. Therefore, the convergence speed of the algorithm further accelerated the convergence rate. The optimized position of the scrounger is iteratively calculated by using the sine-cosine search strategy (equation (13)) and the control factor (expressions (14) and (15)).
(14)D=r4∙xit−xiti=1,2⋯d,where r4 is the random factor on 0,1, which represents the switching condition of the iterative equation of the sine and cosine function.
(15)r3=ε−ε∙tM,where M represents the number of iterations and ε is a constant.


## 3.1. 3DDV-Hop Localization Algorithm

The 3DDV-hop (three-dimensional distance vector-hop) localization algorithm is a distributed localization algorithm based on the range-free approach [39]. The algorithm consists of three phases.Step 1.
Calculate the minimum hop count of the target node and each known node. The known node floods its information group to the neighbour node, including the localization information of the known node and the hop count with an initial value of zero. By receiving the minimum counts of hop for each known node, ignoring the group from the same known node with a larger count of hop, the hop count is automatically added by 1 and finally forwarded to the neighbour nodes.Step 2.
Calculate the distance between the target node and the known node. The known nodes calculate the average hop size by each known node based on the minimum counts of hop of other known nodes recorded in Step1, and broadcast the average hop size information in the network to estimate the average hop size:
(1)AveHopsizeI=∑I≠JxI−XJ′2+yI−YJ′2+zI−ZJ′2∑I≠JhIJ,where xI,yI,zI,XJ′,YJ′,ZJ′ are the coordinates of known nodes I and J, respectively; hIJ is the hop count between the two known nodes; and AveHopsizeI is the average hop size of known node I. Each known node uses equation (1) to estimate the average actual distance per hop based on the localization information and the number of hop counts away from other known nodes recorded in the first phase.
The distance from the known node to the target node is given by the following equation:(2)HSIu=AveHopsizeI×HopIu,where HopIu is the hop count between the known node I and the target node u.Step 3.
Calculate the coordinates of target nodes. After deriving the expected distances between four and more target nodes to the known node in a three-dimensional space, the coordinates of the target nodes are calculated by the great likelihood estimation method.


## 3.2. Sparrow Search Algorithm

The sparrow search algorithm (SSA) is a swarm intelligence optimization algorithm inspired by sparrow foraging and antipredation behaviour proposed by Xue and Shin [21] in 2020. There are two roles in SSA: producer and scrounger. Producers forage and provide guidance, while the scrounger obtains food through the producer. In order to better obtain quality food, members of the population monitor each other’s behaviour, and in order to increase their own predation rate, scroungers compete for food with the high intake sparrows. The localization of the sparrow population can be expressed as
(3)Π=Π1,1Π1,2⋯⋯Π1,dΠ2,1Π2,2⋯⋯Π2,d⋮⋮⋮⋮⋮Πn,1Πn,2⋯⋯Πn,d,where n represents the number of the sparrow population and d is the optimal dimension.The fitness of each sparrow is(4)FitnessΠ=ςΠ1,ςΠ2⋯ςΠnT,where ςΠ1,ςΠ2⋯ςΠn are the fitness values of each sparrow, respectively.Define producer updated localization:(5)xi,jt+1=xi,jt∙exp−iα∙itermax,ifR2<ST,xi,jt+Q∙L,ifR2≥ST,where t represents the current iteration number and itermax represents a constant of the maximum iteration number. xi,j represents the position information of the ith sparrow in dimension j. α∈0,1 is a random number. R2∈0,1 and ST∈0.5,1 represent the warning value and the safe value, respectively. Q is a random number. L represents a 1×d matrix. When R2<ST, it represents that there are no predators around the foraging environment at this time, and the producer can perform extensive search operations. When R2≥ST, indicating the detection of a predator and alerting members, all sparrows fled to a safe place before foraging.The updated localization of the scrounger is defined as follows:(6)xi,jt+1=Q∙expxworstt−xi,jti2,ifi>n2,xpt+1+xi,jt−xpt+1∙A+∙L,otherwise,where Xp is the producer optimal localization and Xworst is the global worst position. A represents a matrix of 1×d, where the elements have random values of −1 or 1, and A+=ATAAT−1. i>n/2 represents that the ith scrounger with a low fitness value has not obtained food, is in a hungry state, and needs to forage for food in order to forage for more food in other places.SSA has strong local search ability and fast convergence speed but weak global search ability and weak operation of jumping out of the local optimum. Therefore, this article initializes the initial coordinates of known nodes and target nodes and proposes a method to further optimize the SSA when figuring out the target node coordinates.


## 3.3. Improved Sparrow Search Algorithm

This article improves the sparrow search algorithm by introducingK-means clustering and sine-cosine search strategy, using mathematical methods and clustering algorithm to optimize the sparrow search algorithm, solving the problem that the sparrow population is prone to fall into the local optimum when initializing, and improving the convergence accuracy and optimization effect of the traditional SSA. The improved SSA is applied to the third phase of the 3DDV-hop localization algorithm calculating target node coordinates. Through simulation experiments, the improved SSA accelerates the convergence speed and solves the problem that the algorithm is easy to fall into the local optimum and corrects the deviation of target node coordinates. In summary, the improved SSA can solve the problem of position deviation when calculating the target node coordinates and improve the positioning accuracy.


### 3.3.1.K-means Clustering Initialization

Since the SSA uses the random distribution principle in population initialization, the principle suffers from the problem that the sparrow population initialization cannot completely cover the solution space and there are coverage voids, which makes it difficult to traverse various cases of the solution set in the population and leads to the problem that the algorithm is prone to fall into the local optimum under complex multipeaked functions. Therefore, in this article, theK-means clustering method is used to solve the deficiency that the algorithm is prone to fall into the local optimum when the population is initialized [40].By choosing a similarity measurement method, the two-sample producer and scrounger are divided separately. Among them, the producer represents the known node coordinate, and the scrounger represents the target node coordinate. This partitioning makes the data within the same category as similar as possible. Using the Euclidean distance as the measurement standard, the samples with similar distances are divided into different class clusters until the set of the two samples initially divided is obtained. The mean value of each class cluster sample was taken as the centre of the next cluster, and the distance between the remaining samples and the new cluster centre was calculated and classified. Iterate repeatedly until the clustering criterion function converges or reaches the number of iterations and finally improves the global search ability of SSA.w=Θ,Ξ is divided into two clusters: w1,w2, where wi=Θi,ΞiT, c1,c2 are the two initial clustering centers, and the methods used in the clustering process are as follows:Euclidean distance between samplesΘ, Ξ:
(7)dΘ,Ξ=Θ−ΞTΘ−Ξ.Average distance from sampleΘ to all samples:
(8)m=1n∑dΘ,Ξ.Sample variance:(9)var=1n−1∑dΘ,Ξ−m2.Average distance of data set samples:(10)d=2nn−1∑∑dΘ,Ξ.Sum of squares of error:(11)S=∑i=12∑Θ−ci2.Assuming a population size of100, Figures 1 and 2 are the populations initialized by random distribution and K-means clustering, respectively. After the comparison between Figures 1 and 2, it is obvious that the population distribution of the latter is more uniform than that of the former, which fully covers the knowledge space. Therefore, the algorithm has better ergodicity and improves the global search ability.Figure 1
Randomly distributed initial population.Figure 2
K-means cluster initialization population.


### 3.3.2. Sine-Cosine Search Strategy

The sine and cosine search strategy was proposed by Mirjalili in 2016 [41], and its main idea is to enhance the convergence of the algorithm by iteratively continuously optimizing the solution set of the objective function through the mathematical method sine and cosine function properties for the local and global search of the population. In the SSA, the scrounger position update is mainly influenced by the discoverer, which leads to the disadvantage of poor algorithm search effect, and in order to improve the convergence accuracy and search effect, this article uses an improved sine and cosine search strategy to optimize the producer position [41].The improved sine and cosine search strategy expression can be expressed as(12)ϕϱ+1=ϕϱ+r1∙sinr2∙Dr3<0.5,ϕϱ+r1∙cosr2∙Dr3≥0.5,where r2,r3 are random factors and the corresponding value ranges are 0,360° and 0,1, respectively. Among them, r2 determines the moving distance in the iterative process, r3 is the random weight coefficient assigned to the current optimal solution to enhance (when r3>1) or weaken (when r3<1) the influence of the optimal solution on the defined distance, and r1 represents the control factor, which is a linear decreasing function that controls the fluctuation amplitude of the sine and cosine function and also determines the movement direction of the iteration. If r1<1, the next solution will move from the current solution to the region of the optimal solution; if r1>1, it will move in the reverse direction. The expression of the control factor is as follows:
(13)r1=ε1−tT,where ε is a constant and T represents the maximum number of iterations.The process of seeking optimization of the sine-cosine optimization algorithm mainly includes two phases: global search and local search. As the number of iterationst increases, r1 demonstrates a linear decreasing trend. Therefore, the convergence speed of the algorithm further accelerated the convergence rate. The optimized position of the scrounger is iteratively calculated by using the sine-cosine search strategy (equation (13)) and the control factor (expressions (14) and (15)).
(14)D=r4∙xit−xiti=1,2⋯d,where r4 is the random factor on 0,1, which represents the switching condition of the iterative equation of the sine and cosine function.
(15)r3=ε−ε∙tM,where M represents the number of iterations and ε is a constant.


## 3.3.1.K-means Clustering Initialization

Since the SSA uses the random distribution principle in population initialization, the principle suffers from the problem that the sparrow population initialization cannot completely cover the solution space and there are coverage voids, which makes it difficult to traverse various cases of the solution set in the population and leads to the problem that the algorithm is prone to fall into the local optimum under complex multipeaked functions. Therefore, in this article, theK-means clustering method is used to solve the deficiency that the algorithm is prone to fall into the local optimum when the population is initialized [40].By choosing a similarity measurement method, the two-sample producer and scrounger are divided separately. Among them, the producer represents the known node coordinate, and the scrounger represents the target node coordinate. This partitioning makes the data within the same category as similar as possible. Using the Euclidean distance as the measurement standard, the samples with similar distances are divided into different class clusters until the set of the two samples initially divided is obtained. The mean value of each class cluster sample was taken as the centre of the next cluster, and the distance between the remaining samples and the new cluster centre was calculated and classified. Iterate repeatedly until the clustering criterion function converges or reaches the number of iterations and finally improves the global search ability of SSA.w=Θ,Ξ is divided into two clusters: w1,w2, where wi=Θi,ΞiT, c1,c2 are the two initial clustering centers, and the methods used in the clustering process are as follows:Euclidean distance between samplesΘ, Ξ:
(7)dΘ,Ξ=Θ−ΞTΘ−Ξ.Average distance from sampleΘ to all samples:
(8)m=1n∑dΘ,Ξ.Sample variance:(9)var=1n−1∑dΘ,Ξ−m2.Average distance of data set samples:(10)d=2nn−1∑∑dΘ,Ξ.Sum of squares of error:(11)S=∑i=12∑Θ−ci2.Assuming a population size of100, Figures 1 and 2 are the populations initialized by random distribution and K-means clustering, respectively. After the comparison between Figures 1 and 2, it is obvious that the population distribution of the latter is more uniform than that of the former, which fully covers the knowledge space. Therefore, the algorithm has better ergodicity and improves the global search ability.Figure 1
Randomly distributed initial population.Figure 2
K-means cluster initialization population.


## 3.3.2. Sine-Cosine Search Strategy

The sine and cosine search strategy was proposed by Mirjalili in 2016 [41], and its main idea is to enhance the convergence of the algorithm by iteratively continuously optimizing the solution set of the objective function through the mathematical method sine and cosine function properties for the local and global search of the population. In the SSA, the scrounger position update is mainly influenced by the discoverer, which leads to the disadvantage of poor algorithm search effect, and in order to improve the convergence accuracy and search effect, this article uses an improved sine and cosine search strategy to optimize the producer position [41].The improved sine and cosine search strategy expression can be expressed as(12)ϕϱ+1=ϕϱ+r1∙sinr2∙Dr3<0.5,ϕϱ+r1∙cosr2∙Dr3≥0.5,where r2,r3 are random factors and the corresponding value ranges are 0,360° and 0,1, respectively. Among them, r2 determines the moving distance in the iterative process, r3 is the random weight coefficient assigned to the current optimal solution to enhance (when r3>1) or weaken (when r3<1) the influence of the optimal solution on the defined distance, and r1 represents the control factor, which is a linear decreasing function that controls the fluctuation amplitude of the sine and cosine function and also determines the movement direction of the iteration. If r1<1, the next solution will move from the current solution to the region of the optimal solution; if r1>1, it will move in the reverse direction. The expression of the control factor is as follows:
(13)r1=ε1−tT,where ε is a constant and T represents the maximum number of iterations.The process of seeking optimization of the sine-cosine optimization algorithm mainly includes two phases: global search and local search. As the number of iterationst increases, r1 demonstrates a linear decreasing trend. Therefore, the convergence speed of the algorithm further accelerated the convergence rate. The optimized position of the scrounger is iteratively calculated by using the sine-cosine search strategy (equation (13)) and the control factor (expressions (14) and (15)).
(14)D=r4∙xit−xiti=1,2⋯d,where r4 is the random factor on 0,1, which represents the switching condition of the iterative equation of the sine and cosine function.
(15)r3=ε−ε∙tM,where M represents the number of iterations and ε is a constant.


## 4. 3D-HCSSA Localization Algorithm

The 3D-HCSSA algorithm in this article is based on the hop size correction and the improved sparrow algorithm to optimize the 3DDV-hop algorithm. The 3DDV-hop algorithm is improved and optimized from three aspects: hop count division, hop size correction, and optimization of target node coordinates. The simulation results demonstrate that the improved algorithm proves that its positioning accuracy has been improved from many aspects, and the node energy consumption is greatly reduced, resulting in a reduction in the overall energy consumption of the algorithm.


### 4.1. Calculate the Hop Count of the Known Node

In the 3DDV-hop algorithm, the distance between the target node within one hop of the known node and the known node in the actual network is different, which will result in lower localization accuracy. Therefore, it is necessary to optimize and improve the partition of hop count. By making a difference between the expected hop count of a known node and the perfect hop count, the ratio of the difference to the expected hop count redefines the amendment factor to reduce the cumulative error caused by hop count division. The specific steps are as follows.Step 1.
Set the perfect hop count. Suppose the real distance between known nodesi and j is dij; the ratio of real distance between known nodes i, j and the maximum communication radius R is defined as the perfect hop count Hij [42]:
(16)Hij=dijR.Step 2.
Set the amendment factor. The expected hop count of a known node makes a difference with the perfect hop count, and the ratio of the difference to the expected hop count is(17)φij=hij−Hijhij,where hij is the expected counts of hop between known nodes i,j. φij represents the amount of correction between the expected counts of hop and the perfect counts of hop which can reflect the difference between the expected counts of hop and the perfect counts of hop. Useφij to redefine the amendment factor φij as
(18)ωij=1−hij−Hijhij2.Step 3.
The corrected optimal hop count can be calculated by the amendment factor as(19)hij′=ωijhij,wherehij′ represents the optimal hop count.
The corrected optimal hop count obtained through the above steps can be used for the calculation of the next section.


### 4.2. Hop Size Correction

This section mainly amends the one-hop size and multihop size between the known node and target node.


#### 4.2.1. Correction of One-Hop Size

In the 3DDV-hop localization algorithm, the same average hop size is used between the known node and the target node to calculate, which not only increases the hop size error but also increases the energy cost. Therefore, in one-hop size, the distance value is derived as the hop size by proposing that through the signal strength value of the Received Signal Strength Indicator (RSSI).Since RSSI is based on the radio wave loss between the transmitting end and the receiving end, the transmission loss is converted into distance according to a specific signal model [43], and the most widely used logarithmic-normal distribution model is
(20)RSSddBm=Ptr−Plossd′−10αlog10dd′+xξ,where RSSd represents the signal strength received by the target node from a known node, d represents the distance between the known node and the target node, Ptr represents the transmission signal energy, Plossd′ represents the signal power loss at the reference distance d′, α represents the path loss index, whose value depends on the transmission medium, and d′ represents the reference distance. xξ represents the noise, which is a Gaussian random variable with a mean of 0. ξ is the standard deviation.According to equation (20), it can be concluded that the hop size between the known node and the target node is
(21)d=10d′RSSddBm−Ptr+Plossd′−xξ/10α.However, the RSSI values received by target nodes will be lost to a certain extent at a certain distance [44], resulting in deviations in the distance values, resulting in a cumulative error in the derived distance value. Therefore, we use the Gaussian fitting function to further correct the distance value. The collected RSSI values are processed through the Gaussian fitting function, the abnormal data are screened, and the processed RSSI values are substituted into equation (22) to obtain a more accurate internode distance. The optimized RSSI value is closer to the real hop size value. The Gaussian fitting function is as follows [45]:
(22)fxi=x0+Aσπ/2×e−2xi−μ2/σ2,where mean μ=∑i=1NRSSIi/N, standard deviation σ=∑i=1NRSSIi−μ2/N−1, x0 and A are undetermined coefficients, which are determined by the relationship between the known node position and the signal value, xi represents the ith signal distance value, and N is the total value of the received RSSI.Most of the RSSI values in the Gaussian function are distributed betweenμ−σ,μ+σ, and the average value of this interval represents that the measured and actual values are close to each other. After being filtered by Gaussian filtering, the currently observed RSSI value output is
(23)RSSI′=1n∑i=1nxixiϵμ−σ,μ+σ,where n represents the number of RSSI values in μ−σ,μ+σ.The ranging distance corrected by Gaussian fitting is the corrected distance of one-hop size:(24)dN=10d′RSSI′−Ptr+Plossd′−xξ/10α.


#### 4.2.2. Correction of Multihop Size

In this article, when calculating the multihop size between a known node and a target node, the maximum distance similar link method is proposed based on the classical similar path search algorithm, which corrects the average hop size between the target node and the known node by finding the most similar pair of known node paths for the link from the target node to the noncoplanar known node. As the corrected average hop size value between the known node and the multihop target node, the optimal distance is obtained by using this average hop size multiplied by the optimized optimal hop size.Step 1.
Determine the maximum similarity link. After the exchange of the node information, each node keeps the information of each known node, as well as the identification of other nodes in the path to the minimum hop count experienced by each known node. The similarity linkSL factor represents the path from the target node to a specific known node [46] and the degree of similarity between the paths from other known nodes to a specific known node. The calculation method is as follows:
(25)SLκ,ϖ=nκ∩ϖnκ×nϖ,where SLκ,ϖ represents the similarity between the path κ and path ϖ, κ represents target node to the specific noncoplanar known nodes by the minimum hop count between nodes on the link set of identification, ϖ represents the residual known node in the network to the specific noncoplanar between known nodes, after the minimum hop count by a collection of node id on a link, and n is the number of elements in set.
The similarity link factorSL is used to calculate the path from the target node to a specific noncoplanar known node and the similarity degree between the paths from other known nodes to a specific noncoplanar known node. The greater the value of SL, the higher the similarity degree. The path between the known nodes with the maximum value is determined as the possible path. When the calculated SL values with multiple paths are the same, compare the Euclidean distance between each known node pair in the same SL value path. When the distance between two points of the node is larger, the calculated energy consumption of the node path is smaller, and the calculated average hop size is closer to the actual each hop size. Therefore, the path with the largest Euclidean distance of known node is selected as the result.Step 2.
Calculate the average hop size of similar links with maximum distance. The path obtained by Step1 is the path between two known nodes, including specific known nodes. The Euclidean distance between nodes is calculated by using the coordinates of the two known nodes. The calculated distance is divided by the optimized minimum hop count between the two nodes, which is the average hop size used by the target node.Step 3.
Calculate the multihop size between the known node and the target node. To obtain the distance to the noncoplanar known node, each target node uses the calculated average hop size multiplied by the optimal hop count.


### 4.3. Calculate Target Node Coordinates

#### 4.3.1. Determine Fitness Value

The sine and cosine function search method effectively enhances the convergence of the sparrow algorithm, improves the convergence accuracy and the optimization effect, and improves the iterative efficiency. For this reason, this article redesigns the fitness function so that the fitness value after iteration can better correct the position deviation of the target node:(26)fitness=1n∙∑I=1nxI−XJ′2+yI−YJ′2+zI−ZJ′2−DI,u,where xI,yI,zI, XJ′,YJ′,ZJ′ are the coordinates of the target node and known node, respectively. DI,u is the distance from the target node u to the known node I.


#### 4.3.2. 3D-HCSSA Algorithm Flow

The localization process of the 3DDV-hop algorithm based on 3D-HCSSA can be described as follows:Step 1.
The algorithm revises the hop counts by redefining the amendment factor to determine the optimal hop counts.Step 2.
Firstly, the Gaussian fitting function is used to reduce the error between the measured and actual values of the one-hop size between the known node and the target node; secondly, the average hop size between the known node and the target node of this path is corrected according to the maximum distance similar link method proposed in this article, and the distance between the known node and the target node is calculated after the correction.Step 3.
In the three-dimensional space,100m×100m×100mk-means clustering and sine and cosine search strategy are used to improve the sparrow search algorithm to optimize the localization of target nodes. Set the number of sparrow populations, and set the number of iterations and the localization of the population in initialization.Step 4.
Calculate the fitness values of all sparrow individuals through the fitness function, sort the fitness values of all sparrow individuals, and record the current optimal and worst sparrow positions.Step 5.
The entire iterative process iterates according to equations (3), (4), (5), and (12)–(15), updates the population position and calculates the new fitness value, and records the fitness value and position of the best individual after the update.Step 6.
The algorithm loops and calculates Step5, and after iterating to the maximum, the global optimal position of the producer is obtained, that is, the optimal value of the coordinates of the target node and the algorithm.The flow chart of the 3D-HCSSA algorithm is shown in Figure3.Figure 3
Flow chart of the 3D-HCSSA algorithm.Algorithm1 is the pseudo-code of the spark search algorithm used to calculate the location of the target node.Algorithm 1: Sparrow optimization algorithm to calculate the target node coordinate value.
Algorithm1: Finalization method to solve the sparrow optimization algorithm to solve the coordinate valueInput: Known node coordinates, the distance from the target node to the corresponding known node.output Expected coordinates of target nodes.Initialize a population of n sparrows and define its relevant parameters: M, Maximum number of iterations; PD, Population Number of Producers; SD, the number of sparrows who perceive the danger; R2, Alert value; N, Total Population Quantity. //Initial parameter Value Represents the initialization parameter value1.While(t<G)// The iteration termination condition is judged2.     Sort the fitness values to find the current individual best and worst.3.   R2=rand (1)4.for i=1: PD5.     The updated producer localization is calculated by equation (3);6.end for7.for i=(PD+1): N8.      The updated scrounger positions are calculated by equations (12-15);9.end for10.for i=1:SD11.      The sparrow position is updated by equation (6);12.end for13.     Get the current latest position;14.    Update if the latest position is better than the previous one;15.    t = t +1;16.end while17.return Xbest, fg.


## 4.1. Calculate the Hop Count of the Known Node

In the 3DDV-hop algorithm, the distance between the target node within one hop of the known node and the known node in the actual network is different, which will result in lower localization accuracy. Therefore, it is necessary to optimize and improve the partition of hop count. By making a difference between the expected hop count of a known node and the perfect hop count, the ratio of the difference to the expected hop count redefines the amendment factor to reduce the cumulative error caused by hop count division. The specific steps are as follows.Step 1.
Set the perfect hop count. Suppose the real distance between known nodesi and j is dij; the ratio of real distance between known nodes i, j and the maximum communication radius R is defined as the perfect hop count Hij [42]:
(16)Hij=dijR.Step 2.
Set the amendment factor. The expected hop count of a known node makes a difference with the perfect hop count, and the ratio of the difference to the expected hop count is(17)φij=hij−Hijhij,where hij is the expected counts of hop between known nodes i,j. φij represents the amount of correction between the expected counts of hop and the perfect counts of hop which can reflect the difference between the expected counts of hop and the perfect counts of hop. Useφij to redefine the amendment factor φij as
(18)ωij=1−hij−Hijhij2.Step 3.
The corrected optimal hop count can be calculated by the amendment factor as(19)hij′=ωijhij,wherehij′ represents the optimal hop count.
The corrected optimal hop count obtained through the above steps can be used for the calculation of the next section.


## 4.2. Hop Size Correction

This section mainly amends the one-hop size and multihop size between the known node and target node.


### 4.2.1. Correction of One-Hop Size

In the 3DDV-hop localization algorithm, the same average hop size is used between the known node and the target node to calculate, which not only increases the hop size error but also increases the energy cost. Therefore, in one-hop size, the distance value is derived as the hop size by proposing that through the signal strength value of the Received Signal Strength Indicator (RSSI).Since RSSI is based on the radio wave loss between the transmitting end and the receiving end, the transmission loss is converted into distance according to a specific signal model [43], and the most widely used logarithmic-normal distribution model is
(20)RSSddBm=Ptr−Plossd′−10αlog10dd′+xξ,where RSSd represents the signal strength received by the target node from a known node, d represents the distance between the known node and the target node, Ptr represents the transmission signal energy, Plossd′ represents the signal power loss at the reference distance d′, α represents the path loss index, whose value depends on the transmission medium, and d′ represents the reference distance. xξ represents the noise, which is a Gaussian random variable with a mean of 0. ξ is the standard deviation.According to equation (20), it can be concluded that the hop size between the known node and the target node is
(21)d=10d′RSSddBm−Ptr+Plossd′−xξ/10α.However, the RSSI values received by target nodes will be lost to a certain extent at a certain distance [44], resulting in deviations in the distance values, resulting in a cumulative error in the derived distance value. Therefore, we use the Gaussian fitting function to further correct the distance value. The collected RSSI values are processed through the Gaussian fitting function, the abnormal data are screened, and the processed RSSI values are substituted into equation (22) to obtain a more accurate internode distance. The optimized RSSI value is closer to the real hop size value. The Gaussian fitting function is as follows [45]:
(22)fxi=x0+Aσπ/2×e−2xi−μ2/σ2,where mean μ=∑i=1NRSSIi/N, standard deviation σ=∑i=1NRSSIi−μ2/N−1, x0 and A are undetermined coefficients, which are determined by the relationship between the known node position and the signal value, xi represents the ith signal distance value, and N is the total value of the received RSSI.Most of the RSSI values in the Gaussian function are distributed betweenμ−σ,μ+σ, and the average value of this interval represents that the measured and actual values are close to each other. After being filtered by Gaussian filtering, the currently observed RSSI value output is
(23)RSSI′=1n∑i=1nxixiϵμ−σ,μ+σ,where n represents the number of RSSI values in μ−σ,μ+σ.The ranging distance corrected by Gaussian fitting is the corrected distance of one-hop size:(24)dN=10d′RSSI′−Ptr+Plossd′−xξ/10α.


### 4.2.2. Correction of Multihop Size

In this article, when calculating the multihop size between a known node and a target node, the maximum distance similar link method is proposed based on the classical similar path search algorithm, which corrects the average hop size between the target node and the known node by finding the most similar pair of known node paths for the link from the target node to the noncoplanar known node. As the corrected average hop size value between the known node and the multihop target node, the optimal distance is obtained by using this average hop size multiplied by the optimized optimal hop size.Step 1.
Determine the maximum similarity link. After the exchange of the node information, each node keeps the information of each known node, as well as the identification of other nodes in the path to the minimum hop count experienced by each known node. The similarity linkSL factor represents the path from the target node to a specific known node [46] and the degree of similarity between the paths from other known nodes to a specific known node. The calculation method is as follows:
(25)SLκ,ϖ=nκ∩ϖnκ×nϖ,where SLκ,ϖ represents the similarity between the path κ and path ϖ, κ represents target node to the specific noncoplanar known nodes by the minimum hop count between nodes on the link set of identification, ϖ represents the residual known node in the network to the specific noncoplanar between known nodes, after the minimum hop count by a collection of node id on a link, and n is the number of elements in set.
The similarity link factorSL is used to calculate the path from the target node to a specific noncoplanar known node and the similarity degree between the paths from other known nodes to a specific noncoplanar known node. The greater the value of SL, the higher the similarity degree. The path between the known nodes with the maximum value is determined as the possible path. When the calculated SL values with multiple paths are the same, compare the Euclidean distance between each known node pair in the same SL value path. When the distance between two points of the node is larger, the calculated energy consumption of the node path is smaller, and the calculated average hop size is closer to the actual each hop size. Therefore, the path with the largest Euclidean distance of known node is selected as the result.Step 2.
Calculate the average hop size of similar links with maximum distance. The path obtained by Step1 is the path between two known nodes, including specific known nodes. The Euclidean distance between nodes is calculated by using the coordinates of the two known nodes. The calculated distance is divided by the optimized minimum hop count between the two nodes, which is the average hop size used by the target node.Step 3.
Calculate the multihop size between the known node and the target node. To obtain the distance to the noncoplanar known node, each target node uses the calculated average hop size multiplied by the optimal hop count.


## 4.2.1. Correction of One-Hop Size

In the 3DDV-hop localization algorithm, the same average hop size is used between the known node and the target node to calculate, which not only increases the hop size error but also increases the energy cost. Therefore, in one-hop size, the distance value is derived as the hop size by proposing that through the signal strength value of the Received Signal Strength Indicator (RSSI).Since RSSI is based on the radio wave loss between the transmitting end and the receiving end, the transmission loss is converted into distance according to a specific signal model [43], and the most widely used logarithmic-normal distribution model is
(20)RSSddBm=Ptr−Plossd′−10αlog10dd′+xξ,where RSSd represents the signal strength received by the target node from a known node, d represents the distance between the known node and the target node, Ptr represents the transmission signal energy, Plossd′ represents the signal power loss at the reference distance d′, α represents the path loss index, whose value depends on the transmission medium, and d′ represents the reference distance. xξ represents the noise, which is a Gaussian random variable with a mean of 0. ξ is the standard deviation.According to equation (20), it can be concluded that the hop size between the known node and the target node is
(21)d=10d′RSSddBm−Ptr+Plossd′−xξ/10α.However, the RSSI values received by target nodes will be lost to a certain extent at a certain distance [44], resulting in deviations in the distance values, resulting in a cumulative error in the derived distance value. Therefore, we use the Gaussian fitting function to further correct the distance value. The collected RSSI values are processed through the Gaussian fitting function, the abnormal data are screened, and the processed RSSI values are substituted into equation (22) to obtain a more accurate internode distance. The optimized RSSI value is closer to the real hop size value. The Gaussian fitting function is as follows [45]:
(22)fxi=x0+Aσπ/2×e−2xi−μ2/σ2,where mean μ=∑i=1NRSSIi/N, standard deviation σ=∑i=1NRSSIi−μ2/N−1, x0 and A are undetermined coefficients, which are determined by the relationship between the known node position and the signal value, xi represents the ith signal distance value, and N is the total value of the received RSSI.Most of the RSSI values in the Gaussian function are distributed betweenμ−σ,μ+σ, and the average value of this interval represents that the measured and actual values are close to each other. After being filtered by Gaussian filtering, the currently observed RSSI value output is
(23)RSSI′=1n∑i=1nxixiϵμ−σ,μ+σ,where n represents the number of RSSI values in μ−σ,μ+σ.The ranging distance corrected by Gaussian fitting is the corrected distance of one-hop size:(24)dN=10d′RSSI′−Ptr+Plossd′−xξ/10α.


## 4.2.2. Correction of Multihop Size

In this article, when calculating the multihop size between a known node and a target node, the maximum distance similar link method is proposed based on the classical similar path search algorithm, which corrects the average hop size between the target node and the known node by finding the most similar pair of known node paths for the link from the target node to the noncoplanar known node. As the corrected average hop size value between the known node and the multihop target node, the optimal distance is obtained by using this average hop size multiplied by the optimized optimal hop size.Step 1.
Determine the maximum similarity link. After the exchange of the node information, each node keeps the information of each known node, as well as the identification of other nodes in the path to the minimum hop count experienced by each known node. The similarity linkSL factor represents the path from the target node to a specific known node [46] and the degree of similarity between the paths from other known nodes to a specific known node. The calculation method is as follows:
(25)SLκ,ϖ=nκ∩ϖnκ×nϖ,where SLκ,ϖ represents the similarity between the path κ and path ϖ, κ represents target node to the specific noncoplanar known nodes by the minimum hop count between nodes on the link set of identification, ϖ represents the residual known node in the network to the specific noncoplanar between known nodes, after the minimum hop count by a collection of node id on a link, and n is the number of elements in set.
The similarity link factorSL is used to calculate the path from the target node to a specific noncoplanar known node and the similarity degree between the paths from other known nodes to a specific noncoplanar known node. The greater the value of SL, the higher the similarity degree. The path between the known nodes with the maximum value is determined as the possible path. When the calculated SL values with multiple paths are the same, compare the Euclidean distance between each known node pair in the same SL value path. When the distance between two points of the node is larger, the calculated energy consumption of the node path is smaller, and the calculated average hop size is closer to the actual each hop size. Therefore, the path with the largest Euclidean distance of known node is selected as the result.Step 2.
Calculate the average hop size of similar links with maximum distance. The path obtained by Step1 is the path between two known nodes, including specific known nodes. The Euclidean distance between nodes is calculated by using the coordinates of the two known nodes. The calculated distance is divided by the optimized minimum hop count between the two nodes, which is the average hop size used by the target node.Step 3.
Calculate the multihop size between the known node and the target node. To obtain the distance to the noncoplanar known node, each target node uses the calculated average hop size multiplied by the optimal hop count.


## 4.3. Calculate Target Node Coordinates

### 4.3.1. Determine Fitness Value

The sine and cosine function search method effectively enhances the convergence of the sparrow algorithm, improves the convergence accuracy and the optimization effect, and improves the iterative efficiency. For this reason, this article redesigns the fitness function so that the fitness value after iteration can better correct the position deviation of the target node:(26)fitness=1n∙∑I=1nxI−XJ′2+yI−YJ′2+zI−ZJ′2−DI,u,where xI,yI,zI, XJ′,YJ′,ZJ′ are the coordinates of the target node and known node, respectively. DI,u is the distance from the target node u to the known node I.


### 4.3.2. 3D-HCSSA Algorithm Flow

The localization process of the 3DDV-hop algorithm based on 3D-HCSSA can be described as follows:Step 1.
The algorithm revises the hop counts by redefining the amendment factor to determine the optimal hop counts.Step 2.
Firstly, the Gaussian fitting function is used to reduce the error between the measured and actual values of the one-hop size between the known node and the target node; secondly, the average hop size between the known node and the target node of this path is corrected according to the maximum distance similar link method proposed in this article, and the distance between the known node and the target node is calculated after the correction.Step 3.
In the three-dimensional space,100m×100m×100mk-means clustering and sine and cosine search strategy are used to improve the sparrow search algorithm to optimize the localization of target nodes. Set the number of sparrow populations, and set the number of iterations and the localization of the population in initialization.Step 4.
Calculate the fitness values of all sparrow individuals through the fitness function, sort the fitness values of all sparrow individuals, and record the current optimal and worst sparrow positions.Step 5.
The entire iterative process iterates according to equations (3), (4), (5), and (12)–(15), updates the population position and calculates the new fitness value, and records the fitness value and position of the best individual after the update.Step 6.
The algorithm loops and calculates Step5, and after iterating to the maximum, the global optimal position of the producer is obtained, that is, the optimal value of the coordinates of the target node and the algorithm.The flow chart of the 3D-HCSSA algorithm is shown in Figure3.Figure 3
Flow chart of the 3D-HCSSA algorithm.Algorithm1 is the pseudo-code of the spark search algorithm used to calculate the location of the target node.Algorithm 1: Sparrow optimization algorithm to calculate the target node coordinate value.
Algorithm1: Finalization method to solve the sparrow optimization algorithm to solve the coordinate valueInput: Known node coordinates, the distance from the target node to the corresponding known node.output Expected coordinates of target nodes.Initialize a population of n sparrows and define its relevant parameters: M, Maximum number of iterations; PD, Population Number of Producers; SD, the number of sparrows who perceive the danger; R2, Alert value; N, Total Population Quantity. //Initial parameter Value Represents the initialization parameter value1.While(t<G)// The iteration termination condition is judged2.     Sort the fitness values to find the current individual best and worst.3.   R2=rand (1)4.for i=1: PD5.     The updated producer localization is calculated by equation (3);6.end for7.for i=(PD+1): N8.      The updated scrounger positions are calculated by equations (12-15);9.end for10.for i=1:SD11.      The sparrow position is updated by equation (6);12.end for13.     Get the current latest position;14.    Update if the latest position is better than the previous one;15.    t = t +1;16.end while17.return Xbest, fg.


## 4.3.1. Determine Fitness Value

The sine and cosine function search method effectively enhances the convergence of the sparrow algorithm, improves the convergence accuracy and the optimization effect, and improves the iterative efficiency. For this reason, this article redesigns the fitness function so that the fitness value after iteration can better correct the position deviation of the target node:(26)fitness=1n∙∑I=1nxI−XJ′2+yI−YJ′2+zI−ZJ′2−DI,u,where xI,yI,zI, XJ′,YJ′,ZJ′ are the coordinates of the target node and known node, respectively. DI,u is the distance from the target node u to the known node I.


## 4.3.2. 3D-HCSSA Algorithm Flow

The localization process of the 3DDV-hop algorithm based on 3D-HCSSA can be described as follows:Step 1.
The algorithm revises the hop counts by redefining the amendment factor to determine the optimal hop counts.Step 2.
Firstly, the Gaussian fitting function is used to reduce the error between the measured and actual values of the one-hop size between the known node and the target node; secondly, the average hop size between the known node and the target node of this path is corrected according to the maximum distance similar link method proposed in this article, and the distance between the known node and the target node is calculated after the correction.Step 3.
In the three-dimensional space,100m×100m×100mk-means clustering and sine and cosine search strategy are used to improve the sparrow search algorithm to optimize the localization of target nodes. Set the number of sparrow populations, and set the number of iterations and the localization of the population in initialization.Step 4.
Calculate the fitness values of all sparrow individuals through the fitness function, sort the fitness values of all sparrow individuals, and record the current optimal and worst sparrow positions.Step 5.
The entire iterative process iterates according to equations (3), (4), (5), and (12)–(15), updates the population position and calculates the new fitness value, and records the fitness value and position of the best individual after the update.Step 6.
The algorithm loops and calculates Step5, and after iterating to the maximum, the global optimal position of the producer is obtained, that is, the optimal value of the coordinates of the target node and the algorithm.The flow chart of the 3D-HCSSA algorithm is shown in Figure3.Figure 3
Flow chart of the 3D-HCSSA algorithm.Algorithm1 is the pseudo-code of the spark search algorithm used to calculate the location of the target node.Algorithm 1: Sparrow optimization algorithm to calculate the target node coordinate value.
Algorithm1: Finalization method to solve the sparrow optimization algorithm to solve the coordinate valueInput: Known node coordinates, the distance from the target node to the corresponding known node.output Expected coordinates of target nodes.Initialize a population of n sparrows and define its relevant parameters: M, Maximum number of iterations; PD, Population Number of Producers; SD, the number of sparrows who perceive the danger; R2, Alert value; N, Total Population Quantity. //Initial parameter Value Represents the initialization parameter value1.While(t<G)// The iteration termination condition is judged2.     Sort the fitness values to find the current individual best and worst.3.   R2=rand (1)4.for i=1: PD5.     The updated producer localization is calculated by equation (3);6.end for7.for i=(PD+1): N8.      The updated scrounger positions are calculated by equations (12-15);9.end for10.for i=1:SD11.      The sparrow position is updated by equation (6);12.end for13.     Get the current latest position;14.    Update if the latest position is better than the previous one;15.    t = t +1;16.end while17.return Xbest, fg.


## 5. Simulation Results and Analysis

### 5.1. Evaluation of the Performance

This article compared HCSSA with SSA [21] and LSSA [47]. The parameters are set as shown in Table 1.Table 1
Parameter settings.
AlgorithmParameterSSAST=0.8PD=0.2SD=0.3LSSAST=0.8PD=0.2SD=0.3HCSSAST=0.8PD=0.2SD=0.3This section analyzes the performance of the improved sparrow search algorithm with20 benchmark functions; as shown in Table 2, most of the benchmark functions come from the literatures [20, 42].Table 2
20 benchmark functions.
NumberFunctionDimensionsIntervalMinimum value1F1x=∑i=1n106i−1n−1xi230[-100,100]02F2x=∑i=1n∑i=1ixj230[-100,100]03F3x=maxixi,1≤i≤n30[-100,100]04F4x=∑i=1n−1100xi+1−xi22+xi−1230[-30,30]05F5x=∑i=1nxi+0.5230[-100,100]06F6x=∑i=1nixi4+random0,130[-1.28,1.28]07F7x=∑i=1nixi4+rand0,130−1.28,−1.2808F8x=∑i=1nxisinxi+0.1xi30[-100,100]09F9x=∑i=1nxi230[-10,10]010F10x=∑i=1nxi2−10cos2πxi+1030[-5.12,5.12]011F11x=∑i=1n−xisinxi30[-500,500]-418.9829n12F12=πn10sinπy1+∑i=1n−1yi−121+10sin2πyi+1+yn−12+yi=1+xi+1430[-50,50]013F13=418.9829n−∑i=1nxisinxi30[-500,500]014F14x=1.5−x1+x1x22+2.25−x1+x1x222+2.625−x1+x1x23230[-4.5,4.5]015F15x=100x12−x22+x1−12+x3−12+90x32−x42+10.1x2−12+x4−1+19.8x2−1x4−130[-10,10]016F16x=0.02+∑i=1251/i+x1−a1i6+x2−a2i6−1a=−32−1601632−32⋯01632−32−32−32−32−32−16⋯32323230[-65.536,65.536]0.99817F17x=∑i=1nxi230[-1,1]018F18x=xi+0.5230[-100,100]019F19x=maxixi,iε1,m30[-100,100]020F20x=∑i=1nixi230[-10,10]0The algorithm in this article is compared with SSA and LSSA by20 benchmark functions; Figures 4–23 show the details of the convergence curves of the SSA, the LSSA, and the HCSSA on the benchmark functions. From the figure, the iterative functions F6, F13, F14, F16, F17, F18, F19, and F20 find the optimal solution before the number of iterations is reached in the iterative process. From this iterative process, the convergence speed of the HCSSA is better than the other two algorithms, and the algorithm is less likely to fall into a local optimum. The convergence curves of each function are shown in Figures 4–23.Figure 4
A roundabout way ofF1.Figure 5
A roundabout way ofF2.Figure 6
A roundabout way ofF3.Figure 7
A roundabout way ofF4.Figure 8
A roundabout way ofF5.Figure 9
A roundabout way ofF6.Figure 10
A roundabout way ofF7.Figure 11
A roundabout way ofF8.Figure 12
A roundabout way ofF9.Figure 13
A roundabout way ofF10.Figure 14
A roundabout way ofF11.Figure 15
A roundabout way ofF12.Figure 16
A roundabout way ofF13.Figure 17
A roundabout way ofF14.Figure 18
A roundabout way ofF15.Figure 19
A roundabout way ofF16.Figure 20
A roundabout way ofF17.Figure 21
A roundabout way ofF18.Figure 22
A roundabout way ofF19.Figure 23
A roundabout way ofF20.


### 5.2. Simulation Analysis

In order to verify the performance of the proposed algorithm in localization, the 3DDV-hop localization algorithm, 3D-GAIDV-hop localization algorithm, and HCLSO-3D localization algorithm were analyzed separately. The relationship between the number of known nodes, the communication radius, and the total number of nodes and energy consumption is compared to analyze the positioning accuracy of the four algorithms.


#### 5.2.1. Experimental Parameter Setting

To verify the performance of the algorithm 3D-HCSSA in localization in this article, simulation experiments are conducted using MATLAB.100 simulation experiments were conducted in the same environment, and the average value is taken as the final result of simulation experiments. 100m×100m×100m is set as the simulation area, and 100 target nodes and 30 known nodes are taken. The specific experimental parameters are shown in Table 3. The random distribution of nodes in the 3D space is shown in Figure 24.Table 3
Network environment and parameter setting.
ParameterValueThe network area100m×100m×100mTotal number of nodes100-300Number of known nodes10-30Communication radius25-45Maximum iteration300Figure 24
Random distribution of nodes in the three-dimensional space.


#### 5.2.2. The Localization Performance of the Model Is Evaluated by Means of the Average Localization Error Metric

(27)γALE=∑I=1nxI−XI′2+yI−YI′2+zI−ZI′2NR,where γALE represents the average localization error, xI,yI,zI represents the actual coordinate value of the target node I, XI′,YI′,ZI′ is the expected coordinate value of the nodeI, N represents the total number of target nodes, and R represents the communication radius of the known node.


#### 5.2.3. Analysis of the Number of Known Nodes and the Average Localization Error

From Figure25, it can be seen that the average localization error of the algorithm in this article is smaller when the known nodes are the same. When the proportion of known nodes is 30%, the average localization error of the 3D-HCSSA algorithm is the smallest at 8.5%. At this time, the average localization errors of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D are 12.5%, 11.3%, and 9.8%, respectively, and the average localization errors of the 3D-HCSSA algorithm reduces compared with these three algorithms by 47.06%, 32.94%, and 15.29%, respectively. Therefore, when the number of known nodes is constant and the average positioning error curve is shown in the figure, the 3D-HCSSA algorithm has the advantage of high positioning accuracy compared with the other three algorithms.Figure 25
Compare and analyze the localization errors of different numbers of known nodes.


#### 5.2.4. Analysis of Different Communication Radii and Average Localization Errors

Figure26 demonstrates the curve of average localization error that varies with communication radius. The proportion of known nodes is10% in the network, and the communication radius is increased from 25m to 45m. By changing the communication radius, the localization performance of the four algorithms is compared and analyzed. The average localization error of the 3D-HCSSA algorithm is always the smallest. As the communication distance increases, the known node communicates directly with more nodes, so the average localization error gradually tends to be stable. The average localization error of the 3D-HCSSA algorithm is 9.6% minimum at the communication radius equal to 45 m. In this case, the average localization errors of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D algorithms are 14.3%, 11.5%, and 11.2%, respectively. Compared with these three algorithms, the average localization errors of the 3D-HCSSA algorithm are reduced by 48.96%, 19.79%, and 16.67%, respectively. In summary, we can see by the change curve of communication radius from the figure that the average positioning error of the 3D-HCSSA algorithm is the smallest in different communication radius ranges, so the proposed algorithm in this article has the feature of high positioning accuracy.Figure 26
Compare the localization errors of different communication radii.


#### 5.2.5. Total Number of Nodes and Average Localization Error Analysis

Figure27 demonstrates the curve of average localization error that varies with the total number of nodes. Sensor nodes are randomly deployed throughout the network with a communication radius of 30m. The performance of the four algorithms demonstrates that the average localization error decreases gradually with the curve. The reason for this is that the network connectivity becomes better as the node density increases. Therefore, when the total number of nodes reaches a certain value, the average localization error of all four algorithms gradually stabilizes and does not change significantly. The average localization error of the 3D-HCSSA algorithm is always the smallest under the same conditions. When the total number of nodes reaches 300, the average localization error of the 3D-HCSSA algorithm is the smallest at 19.2%. In this case, the average localization errors of 3DDV-hop and 3D-GAIDV-hop and HCLSO-3D algorithms are 31.2%, 22.4%, and 19.9%, respectively. The 3D-HCSSA algorithm reduces the average localization error by 62.5%, 16.67%, and 3.64%, respectively, by comparison. Therefore, compared with the other three algorithms, the average positioning error of this algorithm is significantly reduced and the positioning accuracy is improved.Figure 27
Compare and analyze the total number of nodes and the average localization error.


#### 5.2.6. Influence of the Number of Known Nodes on Energy Consumption

Figure28 demonstrates the curve of network energy consumption that varies with the number of known nodes. The energy consumption of the four algorithms increases gradually by randomly deploying sensor nodes throughout the network. The reason for this is that the increase in the number of known nodes leads to an increase in computation time. The energy consumption of the 3D-HCSSA algorithm is always the smallest throughout the process. When the number of known nodes is 30, the minimum energy consumption of 3D-HCSSA is 28. In this case, the energy consumption of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D is 103, 35, and 33, respectively. Compared with the three algorithms, the energy consumption of 3D-HCSSA is reduced by 72.82%, 25%, and 20%, respectively. The known nodes consume large power in the network, which leads to the problem of high energy consumption of the whole network. It can be seen from the energy consumption curve in the figure that as the number of known nodes increases, the energy consumption is also increased, but the algorithm proposed in this paper has the advantage of low energy consumption compared with the other three algorithms.Figure 28
Compare and analyze the number of known nodes and energy consumption.


#### 5.2.7. Influence of the Number of Target Nodes on Energy Consumption

Figure29 demonstrates the curve of network energy consumption that varies with the target number of nodes. The performance of the four algorithms are compared by randomly deploying sensor nodes within the entire network. The energy consumption of the four algorithms gradually increases as the total number of nodes increases, and the increase in the number of target nodes leads to an increase in computation time. The energy consumption of the 3D-HCSSA algorithm is always the smallest throughout the experiment. The energy consumption of the 3D-HCSSA algorithm is the smallest when the target node is 300 at 82. In this case, the energy consumption of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D algorithms is 113, 90, and 87, respectively. Compared with the three algorithms, the energy consumption of the 3D-HCSSA algorithm is reduced by 37.8%,9.76%, and 6.09%, respectively.Figure 29
Compare and analyze the number of target nodes and energy consumption.


#### 5.2.8. Analysis of Calculation Cost

The average running time of the algorithm is analyzed as an index of computational cost. Table4 demonstrates the average running time of 3DDV-hop and 3D-GAIDV-hop and HCLSO-3D and 3D-HCSSA algorithms under the same experimental conditions. As can be seen from the experimental results, the average running time of the 3D-HCSSA localization algorithm is about 1.65 times that of the 3DDV-hop algorithm, about 1.08 times that of the 3D-GAIDV-hop algorithm, and about 1.03 times that of the HCLSO-3D algorithm. Because the 3D-HCSSA algorithm uses an intelligent algorithm to solve the target node coordinates, which results in the increase in the amount of calculation, the small increase in time consumption of the algorithm can be ignored, but the positioning accuracy is significantly improved.Table 4
Average running time of the four algorithms.
AlgorithmsAverage running time per second3DDV-hop32.33D-GAIDV-hop49.2HCLSO-3D51.63D-HCSSA53.4


#### 5.2.9. Time Complexity Analysis of the Localization Algorithm

Since WSNs are usually limited by resources, in addition to positioning accuracy, the complexity of a localization algorithm is also one of the factors that must be considered. Suppose the number of nodes in the whole WSNs isn and the number of nodes is known to be m. The time complexity of computing the minimum counts of hop between nodes is on3 in the 3DDV-hop algorithm, the time complexity of calculating the actual distance between nodes is on, the time complexity of calculating the hop size from the target node to the known node is on×m, and the time complexity of calculating the localization of the target node through the maximum likelihood estimation method is on−m4. Similarly, the complexity of 3D-GAIDV-hop and HCLSO-3D mentioned in this article increases on, respectively, on the basis of the original 3DDV-hop algorithm. The time complexity of the proposed algorithm is also increased by on on the basis of the 3DDV-hop algorithm. Therefore, the time complexity of the 3D-HCSSA algorithm does not increase significantly, but the positioning accuracy is better improved.


## 5.1. Evaluation of the Performance

This article compared HCSSA with SSA [21] and LSSA [47]. The parameters are set as shown in Table 1.Table 1
Parameter settings.
AlgorithmParameterSSAST=0.8PD=0.2SD=0.3LSSAST=0.8PD=0.2SD=0.3HCSSAST=0.8PD=0.2SD=0.3This section analyzes the performance of the improved sparrow search algorithm with20 benchmark functions; as shown in Table 2, most of the benchmark functions come from the literatures [20, 42].Table 2
20 benchmark functions.
NumberFunctionDimensionsIntervalMinimum value1F1x=∑i=1n106i−1n−1xi230[-100,100]02F2x=∑i=1n∑i=1ixj230[-100,100]03F3x=maxixi,1≤i≤n30[-100,100]04F4x=∑i=1n−1100xi+1−xi22+xi−1230[-30,30]05F5x=∑i=1nxi+0.5230[-100,100]06F6x=∑i=1nixi4+random0,130[-1.28,1.28]07F7x=∑i=1nixi4+rand0,130−1.28,−1.2808F8x=∑i=1nxisinxi+0.1xi30[-100,100]09F9x=∑i=1nxi230[-10,10]010F10x=∑i=1nxi2−10cos2πxi+1030[-5.12,5.12]011F11x=∑i=1n−xisinxi30[-500,500]-418.9829n12F12=πn10sinπy1+∑i=1n−1yi−121+10sin2πyi+1+yn−12+yi=1+xi+1430[-50,50]013F13=418.9829n−∑i=1nxisinxi30[-500,500]014F14x=1.5−x1+x1x22+2.25−x1+x1x222+2.625−x1+x1x23230[-4.5,4.5]015F15x=100x12−x22+x1−12+x3−12+90x32−x42+10.1x2−12+x4−1+19.8x2−1x4−130[-10,10]016F16x=0.02+∑i=1251/i+x1−a1i6+x2−a2i6−1a=−32−1601632−32⋯01632−32−32−32−32−32−16⋯32323230[-65.536,65.536]0.99817F17x=∑i=1nxi230[-1,1]018F18x=xi+0.5230[-100,100]019F19x=maxixi,iε1,m30[-100,100]020F20x=∑i=1nixi230[-10,10]0The algorithm in this article is compared with SSA and LSSA by20 benchmark functions; Figures 4–23 show the details of the convergence curves of the SSA, the LSSA, and the HCSSA on the benchmark functions. From the figure, the iterative functions F6, F13, F14, F16, F17, F18, F19, and F20 find the optimal solution before the number of iterations is reached in the iterative process. From this iterative process, the convergence speed of the HCSSA is better than the other two algorithms, and the algorithm is less likely to fall into a local optimum. The convergence curves of each function are shown in Figures 4–23.Figure 4
A roundabout way ofF1.Figure 5
A roundabout way ofF2.Figure 6
A roundabout way ofF3.Figure 7
A roundabout way ofF4.Figure 8
A roundabout way ofF5.Figure 9
A roundabout way ofF6.Figure 10
A roundabout way ofF7.Figure 11
A roundabout way ofF8.Figure 12
A roundabout way ofF9.Figure 13
A roundabout way ofF10.Figure 14
A roundabout way ofF11.Figure 15
A roundabout way ofF12.Figure 16
A roundabout way ofF13.Figure 17
A roundabout way ofF14.Figure 18
A roundabout way ofF15.Figure 19
A roundabout way ofF16.Figure 20
A roundabout way ofF17.Figure 21
A roundabout way ofF18.Figure 22
A roundabout way ofF19.Figure 23
A roundabout way ofF20.


## 5.2. Simulation Analysis

In order to verify the performance of the proposed algorithm in localization, the 3DDV-hop localization algorithm, 3D-GAIDV-hop localization algorithm, and HCLSO-3D localization algorithm were analyzed separately. The relationship between the number of known nodes, the communication radius, and the total number of nodes and energy consumption is compared to analyze the positioning accuracy of the four algorithms.


### 5.2.1. Experimental Parameter Setting

To verify the performance of the algorithm 3D-HCSSA in localization in this article, simulation experiments are conducted using MATLAB.100 simulation experiments were conducted in the same environment, and the average value is taken as the final result of simulation experiments. 100m×100m×100m is set as the simulation area, and 100 target nodes and 30 known nodes are taken. The specific experimental parameters are shown in Table 3. The random distribution of nodes in the 3D space is shown in Figure 24.Table 3
Network environment and parameter setting.
ParameterValueThe network area100m×100m×100mTotal number of nodes100-300Number of known nodes10-30Communication radius25-45Maximum iteration300Figure 24
Random distribution of nodes in the three-dimensional space.


### 5.2.2. The Localization Performance of the Model Is Evaluated by Means of the Average Localization Error Metric

(27)γALE=∑I=1nxI−XI′2+yI−YI′2+zI−ZI′2NR,where γALE represents the average localization error, xI,yI,zI represents the actual coordinate value of the target node I, XI′,YI′,ZI′ is the expected coordinate value of the nodeI, N represents the total number of target nodes, and R represents the communication radius of the known node.


### 5.2.3. Analysis of the Number of Known Nodes and the Average Localization Error

From Figure25, it can be seen that the average localization error of the algorithm in this article is smaller when the known nodes are the same. When the proportion of known nodes is 30%, the average localization error of the 3D-HCSSA algorithm is the smallest at 8.5%. At this time, the average localization errors of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D are 12.5%, 11.3%, and 9.8%, respectively, and the average localization errors of the 3D-HCSSA algorithm reduces compared with these three algorithms by 47.06%, 32.94%, and 15.29%, respectively. Therefore, when the number of known nodes is constant and the average positioning error curve is shown in the figure, the 3D-HCSSA algorithm has the advantage of high positioning accuracy compared with the other three algorithms.Figure 25
Compare and analyze the localization errors of different numbers of known nodes.


### 5.2.4. Analysis of Different Communication Radii and Average Localization Errors

Figure26 demonstrates the curve of average localization error that varies with communication radius. The proportion of known nodes is10% in the network, and the communication radius is increased from 25m to 45m. By changing the communication radius, the localization performance of the four algorithms is compared and analyzed. The average localization error of the 3D-HCSSA algorithm is always the smallest. As the communication distance increases, the known node communicates directly with more nodes, so the average localization error gradually tends to be stable. The average localization error of the 3D-HCSSA algorithm is 9.6% minimum at the communication radius equal to 45 m. In this case, the average localization errors of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D algorithms are 14.3%, 11.5%, and 11.2%, respectively. Compared with these three algorithms, the average localization errors of the 3D-HCSSA algorithm are reduced by 48.96%, 19.79%, and 16.67%, respectively. In summary, we can see by the change curve of communication radius from the figure that the average positioning error of the 3D-HCSSA algorithm is the smallest in different communication radius ranges, so the proposed algorithm in this article has the feature of high positioning accuracy.Figure 26
Compare the localization errors of different communication radii.


### 5.2.5. Total Number of Nodes and Average Localization Error Analysis

Figure27 demonstrates the curve of average localization error that varies with the total number of nodes. Sensor nodes are randomly deployed throughout the network with a communication radius of 30m. The performance of the four algorithms demonstrates that the average localization error decreases gradually with the curve. The reason for this is that the network connectivity becomes better as the node density increases. Therefore, when the total number of nodes reaches a certain value, the average localization error of all four algorithms gradually stabilizes and does not change significantly. The average localization error of the 3D-HCSSA algorithm is always the smallest under the same conditions. When the total number of nodes reaches 300, the average localization error of the 3D-HCSSA algorithm is the smallest at 19.2%. In this case, the average localization errors of 3DDV-hop and 3D-GAIDV-hop and HCLSO-3D algorithms are 31.2%, 22.4%, and 19.9%, respectively. The 3D-HCSSA algorithm reduces the average localization error by 62.5%, 16.67%, and 3.64%, respectively, by comparison. Therefore, compared with the other three algorithms, the average positioning error of this algorithm is significantly reduced and the positioning accuracy is improved.Figure 27
Compare and analyze the total number of nodes and the average localization error.


### 5.2.6. Influence of the Number of Known Nodes on Energy Consumption

Figure28 demonstrates the curve of network energy consumption that varies with the number of known nodes. The energy consumption of the four algorithms increases gradually by randomly deploying sensor nodes throughout the network. The reason for this is that the increase in the number of known nodes leads to an increase in computation time. The energy consumption of the 3D-HCSSA algorithm is always the smallest throughout the process. When the number of known nodes is 30, the minimum energy consumption of 3D-HCSSA is 28. In this case, the energy consumption of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D is 103, 35, and 33, respectively. Compared with the three algorithms, the energy consumption of 3D-HCSSA is reduced by 72.82%, 25%, and 20%, respectively. The known nodes consume large power in the network, which leads to the problem of high energy consumption of the whole network. It can be seen from the energy consumption curve in the figure that as the number of known nodes increases, the energy consumption is also increased, but the algorithm proposed in this paper has the advantage of low energy consumption compared with the other three algorithms.Figure 28
Compare and analyze the number of known nodes and energy consumption.


### 5.2.7. Influence of the Number of Target Nodes on Energy Consumption

Figure29 demonstrates the curve of network energy consumption that varies with the target number of nodes. The performance of the four algorithms are compared by randomly deploying sensor nodes within the entire network. The energy consumption of the four algorithms gradually increases as the total number of nodes increases, and the increase in the number of target nodes leads to an increase in computation time. The energy consumption of the 3D-HCSSA algorithm is always the smallest throughout the experiment. The energy consumption of the 3D-HCSSA algorithm is the smallest when the target node is 300 at 82. In this case, the energy consumption of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D algorithms is 113, 90, and 87, respectively. Compared with the three algorithms, the energy consumption of the 3D-HCSSA algorithm is reduced by 37.8%,9.76%, and 6.09%, respectively.Figure 29
Compare and analyze the number of target nodes and energy consumption.


### 5.2.8. Analysis of Calculation Cost

The average running time of the algorithm is analyzed as an index of computational cost. Table4 demonstrates the average running time of 3DDV-hop and 3D-GAIDV-hop and HCLSO-3D and 3D-HCSSA algorithms under the same experimental conditions. As can be seen from the experimental results, the average running time of the 3D-HCSSA localization algorithm is about 1.65 times that of the 3DDV-hop algorithm, about 1.08 times that of the 3D-GAIDV-hop algorithm, and about 1.03 times that of the HCLSO-3D algorithm. Because the 3D-HCSSA algorithm uses an intelligent algorithm to solve the target node coordinates, which results in the increase in the amount of calculation, the small increase in time consumption of the algorithm can be ignored, but the positioning accuracy is significantly improved.Table 4
Average running time of the four algorithms.
AlgorithmsAverage running time per second3DDV-hop32.33D-GAIDV-hop49.2HCLSO-3D51.63D-HCSSA53.4


### 5.2.9. Time Complexity Analysis of the Localization Algorithm

Since WSNs are usually limited by resources, in addition to positioning accuracy, the complexity of a localization algorithm is also one of the factors that must be considered. Suppose the number of nodes in the whole WSNs isn and the number of nodes is known to be m. The time complexity of computing the minimum counts of hop between nodes is on3 in the 3DDV-hop algorithm, the time complexity of calculating the actual distance between nodes is on, the time complexity of calculating the hop size from the target node to the known node is on×m, and the time complexity of calculating the localization of the target node through the maximum likelihood estimation method is on−m4. Similarly, the complexity of 3D-GAIDV-hop and HCLSO-3D mentioned in this article increases on, respectively, on the basis of the original 3DDV-hop algorithm. The time complexity of the proposed algorithm is also increased by on on the basis of the 3DDV-hop algorithm. Therefore, the time complexity of the 3D-HCSSA algorithm does not increase significantly, but the positioning accuracy is better improved.


## 5.2.1. Experimental Parameter Setting

To verify the performance of the algorithm 3D-HCSSA in localization in this article, simulation experiments are conducted using MATLAB.100 simulation experiments were conducted in the same environment, and the average value is taken as the final result of simulation experiments. 100m×100m×100m is set as the simulation area, and 100 target nodes and 30 known nodes are taken. The specific experimental parameters are shown in Table 3. The random distribution of nodes in the 3D space is shown in Figure 24.Table 3
Network environment and parameter setting.
ParameterValueThe network area100m×100m×100mTotal number of nodes100-300Number of known nodes10-30Communication radius25-45Maximum iteration300Figure 24
Random distribution of nodes in the three-dimensional space.


## 5.2.2. The Localization Performance of the Model Is Evaluated by Means of the Average Localization Error Metric

(27)γALE=∑I=1nxI−XI′2+yI−YI′2+zI−ZI′2NR,where γALE represents the average localization error, xI,yI,zI represents the actual coordinate value of the target node I, XI′,YI′,ZI′ is the expected coordinate value of the nodeI, N represents the total number of target nodes, and R represents the communication radius of the known node.


## 5.2.3. Analysis of the Number of Known Nodes and the Average Localization Error

From Figure25, it can be seen that the average localization error of the algorithm in this article is smaller when the known nodes are the same. When the proportion of known nodes is 30%, the average localization error of the 3D-HCSSA algorithm is the smallest at 8.5%. At this time, the average localization errors of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D are 12.5%, 11.3%, and 9.8%, respectively, and the average localization errors of the 3D-HCSSA algorithm reduces compared with these three algorithms by 47.06%, 32.94%, and 15.29%, respectively. Therefore, when the number of known nodes is constant and the average positioning error curve is shown in the figure, the 3D-HCSSA algorithm has the advantage of high positioning accuracy compared with the other three algorithms.Figure 25
Compare and analyze the localization errors of different numbers of known nodes.


## 5.2.4. Analysis of Different Communication Radii and Average Localization Errors

Figure26 demonstrates the curve of average localization error that varies with communication radius. The proportion of known nodes is10% in the network, and the communication radius is increased from 25m to 45m. By changing the communication radius, the localization performance of the four algorithms is compared and analyzed. The average localization error of the 3D-HCSSA algorithm is always the smallest. As the communication distance increases, the known node communicates directly with more nodes, so the average localization error gradually tends to be stable. The average localization error of the 3D-HCSSA algorithm is 9.6% minimum at the communication radius equal to 45 m. In this case, the average localization errors of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D algorithms are 14.3%, 11.5%, and 11.2%, respectively. Compared with these three algorithms, the average localization errors of the 3D-HCSSA algorithm are reduced by 48.96%, 19.79%, and 16.67%, respectively. In summary, we can see by the change curve of communication radius from the figure that the average positioning error of the 3D-HCSSA algorithm is the smallest in different communication radius ranges, so the proposed algorithm in this article has the feature of high positioning accuracy.Figure 26
Compare the localization errors of different communication radii.


## 5.2.5. Total Number of Nodes and Average Localization Error Analysis

Figure27 demonstrates the curve of average localization error that varies with the total number of nodes. Sensor nodes are randomly deployed throughout the network with a communication radius of 30m. The performance of the four algorithms demonstrates that the average localization error decreases gradually with the curve. The reason for this is that the network connectivity becomes better as the node density increases. Therefore, when the total number of nodes reaches a certain value, the average localization error of all four algorithms gradually stabilizes and does not change significantly. The average localization error of the 3D-HCSSA algorithm is always the smallest under the same conditions. When the total number of nodes reaches 300, the average localization error of the 3D-HCSSA algorithm is the smallest at 19.2%. In this case, the average localization errors of 3DDV-hop and 3D-GAIDV-hop and HCLSO-3D algorithms are 31.2%, 22.4%, and 19.9%, respectively. The 3D-HCSSA algorithm reduces the average localization error by 62.5%, 16.67%, and 3.64%, respectively, by comparison. Therefore, compared with the other three algorithms, the average positioning error of this algorithm is significantly reduced and the positioning accuracy is improved.Figure 27
Compare and analyze the total number of nodes and the average localization error.


## 5.2.6. Influence of the Number of Known Nodes on Energy Consumption

Figure28 demonstrates the curve of network energy consumption that varies with the number of known nodes. The energy consumption of the four algorithms increases gradually by randomly deploying sensor nodes throughout the network. The reason for this is that the increase in the number of known nodes leads to an increase in computation time. The energy consumption of the 3D-HCSSA algorithm is always the smallest throughout the process. When the number of known nodes is 30, the minimum energy consumption of 3D-HCSSA is 28. In this case, the energy consumption of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D is 103, 35, and 33, respectively. Compared with the three algorithms, the energy consumption of 3D-HCSSA is reduced by 72.82%, 25%, and 20%, respectively. The known nodes consume large power in the network, which leads to the problem of high energy consumption of the whole network. It can be seen from the energy consumption curve in the figure that as the number of known nodes increases, the energy consumption is also increased, but the algorithm proposed in this paper has the advantage of low energy consumption compared with the other three algorithms.Figure 28
Compare and analyze the number of known nodes and energy consumption.


## 5.2.7. Influence of the Number of Target Nodes on Energy Consumption

Figure29 demonstrates the curve of network energy consumption that varies with the target number of nodes. The performance of the four algorithms are compared by randomly deploying sensor nodes within the entire network. The energy consumption of the four algorithms gradually increases as the total number of nodes increases, and the increase in the number of target nodes leads to an increase in computation time. The energy consumption of the 3D-HCSSA algorithm is always the smallest throughout the experiment. The energy consumption of the 3D-HCSSA algorithm is the smallest when the target node is 300 at 82. In this case, the energy consumption of 3DDV-hop, 3D-GAIDV-hop, and HCLSO-3D algorithms is 113, 90, and 87, respectively. Compared with the three algorithms, the energy consumption of the 3D-HCSSA algorithm is reduced by 37.8%,9.76%, and 6.09%, respectively.Figure 29
Compare and analyze the number of target nodes and energy consumption.


## 5.2.8. Analysis of Calculation Cost

The average running time of the algorithm is analyzed as an index of computational cost. Table4 demonstrates the average running time of 3DDV-hop and 3D-GAIDV-hop and HCLSO-3D and 3D-HCSSA algorithms under the same experimental conditions. As can be seen from the experimental results, the average running time of the 3D-HCSSA localization algorithm is about 1.65 times that of the 3DDV-hop algorithm, about 1.08 times that of the 3D-GAIDV-hop algorithm, and about 1.03 times that of the HCLSO-3D algorithm. Because the 3D-HCSSA algorithm uses an intelligent algorithm to solve the target node coordinates, which results in the increase in the amount of calculation, the small increase in time consumption of the algorithm can be ignored, but the positioning accuracy is significantly improved.Table 4
Average running time of the four algorithms.
AlgorithmsAverage running time per second3DDV-hop32.33D-GAIDV-hop49.2HCLSO-3D51.63D-HCSSA53.4


## 5.2.9. Time Complexity Analysis of the Localization Algorithm

Since WSNs are usually limited by resources, in addition to positioning accuracy, the complexity of a localization algorithm is also one of the factors that must be considered. Suppose the number of nodes in the whole WSNs isn and the number of nodes is known to be m. The time complexity of computing the minimum counts of hop between nodes is on3 in the 3DDV-hop algorithm, the time complexity of calculating the actual distance between nodes is on, the time complexity of calculating the hop size from the target node to the known node is on×m, and the time complexity of calculating the localization of the target node through the maximum likelihood estimation method is on−m4. Similarly, the complexity of 3D-GAIDV-hop and HCLSO-3D mentioned in this article increases on, respectively, on the basis of the original 3DDV-hop algorithm. The time complexity of the proposed algorithm is also increased by on on the basis of the 3DDV-hop algorithm. Therefore, the time complexity of the 3D-HCSSA algorithm does not increase significantly, but the positioning accuracy is better improved.


## 6. Conclusion

Aiming at the obvious error problem of node localization in the 3DDV-hop algorithm, a sparrow search localization algorithm 3D-HCSSA based on hop size correction and improvement is proposed. The algorithm redefines the amendment factor based on the original hop count to reduce the hop count error and proposes the maximum distance similar link method to correct the multihop size between nodes and usesK-means clustering and sine-cosine search strategy to improve the traditional sparrow search algorithm. If it is insufficient, optimize the position of the target node and improve the positioning accuracy. The simulation results demonstrate that the average positioning errors of the 3D-HCSSA algorithm are reduced by 52.84%, 23.13%, and 11.87%, respectively, compared with the 3DDV-hop algorithm, the 3D-GAIDV-hop algorithm, and the HCLSO-3D algorithm. Therefore, the algorithm improves the node positioning accuracy and reduces the energy consumption of the algorithm. For the future research directions, we will focus on these aspects: firstly, to explore a better way to build an integrated network with seamless coverage within the network by combining 5G/6G technology with WSNs to solve the solution set coverage problem in the sparrow optimization search algorithm, reduce coverage voids, and improve positioning accuracy, and secondly, how to constrain the residual energy of nodes and enhance the application of the algorithm in various heterogeneous networks.



---

*Source: 1540110-2022-05-11.xml*