Skip to main content
. 2018 Mar 19;18(3):907. doi: 10.3390/s18030907
Algorithm 1 Leader Election Algorithm.
  •   1:

    Kopt←n2×π×20.765

  •   2:

    Popt←Koptn

  •   3:

    ThresholdLEACH←Popt1−Popt×(rmod(1Popt))

  •   4:

    MaxNumberElection←GetMaxNumberOfElections()

  •   5:

    ElectionCounter←0

  •   6:

    while “Node without a leader” do

  •   7:

     ThresholdEnergy←GetCurrentBatteryPowerLevel()GetFullBatteryPowerLevel()

  •   8:

     Threshold←ThresholdLEACH×α+ThresholdEnergy×(1−α)

  •   9:

     RandomNumber←random(0,1)

  • 10:

     ElectionCounter←ElectionCounter+1

  • 11:

     if RandomNumber<Threshold or ElectionCounter>MaxNumberElection then

  • 12:

      SetNodeAsLeader()

  • 13:

     else

  • 14:

      wait(random(0,1))

  • 15:

     end if

  • 16:

    end while