Skip to main content
. 2015 Oct 20;15(10):26583–26605. doi: 10.3390/s151026583
Algorithm 1 Clustering and routing algorithm in R(1).
  • 1:

    Node i receives Eave(1) from the sink;

  • 2:

    if Er(i)Eave(1) then

  • 3:

      NEXT(i)1;

  • 4:

    else

  • 5:

      NEXT(i)0;

  • 6:

    end if

  • 7:

    Sets up random backoff timer Tb(i) (Equation (5));

  • 8:

    repeat

  • 9:

      if Receives AC message from CH j then

  • 10:

          Records CH j to JOIN list;

  • 11:

      end if

  • 12:

      if Receives AR message from CH j AND k(j)=2 then

  • 13:

          if NEXT(j)=0 then

  • 14:

                Records CH j to SERV list;

  • 15:

          else if NEXT(j)=1 AND CH j is in SERV list then

  • 16:

                Deletes CH j from SERV list;

  • 17:

          end if

  • 18:

      else if Receives AR message from CH j AND k(j)=1 then

  • 19:

          if NEXT(j)=1 AND d(i,j)<d(i,0) then

  • 20:

                Records CH j to RELAY list;

  • 21:

          end if

  • 22:

      end if

  • 23:

    until Tb terminates

  • 24:

    if NEXT(i)=1 then

  • 25:

      statusCH;

  • 26:

      Forwards the data to the sink directly;

  • 27:

      Broadcasts AC and AR message;

  • 28:

    else if SERV is not empty or JOIN is empty then

  • 29:

      statusCH;

  • 30:

      if RELAY is empty then

  • 31:

          Forwards the data to the sink directly;

  • 32:

      else

  • 33:

          Selects the relay with minimum Croute from RELAY list (Equation (7));

  • 34:

      end if

  • 35:

      Broadcasts AC and AR message;

  • 36:

    else

  • 37:

      statusCM;

  • 38:

      Selects its CH with minimum Cform from JOIN list (Equation (8));

  • 39:

    end if