# Data Collection Based on Opportunistic Node Connections in Wireless Sensor Networks
## 4 Data Collection Scheme Based on Opportunistic Node Connections
### The Optimal Path Calculation Based on the Opportunistic Connection Random Graph
\(PC_{path(v_{\text{sink},v_{j},*})}=P_{v_{\text{sink},v_{i}}}\);//\(PC_{path(v_{\text{sink},v_{j},*})}\) is the PC of the path from \(v_{\text{sink}}\) to \(v_{i}\)
8. \(PATH(v_{\text{sink},v_{i},*})=\{v_{\text{sink},v_{i}}\}\);//\(PATH(v_{\text{sink},v_{i},*})\) is used to store the nodes on the path from \(v_{\text{sink}}\) to \(v_{i}\)
9. else
10. \(PC_{path(v_{\text{sink},v_{i},*})}=0\);
11. \(PATH(v_{\text{sink},v_{i},*})=\emptyset\);
12. end if
13. end for
14. \(PC_{path(v_{\text{sink},v_{\text{sink},*}})}=1\);//set the PC of the path from \(v_{\text{sink}}\) to \(v_{\text{sink}}\) is 1
15. while (set U is not empty)
16. Select the node \(v_{i}\) with max \(PC_{path(v_{\text{sink},v_{i},*})}\) from set U;
17. Transfer \(v_{i}\) from set U to set K;
18. for each neighbor \(v_{j}\) of \(v_{i}\)do//\(v_{j}\)is still in set U
19. temp \(\leftarrow\)\(PC_{path(v_{\text{sink},v_{i},*})}\times P_{v_{0}v_{j}}\);
20. if(temp > \(PC_{path(v_{\text{sink},v_{j},*})}\))
21. \(PC_{path(v_{\text{sink},v_{j},*})}\leftarrow\)temp;//update the PC of the path from \(v_{\text{sink}}\) to \(v_{j}\)
22. \(PATH(v_{\text{sink},v_{j},*})\leftarrow\)\(PATH(v_{\text{sink},v_{i},*})+v_{j}\);//update the nodes on the path from \(v_{\text{sink}}\) to \(v_{j}\)
23. end if
24. end for
25. end while
```  
**Algorithm 2**The spanning tree algorithm  
Figure 7 depicts the detailed process of constructing the spanning tree step by step in an OCRG with seven nodes. From Figure 7a we can see, sets K and U can be denoted as \(\{v_{\text{sink}}\}\) and \(\{v_{1}\),\(v_{2}\),\(v_{3}\),\(v_{4}\),\(v_{5}\),\(v_{6}\)}, respectively. In the first phase of the algorithm,\(v_{\text{sink}}\) calculates the PC of the paths from itself to all nodes in set U and finds the nodes on each path, the results of which are shown in Table 3 and Figure 7b, respectively. The PC[\(v_{i}\)] (\(i=1,2,\ldots,6\)) used in this table indicates the PC of the path from the mobile sink to node \(v_{i}\), and the value with bold format is the max value of PC in set U. The second phase of this algorithm includes 6 steps, which can be seen from Figure 7c-h. In step 1,  
node \(v_{1}\) is transferred to set K due to it has the max value of PC among that of all nodes in set U, which can be seen in the table. By checking the OCRG, \(v_{\text{sink}}\) learns that only \(v_{6}\) in set U is directly connected to \(v_{1}\), so it updates the PC of the path from itself to \(v_{6}\) and the nodes on this path. In the next 5 steps, by repeating the work in step 1, a spanning tree is generated which can be seen in Figure 71.  
When the spanning tree is generated, the mobile sink should broadcast it to the nodes under its long radio range \(R_{l}\) so that they can forward the sensing data to it according to this spanning tree. On receiving the spanning tree, here it is noticing that, only a node that is on it could obtain the optimal path from itself to the mobile sink, and store the path and the PC of the path locally. However, if a node does not find itself on the spanning tree, it will re-send its probe message to the mobile sink according \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Step** & **PC[\(v_{1}\)]** & **PC[\(v_{2}\)]** & **PC[\(v_{3}\)]** & **PC[\(v_{4}\)]** & **PC[\(v_{5}\)]** & **PC[\(v_{6}\)]** \\ \hline Initialization & 0.7 & 0.6 & 0.4 & 0 & 0 & 0 \\
1 & **0.7** & 0.6 & 0.4 & 0 & 0 & 0.441 \\
2 & 0.7 & **0.6** & 0.4 & 0.228 & 0.228 & 0.441 \\
3 & 0.7 & 0.6 & 0.4 & 0.228 & 0.318 & **0.441** \\
4 & 0.7 & 0.6 & **0.4** & 0.228 & 0.318 & 0.441 \\
5 & 0.7 & 0.6 & 0.4 & 0.228 & **0.318** & 0.441 \\
6 & 0.7 & 0.6 & 0.4 & **0.228** & 0.318 & 0.441 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: The Path Connectivity (PC) of the path from \(v_{\text{sink}}\) to each node.