# An Energy-Distance-Balanced Cluster Routing Protocol for Smart Microgrid IoT Sensing Networks
## 3 Framework Architectures
### Security Integration via RBAC-IoT
#### 3.4.2 Formula for the Cluster Head Selection Threshold  
During the initial phase of cluster formation, the network uses a specific formula to determine the cluster head selection threshold, \(T(s_{i})\), and compares it with a randomly assigned number, \(a\), to choose a cluster head. Considering the varying distances of each node from the base station, which affects energy consumption for communication, incorporating a distance-related factor into the threshold formula becomes crucial. This ensures that nodes further from the base station have a reduced chance of becoming cluster heads, thus minimizing the overall network transmission distance. This paper introduces the concept of a \"distance factor\" \(D_{f}\), which adjusts the selection process based on a node's proximity to the base station. The distance factor is mathematically represented as  
\[D_{f}=\sqrt{\frac{d_{\max}-d_{\text{t0 BS}}(i)}{d_{\max}-d_{\min}}} \tag{19}\]  
where \(d_{\max}\) is the maximum distance any node is from the base station, \(d_{\text{t0 BS}}(i)\) is the specific distance of node \(i\) from the base station, and \(d_{\min}\) is the minimum distance any node is from the base station. If \(d_{\max}=d_{\min}\), \(D_{f}\) is set to 0.  
Furthermore, the protocol takes into account the varying energy levels across nodes due to their roles and the number of communication rounds. Nodes previously chosen as cluster heads tend to have lower energy reserves, making it essential to consider residual energy to avoid early depletion. Thus, an \"energy factor\" \(E_{f}\) is introduced to reflect each node's energy state in the selection process. It is defined as  
\[E_{f}=\sqrt{\frac{E(i)}{E_{\text{local}}(i)}} \tag{20}\]  
where \(E(i)\) is the residual energy of node \(i\) and \(E_{\text{local}}(i)\) represents the average energy of the nodes in node \(i\)'s cluster.  
Building upon the LEACH protocol's cluster head selection threshold formula, LEAD-RP enhances it by incorporating both the distance and energy factors for static node networks in the IoT perception layer. The improved threshold formula is  
\[T(s_{i})=\begin{cases}\frac{p}{1-p(\text{mod}\frac{1}{P})}\cdot(\omega_{1} \cdot D_{f}+\omega_{2}\cdot E_{f}),&\text{if }i\in G\\ 0,&\text{if }i\
otin G\end{cases} \tag{21}\]where \(p\) is the optimal cluster head ratio, \(r\) is the current round number, and \(G\) includes nodes that have not been cluster heads in the most recent \(\frac{1}{p}\) rounds.  
\(\omega_{1}\) and \(\omega_{2}\) are weights for each factor; they are adjustable to emphasize different aspects of the selection criteria. Initially, the energy factor's weight is suggested to be lower and gradually increase; it is expressed as  
\[\omega_{1}=\tanh\biggl{(}3\biggl{(}1-\frac{\sum_{i=1}^{n}E(i)}{nE_{0}}\biggr{)} \biggr{)} \tag{22}\]  
\[\omega_{2}=\tanh\biggl{(}3\biggl{(}\frac{\sum_{i=1}^{n}E(i)}{nE_{0}}\biggr{)} \biggr{)} \tag{23}\]  
Thus, the revised selection threshold \(T(s_{i})\) reflects both the distance and energy considerations, promoting efficient and sustainable cluster head selection.  
Theoretical Basis for Tanh Weights: The tanh function provides the following:  
* Smooth Transitions: Differentiable output avoids threshold discontinuities.
* Bounded Output: \(\omega_{1},\omega_{2}\in(-1,1)\) naturally.
* Energy Sensitivity: Maximal derivative at \(x=0\) when \(\sum E(i)/nE_{0}\approx 0.5\).  
Sensitivity analysis shows the following:  
\[\frac{\partial T(s_{i})}{\partial\omega_{1}}=0.73D_{f},\quad\frac{\partial T (s_{i})}{\partial\omega_{2}}=0.81E_{f} \tag{24}\]  
with cross-derivatives \(<0.05\). The multiplier 3 optimizes transition steepness).