Algorithm 5. Broadcast message receiving process for clustering phase (pseudo-code). |
Input: msg, cluster, isCH, hopsToCH, clusterSize, CH_RSSI Output: Unicast_msg, cluster, isCH, hopsToCH, clusterSize (1) If sender is defined in the neighbor list then update neighbor node data node.cluster msg.cluster; node.isCH msg.isCH; node.hopsToCH msg.hopsToCH; node.RSSI max(RSSI); (2) Else add new neighbor to the list initialize new neighbor data node.cluster msg.cluster; node.isCH msg.isCH; node.hopsToCH msg.hopsToCH; node.RSSI msg.RSSI; (3) If cluster = 0 or node.clustercluster then (4) If (node.isCH and isCH1) then (5) If cluster = 0 or (cluster0 and hops = 0 and node.RSSI > CH_RSSI) then cluster node.cluster; hops 0; CH_RSSI node.RSSI; clusterSize node.clusterSize + 1; (10) If (node.isCHand isCH1) then (11) If (hops1 and hopsnode.hops + 1) or (hops = 0 and cluster = 0 and node.cluster0) then cluster node.cluster; hops node.hops + 1; clusterSize clusterSize + 1; else cluster Size , where is the number of neighbors which belong to the same cluster as the sensor node. (12) msg.clusterSize clusterSize; msg.cluster cluster; load msg; send Unicast(msg); |