A Two-Stage Particle Swarm Optimization Algorithm for Wireless Sensor Nodes Localization in Concave Regions

At present, range-free localization algorithm is the mainstream of node localization method, which has made tremendous achievements. However, there are few algorithms that can be used in concave regions, and the existing algorithms have defects such as hop distance error, excessive time complexity and so on. To solve these problems, this paper proposes a two-stage PSO (Particle Swarm Optimization) algorithm for wireless sensor nodes localization in “concave regions”. In the first stage, it proposes a method of distance measuring based on similar path search and intersection ratio, and completes the initial localization of unknown nodes based on maximum likelihood estimation. In the second stage, the improved PSO algorithm is used to optimize the initial localization results in the previous stage. The experimental result shows that the localization error of this algorithm is always within 10% and the execution time is maintained at about 20 s when the communication radius and beacon node ratio is changing. Therefore, the algorithm can obtain high localization accuracy in wireless sensor network with “concave regions”, requiring low computing power for nodes, and energy consumption. Given this, it can greatly extend the service life of sensor nodes.


Research Significance
The WSN (Wireless Sensor Network) is a distributed sensor network, and its tip is a sensor node that can perceive physical, chemical, behavioral, and biological information in the external environment. The nodes in WSN communicate through wireless, so the deployment of the network is simple, the setting is flexible, and it can be connected to the Internet through wireless [1]. Therefore, this technology has been widely used. When the sensor node in WSN is working, it sends the physical, chemical, behavioral, and biological information collected from the environment to the gathering node, then the gathering node transmits it to the internet or terminal computer. In the end, users analyze the obtained information and carry out corresponding operations. However, in actual application, it is useful only when the information collected by sensor nodes is combined with the coordinates. For example: in a large farmland where WSN is deployed, a certain node has monitored the drought situation of crops in its location. If the user also knows the coordinates of this node while receiving the information, then the user only needs to accurately irrigate the crops there. Otherwise, the information transfer by the node will be valueless. Therefore, the sensor node localization technology is the core technology of WSN.

Research Status
The current wireless sensor nodes localization methods for concave areas could be classified into two categories.
The first category: According to structural properties of the wireless sensor networks and the coordinates of some beacon nodes, unknown nodes are located by methods such as beacon node selection, communication area division, and shortest distance correction.
Li Mo et al. proposed a range-free Rendered Path (REP) localization algorithm for concave regions in Reference [2]. First, the algorithm assumed that the boundary nodes deployed around the obstacle are known, then determined the shape and location of the network cavity. Based on the location of obstacle, the shortest paths between all nodes in the network is classified into several sub-

Research Status
The current wireless sensor nodes localization methods for concave areas could be classified into two categories.
The first category: According to structural properties of the wireless sensor networks and the coordinates of some beacon nodes, unknown nodes are located by methods such as beacon node selection, communication area division, and shortest distance correction.
Li Mo et al. proposed a range-free Rendered Path (REP) localization algorithm for concave regions in Reference [2]. First, the algorithm assumed that the boundary nodes deployed around the obstacle are known, then determined the shape and location of the network cavity. Based on the location of obstacle, the shortest paths between all nodes in the network is classified into several Information 2020, 11, 488 3 of 16 sub-segments, then, the Euclidean distance between nodes is calculated by constructing a virtual unit circle at the intersection of the concave boundary and the shortest path between nodes. Although this method has improved the estimation accuracy of Euclidean distance between nodes, the main disadvantage is that the communication volume and energy consumption of the algorithm are very huge, and the computing power of the node is relatively high. Lim et al. proposed a Proximity-Distance Map (PDM) algorithm in Reference [3], in this algorithm, the estimated Euclidean distance and real Euclidean distance between all beacons nodes in WSN are represented by matrices, then, the estimated distance are processed according to the linear transformation matrix of the two matrices, so as to improve the estimation accuracy of Euclidean distance. A location calculation method was proposed in Reference [4], which uses cubic spline interpolation to filter out the shortest path affected by the concave boundary, improving the estimation accuracy of the distance. According to friendly beacon nodes selection, Paul et al. proposed a Friendly Anchor Based Range Free Localization (FABL) algorithm in [5]. The algorithm used the true distance and estimated distance between beacon nodes to calculate an angle value, the unknown node takes the eight beacon nodes with the largest angle value for localization calculation. Bulusu et al. proposed a Convex-Hull Partitioning (CHP) localization algorithm in [6]. The CHP algorithm divided the beacon nodes into convex hulls. After the partitioning, the shortest distance between beacon nodes in each convex hull are uninfluenced by the concave shape, then the coordinates of the target unknown nodes are calculated based on the convex hull where they are located.
The second category of localization methods use intelligent optimization algorithm to locate unknown nodes.
Z. Zhang et al. improved the particle swarm algorithm in [7] and proposed the waves function, which uses waves function to represent the performance of particles location. Aiming at the shortcomings of DV-Hop (Distance Vector-Hop), in Reference [8], Ahmad et al. came up with a coordinate estimation method based on artificial bee colony algorithm, which reduces the localization error by restricting the optimized area. Mirjalili et al. proposed an improved Gray Wolf Optimization (GWO) localization algorithm in Reference [9], this algorithm simulates the social hierarchy of wolves dividing unknown nodes into four levels: α, β, γ and ω, guiding ω to complete localization with α, β and γ.
On the basis of the structure of the sensor network, the first category of localization algorithms reduces the influence of the concave boundary on the shortest distance between nodes through methods such as beacon node selection, shortest distance correction and so on. However, when estimating the Euclidean distance between nodes, it still uses the DV-HOP algorithm to calculate the Euclidean distances, which will cause a larger hop distance error, thereby greatly reducing the localization accuracy of the nodes. In Figure 2, O, A, B, C are sensor nodes, and R is the radius of the nodes which are in the WSN. The distances of OA, OB, OC are obviously different. O to A, B, and C are all one hop, if the hop number and hop distance are used to estimate the distance of OA, OB, OC, OA = OB = OC is obtained, so the calculation result is inconsistent with the actual situation, this is the hop distance error. The first category of localization algorithm uses the estimated distance with hop distance error to calculate the location of the nodes, which will inevitably cause a larger localization error. The second category of localization algorithms directly introduces intelligent optimization algorithms to locate unknown nodes through thousands of iterations, which reduces the overall localization error of some target nodes. However, due to lack of constraints, the coordinates of individual nodes even may be located outside the network. In addition, thousands of iterations require huge energy consumption, which will greatly shorten the service period of sensor nodes. In summary, in view of the shortcomings of the above localization algorithms, in this paper, a two-stage PSO algorithm for wireless sensor node localization in the concave region is proposed. The first stage: base on the similar path and intersecting ratio to determine whether the multi-hop shortest path between nodes is affected by the concave boundary, then calculate the distances between target unknown nodes and beacon nodes, finally, using the least square method to complete nodes localization. The second stage: using the improved PSO method to optimize the coordinates which are calculated in the previous stage. Experiment results Information 2020, 11, 488 4 of 16 indicate that this method uses intersection ratio to estimate the distance between nodes, so it can effectively avoid the hop error. In addition, using the improved PSO to optimize the consequence of the initial stage could greatly reduce the number of iterations and extend the service life of nodes.

Calculate the Euclidean Distance of One Hop Based on the Intersection Ratio
In WSNs, the target unknown node could be located only after the Euclidean distance between nodes in the communication area is obtained. First of all, this paper uses the method of intersection ratio to estimate the Euclidean distance of one hop. Then the Euclidean distances between the target unknown node to beacon nodes are calculated basing on the multi-hop shortest path between nodes and the Euclidean distance of one hop. In this paper the intersection ratio is: the ratio of the distance between nodes to the radius.
As shown in Figure 3, , are the nodes with communication radius , and they are neighbor nodes with each other.
is the area of the intersection part, is the amount of sensor nodes in the circle of the node , is the amount of sensor nodes in the circle of node , the amount of sensor nodes in the intersecting area is , the Euclidean distance between and is , the intersection ratio between nodes and is . So the area of the intersection is: Divide by to get: There is only one unknown number on the right side of Formula (2), and the intersection ratio can indicate the distance between neighbor nodes, so assign = to get: According to Taylor Expansion:

Calculate the Euclidean Distance of One Hop Based on the Intersection Ratio
In WSNs, the target unknown node could be located only after the Euclidean distance between nodes in the communication area is obtained. First of all, this paper uses the method of intersection ratio to estimate the Euclidean distance of one hop. Then the Euclidean distances between the target unknown node to beacon nodes are calculated basing on the multi-hop shortest path between nodes and the Euclidean distance of one hop. In this paper the intersection ratio is: the ratio of the distance between nodes to the radius.
As shown in Figure 3, a, u are the nodes with communication radius R, and they are neighbor nodes with each other. S au is the area of the intersection part, N a is the amount of sensor nodes in the circle of the node a, N u is the amount of sensor nodes in the circle of node u, the amount of sensor nodes in the intersecting area is N au , the Euclidean distance between a and u is d au , the intersection ratio between nodes a and u is d au R . So the area S au of the intersection is: Divide by πR 2 to get: There is only one unknown number d au R on the right side of Formula (2), and the intersection ratio d au R can indicate the distance between neighbor nodes, so assign x = d au R to get: According to Taylor Expansion: The value range of x is [0, 1], so, the polynomials after cubes can be ignored: Which is: In the communication circle u or communication circle a, the probability of a sensor node located in the intersection area and outside the intersection area approximately satisfies the Poisson distribution model [10]. Its probability function is: The ratio of the intersection area to the communication circle area is S au πR 2 , the ratio of the amount of nodes in intersecting area to the amount of nodes which are in the communication circle is 2N au N a +N u , The values of the two ratios should be approximately equal, so: Substituting Formula (9) into Formula (7), the intersection ratio is: The estimated distance of a hop between node u and node b is: Information 2020, 11, x FOR PEER REVIEW 5 of 16 Substitute Formula (4) into Formula (3): The value range of is 0,1 , so, the polynomials after cubes can be ignored: Which is: In the communication circle u or communication circle a, the probability of a sensor node located in the intersection area and outside the intersection area approximately satisfies the Poisson distribution model [10]. Its probability function is: The ratio of the intersection area to the communication circle area is , the ratio of the amount of nodes in intersecting area to the amount of nodes which are in the communication circle is , The values of the two ratios should be approximately equal, so: Substituting Formula (9) into Formula (7), the intersection ratio is: The estimated distance of a hop between node u and node b is:

Judge Whether the Multi-Hop Shortest Path between Beacon Nodes Is Affected by Concave Boundary
In the concave region, there are two cases when calculating the Euclidean distance between nodes: whether the multi-hop shortest path between sensor nodes influenced by the concave boundary. So, this paper proposes a method for judging whether the shortest multiple paths between nodes are affected by the concave boundary, and a similar path search algorithm to calculate the Euclidean distance between nodes.

Judge Whether the Multi-Hop Shortest Path between Beacon Nodes Is Affected by Concave Boundary
In the concave region, there are two cases when calculating the Euclidean distance between nodes: whether the multi-hop shortest path between sensor nodes influenced by the concave boundary.
Information 2020, 11, 488 6 of 16 So, this paper proposes a method for judging whether the shortest multiple paths between nodes are affected by the concave boundary, and a similar path search algorithm to calculate the Euclidean distance between nodes.

Judgment Method
As shown in Figure 4, u i are target unknown sensor nodes, a 1 , a 2 , a 3 , a 4 are beacon nodes, the solid line is the multi-hop shortest path, the dashed line is the actual shortest path. Affected by the concave boundary, the multi-hop shortest path between nodes a 3 and a 4 is quite different from the actual shortest path. Since the multi-hop shortest path between nodes a 1 to a 2 is not affected by the concave boundary, it is similar to the actual shortest path. Therefore, when estimating the Euclidean distance between a 1 and u 3 , the method d a 1 u 3 = d a 1 u 1 + d u 1 u 2 + d u 2 u 3 can be used. If using the same method to estimate the Euclidean distance between a 3 and u 4 by adding the distance of each hop on the multi-hop shortest path, it will inevitably result in a great error [11]. Therefore, in the concave region, there are two cases when calculating the Euclidean distance between nodes: whether the multi-hop shortest path between sensor nodes influenced by the concave boundary.

Judgment Method
As shown in Figure 4, are target unknown sensor nodes, , , , are beacon nodes, the solid line is the multi-hop shortest path, the dashed line is the actual shortest path. Affected by the concave boundary, the multi-hop shortest path between nodes and is quite different from the actual shortest path. Since the multi-hop shortest path between nodes to is not affected by the concave boundary, it is similar to the actual shortest path. Therefore, when estimating the Euclidean distance between and , the method = + + can be used. If using the same method to estimate the Euclidean distance between and by adding the distance of each hop on the multi-hop shortest path, it will inevitably result in a great error [11]. Therefore, in the concave region, there are two cases when calculating the Euclidean distance between nodes: whether the multi-hop shortest path between sensor nodes influenced by the concave boundary.
This paper proposes a similar path search algorithm, the purpose is to find a multi-hop shortest path between beacon node pair, which is most similar to the multi-hop shortest path of the target to beacon node. After judgment, if the path is affected by the concave boundary, the multi-hop shortest path that beacon node to the target node is also affected by the boundary; Otherwise, it is not affected. For example: in Figure 4, when judging whether the multi-hop shortest path that from to is affected by the concave boundary, first, according to the similar path search algorithm, it can be obtained that the multi-hop path between the beacon nodes and is most similar to the multihop path between and . Then, it is judged that the multi-hop path between and is affected by the concave boundary, so, the multi-hop shortest path between and is also affected by the concave boundary. The method for judging whether the multi-hop shortest path between beacon nodes is affected by the concave boundary is as follows: 1. Calculate the distance between beacon nodes and . Divide by the communication radius to obtain the true shortest path intersection ratio between beacon nodes .
2. According to Formula (11), figure out the distance of each hop. The distance of each hop on the multi-hop shortest path between beacon nodes is summed to obtain the multi-hop path distance (Multi-Hop Distance), and then divided by the communication radius , Obtain the intersection ratio of the multi-hop shortest path between beacon nodes. If there is: it is determined that the multi-hop shortest path between beacon nodes is not affected by the concave boundary; otherwise, it is affected by the concave boundary. This paper proposes a similar path search algorithm, the purpose is to find a multi-hop shortest path between beacon node pair, which is most similar to the multi-hop shortest path of the target to beacon node. After judgment, if the path is affected by the concave boundary, the multi-hop shortest path that beacon node to the target node is also affected by the boundary; Otherwise, it is not affected. For example: in Figure 4, when judging whether the multi-hop shortest path that from u 4 to a 3 is affected by the concave boundary, first, according to the similar path search algorithm, it can be obtained that the multi-hop path between the beacon nodes a 3 and a 4 is most similar to the multi-hop path between u 4 and a 3 . Then, it is judged that the multi-hop path between a 3 and a 4 is affected by the concave boundary, so, the multi-hop shortest path between u 4 and a 3 is also affected by the concave boundary.
The method for judging whether the multi-hop shortest path between beacon nodes is affected by the concave boundary is as follows: 1.
Calculate the distance d a i a j between beacon nodes a i and a j . Divide d a i a j by the communication radius R to obtain the true shortest path intersection ratio between beacon nodes d a i a j R .

2.
According to Formula (11), figure out the distance of each hop. The distance of each hop on the multi-hop shortest path between beacon nodes is summed to obtain the multi-hop path it is determined that the multi-hop shortest path between beacon nodes is not affected by the concave boundary; otherwise, it is affected by the concave boundary.

Similar Path Search Algorithm
This paper proposed a similar path search algorithm, which aims to looks for a multi-hop shortest path between two beacon nodes. It requires that the path is most similar to the multi-hop shortest path between unknown node and the target beacon node. The algorithm uses the Ochiai coefficient [12] to measure the similarity between paths. The larger the value of Ochiai, the higher the similarity between paths; the smaller the value of Ochiai, the lower the similarity between paths. The calculation method of Ochiai coefficient is: A and B are sets, N(x) is the amount of elements contained in the set x. The details of the similar path search algorithm are: 1.
Find the multi-hop shortest path of the target unknown node to a i . Record this sensor nodes passed by the path into set A.

2.
Find the multi-hop shortest paths from the remaining beacon nodes which are in the WSN to node a i , and record the nodes passed by these paths into the sets B 1 , B 2 · · · · · · B j · · · · · · B n (i j).
Arrange the Ochiai coefficient values obtained in step 3 in descending order. If the coefficient value corresponding to Ochiai(A, B j ) is the largest, the multi-hop shortest path from a i to a j is taken as the most similar path Most Similar Path (MSP) of the target unknown node to a i .
For example, as shown in Figure 5, a 1 , a 2 , a 3 , a 4 , a 5 , a 6 are beacon nodes, u 1 , u 2 , u 3 , u 4 , u 5 , u 6 , u 7 , u 8 , u 9 are unknown nodes. When looking for the most similar path that u 1 to a 6 , first, find the multi-hop shortest path from u 1 to a 6 , and record the sensor nodes on the path into the set A, so set A is: {u 1 , a 2 , u 3 , u 6 , u 7 , a 6 ,}. Then record the multi-hop shortest path that between the remaining beacon nodes and a 6 , and record the nodes on these paths to the set B 1 , B 2 · · · · · · B j · · · · · · B n (i j). The results are as follows: B 1 = {a 1 , u 2 , u 3 , u 6 , u 7 , a 6 }, B 2 = {a 2 , u 3 , u 6 , u 7 , a 6 }, B 3 = {a 3 , u 4 , u 3 , u 6 , u 7 , a 6 }, B 4 = {a 4 , u 5 , u 4 , u 3 , u 6 , u 7 , a 6 }, B 5 = {a 5 , u 6 , u 7 , a 6 }. This paper proposed a similar path search algorithm, which aims to looks for a multi-hop shortest path between two beacon nodes. It requires that the path is most similar to the multi-hop shortest path between unknown node and the target beacon node. The algorithm uses the Ochiai coefficient [12] to measure the similarity between paths. The larger the value of Ochiai, the higher the similarity between paths; the smaller the value of Ochiai, the lower the similarity between paths. The calculation method of Ochiai coefficient is: and are sets, ( ) is the amount of elements contained in the set x. The details of the similar path search algorithm are: 1. Find the multi-hop shortest path of the target unknown node to . Record this sensor nodes passed by the path into set . 2. Find the multi-hop shortest paths from the remaining beacon nodes which are in the WSN to node , and record the nodes passed by these paths into the sets , ⋯ ⋯ ⋯ ⋯ ( ≠ ).   According to Formula (11), the Ochiai coefficients of path A and other paths can be calculated as: 0.667, 0.913, 0.667, 0.617 and 0.612. Therefore, the multi-hop shortest path between a 2 and a 6 is used as the MSP from u 1 to a 6 .

Calculate Distance
Base on the above, in the concave region, there are two situations in which the multi-hop shortest path is affected by the concave boundary and not affected by the concave boundary. The distance estimation method in these two cases is as follows: (1) When the multi-hop shortest path is not affected by the concave boundary, according to Formula (11), the sum of the distances of each hop between neighbor nodes on the multi-hop shortest path is used as the estimated distance between nodes. For example, as shown in Figure 6, u i is unknown nodes, a i is beacon nodes. If the multi-hop shortest path between u 3 and a 1 is not affected by the concave boundary, so, the distance between u 3 and a 1 is: The values of d a 1 u 1 , d u 1 u 2 , d u 2 u 3 can be obtained according to Formula (11).
(2) The multi-hop shortest path is affected by the concave boundary. As shown in Figure 6, if the distance from u 4 to a 3 and the distance from u 5 to a 3 need to be calculated, the multi-hop shortest path between beacon nodes a 3 and a 4 is known, and this path is the MSP of u 4 to a 3 and u 5 to a 3 . So u 5 is on the MSP, u 4 is outside the MSP. Therefore, when the multi-hop shortest path is affected by the concave boundary, there are two situations that the unknown node is on the MSP and the unknown node is outside the MSP.
When calculating the distance from u 5 to a 3 , it is known that the unknown node u 5 is on the MSP. As shown in Figure 6, connecting a 3 , u 5 , draw a perpendicular line from u 5 to a 3 a 4 in triangle a 3 a 4 u 5 , and the perpendicular line intersect a 3 a 4 at point g, according to the Pythagorean theorem: The value of d u 5 a 4 in Formula (15) can be calculated according to Formula (11), so there is only one unknown number d a 4 g in Formula (15). The distance between a 4 and g can be estimated according to the intersection ratio of paths and the Ochiai coefficient of MSP. The calculation method is as follows: In Formula (16), Ochiai u 5 a 3 is the Ochiai coefficient of the multi-hop shortest path between nodes u 5 and a 3 . Substituting Formula (16) into Formula (15): When the distance between u 4 and a 3 needs to be calculated, and u 4 is outside the MSP, similarly: In summary, when the u k is on the MSP, the estimation formula of the distance from u k to a i is: When the unknown node u k is outside the MSP, the estimation formula of the distance from u k to a i is: the distance from u k to a i is d a i u k ; the multi-hop shortest path between beacon nodes a i and a j is the MSP of u k to a i , and the distance from a i to a j is d a i a j ; The multi-hop path between u k and a i has a non-coincidence part with its MSP. The non-coincidence path is defined as Dissimilar Path (DSP), and d DSP is the length of the DSP; Ochiai u k a i is the Ochiai coefficient that the multi-hop shortest path from u k to a i ; d a i a j /R is the actual shortest path intersection ratio of a i and a j ; d MHP /R is the multi-hop shortest path intersection ratio of a i and a j .
Information 2020, 11, x FOR PEER REVIEW 9 of 16 the distance from to is ; the multi-hop shortest path between beacon nodes and is the MSP of to , and the distance from to is ; The multi-hop path between and has a non-coincidence part with its MSP. The non-coincidence path is defined as Dissimilar Path (DSP), and is the length of the DSP; ℎ is the Ochiai coefficient that the multi-hop shortest path from to ; ⁄ is the actual shortest path intersection ratio of and ; ⁄ is the multi-hop shortest path intersection ratio of and .

Location Calculation of Unknown Nodes
n is the amount of beacon nodes in the sensor network, the coordinates of the beacon nodes are: a 1 (x 1 , y 1 ) · · · · · · a i (x i , y i ) · · · · · · a n (x n , y n ). The distances from u to the beacon nodes are d 1u · · · · · · d iu · · · · · · d nu , so: . .
Using the least squares method: According to Formula (26), the location of the target node u is (x u , y u ). Figure 6 manifests that if the deployment of sensor nodes in this area is extremely sparse, although the unknown node u 5 is on the MSP, the node u 5 may also be far away from a 3 compared with a 4 ; in the same way, although the node u 4 is outside the MSP, it is also possible closer to a 3 than a 4 . Therefore, in the case of extremely sparse node deployment, there will be a slight error in the calculation of dissimilar paths using Formula (16). However, constrained by the Ochiai coefficient and the distance between beacon nodes on the MSP, the error can be ignored. In view of this situation, this paper uses PSO to iteratively optimize the localization results of the first stage.

Improved PSO Algorithm
The PSO algorithm has the advantages of few parameters, faster convergence, no need for gradient information and so on [13]. In the algorithm, using the massless particle swarm to looking for the optimal location. The basic principle of the PSO algorithm is: If there are m particles in the particle swarm, looking for the optimal solution in the space with D-dimensional, then the location of the i-th particle is: X i = (x i1 , x i2, · · · · · · x iD ). Each location of the particle is a potential solution, and the pros and cons of the position are measured according to the objective function. The optimal location that the particle passed is: P best(i) = (p i1 , p i2, · · · · · · p iD ), record the optimal coordinate currently searched in the entire particle swarm as: G best = (p g1 , p g2, · · · · · · p gD ). During the execution, particles find better G best by iteratively updating their moving speed and location. The updated iterative formulas for the speed and location of the particles are: In the Formulas (27) and (28), i = 1, 2, · · · m, d = 1, 2, · · · D, t is the current iteration number, P best(i) is the individual extreme value of the i-th particle, and G best is the current optimal solution. The random numbers are r 1 , r 2 , whose values are between in [0,1], ω is the inertia weighting factor, the acceleration factors are c 1 , c 2 , which enable particles to have the ability to learn, so as to approach the individual best points and the global best points. The research uses PSO algorithm in the second stage to iteratively optimize the results obtained in the first stage. With the aim of declining the impact of distance error on the results and improving localization accuracy. The location of beacon nodes are: a 1 (x 1 , y 1 ) · · · a i (x i , y i ) · · · a n (x n , y n ), According to the first-stage ranging algorithm, the distances from beacon nodes to u are: d 1u · · · d iu · · · d nu . If the errors of distance estimation are: ε 1u · · · ε iu · · · ε nu , we can get the following Formula (29): The value of |ε 1u | + · · · + |ε iu | + · · · + |ε nu | is smaller, the result is more accurate, so the fitness function is designed as: The specific steps of using particle swarm to optimize the coordinates of sensor nodes are as follows: 1.
Initialize particle population. The difference between the two-stage localization algorithm and other localization algorithms is that the initial position of the particle population is not completely random when locating the unknown node u [14], but is limited to a specific circle. The center of the circle is the localization result (x u , y u ) of node u obtained in the first stage. The radius is the maximum value D DSP of all non-similar path lengths of the unknown node u in the ranging stage. The calculation formula of D DSP is: , · · · · · · d DSPi } (i = 1, 2, 3, · · · · · ·) (31) That is, the initial location of the particle population is randomly generated within the circle, assigning the initial speed of all particles to 0, and the maximum iteration t max to 100.

2.
Figure out the fitness function value of every particle base on Formula (30).

3.
Update the P best(i) and G best base on the Formulas (32) and (33): 4. According to Formulas (27), (28) and (34), the coordinates and speed of each particle are updated. The smaller the ω value, the stronger local search capability. The larger the value of ω, the stronger global search capability. Because the optimization is based on the existing results, the particles need strong local search capability, and there is no requirement for the global search ability of the particles [15]. So it will be designed ω t as a function that gradually decreases as the times of iterations increases. That is, as the times of iterations increases, the local optimization ability of the particles is gradually increased. Lots of experiments have proved that the highest localization accuracy is obtained when ω min = 0.25 and ω max = 0.75. ω t is the current inertia factor.

5.
If t max = 100, the algorithm ends, and the G best is taken as the final coordinate of the target unknown node. Otherwise, perform step 2. 6.
Select the next unknown node and operate step 1.
The pseudo code of the improved PSO algorithm in the second stage is shown in Algorithm 1.

Experiment Results and Analysis
Experiments were carried out under the Windows 10 computer operating system, and matlab2016a was used for simulation experiment.
In Formula (35), T represents the times of experiments, (x, y) is the actual coordinate of node u, the estimated coordinate is (x u , y u ), communication radius is R, the total amount of sensor nodes is NAmount, the amount of beacon nodes is BAmount.
A concave boundary was randomly generated within the square communication region which with the area of 40,000 square meters, so that the communication region became a concave region, then, 100 nodes were randomly deployed in the communication area to simulate various sensor networks by changing communication radius and proportion of beacon nodes in the WSN. Then, we studied the influence of these parameter changes on the results and algorithm execution time.

Relationship between Beacon Node Ratio and Localization Results
We can see from Figure 7 that the localization accuracy of FABL algorithm, CHP algorithm and REP algorithm fluctuated greatly with the change of beacon node ratio, and when the ratio is less than 15%, the error of these three algorithms was more than 20%. This is because when the beacon nodes were relatively sparse, the ranging method based on the hop count multiplied by the hop distance caused larger localization errors due to the accumulation of hop distance errors [16]. This study invented a method that based on the intersection ratio to calculate the distance, which did not depend on the coordinate of the target beacon nodes, and discarded the traditional ranging idea of multiplying the number of hops by the hop distance, effectively avoiding the hop error and improving the accuracy. In Figure 7, the error of two-stage PSO algorithm proposed in this paper was always within 10%. Compared with the others three methods, it was less affected by the proportion of beacon nodes and had higher localization accuracy.

Relationship between Beacon Node Ratio and Execution Time of Algorithm
In Figure 8, the REP algorithm took more than 110 s to execute; the higher the beacon node ratio, the longer the execution time required for the algorithm. The execution time of CHP algorithm was between 70 s and 80 s, and the execution time of FABL algorithm and two-stage PSO algorithm was about 20 s. The REP algorithm and the CHP algorithm needed to construct a virtual circle and divide the communication area, so more calculation time was required. The two-stage PSO algorithm did not need to split the path, divide the communication area operations, just by judging whether the path between the nodes was affected by the concave boundary, and could complete the ranging. The PSO was used in this algorithm, but optimization on the basis of the existing results required very few iterations and took a short time.   Figure 9 indicates that when radius was less than 20 m, the average error of FABL and CHP were both above 45%, the error of the REP also reached 29%. This is because when the communication radius was small, the hop count on the shortest path suddenly increased, which resulted in a large accumulation of hop distance error during the ranging process and greatly reduced the accuracy of

Relationship between Beacon Node Ratio and Execution Time of Algorithm
In Figure 8, the REP algorithm took more than 110 s to execute; the higher the beacon node ratio, the longer the execution time required for the algorithm. The execution time of CHP algorithm was between 70 s and 80 s, and the execution time of FABL algorithm and two-stage PSO algorithm was about 20 s. The REP algorithm and the CHP algorithm needed to construct a virtual circle and divide the communication area, so more calculation time was required. The two-stage PSO algorithm did not need to split the path, divide the communication area operations, just by judging whether the path between the nodes was affected by the concave boundary, and could complete the ranging. The PSO was used in this algorithm, but optimization on the basis of the existing results required very few iterations and took a short time.

Relationship between Beacon Node Ratio and Execution Time of Algorithm
In Figure 8, the REP algorithm took more than 110 s to execute; the higher the beacon node ratio, the longer the execution time required for the algorithm. The execution time of CHP algorithm was between 70 s and 80 s, and the execution time of FABL algorithm and two-stage PSO algorithm was about 20 s. The REP algorithm and the CHP algorithm needed to construct a virtual circle and divide the communication area, so more calculation time was required. The two-stage PSO algorithm did not need to split the path, divide the communication area operations, just by judging whether the path between the nodes was affected by the concave boundary, and could complete the ranging. The PSO was used in this algorithm, but optimization on the basis of the existing results required very few iterations and took a short time.   Figure 9 indicates that when radius was less than 20 m, the average error of FABL and CHP were both above 45%, the error of the REP also reached 29%. This is because when the communication   Figure 9 indicates that when radius was less than 20 m, the average error of FABL and CHP were both above 45%, the error of the REP also reached 29%. This is because when the communication radius was small, the hop count on the shortest path suddenly increased, which resulted in a large accumulation of hop distance error during the ranging process and greatly reduced the accuracy of localization [17]. Although the localization accuracy of these three algorithms was improved with the increase of radius, the coordinate error was still large, and an excessive communication radius greatly increased the cost of the network. In Figure 9, the average error of the two-stage PSO algorithm was always within 10%, which had the higher localization accuracy. The algorithm was unacted on the radius, and was more suitable for the localization of complex and diverse concave regions.
Information 2020, 11, x FOR PEER REVIEW 14 of 16 increased the cost of the network. In Figure 9, the average error of the two-stage PSO algorithm was always within 10%, which had the higher localization accuracy. The algorithm was unacted on the radius, and was more suitable for the localization of complex and diverse concave regions.

Relationship between Communication Radius and Execution Time of Algorithm
In Figure 10, the REP algorithm and the CHP algorithm in the four algorithms took a long time. The execution time of the REP was about 120 s, and the execution time of the CHP was about 80 s. The execution time of these two algorithms was mainly consumed in the process of path segmentation and region partitioning, so it was not affected by the radius. The execution time of FABL algorithm and two-stage PSO algorithm was relatively short. As the radius changed, the execution time of these two algorithms changed slightly. This was because as the radius increased, the amount of hops between nodes gradually decreased, reducing the ranging time. On the whole, compared with other algorithms, the execution time of the two-stage PSO was shorter, which could extend the service life of the node.

Conclusions
For the problem of the nodes localization algorithm in the concave area, this paper studied the deficiencies of various concave area localization algorithms based on beacon node selection, communication area division, shortest distance correction, etc. Considering the shortcomings of

Relationship between Communication Radius and Execution Time of Algorithm
In Figure 10, the REP algorithm and the CHP algorithm in the four algorithms took a long time. The execution time of the REP was about 120 s, and the execution time of the CHP was about 80 s. The execution time of these two algorithms was mainly consumed in the process of path segmentation and region partitioning, so it was not affected by the radius. The execution time of FABL algorithm and two-stage PSO algorithm was relatively short. As the radius changed, the execution time of these two algorithms changed slightly. This was because as the radius increased, the amount of hops between nodes gradually decreased, reducing the ranging time. On the whole, compared with other algorithms, the execution time of the two-stage PSO was shorter, which could extend the service life of the node. increased the cost of the network. In Figure 9, the average error of the two-stage PSO algorithm was always within 10%, which had the higher localization accuracy. The algorithm was unacted on the radius, and was more suitable for the localization of complex and diverse concave regions.

Relationship between Communication Radius and Execution Time of Algorithm
In Figure 10, the REP algorithm and the CHP algorithm in the four algorithms took a long time. The execution time of the REP was about 120 s, and the execution time of the CHP was about 80 s. The execution time of these two algorithms was mainly consumed in the process of path segmentation and region partitioning, so it was not affected by the radius. The execution time of FABL algorithm and two-stage PSO algorithm was relatively short. As the radius changed, the execution time of these two algorithms changed slightly. This was because as the radius increased, the amount of hops between nodes gradually decreased, reducing the ranging time. On the whole, compared with other algorithms, the execution time of the two-stage PSO was shorter, which could extend the service life of the node.

Conclusions
For the problem of the nodes localization algorithm in the concave area, this paper studied the deficiencies of various concave area localization algorithms based on beacon node selection, communication area division, shortest distance correction, etc. Considering the shortcomings of

Conclusions
For the problem of the nodes localization algorithm in the concave area, this paper studied the deficiencies of various concave area localization algorithms based on beacon node selection, communication area division, shortest distance correction, etc. Considering the shortcomings of intelligent optimization algorithm in WSN location, the energy consumption is too large and the result is not qualified. In this paper, a two-stage PSO node localization algorithm which suitable for concave areas was proposed. The algorithm creatively uses the ranging method based on the idea of similar path and intersection ratio in the node location of concave area, and combines it with the PSO algorithm. It not only effectively improves the accuracy of the distance, but also solves the problem that the amount of iterations of the intelligent optimization methods in the WSN localization application is too large. Through a lots of experiments, it is proved that the localization error of this algorithm is always within 10% and the execution time is maintained at about 20 s when the communication radius and beacon node ratio is changing. So, the algorithm has good localization accuracy and good stability, which can greatly reduce the computational energy consumption. In the next step of research, we will continue to study the other algorithms that the localization of wireless sensor nodes, as well as the impact of beacon node coordinates on the localization results.