## 3 The Proposed Routing Mechanism
### Clustering Algorithm  
According to the stability of the node, the clustering algorithm determines whether a node joins or leaves a cluster. The algorithm is event-driven. Two possible events could happen at each node, which are Slot-Timeout and Meet-A-Node. The Slot-Timeout event is when at the end of each timeslot, the contact probability lists at each node will be updated according to the definition of contact probability (Definition 1). The Meet-A-Node event describes that when two nodes come to communication, they will exchange and update their clustering information.  
As shown in Algorithm.1, at the end of each time slot, the contact probability will be updated according to formula (1). When node \(i\) meets node \(j\), according to whether node \(i\) and node \(j\) belong to the same cluster, there are two cases.  
If node \(i\) and node \(j\) are in the same cluster, it needs to verify whether the two nodes still stay in the same cluster. If the contact probability between node \(i\) and node \(j\) is lower than or equal to the given threshold \(\gamma\), one of them has to leave the cluster. First, we compute the stability of node \(i\) in the cluster which do not include node \(j\) and the stability of node \(j\) in the cluster which do not include node \(i\). The node with lower stability will leave the cluster and form a new cluster containing itself. Otherwise, synchronization between node \(i\) and node \(j\) is required.  
```
INPUT: nodes with contact probability list, stability OUTPUT: different clusters  Upon the Slot-Timeout Event do  updateContactProbability(); //according to (1) Upon the Meet-A-Node Event do //for any two node (node \(i,j\))  if\(C_{i}==C_{j}\)then if\(\varepsilon_{ij}\leq\gamma\)then if\(\exists k\in C_{j},\varepsilon_{ik}\leq\gamma\) if\((S_{i}\leq S_{j})\)then  removeNode(\(i\), \(C_{j}\));  else if\(\exists k\in C_{j},\varepsilon_{ik}\leq\gamma\)then  removeNode(\(j\), \(C_{i}\));  else if\(\exists k\in C_{i},\varepsilon_{jk}\leq\gamma\)then  nodeSynchronization(\(i,j\));  end if else if\(S_{i}\leq S_{j}\)then addNode(\(i\), \(C_{j}\)); else addNode(\(j\), \(C_{i}\));  end if
```  
**Algorithm 1** the clustering phase of the proposed CCS-DTN  
On the other hand, when node \(i\) and node \(j\) are in different clusters, a verification function will be invoked to check whether the two nodes need to update their clusters. Specifically, a node \(i\) can be added to a cluster \(C_{j}\) if the contact probability between node \(i\) and each node in \(C_{j}\) are greater than the given threshold \(\gamma\). As shown in Figure 3, there are four cases to be processed. (1) If node \(i\) cannot join \(C_{j}\) and node \(j\) cannot join \(C_{i}\), no action is required; (2) If node \(i\) can be added to \(C_{j}\) and node \(j\) cannot be added to \(C_{i}\), add node \(i\) to \(C_{j}\) and update \(M_{i},M_{j}\); (3) If node \(i\) cannot be added to \(C_{j}\) and node \(j\) can be added to \(C_{i}\), add node \(j\) to \(C_{i}\) and update \(M_{i},M_{j}\); (4) If node \(i\) can join \(C_{j}\) and node \(j\) can join \(C_{i}\), add the node which has lower stability to the other node's cluster and update \(M_{i},M_{j}\).  
According to the clustering mechanism, there are three situations which are shown in Figure 3: (1) in a hot spot, nodes contact frequently with each other and they will be grouped into one cluster, such as node \(a\), node \(b\) and node \(c\); (2) in the movement, a node maybe leave it's hot spot, such as node \(A\). In this situation, according the clustering mechanism, node \(A\) will leave its original cluster and form a new cluster including itself; (3) in contrast, a node maybe join a hot spot, such as node \(B\). it will join the cluster in \(H_{3}\).