## 3 Materials and Methods
### K-Means Clustering  
K-means clustering is used to make clusters with similar data points to identify the pattern hidden in a dataset. It finds an association between two points, and groups are formed in multiple numbers depending on the data available. Here, in Algorithm 1, for clustering, the nodes in the networks are treated as data and the clusters are formed using the distance between the two nodes. With all the data, we carry out the process of finding the points which are related to each other. On that basis, related points are grouped in a process called clustering. For grouping, data are divided into a certain number of groups and the clusters are referred to as W, defined in the algorithm. Based on the similarity of data points to each other, clusters are formed on W groups. W can also be referred to as the number of centroids in the dataset, which is considered a location that determines the center of a cluster.  
```
1. While True do
2.for i = 1 to m... do
3. \(u^{(i)}\): = index (1 to k) cluster centroid closest to p\({}^{i}\)
4. endfor
5.for W = 1 to W... do
6. \(\mu_{(W)}\): = average (mean) of points assigned to cluster W.
7. endfor
8. endwhile
```  
**Algorithm 1**K-means clustering  
Based on Algorithm 1, W defines the total number of centroids, and \(P^{i}\) is considered the current data point. \(u^  
\[R_{i}=-\sum_{j=1}^{N}Q-Q_{i} \tag{3}\]  
In Equation (3), \(Q\) indicates this individual position. \(Q_{i}\) is the \(i\)th neighboring dragonfly position. \(N\) is the total number of individual neighbors of the dragonfly swarm, and S indicates the separation motion for the \(i\)th individual.  
\[M_{i}=\frac{\sum_{j=1}^{N}D_{i}}{N} \tag{4}\]  
The alignment is calculated using Equation (4), where \(M_{i}\) is the alignment motion. \(D_{i}\) is the velocity of the \(i\)th neighboring dragonfly.  
\[K_{i}=\frac{\sum_{i=1}^{N}Q_{i}}{N}-Q \tag{5}\]  
Equation (5) represents the cohesion, where \(K_{i}\) is the \(i\)th individual cohesion, \(N\) is neighborhood size, \(Q_{i}\) is the \(i\)th neighboring dragonfly position, and \(X\) is the current dragonfly individual.  
\[T_{i}=Q^{+}\ -\ Q \tag{6}\]  
The attraction motion \(T_{i}\) for searching for food is calculated using Equation (6), where \(Q^{+}\) is the food position and \(Q\) is the position of the dragonfly.  
\[L_{i}=Q^{-}+Q \tag{7}\]  
The distraction or escape motion \(L_{i}\) for searching for food is calculated using Equation (7), where \(Q^{-}\) is the enemy's position and \(Q\) is the dragonfly position.  
\[\Delta Q_{t+1}=(rR_{i}+mM_{i}+kK_{i}+nT_{i}+IL_{i})+w\Delta Q_{t} \tag{8}\]  
The step vector, denoted by the symbol \(Q_{t}\), can be found by solving Equation (6). Similarly to how PSO's \"position update\" function operates, this PSO-inspired equation provides a solution. The step vector sums Equations (3)-(8) with inertia, where weight \(w\) and \(t\) are the iteration.  
\[Q_{t+1}=Q_{t}+\Delta Q_{t+1} \tag{9}\]  
Equation (9) gives the position of the dragonfly in the current iteration \(t\).  
In case of the absence of neighboring solutions, the swarm improves the randomness of the search by applying the random walk. This refers to a levy flight mechanism. The DFO can choose a food source from the smaller population, and in a WSN, the number of nodes in a cluster could be less or more. This makes the DFO an ideal optimization technique for finding the optimal local solution. It is also quicker in terms of searching, and has fewer parameters while configuring. However, the exploitation behavior and large search steps of DFO make it difficult to optimize the global solution. Therefore, in this study, the DFO exploitation behavior is applied only for finding the local optimal solution [23].