## 3 Adaptive Routing Optimization Algorithm
### Community Detection  
Community detection is a complex and difficult task. Researchers proposed many community detection algorithms [36], such as Laplace matrix spectral bisection algorithm [37], Kernighan-Lin algorithm [38], GN algorithm [39], and the fast algorithm [40].  
In the actual application of OppNets for mHealth, the global attribute of the network is usually very hard to get due to the network partition. On the other side, some nodes may belong to multiple different communities. Therefore, the community detection algorithm of OppNets should meet two conditions: it is based on the local attribute of the network and can deal with the overlapping communities. For this reason, we present a local community detection algorithm on the basis of the relationship between nodes. Its details are as follows:  
Step 1. Compute the active value of nodes: Considering a large degree of nodes is often the center of a community, we simplify the computation of the active value as follows:  
\[C_{i}=\frac{\sum\limits_{j\
eq i}m_{ij}}{N_{i}} \tag{7}\]  
where, \(C_{i}\) is the active value of node \(v_{i}\), \(m_{ij}\) is the proposed metric, and \(N_{i}\) is the number of nodes which have the close relationship with \(v_{i}\).  
Step 2. Select the core nodes: Sorting by the active value, the nodes with the larger value are picked out. Considering some of the selected node are intimate and may belong to the same community, they cannot be a core node and should be removed. Hence, we have:  
\[S_{ij}=\frac{\left|\Gamma_{i}\cap\Gamma_{j}\right|}{\left|\Gamma_{i}\cup \Gamma_{j}\right|} \tag{8}\]  
where, \(\Gamma_{i}\) is the intimate node set of \(v_{i}\), \(\left|\Gamma_{i}\cap\Gamma_{j}\right|\) is the number of the common intimate nodes between \(v_{i}\) and \(v_{j}\), \(S_{ij}\) is the similarity value between node \(v_{i}\) and \(v_{j}\). If \(S_{ij}\) is greater than a threshold (e.g., 0.8), \(v_{i}\) and \(v_{j}\) is thought to be similar, and one of them is removed.  
Step 3. Expand community according to the fitness degree: The fitness degree of node \(v_{i}\) for community \(C\) can be defined as:  
\[F_{i}=\frac{K_{in}(C+i)}{\left(K_{in}(C+i)+K_{out}(C+i)\right)^{\alpha}}-\frac{K _{in}(C)}{\left(K_{in}(C)+K_{out}(C)\right)^{\alpha}} \tag{9}\]  
where \(K_{in}(C)\) is the metric sum of internal node in community \(C\), \(K_{out}(C)\) is the metric sum between \(C\) and other community, \(\alpha\) is a regulatory factor which can control the size of the community, and \(C+i\) is node \(v_{i}\) join \(C\). If \(F_{i}>0\), \(v_{i}\) is allowed to join \(C\).  
Step 4. Combine redundant communities:  
\[O_{12}=\frac{|C_{1}\cap C_{2}|}{min(|C_{1}|,|C_{2}|)} \tag{10}\]  
where, \(|C_{1}|\) is the number of nodes in \(C_{1}\), \(|C_{1}\cap C_{2}|\) is the number of identical nodes in \(C_{1}\) and \(C_{2}\), \(O_{12}\) is the overlap value between \(C_{1}\) and \(C_{2}\). If \(O_{12}\) is bigger than a value (for example, 0.75), \(C_{1}\) and \(C_{2}\) are redundant and need to be combined into a new community.  
Step 5. Repeat Steps 3 to 4 above for the rest of nodes until each node is added in a community.