*4.4. Clustering and CH Selection*

Next, we discuss how to form appropriate clusters and select the optimal CH. The proposed clustering and CH selection algorithm is described in Algorithm 2. When the number of clusters is *K*, let N*<sup>k</sup>* be the set of nodes in cluster *k* ∈ {1, 2, ··· , *K*}. Without loss of generality, we denote *ik* as the CH in cluster *k*, where ∃*ik* ∈ N*k*, and *jk* as a sensor node in the cluster *k*, where ∀*jk* ∈ N*<sup>k</sup>* \ {*ik*}. The proposed algorithm is based on the well-known K-means clustering algorithm [45]. Thus, the initial *K* clusters are determined using the K-means algorithm, and the initial CH in each cluster is determined to be the node closest to the centroid of each cluster. Consequently, the initial cluster and CH are determined by only the distance among sensor nodes without considering the distance between the sensor node and the HAP. However, this distance directly affects the amount of energy harvested, so it is necessary to modify the basic process of the K-means algorithm to make it suitable for the proposed ENO scheme.

The proposed algorithm mainly consists of two parts, similarly to the K-means algorithm. Firstly, each node reselects the best cluster among the predetermined clusters. After calculating *Rik <sup>j</sup>* and *Rik* for each CH *ik*, node *j* selects the cluster that provides the highest *Rik <sup>j</sup>* among the clusters satisfying *Rik <sup>j</sup>* > *Rik* . This step is included so that SWIPT can be performed without decreasing the rate of the predetermined clusters. Thereafter, the best CH is reselected in each cluster. For all nodes in each cluster <sup>∀</sup>*ik* ∈ {N*k*}, the rate of cluster *<sup>k</sup>*, *<sup>R</sup>*swipt *<sup>k</sup>* , is calculated using Equation (12). Then, the best CH, *i* ∗ *k* , is determined as

$$\begin{aligned} i\_k^\* &= \underset{i\_k}{\arg\max} \mathcal{R}\_k^{\text{swlpt}} \\ &= \underset{i\_k}{\arg\max} \min \left[ \min\_{j\_k \in \mathcal{N}\_k} \{ \min\_{l\_k}, \left\{ \mathcal{R}\_{l\_k j\_k}^{\text{swlpt}} \right\}, \mathcal{R}\_{l\_k}^{\text{swlpt}} \right] \end{aligned} \tag{20}$$

where *i* ∗ *<sup>k</sup>* can be found by exhaustive searching with a complexity of *O*(|N*k*|). This clustering and CH selection algorithm is repeated until all of the cluster sets and CHs are no longer changed. The computational complexity of this algorithm is given by *O*(*N*2) because it is based on k-means algorithm, which has a time complexity of *O*(*n*2) where *n* is the input data size [45].

**Algorithm 2:** Clustering and CH selection **Ensure:** N*<sup>k</sup>* is the set of nodes in cluster *k* ∈ {1, 2, ··· , *K*} *ik* is the CH in the cluster *k*, ∃*ik* ∈ N*<sup>k</sup> jk* is a sensor node in the cluster *k*, ∀*jk* ∈ N*<sup>k</sup>* \ {*ik*} 1: Initialize N*<sup>k</sup>* and *ik* ← K-means algorithm [45] 2: **repeat** 3: /\* Select the best cluster in the network \*/ 4: **for** *each node j* ∈ {N<sup>1</sup> ∪···∪N*K*} **do** 5: **for** *each CH ik* **do** 6: Determine *Rik <sup>j</sup>* from Equation (3) 7: Determine *Rik* from Equation (5) 8: **end for** 9: **if** ∃*ik* ∈ {*ik*|*Rik <sup>j</sup>* > *Rik*} = ∅ **then** 10: *j*'s cluster ← arg*<sup>k</sup>* max{*Rik <sup>j</sup>*} for ∃*ik* ∈ {*ik*|*Rik <sup>j</sup>* > *Rik*} 11: **else** 12: *j*'s cluster ← arg*<sup>k</sup>* max{*Rik <sup>j</sup>*} for ∀*ik* 13: **end if** 14: **end for** 15: /\* Select the best CH in each cluster \*/ 16: **for** *each cluster k* **do** 17: **for** *each node ik* ∈ {N*k*} **do** 18: Calculate *R*swipt *<sup>k</sup>* from Equation (12) 19: **end for** 20: CH *i* ∗ *<sup>k</sup>* <sup>←</sup> arg*ik* max{*R*swipt *<sup>k</sup>* } from Equation (20) 21: **end for** 22: **until** ∀N*<sup>k</sup> and* ∀*ik are no longer changed*
