# Data Transmission in Wireless Sensor Networks Based on Ant Colony Optimization Technique
## 2 Materials and Methods
### Increase the Coverage of WSNs
Set the set of data points in the improved K-means algorithm as follows:  
\[\bigcup_{i=1}^{k}C=\left\{C_{1},C_{2},\cdots,C_{N}\right\} \tag{7}\]  
\[C_{i}\
eq\phi\ i=1,2,\cdots,k \tag{8}\]  
\[C_{i}\cap C_{j}=\phi,i,j=1,2,3,\  
1. Initialize the data point set \(X\) and cluster radius \(r\);
2. Run the canopy algorithm to obtain the number of clusters \(k\);
3. Calculate the average distance \(AveDis\) and data point density \(density\) between non-cluster-center data points;
4. Select the data point with the highest density among all data points as the first initial clustering center;
5. Select the data point with the highest density outside the cluster radius of the first initial cluster center as the second initial clustering center;
6. To determine whether \(k\) cluster centers have been selected, proceed to step 7; otherwise, jump to step 3;
7. Calculate the distance (Euclidean distance) between all data points in the data point set \(X\) and all initial cluster centers.  
Then, based on the distance from the data points to each initial cluster center, assign the data points to the nearest cluster.
8. Update all cluster centers, recalculate the mean of each cluster, and adjust the position of the point closest to the mean. The nearest point serves as the new cluster center;
9. Continuously perform steps 7 and 8 until the positions of all cluster centers no longer change or reach the maximum number of iterations;
10. Output the clustering results.
3. Improved K-means algorithm for WSN clustering  
The design of clustering routing for wireless sensor networks first requires reasonable clustering of nodes in WSNs.  
Each node in a WSN can be regarded as a data point, and the number of clusters and the initial cluster head position can be improved, as mentioned earlier.  
The K-means algorithm is used to calculate the clustering results, and the improved K-means algorithm can meet the clustering requirements of wireless sensor networks.  
The specific design steps of the WSN clustering method based on the improved K-means algorithm are as follows:  
1. Input the wireless sensor network node set \(X\) and clustering radius \(r\);
2. Run the canopy algorithm to obtain the number of clusters \(k\);
3. Calculate the average distance \(AveDis\) and node density \(density\) between non-cluster-head nodes;
4. Select the node with the highest node density as the cluster head;
5. Select the node with the highest density outside the clustering radius of the cluster head as the next cluster head;
6. Determine whether to select k cluster heads. If yes, proceed to step 7; otherwise, jump to step 3;
7. Substitute the initial cluster head and the number of clusters into the K-means algorithm for clustering;
8. Output the clustering results.
4. Simulation verification  
In order to test the performance of the improved K-means clustering algorithm proposed in this article, the MATLAB 2023a simulation platform was used for calculation.  
We conducted simulation experiments using four typical datasets from UCI, namely Iris, Wine, Seeds, and Glass.  
Using clustering accuracy as the evaluation criterion, the improved K-means algorithm and the traditional K-means algorithm were used to conduct ten experiments on four different datasets to obtain the clustering accuracy, and the accuracy of each cluster was evaluated.  
The average was obtained, and the experimental results are shown in Table 2.  
From the Table 3, it can be seen that the improved K-means algorithm has higher accuracy, which is also the result of optimizing the selection of initial cluster centers.  
(3) Improving the Whale Algorithm to Determine WSN Cluster Heads  
Due to the weak global exploration ability of the whale algorithm, it is prone to becoming stuck in local searching. Therefore, improvements should be made to the whale algorithm.  
Basic Principles of the Whale Algorithm  
The standard WOA simulates the unique search methods and trapping mechanisms of humpback whales, mainly including three important stages: trapping prey, bubble net predation, and searching for prey. The position of each humpback whale in the WOA represents a potential solution, and by continuously updating the whale's position in the solution space, the global optimal solution is ultimately obtained.  
Surround and hunt prey  
\[D_{best} =\left|C\cdot X_{best}^{t}-X_{i}^{t}\right| \tag{12}\] \[X_{i}^{t+1} =X_{best}^{t}-A\cdot D_{best}\] (13) Figure 7:0  
In Equations (9) and (10), \(X_{i}^{t+1}\) represents the \(t+1\)-th iteration of the \(i\)-th individual, \(X_{best}^{t}\) represents the position of the optimal whale in the \(t\)-th iteration, \(D_{best}\) is the displacement of the optimal individual in the current t-th iteration, \(\alpha\) decreases linearly from 2 to 0 with the number of iterations, \((0,1)\) is a random number of \(C\), and L is a random number uniformly distributed within \((0,2)\).