## 4 EMOR Protocol Design for WSN in NAN
### Optimal Paths Calculation and Spanning Tree Design
According to the optimal path connectivity rule, we have to choose the maximum values between the current path connectivity value and updated path connectivity value. The optimal path connectivity values for Figure 5 are given in Table 2. The initialization step of Table 2 is synchronized with Figure 5b where only immediate neighbors are connected to the mobile sink. From steps 1-7, the optimal path connectivity rule is followed to reduce the overall delay in the network. Figure 5: Formation of spanning tree based on OCRG. (**a**) OCRG with V\({}_{SINK}\) and 10 sensor nodes; (**b**) initialization and path connectivity of immediate neighbors of V\({}_{SINK}\); (**c**) path connectivity of V\({}_{4}\) and V\({}_{5}\); (**d**) path connectivity of V\({}_{6}\), V\({}_{7}\) and V\({}_{8}\); (**e**) path connectivity of V\({}_{9}\) and V\({}_{10}\); (**f**) alternate paths for immediate nodes of V\({}_{SINK}\); (**g**) alternate paths for intermediate and far end nodes; (**i**) spanning tree completed. ```
1. Formation of data set \(D(S,N_{s},\)W/\(S,F_{ST},R_{E},\)\(B_{S},\)S/N)
2. Construction of opportunistic connection random graph (OCRG) Output:
3. Optimal path connectivity and spanning tree formation Begin:
4. Determine link connectivity \(L_{V\Pi Vj}\) in terms of \(TF,\)\(R_{E},\)\(B_{S},\)\(S/\)N of adjacent nodes
5. \(L_{V\Pi Vj}=\max\limits_{Vj\in N}\{\alpha TF_{V\Pi Vj}+\beta R_{E,Vj}+\gamma B_{ S,Vj}+\sigma S/N_{V\Pi Vj}\}\)
6. Set the path connectivity of \(V_{S\Pi NK},\) i.e., \(PC_{V_{S\Pi NK}V_{S\Pi NK}}=1;\)
7. Determine the path connectivity for neighboring nodes \(V_{i}\) of mobile sink node \(V_{S\Pi NK}\)
8. \(PC_{V_{S\Pi NK}V_{i}}=L_{V_{S\Pi NK}V_{i}}\)
9. for each awake node \(V_{j}\) in network, do //subroutine_wakeup
10. if(\(V_{j}\) is directly connected to neighboring node \(V_{i}\) of mobile sink node \(V_{S\Pi NK}\)), then
11. \(PC_{V_{S\Pi NK}V_{i}}=L_{V_{S\Pi NK},V_{i}\times L_{V_{i},V_{j}}}\)
12. \(PATH(V_{S\Pi NK},V_{j}\,\)*) = \(\left\{V_{S\Pi NK},V_{j},2\right\}=\left\{V_{S\Pi NK},V_{i},V_{j}\right\}\)
13. elseif(\(V_{j}\) is not directly connected to neighboring nodes \(V_{i}\) of mobile sink node \(V_{S\Pi NK}\)), then
14. \(PC_{V_{S\Pi NK}V_{i}}=PC_{V_{S\Pi NK}V_{i}}\times\prod\limits_{k=0}^{t-1}L_{V _{i+k},V_{i+k+1}}\) where\(V_{i+t}=V_{j}\)
15. \(PATH(V_{S\Pi NK},V_{j}\,\)*) = \(\left\{V_{S\Pi NK},V_{j},t+1\right\}=\left\{V_{S\Pi NK},V_{i}\ldots V_{i+t-1}, V_{j}\right\}\)
16. else\(PC_{V_{S\Pi NK}V_{i}}=0;\)
17. \(PATH(V_{S\Pi NK},V_{j}\,\)*) = \(\varnothing;\)
18. end if
19. end for
20. for each sleeping node \(V_{j}\) in network, do
21. if(\(V_{j}\) wakes up); it should send the probe message to mobile sink with updated information
22. \(V_{S\Pi NK}\) should reconstruct OCRG in the next iteration
23. subroutine_wakeup: go to 9 //execute steps 9-20
24. end if
25. end for
26. while(PC from \(V_{S\Pi NK}\) to entire network is not yet established)
27. Select the optimal path using following expression
28. \(PC_{V_{S\Pi NK}V_{j}}^{updated}=\max\{PC_{V_{S\Pi NK}V_{j}},PC_{V_{S\Pi NK}V_{ i}}\times\prod\limits_{k=0}^{t-1}L_{V_{i+k},V_{i+k+1}}^{updated}\}\)
29. Update the path from \(V_{S\Pi NK}\) to \(V_{j}\)
30. \(PATH(V_{S\Pi NK},V_{j},t+1)=\left\{V_{S\Pi NK},V_{j},t+1_{(updated)}\right\} =\left\{V_{S\Pi NK},V_{i}\ldots V_{i+t-1(updated)},V_{j}\right\}\)
31. end while
```  
**Algorithm 2**Optimal Paths Calculation and Spanning Tree Design for Non-Distinguishable Service  
After the formation of spanning tree, the mobile sink should broadcast it to the sensor nodes within long radio range \(R_{l}\) in every round of communication. The sensor nodes send the sensing data to mobile sink using this spanning tree information. If a sensor node does not find itself on the spanning tree, it can wait for the next broadcast message from the mobile sink during data collection period and resend its probe message to mobile sink. Upon receiving this probe message, the mobile sink will reconstruct OCRG, re-formulate the spanning tree by re-calculating the optimal path from itself to that node.