Skip to main content
. 2020 Jan 15;20(2):482. doi: 10.3390/s20020482
Algorithm 1 Cluster initialization based on improved K-medoids algorithm
Input: Location and energy information of T sensor node in in the monitoring sub-network area of N×N
Output: T sensor nodes are allocated to K clusters in the mode of optimal energy consumption
Step 1: Determining the optimal clustering group number kopt;
Step 2: Selecting a sensor node as the first cluster center randomly;
Step 3: Calculating the distance from each node to the selected cluster center;
    repeat
      for i = 1, 2, …, k
        for j = 1, 2, …, Tk
          dCtoCji=(x(j)x(i))2+(y(j)y(i))2
    until the distances between all nodes are calculated
Step 4: Selecting the k-th (1<k<kopt) clustering center
    repeat
      for j = 1, 2, …, Tk
        for i = 1, 2, …, k
          dCtoCj=min(dCtoCji);
                sum(d(xCtoHj))=j=1TkdCtoCj
                  pj=d(xCtoHj)sum(d(xCtoHj))
      until all kopt cluster centers had been selected
Step 5: Initialization of all clusters based on selected kopt cluster centers
    repeat
        for i = 1, 2, …,k opt
          for j = 1, 2, …, Tkopt
              dCtoCji=(x(j)x(i))2+(y(j)y(i))2
            for j = 1,2,…,T-kopt
             for i = 1, 2, …, kopt
              dCtoCj=min(dCtoCji);
    until all sensor nodes are allocated to the cluster with the lowest energy consumption.