## 4 Proposed Algorithm
### PSO for Choosing Routing Paths  
The final step of our algorithm is to find the routing paths, then the measurement matrix. PSO is used in this stage as well and herein each particle contains \(M\) sub-particles, where \(M\) is the number of CHs. A sub-particle includes the nodeID information while sub-particle position includes priorities corresponding to all the nodes denoted in the sub-particle. Each sub-particle determines a single rout from each cluster to the base station. Since we have already chosen all the CHs, there are two steps left for each CH to fulfill the corresponding routing path: (1) Each CH chooses the nodes in its cluster which transmit the messages to it in one hop; (2) After collecting messages in its cluster, each CH starts a multi-hop rout to the base station. In one word, a complete routing path contains two parts, the one-hop inner cluster part and the multi-hop outer part. Therefore we divide the sub-particle into two parts, \(a\) and \(b\). Part \(a\) determines which nodes from the inner cluster transmit their data to the CH while part \(b\) finds the routing path from the CH to the base station. It is difficult to jointly optimize these two part. Instead, we construct inner cluster part and outer cluster part separately. The dimension of part \(a\) of sub-particle \(i\) equals to \(K_{i}\), where \(K_{i}\) is the node numbers of each cluster except the \(i\)-th CH. The sub-particle \(i\) selects \(\epsilon\times K_{i}\) nodes with highest priorities from part \(a\) to transmit data to the \(i\)-th CH in one hop. \(\epsilon\) is the ratio controlling parameter which we would optimize in the simulation section. Figure 5 gives an example on how to choose nodes within one cluster and how to map part \(a\) of a sub-particle into real measurement matrix. The measurement matrix with dimension \(M\times N\) is initially set to all zero matrix, where \(M\) is the number of CHs and \(N\) is the total number of nodes. Once a node is chosen into \(i\)-th rout, its corresponding position in the \(i\)-th row of measurement matrix is set to a randomly distributed coefficient which obeys Gaussian distribution. The algorithm to find a multi-hop routing path from the \(i\)-th CH to the base station from part \(b\) is more sophisticated and will be illustrated in detail in the following. **i. Choosing candidate nodes**  
Regarding that if we take all nodes into consideration for each rout, the dimension of a sub-particle would be too large. Given the fact that when a node try to find its rout, those nodes in the opposite area from sink node may never be included. Therefore, before the initialization, we calculate the distances of all nodes to the sink node \(Dis_{s}\) and the distance of all nodes to the CHs \(Dis_{c}\). Then choose an appropriate group of candidate nodes for each CH first. \(Dis_{s}=d_{s,1},...,d_{s,N}\) represents nodes' distances to the sink node while \(Dis_{c}=d_{c,1},...,d_{c,N}\) represents nodes' distances to the CH. \(dis=\sqrt{(x_{s}-x_{c})^{2}+(y_{s}-y_{c})^{2}+(z_{s}-z_{c})^{2}}\) is the distance between the CH and sink node where \(x_{s},y_{s},z_{s}\) represent the coordinates of the sink node and \(x_{c},y_{c},z_{c}\) are the coordinates of the CH. Note that these coordinates values could be obtained by range-based or range-free localizations before the data transmission. Only when a node \(k\) satisfies \(d_{s,k}\leq dis\) and \(d_{c,k}\leq dis\), it would be added to the candidate group. Once the candidate groups are chosen, they will not be altered during the whole iteration period. Suppose the size of candidate group for the \(i\)-th CH is \(N_{i}^{\prime}\), then the dimension of part \(b\) of the sub-particle \(i\) equals to \(N_{i}^{\prime}\). **ii. Initialization**  
To find part b, we make use of the network's layered structure as we need to take directions into consideration. The nodes that are in the closer layer to the base station ought to have higher priority.