# ERCP: Energy-Efficient and Reliable-Aware Clustering Protocol for Wireless Sensor Networks
## 4 Proposed ERCP Clustering Algorithm
### Cluster Head Selection
 \tag{7}\]  
According to Equation (6), the cluster load of node \(x\) at a specific time interval, \(t\), is the number of times it was chosen as a cluster head from the start of network operation until \(t1\). ERCP's clustering technique is two-staged. First, sensor nodes are deployed and switched on with the same initial energy. Sensor nodes transmit \"hello\" messages that contain the location, ID, and energy. Nodes construct neighbor tables after exchanging messages. The first cluster head is the node with the most neighbors. The first cluster head is selected based on heterogeneous network node residual energy. Advanced and super nodes are given preference to become cluster heads as they have more energy. A unique cost function elects the cluster head. The new cost function is designed to identify the best cluster heads to reduce and balance energy consumption and increase network dependability. The cost function may pick the optimal node even if distance, quality, cluster load, and energy have different metrics. During each time interval \(t\), the sink node broadcasts an advertisement message to trigger cluster head rotation. After scanning its neighbors, the node with the highest cost becomes the cluster's head. Equation (8) defines the cost of selecting node \(x\) as the cluster head. \[CHCost_{x}(t)=\frac{EM_{x}(t)}{ICD_{x}*ED_{(x,sink)}*(CL_{x}(t)+1)*(1+QM_{x}(t))} \tag{8}\]  
As given in Equation (6), the cost function is designed so that the node that has a lower quality metric will have more chance of being the cluster head, as it has a better link quality metric than other candidates. Furthermore, the node that has a higher energy metric has more chance of being the next cluster head as this node will have higher energy. Finally, the node with the minimum average intra-cluster and inter-cluster distance is more likely to be picked as a cluster head. The pseudo-code of the ERCP cluster head selection algorithm is given as Algorithm 1. ```
1:\(ch\ is\ the\ cluster\ head\ ID\);
2:\(NEB_{i}\), is the neighbor set of sensor node \(x\). 3:next, cluster head \(|\) is the array containing the selected cluster head nodes;
4:\(NM_{i}\), \(|\) is the array containing the neighbor nodes of sensor node \(x\) that is not covered by any cluster head;
5:\(y\) is the neighbor node;
6:\(CH\ is\ the\ number\ of\ candidate\ cluster\ head\ nodes\);
7:\(RCI(i)\) the array for sorting probability amount of candidate cluster heads;
8:\(\text{{Proc}}\ 1\ \text{{Candidate member nodes calculation}}\)
9: Node \(x\) sends the \"member\" message to its all neighbors \(NEB_{i}\);
10: When a response is received from a node \(y\), it does:
11: if \(y\) is not covered by any cluster head
12: then add \(y\) to \(NM_{i}\), array
13: Endproc
14:\(\text{{Proc}}\ 2\ \text{{Decision Making}}\)
15:\(\text{{Node \& sends }}\ \text{{Sipin}}\ \text{{message to its neighbors with the value of its }}\ \text{{CHCost}}_{i}(t)\) as given in Equation (8);
16:\(R_{mn}=0\);
17:\(\text{{For}}\ (m=n=CH::n++)\)
18:\(\text{{If}}\ (R[nl]>R_{mn})\)
19:\(\text{{R}}_{mn}=R[n]\);
20:\(ch=x\), \(R_{mn}\);
21:\(\text{{next,cluster head }}[\ ]\gets x\);
22: EndFor
23: Endproc
```  
**Algorithm 1** ERCP cluster head selection algorithm