# An Opportunistic Network Routing Algorithm Based on Cosine Similarity of Data Packets between Nodes
## 3 An Efficient Forwarding Strategy Based on Cosine Similarity between Nodes
### The Traversal Process of Node  
Each node in the sub-network topology shown in Figure 2 maintains a buffer. The buffer stores the data packets that need to be forwarded by the node, and the each data packet has a globally unique identifier. Assume that the data packets of each node in the sub-network topology is shown in Table 1. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Node** & **Data Packet Set** & **Data Packets Vector** \\ \hline \(V_{1}\) & \{’g’,’h’,’o’,’p’\} & (1,1,2,1) \\ \(V_{2}\) & \{’f’,’g’,’o’,’p’\} & (1,1,2,2) \\ \(V_{3}\) & \{’f’,’f’,’p’,’t\} & (2,2,1,1) \\ \(V_{4}\) & \{’i’,’o’,’u’\} & (1,1,1) \\ \(V_{5}\) & \{’f’,’h’,’t’\} & (1,1,2) \\ \(V_{6}\) & \{’f’,’f’,’o’,’p’\} & (1,1,1,2) \\ \(V_{7}\) & \{’i’,’f’,’m’,’s’\} & (1,2,2,1) \\ \(V_{8}\) & \{’g’,’f’,’j’,’p’\} & (1,1,1,2) \\ \(V_{9}\) & \{’f’,’j’,’o’,’p’\} & (1,1,1,1) \\ \(V_{10}\) & \{’h’,’p’,’r’,’s’,’u’\} & (2,3,2,1,1) \\ \(V_{11}\) & \{’f’,’h’,’o’,’u’\} & (1,2,1,3) \\ \(V_{12}\) & \{’g’,’u’,’s’,’y’\} & (2,1,1,1) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Data packet set and data packets vector of nodes. The node traversal process based on Figure 2 is as follows. First, initializes a directed tree T, which takes the node \(V_{1}\) currently sending information as the root node. According to the transmission distance from node \(V_{1}\), the first K neighbor nodes are inserted into the tree in turn as the children of node \(V_{1}\), as shown in Figure 3.  
The nodes \(V_{2}\), \(V_{3}\), \(V_{4}\), \(V_{5}\), \(V_{6}\) are sequentially accessed to calculate their similarity to the current node \(V_{1}\). The similarity calculation process of nodes \(V_{1}\) and \(V_{2}\) is as follows:  
Merge the data packet sets of nodes \(V_{1}\) and \(V_{2}\):  
\[D_{12}=D_{1}\cup D_{2}=\{f,g,h,o,p\} \tag{12}\]  
Recalculate the data packet vectors of nodes \(V_{1}\) and \(V_{2}\):  
\[\textbf{C}^{\prime}_{1}=(0,1,1,2,1),\ \textbf{C}^{\prime}_{2}=(1,1,0,2,2) \tag{13}\]  
Calculate the similarity between nodes \(V_{1}\) and \(V_{2}\):  
\[SIM_{12}=\cos(\textbf{C}^{\prime}_{1},\textbf{C}^{\prime}_{2})=\frac{0\times 1 +1\times 1\times 0+2\times 2+1\times 2}{\sqrt{6^{2}+1^{2}+1^{2}+2^{2}+1^{2} \times\sqrt{1^{2}+1^{2}+2^{2}+2^{2}+2^{2}}}}=\frac{7}{\sqrt{7}\times\sqrt{10}} \approx 0.84 \tag{14}\]  
According to the above calculation process of the nodes \(V_{1}\) and \(V_{2}\), the similarities between the nodes \(V_{1}\) and \(V_{3}\), \(V_{4}\), \(V_{5}\), \(V_{6}\) are calculated. The results are as follows: \(SIM_{13}\approx 0.12\), \(SIM_{14}\approx 0.44\), \(SIM_{15}\approx 0.15\), \(SIM_{16}\approx 0.57\). Assume that both \(SIM_{13}\) and \(SIM_{15}\) are less than the lower threshold \(\alpha\), \(SIM_{12}\) is greater than the upper threshold \(\beta\); \(SIM_{14}\) and \(SIM_{16}\) are located between the lower threshold and the upper threshold. Therefore, the nodes \(V_{2}\), \(V_{3}\), and \(V_{5}\) are deleted from the tree T, leaving nodes \(V_{4}\) and \(V_{6}\) as the next hop for node \(V_{1}\). The neighbor nodes of nodes \(V_{4}\) and \(V_{6}\) are prioritized to insert the top K nodes into the tree T according to the transmission distance, as the children of the corresponding nodes. At this point, the structure of the tree T is shown in Figure 4.  
Figure 4: The structure of the tree. Figure 3: The structure of the tree. The neighbor nodes \(V_{7}\), \(V_{10}\) and \(V_{12}\) of the node \(V_{4}\), and the neighbor nodes \(V_{8}\), \(V_{9}\) and \(V_{11}\) of the node \(V_{6}\) are sequentially accessed to calculate the degree of similarity between the corresponding nodes. The results are as follows: \(SIM_{47}\approx 0.18\), \(SIM_{4,10}\approx 0.13\), \(SIM_{4,12}\approx 0.22\), and \(SIM_{68}\approx 0.86\), \(SIM_{69}\approx 0.96\), \(SIM_{6,11}\approx 0.20\). Assume that \(SIM_{47}\), \(SIM_{4,10}\) and \(SIM_{4,12}\) are all smaller than the lower threshold \(\alpha\).