# Energy-Aware Adaptive Weighted Grid Clustering Algorithm for Renewable Wireless Sensor Networks
## 5 Weighted Grid Clustering Algorithm
### Selection of Cluster Heads  
After the construction of the Hop Tree, the next stage is the selection of cluster heads, which is described in Algorithm 2. ```
1. Initialization with the input S // S is the number nodes from set S that exposed event
2. For u \(\in\) S do
3. W(u) \(\leftarrow\) Er\({}_{\text{ru}}\)\(\times\)\(\gamma\) + D\({}_{\text{u}}\)\(\times\)\(\beta\) + B\({}_{\text{u}}\)\(\times\)\(\alpha\) // Each node calculates the weight
4. End
5. For u \(\in\) S do // After measuring weight by each node, it broadcasts the calculated weight to its one hop neighbors
6. If W(u) < received W(u)
7. Role (u) \(\leftarrow\) Cluster Head
8. End
9. End
```  
**Algorithm 2** Selection of a Cluster Head among Clusters  
The higher energy nodes in the network are the best candidates for CH selection. The algorithm starts selecting the CH when an event occurs, i.e., two nodes want to communicate with each other or with the base station. This phase depends on the weights of the nodes. Each node calculates its weight with its remaining energy (residual energy), the distance between the node to the sink and its buffer size. The node distance may vary from the sink, so the node which is closest to the sink node will be more eligible. If there is a tie between two nodes having the same distance, then the node with the smallest NID wins the race. The other option is energy calculation among all the sensor nodes, these nodes, which frequently participate in the communication, are exhausted rapidly due to more usage of their energy than other nodes that contain less data and hence use a lesser amount of energy. For effective CH selection, each node must know its remaining energy, since election takes place based on the highest remaining energy among the sensor nodes. After that, the buffer size of that node will be calculated to accumulate the weight (W\({}_{\text{u}}\)). Finally, a single node with maximum weight is selected as a cluster head, which is then broadcast to the entire network member nodes. Every member node of the grid remembers its CH and all the event detection reports are sent directly to the CH. During the CH selection, we assume S number of nodes within one cluster, where u is a single node in S.  
\[\mathrm{W_{u}}=\mathrm{E_{ru}}\times\gamma+\mathrm{D_{u}}\times\beta+\mathrm{B_{ u}}\times\alpha \tag{12}\]  
where \(\mathrm{E_{ru}}\) denotes the residual energy of that node u, \(\mathrm{D_{u}}\) denotes the distance between the member node u and the sink node. The remaining buffer size of the node u is designated by the \(\mathrm{B_{u}}\); and \(\alpha\), \(\beta\), \(\gamma\) are weights. These weights (\(\alpha\), \(\beta\), \(\gamma\)) are assigned to \(\mathrm{E_{ru}}\), \(\mathrm{D_{u}}\) and \(\mathrm{B_{u}}\) respectively as expressed in the Equation (12). The following criteria for assigning the weights are considered:  
\[\gamma>\beta>\alpha\text{ and }\alpha+\beta+\gamma=1 \tag{13}\]  
The value of \(\gamma\) cannot be greater than 0.45 as the maximum energy (\(\mathrm{E_{max}}\)) of each node is 10,800 J. The sum of these weights is calculated with 1 as a probability factor for most appropriate selection of the CH. This criterion is defined after the empirical evaluation of each node's status. During the calculation process of \(\mathrm{W_{u}}\), the most important factor is residual energy which is directly dependent on the initial \(\mathrm{E_{max}}\) of a particular node. Thus, the highest value of weight \(\gamma\) is assigned to the residual energy which is measured in Joule. The value \(\beta\) is assigned as the second significant weight to the buffer size of the node which can be calculated in KB. Lastly, the smallest value of weight \(\alpha\) is assigned to the distance. The distance \(\mathrm{D_{u}}\) is measured regarding the number of hops (e.g., node u has seven hops to the sink node).