Skip to main content
. 2020 Jan 2;20(1):262. doi: 10.3390/s20010262
Algorithm 1 Simulation algorithm for CF process
  • 1:

    Initialize Rcov, Nch, N, L= 100,000, consumedEnergyCF(), collisionCount, trOne=0, numSuccessSlots=0, Aobs;

  • 2:

    deploySensors(), deploys N sensors with uniform random distribution;

  • 3:

    forl=0 to l<L do

  • 4:

     Define k=0, σ=0.1, τ=0.1, successfulNode=0, N=Nnew, Ncol,nodoId=[], nodoCH;

  • 5:

     Program event objectType[0,1]=slot;

  • 6:

    if successfulNode<Nnew then

  • 7:

      Delete first event objectType.splice[0];

  • 8:

      if objectType[0]==slot" then

  • 9:

       Program next event objectType.push[0];

  • 10:

       tr=0, trOne=0;

  • 11:

       for j=0 to j<Nnew do

  • 12:

        u=random(1e6)/1e6

  • 13:

        if u<σ then

  • 14:

         tr++

  • 15:

        end if

  • 16:

       end for

  • 17:

       for i=0 to tr do

  • 18:

        Choose 1 from N: nodoId[i]=random(0,N)

  • 19:

        for j=0 to successfulNode[j] do

  • 20:

         if nodoId[i]==successfulNode[j] then

  • 21:

          repeat if succesfulNode[i] is already successful: i=i1

  • 22:

         end if

  • 23:

        end for

  • 24:

        consumedEnergyCF();

  • 25:

       end for

  • 26:

       if tr==1 then

  • 27:

        trOne=1;

  • 28:

       end if

  • 29:

       collisionCount=0;

  • 30:

       for j=0 to j<Ncol do

  • 31:

        u=random(1e6)/1e6

  • 32:

        if u<τ then

  • 33:

         tr++, collisionCount++;

  • 34:

        end if

  • 35:

       end for

  • 36:

       if tr==1 then

  • 37:

        numSuccessSlots++;

  • 38:

        Ncol=NcolcollisionCount;

  • 39:

        Nnew=Nnew+collisionCount;

  • 40:

        successfulNode[i]=nodoId[0];

  • 41:

        k=k+1;

  • 42:

       end if

  • 43:

       if tr>=2 then

  • 44:

        Ncol=Ncol+trOne;

  • 45:

        Nnew=NnewtrOne;

  • 46:

       end if

  • 47:

       if succesfullNode[i].length>=Nn then

  • 48:

        k=0;

  • 49:

       end if

  • 50:

       for j=0 to j<Nch do

  • 51:

        k=0;

  • 52:

        nodoCH[j]=successfulNode[j];

  • 53:

        and the rest are CMs

  • 54:

       end for

  • 55:

      end if

  • 56:

    end if

  • 57:

    end for