Skip to main content
. 2018 Nov 30;18(12):4202. doi: 10.3390/s18124202
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.cluster  cluster then
(4)  If (node.isCH =1 and isCH  1) then
(5)    If cluster = 0 or (cluster  0 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.isCH 1 and isCH  1) then
(11)     If (hops > 1 and hops > node.hops + 1) or (hops = 0 and cluster = 0 and node.cluster  0) then
       cluster   node.cluster;
       hops  node.hops + 1;
       clusterSize  clusterSize + 1;
else
       cluster Size i=1NjclusterSize/Nj, where Nj 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);