# Applying Machine Learning to DEEC Protocol: Improved Cluster Formation in Wireless Sensor Networks
## 3 Implementation
### Original DEEC  
The original method employs a probabilistic approach, where each node's likelihood of becoming a CH is proportional to its residual energy relative to the network average. After 2000 simulation rounds, some nodes remained active, underscoring the protocol's ability to ensure robust network longevity. Throughout the simulation, 5982 data packets were successfully delivered to the base station. The packet delivery trend remained consistent over most of the network's operational period, with a stable transmission rate observed until the onset of node failures. This consistency highlights the protocol's reliability in maintaining data flow across a network lifetime. Each node was initialised with 0.5 J of energy, resulting in a total network energy of 50 J. At the end of the simulation, the residual network energy was measured at 0.0065 J, corresponding to an average energy consumption rate of 0.024997 J per round. The energy depletion profile exhibited a linear and controlled decline, indicative of efficient energy utilisation and management by the protocol. Table 3 shows the DEEC protocol simulation results summary.  
The simulated network comprised 100 sensor nodes randomly distributed in the network within a 100 m \(\times\) 100 m area. The base station (sink) was centrally located at coordinates (50, 50). This uniform node distribution ensured comprehensive network coverage and facilitated effective communication with the base station. Figure 2 shows the implementation results of the original DEEC protocol.  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**No** & **Parameters** & **Definition** \\ \hline
1 & x \(\times\) y & 100 m \(\times\) 100 m & Area of network, dimensions \\
2 & \(n\) & 100 \(\times\) Number of nodes in the network \\
3 & \(R_{max}\) & 2000 \(\times\) Maximum number of rounds \\
4 & \(P_{opt}\) & 0.1 \(\times\) The probability of a node becoming CH \\
5 & \(E_{elc}\) & 50 nJ/bit & Energy dissipation per bit \\
6 & \(E_{f}\) & 10 pJ/bit/m\({}^{2}\) & Energy dissipation for free space \\
7 & \(E_{mp}\) & 0.0013 pJ/bit/m\({}^{4}\) & Energy dissipation for multipath delay \\
8 & \(E_{Rx}\) & 50 nJ/bit & Receiving the energy of the sensor \\
9 & \(E_{D}\) & 5 nJ/bit/message & Data aggregation energy \\
10 & \(P_{x}\) & 0.1 \(\times\) Probability of a node to become a cluster head \\
11 & \(L\) & 4000 bits & Packet size \\ \hline \hline \end{tabular}
\end{table}
Table 2: Parameters used to implement the proposed protocols in MATLAB(2024).  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**No** & **Metrics** & **Value** \\ \hline
1 & Total Nodes & 100 \\
2 & Initial Energy per Node & 0.5 J \\
3 & FND (First Node Death at Round) & 1010 \\
4 & LND (Last Node Death at Round) & N/A \\
5 & Total Packets Sent to BS & 5982 \\
5 & Remaining Network Energy & 0.0065 J \\
6 & Energy Consumption Rate & 0.024997 J/round \\ \hline \hline \end{tabular}
\end{table}
Table 3: DEEC protocol simulation results summary.  
The modification approach provides formal justification for the key design choices implemented in the K-NN and K-Means-based DEEC protocols. Regarding cluster size selection, the proposed approach dynamically adjusts the number of clusters based on the current number of active nodes, following the theoretical insight that optimal cluster size in WSNs is a function of node density and network area. This adaptive strategy reduces communication overhead and prevents cluster head overload, as supported by empirical results in the literature. Furthermore, the choice of K-NN and K-Means is justified by their proven ability to efficiently partition nodes in a distributed manner, with low computational complexity and strong performance in both static and dynamic network scenarios. By grounding our design in these theoretical and empirical findings, we ensure that the proposed protocol modifications are intuitive, robust, and generalizable to a wide range of WSN applications.