# Ocean-Current-Motion-Model-Based Routing Protocol for Void-Avoided UASNs
## 4 OCMR Protocol
### Searching Process of the Optimal Relay Node
Subsequently, the opposing population is expressed as  
\[v^{j}_{i}=d^{j}_{i}+rand(u^{j}_{i}-d^{j}_{i}) \tag{29}\]  
\[v^{j}_{i}=d^{j}_{i}+u^{j}_{i}-v^{j}_{i} \tag{30}\]  
We initialize the population of whales as \(N\) and the searching dimension as \(d\), generating the velocity \(\overset{\rightarrow}{v_{i}}\) of the \(i\)th whale randomly by Equation (29) and the velocity \(\overset{\rightarrow}{v^{\prime}_{i}}\) of the \(i\)th whale randomly by Equation (30). Whereafter, a fitness function is designed to calculate the fitness value between \(\overset{\rightarrow}{v_{i}}\) and \(\overset{\rightarrow}{v^{\prime}_{i}}\) iteratively to obtain the whales of \(N\) with the optimal fitness value as the initial population. The optimal velocity \(V\) is finally obtained iteratively. The probability of a communication outage will increase if the number of nodes is higher or lower. The density of relay nodes in a limited space and selecting an appropriate threshold are most important when selecting the relay nodes in UASNs. The node with a higher residual energy is preferentially selected as the relay node in this density to equalize the energy consumption. Simultaneously, nodes with a relatively low speed should be selected as alternative nodes when the shift in nodes happens. Therefore, the fitness function is defined as Equation (31) based on the above factors. \[f_{fitness}(V_{i})=\omega_{i}f_{rj}+\lambda_{\varepsilon}(1-\varepsilon)+ \overset{\rightarrow}{R^{d}}(V_{i})\cdot cos\theta(V_{i}),\;\theta\in(0,\pi) \tag{31}\]  
\[f_{rj}=\frac{1-E_{\text{rest}}(V_{i})}{E_{init}} \tag{32}\]  
Figure 6: (a) space diagram of search area. (b) planform of search area. where \(\omega_{i}\) is the energy coefficient, \(f_{rj}\) is an energy parameter, \(E_{init}\) represents the initial energy of the node, \(E_{\text{rest}}(V_{i})\) indicates the residual energy of the node with velocity \(V_{i}\), \(\varepsilon\) is the outage probability, \(\lambda_{\varepsilon}\) is the node density with the optimal outage probability, \(\overset{\rightarrow}{R}^{d}(V_{i})\) represents the relative velocity difference between the node with current velocity \(V_{i}\) and other moving nodes in the search coverage, and \(cos\theta\) is the angle between the node with current velocity \(V_{i}\) and other nodes. Finally, the node with the velocity that has the minimum value of the fitness function is the optimal node. The pseudo-code of the searching process is show in Algorithm 1. ```
- \(C(V_{i})\): candidate forwarding set based on \(d_{\varepsilon}\)
- \(n_{V_{i}}\); node with velocity V*\(\dagger\)
- MaxT: maximum number of iterations Input: The parameters of nodes including \(\alpha\), \(V_{i}\), \(\varepsilon\), \(E_{\text{rest}}(V_{i})\), and \(E_{init}\) Output: Vi. 1: Initialize the whale population and velocity Vi
2: Calculate the protection radius with optimal outage probability by (19)
3: Generate the opposing population by (29) and (30)
4:while (t < MaxT)
5:for\(n_{V_{i}}\in C(V_{i})\)
6: Calculate the fitness value to reinitialize population
7: Update the optimal velocity by (32)
8:for each search agent
9: update parameters \(\alpha\), A, C, \(l\), and Q
10:if1 (Q < 0.5)
11:if2 (\(\left\lvert\text{A}\right\rvert<1\))
12: Update the position of the current search agent by Equation (25)
13:elseif2 (\(\left\lvert\text{A}\right\rvert\geq 1\))
14: Update the position of the current search agent by Equation (28)
15:endif
16:elseif1 (Q \(\geq\) 0.5)
17: Update the position of the current search agent by Equation (26)
18:endif
19:endfor
20:endfor
21:for\(n_{V_{i}}\
otin C(V_{i})\)do
22: Update \(\alpha\) and calculate \(d_{\varepsilon}\)
23: end for
24: Calculate the fitness by Equation (31)
25: Update V* when a better solution is obtained
26: t = t + 1
27:endwhile
28: Return V*i
```  
**Algorithm 1** Searching process of optimal relay node