## 3 Adaptive Routing Optimization Algorithm
### Deployment of Ferry Nodes  
The community can be introduced into the OppNets for mHealth to improve their routing performance. However, there is a communication bottleneck between communities because nodes are very rare and inactive in these areas. Considering the role of ferry nodes, this section will discuss how to deploy the ferry nodes in the community boundary. The network topology of OppNets is dynamically changing because of node movement. In order to achieve adaptive deployment of ferry nodes, we introduce the virtual potential field theory to control the movement of ferry nodes. In the virtual potential field theory [41], there is a pair of forces between two objects in the vacuum as follows:  
\[\vec{F_{12}}=-\vec{F_{21}}=K\times\frac{M_{1}M_{2}}{D^{2}}\times\vec{D_{0}} \tag{11}\]  
where, \(K\) is a coefficient, \(M\) is the mass of the object, \(D\) is the distance of two objects, \(\vec{D_{0}}\) is the direction of the force. Just like the objects in the vacuum, the ferry nodes in OppNets will be subject to the repulsion and attraction forces of the neighbor nodes. Furthermore, we improve the Formula (11) as follows: First, we simplify the calculation of forces and set \(K=1\), \(M_{1}=1\), \(M_{2}=1\), namely, \(\vec{F}=\frac{\vec{D_{0}}}{D^{2}}\). Next, we only consider the effect of force upon the ferry nodes. Then, the repulsion or attraction forces of the ferry nodes are determined by their position, not their distance. Specifically, we consider the two cases as follows:  
(1) Ferry node is located in a community. In this case, the ferry node should be away from the center of the community and move to the edge. Therefore, it will be excluded by the nodes located in the inner layer of the community, and be attracted to the outer layer nodes. To achieve this goal, the following two problems need to be addressed: First, the layer-number of a node located in the community can be determined. It is obtained by tagging, in the process of community detection, based on the breadth-first search algorithm. For example, the layer-number of the center node in the community is determined to be 0, and its neighbor nodes are 1, and so on. Second, the position of a node relative to the ferry node in the community can be determined. We take the reference layer to be \(n_{r}=(n_{1}+n_{2})/2\), where \(n_{1}\) and \(n_{2}\) are the two layers' numbers of nodes that have nearer distance from the ferry node. If the layer number of a node \(n>n_{r}\)it is located in the inner layer of the community, and it is attracted to the ferry node. Otherwise, it is in the outer layer and excludes the ferry node. The forces diagram of ferry nodes located in a community is shown in Figure 2A. In the perceptual boundary of the ferry node \(fn\), there are four ordinary nodes \(n_{21}\), \(n_{22}\), \(n_{31}\), \(n_{32}\). Where \(n_{21}\) and \(n_{22}\) are ordinary nodes in the second layer of the community, and \(n_{31}\) and \(n_{32}\) are ordinary nodes in the third layer of the community. There are two repulsion forces, \(f_{21}\) and \(f_{22}\), and two attraction forces, \(f_{31}\) and \(f_{32}\). The resultant force is as follows:  
\[\overrightarrow{f}=\overrightarrow{f_{21}}+\overrightarrow{f_{22}}+ \overrightarrow{f_{31}}+\overrightarrow{f_{32}} \tag{12}\]  
Under the action of this resultant force, the ferry node moves to the edge of the community. (2) Ferry node is located in the area between communities. In this case, the ferry node should be excluded by all its neighbor nodes, including ordinary nodes in communities and other ferry nodes, and it should move to the center area between the communities. The force diagram of ferry nodes located in the area between communities is shown in Figure 2B. In the perceptual boundary of the ferry node \(fn_{1}\), there are two ordinary nodes, \(n_{a}\) and \(n_{b}\), and two ferry nodes, \(fn_{2}\) and \(fn_{3}\). Where \(n_{a}\) is in the \(a\)th community and \(n_{b}\) is in the \(b\)th community. There are four repulsion forces, \(f_{a}\), \(f_{b}\), \(f_{2}\), and \(f_{3}\).