Skip to main content
. 2022 Nov 30;22(23):9332. doi: 10.3390/s22239332
Algorithm 2: Pseudocode to select cluster heads in the HSFZ.

Input:X=X1,X2,,Xn: set of LoRa Devices (LDs)

Input:A(i): LoRa Device metric attributes

Input: N: number of LoRa Devices

Input:κ: optimal number of CHs

Output: Clusters of all LDs in HSFZ, CH allocation

  • 1:

    Network initialization

  • 2:

    All C(i)=b0

  • 3:

    fori1: N do

  • 4:

        Calculate the Ere_Ni(t),L(i),Dratio(ni,Ni)

  • 5:

        if L(i)Lth && Ere_Ni(t)Eth then

  • 6:

            Add LD(i) to CH candidate set

  • 7:

        else

  • 8:

            Add LD(i) to cluster member (CM)

  • 9:

        end if

  • 10:

    end for

  • 11:

    forAllLDsCHcandidatesetdo

  • 12:

        Calculate the P(C=b1|A(i))

  • 13:

        if P(C=b1|A(i))=max{P(C=b1|A(i))} then

  • 14:

            C(i)={b1}// LD(i) is set as a CH

  • 15:

        else

  • 16:

            C(i)={b0} // LD(i) is set as a CM

  • 17:

        end if

  • 18:

    end for

  • 19:

    return CH