A Two-Stage Wireless Sensor Grey Wolf Optimization Node Location Algorithm Based on K-Value Collinearity

In the practical application of WSN (wireless sensor network), location information of the sensor nodes has become one of the essential information pieces in the whole network. At present, some localization algorithms use intelligent optimization algorithm to optimize the node group directly. Although the overall localization error is reduced, the location deviation of individual unknown nodes will be larger, and the large number of iterations will cause a large energy consumption of nodes. Aiming at the above problems, this paper comes up with a two-stage WSN localization algorithm based on the degree of K-value collinearity (DC-K) and improved grey wolf optimization.'e first stage is aiming at the defects of the existing collinearity algorithm, putting forward the concept of DC-K, according to the K-value to carry out the initial location in the first stage. 'e second stage is using the improved grey wolf optimization algorithm to optimize the location results which were obtained in the first stage, so as to get more accurate location results. 'e experimental results display that this localization algorithm with a better localization accuracy has high robustness and has fewer iterations in the optimization process, which greatly reduces the energy consumption of nodes.


Introduction
Localization is to identify the coordinates of something in a geographical environment. e significance of node localization technology in WSN is to deduce the coordinates about the unknown nodes which are located in the network. Due to the continuous development and progress of sensing technology, the use of the WSN (wireless sensor network) is more and more powerful. At present, the application of WSN in transportation, medical and electrical appliance, and other areas of life is wide. WSN deploys a large number of stationary or mobile sensor nodes in the area to be monitored, making these sensor nodes form a network system through radio communication.
e purpose is to collaboratively perceive multidimensional information within the monitoring area (such as humidity, temperature, noise, geological characteristics, and life characteristics) and then process and transmit the collected data. When the sensor node is working, firstly, the node sends it, collecting the physical, chemical, biological, and other information to the terminal computer, and then feeds back the information to the user. Finally, the user makes corresponding operations according to the information. In most applications, the information sent back by the node must be combined with the coordinate of the node to make sense. Sometimes, it is even necessary for the node to simply send the location information. In conclusion, sensor node location is the critical technology in sensor networks.
At present, according to whether it is necessary to acquire the angle information or distance information between nodes through physical measurement, sensor node location technology could be divided into two parts that are rangefree algorithm and range-based algorithm [1]. Due to the use of measuring equipment, the location accuracy of rangebased is higher, such as RSSI (received signal strength indication). However, the cost of adding additional distance measurement equipment to the node is very high; the lifetime of the sensor node is also greatly shortened by frequent receiving of ranging information. In addition, this method fails in extremely complex geographical environments.
e range-free technique is using the localization algorithm to estimate the Euclidean distance from the unknown sensor nodes to the beacon sensor nodes or estimating the possible area containing the unknown node according to some nodes with known coordinates (beacon nodes) and then inferring the coordinates of the unknown nodes [1]. is type of technology does not require hardware ranging modules. e classical range-free node localization methods are such as DV-hop (distance vector-hop algorithm), centroid algorithm, and APIT algorithm (approximate point-in-triangulation test). Range-free technology does not require additional hardware support; its advantages are easy implementation, having low cost, low energy consumption, and high computational efficiency, compared to the range-based algorithm which can be more suitable for the actual application of the sensor network.
For increasing the location accuracy of range-free location technology, many experts and scholars have studied and improved the DV-hop, which can be divided into two steps. So, the first stage is to estimate the Euclidean distance of beacon nodes to unknown nodes. And the second stage is to infer the coordinates of the unknown nodes from the distance. For raising the accuracy of distance estimation from unknown nodes to beacon nodes, in [2], a search algorithm for similar paths is proposed to find a path between beacon node pairs with the highest similarity according to the Ochiai coefficient and calculate the single hop correction value according to the hop's number and the Euclidean distance of the pair of beacon sensor nodes, thus raising the accuracy of Euclidean distance estimation; in [3], it is assumed that the communication radius of the sensor node is R, and the one-hop's distance within the whole wireless sensor network is modified to R/2, which reduces the error within the one-hop range; in [1], the authors put forward the concept of intersection ratio; first, they calculated the area of intersection between the unknown node and the neighboring beacon node communication circle, then they calculated the ratio of this area to the entire communication range, and finally they estimated the distance between the unknown node and the beacon node according to the ratio. In the second stage, more and more scholars apply the intelligent optimization method to location estimation of wireless sensor node; in [4], PSO (particle swarm optimization algorithm) is introduced, through hundreds of iterations of the particle swarm optimization model; the coordinates of the unknown nodes that are consistent with the fitness function are finally obtained; implementing localization algorithm [5] improved the particle swarm optimization localization method and came up with the concept of quantum particle swarm, choosing the wave function to describe the state of the particle and increasing the location accuracy, but the computational cost is higher. At present, there are few improved two-stage localization algorithms for both distance estimation and coordinate calculation. In summary, the existing researches still have large errors in the distance estimation stage; in the second stage, particle swarm optimization, simulated annealing optimization, and other intelligent optimization algorithms are used directly, which can easily fall into local optimization and cause huge energy consumption due to too many iterations. However, the existing two-stage positioning algorithm directly refers to DV-hop and intelligent optimization algorithm which cannot solve the defects of intelligent optimization algorithm that consumes too much energy and easily falls into local optimization. In this paper, aiming at the shortcomings of the above studies, we came up with a two-stage wireless sensor grey wolf optimization node localization algorithm based on K-value collinearity. In the first stage, according to the defects of collinearity [6][7][8], in this paper, we propose the new collinearity based on K-value and then infer to the initial location of the node from the collinearity of K-value; in the second stage, the improved localization algorithm of GWO is used to optimize the node location. Experiments show that two-stage DC-K localization method could raise the location accuracy effectively. In the optimization stage, only 30 iterations are needed to obtain a better location result, which greatly reduces the energy consumption of nodes.

Selection of Location Unit
Based on Collinearity 2.1. Error Analysis. After obtaining the Euclidean distance which is from beacon nodes to unknown node, localization algorithms perform the trilateral measurement or maximum likelihood method to infer the coordinate of unknown sensor nodes. In the process of location estimation, the location topology between beacon sensor nodes and topology shape from beacon nodes to unknown nodes will greatly affect the localization accuracy [9]. Generally, the more uniform the distribution of beacon nodes is, the more accurate the localization will be. In the following, we take three beacon nodes as an example to discuss the influence of location topology between nodes on localization accuracy.

Case 1.
When any two of the three beacon nodes of the localization unit are too close to each other, meanwhile, the unknown sensor node is very far from the two beacon sensor nodes and there will be a large localization error. As is displayed in Figure 1, A, B, and C are beacon sensor nodes and D is unknown sensor node in the localization unit, compared with the distance from node D to the localization unit; the distance between B and C is easy to be ignored; therefore, the localization result of the unknown node D may appear at the location of D′, which causes a large localization error.

Case 2.
When the beacon nodes in the localization unit are collinear or close to collinear, the localization matrix is irreversible, resulting in a large localization error and even leading to the localization failure. From Figure 2 we could get that when the beacon nodes A, B, and C are close to collinear, then the unknown node D is located that will lead to the localization result which may be at the location of D′.
Case 3. When the three beacon nodes in the localization unit are very close to each other and the unknown node is very far away from the localization unit, it will cause a large localization error. As shown in Figure 3, A, B, and C are beacon nodes, D is unknown sensor node, and D′ is localization result that may occur.

Degree of Collinearity Based on Minimum Height (DC-H) and Minimum Cosine of Interior Angle (DC-A).
In [8], the authors came up with the concept of collinearity. According to the collinearity estimate for whether the topological shape between beacon nodes is suitable for localization, this came up with the concept of DC-H. As shown in Figure 4, ΔABC is a triangle formed by beacon nodes A, B, and C. e minimum height is the minimum value of three heights in ΔABC (the height on the longest side). erefore, the value of minimum height is the collinearity of the three beacon nodes: (1) Under this definition, the value range of collinearity is ; the communication radius of the nodes is R, which is in the network. When the degree of collinearity is equal to 0, it indicates that the nodes A, B, and C are collinear and the localization accuracy is the worst; when the degree of collinearity is equal to ( � 3 √ /2)R, beacon sensor nodes A, B, and C constitute an equilateral triangle, which is most suitable for locating unknown node. In summary, when the minimum height is closer to ( � 3 √ /2)R, the localization accuracy is higher.
According to [7], the interior angle size of a triangle can better reflect the shape of a triangle; therefore, the degree of collinearity is defined by the cosine of the minimum interior angle, as shown in Figure 5. ΔABC is a triangle formed by beacon nodes A, B, and C: In ΔABC, the cosine of the three interior angles is In a triangle, the value range of the minimum interior angle is [0, π/3]; therefore, the value range of the cosine of the minimum internal angle is [0.5, 1], which is inversely proportional to the angle. When the degree of collinearity is equal to 0.5, it means that the topology formed by the localization unit is an equilateral triangle; when the degree of collinearity is equal to 1, it means that the beacon nodes in the localization unit are collinear. In summary, the closer the DC-A is to 0.5, the higher the localization accuracy is and vice versa.
In [6], the authors considered the minimum height and the minimum angle at the same time and came up with the concept of Degree of Aggregation-Collinearity (DAC). However, in the first stage, it still uses the RSSI algorithm and needs to add peripheral devices to the nodes; it belongs to the category of the range-based algorithm, so it will not be described in this paper.

Defects of DC-H.
rough the above research, it is not difficult to find that the collinearity localization algorithm based on the minimum height cannot accurately reflect the topological shape of the triangle. When the area of a triangle is also larger, the minimum height of the triangle is larger, but the topological shape may not be closer to an equilateral triangle. As shown in Figure 6, the minimum height of ΔABC is obviously larger than the minimum height of ΔA 1 B 1 C 1 ; however, ΔA 1 B 1 C 1 is an equilateral triangle with better localization effect, which is contrary to the statement in [8].

Defects of DC-A.
If the topological shape of the three beacon nodes of a localization unit is an equilateral triangle, so, the DC-A is equal to 0.5; according to [7], the localization effect is the best. However, if the three beacon sensor nodes are close to each other, the unknown sensor nodes are far away from the beacon sensor nodes; as described in Case 3 of the above error analysis, the localization accuracy is very low.
At the same time, whether it is DC-H or DC-A, the DAC localization algorithm will have the following disadvantages: once a group of optimal localization units is found, the unknown nodes of the whole network will use it for location estimated. It can not only effectively make full use of other beacon sensor nodes' coordinate conditions which are in the WSN, but also cause large localization error.

K-Value Collinearity (DC-K) Based on APIT Algorithm.
e theory of APIT (approximate point-in-triangulation test) is triangular coverage approximation [10], as shown in Figure 7. e unknown node randomly selects three beacon nodes from the whole sensor network and then determines whether it is located in the triangular topology formed by the three beacon nodes, repeating the process until enumerating all the beacon nodes units; finally, the center of mass of all the overlapped triangles that can make the unknown node inside is taken as its estimated location [11]. How to control the unknown sensor node is located inside the triangle which consists of the beacon sensor nodes, being key of APIT algorithm. APIT algorithm adopts PIT test method; the principle of PIT is as follows: Figure 8 shows that A, B, and C are beacon nodes and D is unknown node; if there is a direction that enables the unknown node D to move in this direction, approaching or being away from the beacon sensor nodes A, B, and C at the same time, it indicates that D is located outside of the triangle; if it does not exist, this indicates that the unknown sensor node D is located inside of the triangle. In practice, it is impossible to test all directions [12]; so, T. HE came up with the APIT algorithm based on PIT; the principle of APIT is as follows: if there is a neighbor node away from or close to the beacon nodes at the same time relatively to D, it indicates that the unknown node is outside of the triangle; or, else, D is in the triangle [13].
In the above error analysis, it is pointed out that although the topological shape of beacon nodes in the localization unit is equilateral triangle or close to equilateral triangle, the Euclidean distance of the three beacon nodes is very close to the unknown sensor node which is very far away from the beacon nodes; it will cause a large localization error. is is a problem that has not been solved in previous research of DC algorithm. In this paper, aiming at the shortcomings and limitations of the existing DC algorithm, we came up with the K-value collinearity based on APIT algorithm; its basic principle is as follows: by executing APIT algorithm, we found the localization unit which could locate the unknown node inside the triangle and meet the K-value condition; then, these beacon nodes are used to locate the unknown node's coordinate in the localization unit. In this way, the unknown node could be controlled inside the triangle and consists of the three beacon nodes in the localization unit, which not only make full use of the location information of beacon nodes in the WSN, but also avoid the situation described in the error analysis above and make up for the common defects of other DC algorithms. e calculation method of K-value is as follows: h is the minimum height (the height corresponding to the longest side or the largest interior Angle) and l is the value of the longest side in the triangle. When K is equal to the minimum value of 0, 2h So, when K � 0, the topological shape of beacon nodes is an equilateral triangle. In summary, when K-value is smaller, the distribution of beacon nodes A, B, and C is closer to equilateral triangle and the localization accuracy is higher. Using 2h/ � 3 √ l, the influence of the maximum angle and the minimum height on the shape of the triangle is considered as shown in Figure 9.
Each time the algorithm is executed, an unknown node is located, so the maximum number of the iteration is set as T max � UNAmount (the count of unknown nodes). (10) e steps of wireless sensor node location algorithm based on K-value collinearity are as follows: (1) Execute the APIT algorithm, enumerate all locating units, and record the localization units in M set which can make the unknown sensor node u located inside topological triangle. If the set is empty, execute step (6) directly; otherwise, execute the next step: (2) For the unknown node u, enumerate all the localization unit combinations which are in M set: . .ΔA n B n C n . According to (6), respectively, calculate the K-value of this localization unit; if the K-value meets (12), then record the localization units in N set. If N is empty, then execute step (6) directly. Otherwise, execute the next step: (3) At this moment, the unknown node u is inside the ΔA i B i C i formed by the localization unit in set N. If the actual distance from u to beacon nodes A i , B i , and C i is smaller, then, iteration error will be smaller when using the single hop size and hops to estimate the distance. Otherwise, the localization error will be larger [14]. erefore, calculate the area of topological triangles in set N and take the combination of beacon nodes with the smallest area as the localization unit of unknown node u. Figure 6: Schematic diagram of the minimum height contrast of a triangle.
So, S k � min . . . S i . . . ; assuming that the three vertices are A k , B k , and C k of the triangle whose area is S k , then the sensor nodes A k (x Ak , y Ak ), B k (x Bk , y Bk ), and C k (x Ck , y Ck ) are regarded as the localization unit of unknown sensor node u. (4) Estimate the Euclidean distance of the unknown node u to beacon nodes A k , B k , and C k ; then, preliminarily locate node u. ① Estimate the Euclidean distance of the node u to beacon nodes A k , B k , and C k . e sensor node u is inside triangle which consists of the beacon nodes which are in the localization unit, improving the single hop size in DV-hop sensor node localization method; in the case of only considering the distances and the number of hops between beacon nodes in the localization unit, calculate the local single hop size to estimate the distance. Moreover, because the topological triangle area constituted by the localization unit of unknown node u is the smallest among all triangles meeting (12), the calculation method of local single hop size can greatly improve the accuracy of distance estimation. e calculation method of local single hop size and distance estimation is as follows: If the estimated distance from u to A k , B k , or C k is larger than the longest side of the triangle, then the value of this distance is modified to the value of the longest side of the triangle. is is because when u is inside the triangle, the distance from u to any vertex cannot be larger than the longest side of the triangle. If ② Preliminary localization of unknown node u: rough carrying out the maximum likelihood estimation of (22), get Figure 9: Diagram of DC-A. 6 Mathematical Problems in Engineering Transform (23) into a matrix: According to the least square method, X � x u y u .
(27) (5) Promote node u to anchor node and give it a low credibility, in the next round of localization; when anchor nodes are insufficient or the K-value of all localization units does not meet (12), node u will participate in locating as a beacon node. (6) If the execution time of the localization algorithm is less than T max , then select the next unknown node and execute step (1). Otherwise, the loop ends. When the execution times of the localization algorithm are equal to T max , there are still unknown nodes that have not been located; then, regard this part of unknown nodes as boundary nodes and execute step (7). (7) Dealing with boundary nodes, diffuse the beacon nodes in one-hop range of the boundary node by using x i � a · r cos(2πb) + x Ai , y i � a · r cos(2πb) + y Ai , (a < 1, b < 1).
e beacon node's original coordinate is (x Ai , y Ai ), and (x i , y i ) is the random coordinate after diffusion. After diffusion, reexecute the above DC-K algorithm to infer the coordinate of the boundary nodes. So far, the localization algorithm of the first stage has been completed.

Improved Grey Wolf Optimization Algorithm
e Grey Wolf Optimizer (GWO) is a swarm intelligence optimization algorithm. e paper [15] simulated the hierarchy and predation activities of wolves, proposing and analyzing the GWO algorithm.
is algorithm has the characteristics of having a few parameters, strong convergence, and easy implementation. e principle of the GWO algorithm is as follows: all grey wolves were divided into groups of α, β, δ, and ω; according to the level of the social hierarchy, when hunting prey, α, β, and δ will guide the lowest level of ω wolf to search for prey, and the location of α wolf is the final result at the end of hunting. e classical DV-hop algorithm uses the least square method to get the solution of (22), and according to the estimated distance this completes the localization calculation [16]. In this paper, in the second stage, the three beacon nodes in the localization unit and the estimated distance obtained by DC-K algorithm participate in the iterative calculation, and the improved GWO is used to obtain the optimal solution of the (22). In order to reduce the impact of the Euclidean distance estimation error in the first stage on the final localization result, in this paper, the distance (d Au , d Bu , d Cu ) of the beacon nodes and the sensor node u in the localization unit is included in the vector of each individual for synchronous iteration, according to the vector to design the fitness function. is method can not only solve the influence of distance estimation errors on the final localization results, but also add constraints of the fitness function, thereby greatly reducing the times of iterations [17]. In this paper, the specific steps of applying the improved grey wolf optimization algorithm to wireless sensor node location are as follows: (1) e coordinates of the unknown sensor nodes in the first stage and the three distances to the beacon nodes of the localization unit constitute such a 5-dimensional vector: [x u , y u , d Au , d Bu , d Cu ].
(2) Calculating the fitness function about each individual wolf, (x u , y u ) is the coordinate of the sensor node u, (x i , y i ) is the coordinate of the beacon node in localization unit of the unknown node u, and d iu is the estimated Euclidean distance of the beacon node to unknown sensor node which is in localization unit. e three unknown nodes with the smallest fitness are α wolf, β wolf, and δ wolf, respectively, and the rest are ω wolves.
(3) e iterative model is as follows (max � 20): A is the convergence factor; r 1 , r 2 are random numbers in [0, 1]; and C is the swing factor; X(t) is the vector of the wolf when the times of iteration are equal to t; X(t − 1) is the vector of the wolf when the times of iteration are equal to t − 1. In each iteration, the location of α wolf changes according to (30)-(32). e process of ω wolf location changes is the process of hunting, which is the process of looking for the optimal solution. (4) After the iteration of step (3)

Experimental Results and Analysis
e experiment was conducted with Windows10 computer operating system, and the simulation experiment was carried out with matlab2016a. Randomly deploy 100 sensor nodes in a 100 × 100 square area, compare and analyze the performance of the wireless sensor node localization algorithm from different communication radius and beacon node ratio, and compare with the DC-H, DC-A, GWO, and DVhop. Average localization error is defined as T is the time of the experiment; (x, y) is the actual coordinate of the sensor node u; R is the communication radius; the amount of sensor nodes is NAmount, located in this network; BAmount is the number of beacon sensor nodes. When the beacon sensor node ratio is 20%, the distribution diagram about the nodes is shown in Figure 10.

Influences of Beacon Node Ratio on Algorithm.
Under the same communication radius (R � 35 m), the influence of different beacon node ratio on each algorithm is shown in Figure 11: (1) As shown in the figure, compared with DV-hop, the localization results accuracy of the other four localization algorithms is higher, especially when the beacon node ratio is more than 20%. (2) Using the localization method of intelligent optimization algorithm GWO, when beacon sensor node ratio is 10%, the average localization error is more than 50%. (3) e two-stage GWO algorithm has better localization accuracy than other algorithms and solves the problem that GWO algorithm cannot converge when the beacon node ratio is low. As shown in Figure 10, although the localization accuracy of DC-A and DC-H algorithms is less affected by the anchor node ratio, the localization error is large. is is because once the best localization unit in DC-A or DC-H is founded, all unknown nodes will use it to locate, and the coordinates of other beacon nodes in this network cannot be effectively utilized, resulting in a large localization error [18]. In this paper, based on the APIT algorithm, we came up with the DC-K algorithm, by controlling the unknown nodes in the topological triangle formed by beacon nodes in the localization unit, which solves this problem effectively.

Influences of Communication Radius on Algorithm.
Under the same beacon node ratio (Beacon/100 � 25%), the influence of different communication radius on the localization result of each algorithm is shown in Figure 12:   Mathematical Problems in Engineering (1) As shown in Figure 11, the DV-hop's localization error decreases when the communication radius increases; hence, the DV-hop's performance is greatly affected by the communication radius. Because of using the distance estimation method of single hop size and hops, when the communication radius decreases, the minimum hops from beacon nodes to unknown node increase, resulting in a large distance estimation error. (2) e DC-A and DC-H were improved in the localization stage but still fully use the distance estimation method of DV-hop localization method in the first stage. erefore, the localization accuracy will be greatly affected by the communication radius. Because of the shortcomings of the collinearity algorithm, the overall localization error is still large.
(3) Although GWO algorithm is less affected by the communication radius, the fitness function lacks constraints, resulting in the poor localization accuracy. (4) With the same beacon node ratio, the two-stage degree of K-value collinearity GWO algorithm integrates the advantages of DC-A, DC-H, and GWO, reducing the impact of node communication radius on the performance of the algorithm, and improves the localization accuracy.

Conclusion
In order to increase the localization accuracy of wireless sensor nodes, this paper studies the shortcomings of the existing collinearity algorithm and the disadvantages of intelligent optimization algorithm in WSN localization and proposes a two-stage wireless sensor grey wolf optimization node location algorithm based on K-value collinearity. Based on the APIT algorithm and putting forward the concept of DC-K, organically combined with the improved grey wolf optimization algorithm, this not only makes up for the shortcomings of previous DC algorithms, but also solves the problem that intelligent optimization localization algorithm is easy to fall into the local optimization and reduces the times of iteration. e experimental results show that the two-stage DC-K localization algorithm with the better localization accuracy and strong robustness can greatly decrease the calculation energy consumption in the localization process and extend the service life of the sensor nodes. e DC-K algorithm is suitable for the regions with random distribution of nodes. However, in concave regions, the shortest distance between sensor nodes is easily affected by concave boundaries, which will increase the error of distance estimation and affect the localization accuracy. In the next research, the localization algorithm with higher accuracy in concave regions will be studied; in the second stage, dynamic changes or other improvements to the weight factor of prey localization will be considered.

Data Availability
e experimental code used to support the findings of this study is available from the corresponding author upon request. Mathematical Problems in Engineering 9