## 3 A Resilient Routing Protocol
### Protocol Design
#### 3.1.1 Node Clustering
Nodes closer to the center typically have better connectivity to a larger number of nodes, facilitating shorter and more efficient routing paths with fewer hop counts. By considering \(D_{i}\), the network can optimize routing decisions to minimize transmission delays and energy consumption by selecting strategically positioned nodes, thereby enhancing overall routing efficiency and network performance. The distance to the center is calculated using the following formula: \[D_{i}=\sqrt{(x_{i}-x_{c})^{2}+(y_{i}-y_{c})^{2}}\] In this formula, \(D_{i}\) represents the distance to the center for node \(i\), \((x_{i},y_{i})\) are the coordinates of node \(i\), and \((x_{c},y_{c})\) are the coordinates of the network center. This Euclidean distance calculation provides a straightforward measure of a node's centrality within the network, which is instrumental in determining optimal routing paths. These parameters are normalized to ensure equal contribution during clustering and routing decisions. Each node constructs a normalized feature vector:  
\[\mathbf{x}_{i}=[\hat{N}_{i},\hat{T}_{i},\hat{U}_{i},\hat{R}_{i},\hat{D}_{i}]\]  
Normalization is performed as follows:  
\[\hat{P}_{i}=\left\{ \begin{array}{ll}\frac{P_{i}-P_{\min}}{P_{\max}-P_{\min}}& \text{if higher is better}\\ 1-\frac{P_{i}-P_{\min}}{P_{\max}-P_{\min}}&\text{if lower is better}\\ \end{array} \right.\]  
In these formulas, \(P_{i}\) is the parameter value for node \(i\), and \(P_{\min}\) and \(P_{\max}\) are the minimum and maximum values of that parameter across all nodes, respectively. This normalization ensures that all parameters are scaled to a [0,1] range, allowing them to contribute uniformly during the clustering and routing decision-making processes. The K-means clustering algorithm is then applied to partition the nodes into clusters based on their normalized feature vectors. The objective is to minimize the Within-Cluster Sum of Squares (WCSS), defined as:  
\[\text{WCSS}=\sum_{k=1}^{K}\sum_{i\in C_{k}}\|\mathbf{x}_{i}-\mu_{k}\|^{2}\]  
where \(K\) is the number of clusters, \(C_{k}\) is the set of nodes in cluster \(k\), and \(\mu_{k}\) is the centroid of cluster \(k\). The clustering process involves initializing the centroids by randomly selecting \(K\) nodes from the dataset, assigning each node to the nearest centroid based on Euclidean distance, and updating the centroids by calculating the mean of the feature vectors within each cluster. This iterative process continues until the change in centroids falls below a predefined threshold \(\epsilon\). To maintain clustering stability and network adaptability, the clustering algorithm is executed periodically at defined intervals, ensuring that cluster formations reflect the current network state without being overly sensitive to transient fluctuations. Nodes within higher-level clusters (e.g., Level 1 and Level 2) are deemed more reliable and are prioritized in subsequent routing decisions. This prioritization ensures that data packets are transmitted through the most stable and reliable paths, enhancing the overall performance and resilience of the network.