# Tracking Mobile Sinks via Analysis of Movement Angle Changes in WSNs
## 3 Details of Damst
### Routing Algorithm based on Route Deviation Angles  
Algorithm 1 cancels the useless footprints on detours from the DAMST point list. In forwarding the query from the mobile sink to the RA, it may happen that the distance between two adjacent DAMST points is over the node communication radius. In order to find a shortest path between these two unconnected adjacent DAMST points, Algorithm 2 is designed. In Algorithm 2, no matter whether the current node is a DAMST point or not, it needs to find a neighbor as a relay node to forward the query, according to its neighbors' route deviation angles and the next DAMST point the query will go to. The route deviation angle is defined in Definition 2 and depicted in Figure 8.  
**Definition 2**.: _The route deviation angle of a neighbor node is an angle that is between the edge from the current node to the next DAMST point and the edge from the current node to the neighbor node._  
As shown in Figure 8, the current node is the DAMST point P[k], the next DAMST point is the DAMST point P[k-1], the neighbor nodes of P[k] are nodes A, B and C, route deviation angles of the neighbor nodes are respectively angle 1, angle 2 and angle 3. Through observation of Figure 8, it can be seen that the neighbor having a smaller route deviation angle brings a shorter detour. So the neighbor having the minimum route deviation angle could be chosen as the next relay node. While choosing the next relay node, all neighbors of the current node are put into a neighbor list and all route deviation angles of these neighbors are calculated and then put into a route deviation angle list.  
Algorithm 2 is executed according to the neighbor list and the route deviation angle list. In Algorithm 2, if the current node finds that the next DAMST point is in its neighbor list, it would transmit the query to the next DAMST point directly. Otherwise, it chooses a neighbor having the minimum route deviation angle as the next relay node. Furthermore, if this next relay node still can not find out the next DAMST point in its neighbor list, it executes Algorithm 2 according to its own neighbor list and route deviation angle list.  
For example, in Figure 8, because P[k\(-\)1] is not a neighbor of P[k], and angle 2 \(<\) angle 3 \(<\) angle 1, P[k] chooses B who has the minimum route deviation angle as a relay node. Then B also can not find P[k\(-\)1] in its neighbor list, so it chooses D as its next relay node for angle 5 \(<\) angle 4.  
To make sure the RA can transmit data back after receiving the query, the mobile sink also generates a route list in the query. The route list is then updated in forwarding the query by Algorithm 2. Specifically, a node is added into the route list once be chosen as a relay node.  
```
1.Input P[n] and R[i] // P[n] is the next DAMST point, R[i] is the next node in the route list
2.if( P[n]\(\in\)\(N_{c}\)) // If the next DAMST point P[n] is in the neighbor list of the current node
3.R[i] = P[n]; n - ; i ++ ; // Add P[n] into the route list
4.transmit the query to P[n]; // Transmit the query to P[n]
5.else // If the next DAMST point P[n] is not in the neighbor list of the current node
6.calculates DA; // Calculate route deviation angle list of the current node' neighbors
7.R[i] = \(N_{c}^{0}\); i ++ ; // Add the neighbor node \(N_{c}^{0}\) having the minimum route deviation angle into the route list
8.transmit the query to \(N_{c}^{0}\); // Transmit the query to \(N_{c}^{0}\)
```  
**Algorithm 2** The routing algorithm based on route deviation angles.