# An Efficient Opportunistic Routing Protocol with Low Latency for Farm Wireless Sensor Networks
## 4 Opportunistic Transmission Strategy for Farm WSN  
### Constructing Candidate Set Based on Improved Bellman-Ford  
Although the more forwarding nodes, the higher the packet delivery rate, the corresponding transmission cost will increase, which affects the network performance. When the network gain brought by the forwarding nodes is not enough to offset its side effects, the number of forwarding nodes should be controlled. We adopt theBellman-Ford algorithm to calculate the remaining opportunistic routing transmission cost. Firstly, based on the _ETX_ and energy threshold, the EXOR algorithm is used to obtain the initial candidate sets. Then, the initial candidate set is regarded as the neighbor set of node \(i\) to obtain the final candidate set by iteration. Then, the transmission cost is calculated when the current node is added to the final candidate set. If the cost is reduced, it is added to the final candidate set. On the contrary, if adding the current candidate node will increase the transmission cost of node \(i\), this node should not be added to the final set. It is necessary to search the subset of each neighbor set in the iterative process, which has a large algorithm overhead. Therefore, we study the improved Bellman-Ford algorithm to select candidate sets of the farm WSN opportunistic routing. Set \(A\) is defined as the set of nodes whose transmission cost becomes smaller in the last iteration and set \(B\) is defined as the set of nodes whose transmission cost becomes smaller in this iteration. The improved algorithm for building the candidate set is as follows:Let \(CQ_{\text{sink}}=0\), \(CQ_{i}=+\infty\), \(2\leq I\leq N\), and add the sink to set \(A\). Initialize algorithm parameters, \(h=1\), \(CQ_{1}{}^{0}=0\), \(CQ_{i}{}^{0}=+\infty\), \(2\leq i\leq N\). 2. In the \(h\)-th iteration, the transmission cost of node \(i\) in \(A\) is calculated. If the neighbor node \(j\) joins the candidate set and makes the transmission cost \(CQ_{j}{}^{h}\) smaller, node \(j\) is added to the candidate set. At the same time, it is judged whether node \(i\) belongs to \(B\), if not, node \(i\) is added to set \(B\). 3. When the candidate set of all nodes no longer changes, the algorithm ends, otherwise, the next step is executed. 4. Empty set \(A\), transfer the elements in set \(B\) to set \(A\), and then empty set \(B\). At the same time, for any node \(i\), let \(CQ_{1}{}^{0}=CQ_{h}{}^{0}\), then let \(h=h+1\), go to step 2. \begin{tabular}{l} \hline \hline Input: Node number \(N\), node location (\(x_{i},y_{i}\)), and probability \(pe_{ij}\) \\ \hline \hline \multicolumn{2}{l}{Output: Candidate set} \\ \hline
1.Parameter initialization \\
2.\(S=\omega\); \(S0=\omega\); \(CQ_{\text{sink}}=0\); \(CQ_{i}{}^{0}=+\infty\), \(1\leq i\leq N\); \(A=\{\text{sink}\}\), \(B=\omega\), \(h=1\);3.Initialization of the candidate sets based on ETX \\
4.for \(i=1\):\(N\) \\
5.for j = 1: 1 Ne(vi)! \\
6.if \(ETX\) (\(j\),sink) \(<ETX\) (\(i\),sink) and \(\text{Erth}\leq\text{Erj}\) \\
7.\(S0_{i}=S0_{i}\cup j\) \\
8.end if \\
9.end for \\
10.end for11. Calculate the minimum expected transmission cost iteratively \\
12.while \(CQ_{i}{}^{h}=CQ_{i}{}^{h-1}\) do \\
13.\(h=h+1\) \\
14.for i = 1:\(N\) \\
15.Judge whether there is an intersection between the initial candidate set \(S0_{i}\) and set \(A\) \\
16.Store the transmission cost \(CQ_{h-1}\) of the neighbor node j in set \(S0_{i}\) and the candi-date set in the \(h-1\) round \\
17.if \(CQ_{i}{}^{h}<CQ_{i}{}^{h-1}\) \\
18.\(B=B\cup i\) \\
19.According to the Equation (10), the candidate set and transmission cost of \(i\) in round \(h\) is calculated. \\
20.end if \\
21.end for \\
22.\(S=S0\), \(A\)\(\leftarrow\)\(B\), \(B=\omega\) \\
23.end while \\ \hline \hline \end{tabular}   
As shown above, the improved Bellman-Ford algorithm and LCOR algorithm have the same algorithm complexity in the worst case, and both are \(\text{O}(nl)\). However, the improved algorithm in this paper adopts priority queues \(A\) and \(B\).