# Improvement of Perception Layer Routing Protocol with Static Nodes in IoT-Based Microgrids
## 3 System Models
### Algorithm Improvement under Static Nodes
#### 3.3.3 Formula for Cluster Head Selection Threshold  
In the cluster establishment stage, \(T(s_{i})\) calculated by the network according to the formula for the cluster head selection threshold and, \(a\), the random number assigned, were compared to select a cluster head. As the positions of each node relative to the base station are different, the energy consumption of the communication with the base station will increase with the distance. Therefore, the factor of distance must be included in the cluster head selection threshold formula to reduce the probability of a node far from the base station being selected as a cluster head for decreasing the total network transmission distance. The paper introduces \(D_{f}\), the \"distance factor\", which represents the feedback of the node's position to the cluster head selection. The distance factor \(D_{f}\) can be expressed as:  
\[D_{f}=\sqrt{\frac{d_{\text{max}}-d_{tongs}(i)}{d_{\text{max}}-d_{\text{min}}}}. \tag{13}\]  
In Formula (16), \(d_{\text{max}}\) represents the farthest distance between a node in the entire network and the base station, \(d_{tongs}(i)\) is the distance between the node \(i\) and the base station, and \(d_{\text{min}}\) denotes the closest distance between a node in the entire network and the base station. In particular, when \(d_{\text{max}}=d_{\text{min}}\), let \(D_{f}=0\). On the other hand, in additionto the effects of node location on the selection of cluster heads, the differences of nodes in energy in each area of the network should also be taken into account in the selection of cluster heads. In the entire network, as the number of rounds increases, the energy stored in the nodes will gradually decrease. In particular, the nodes that have been selected as cluster heads consume more energy than nodes that have not been selected as cluster heads. To prevent such nodes with low residual energy from being repeatedly selected as cluster heads and early death of nodes in some areas of the network, the residual energy of the nodes should be regarded as one of the influencing factors of the cluster head selection threshold, and the average energy of other nodes should also be considered. Hence, the paper introduces the \"energy factor\" \(E_{f}\), which represents the feedback of the node's energy to the cluster head selection. The energy factor \(E_{f}\) can be expressed as:  
\[E_{f}=\sqrt{\frac{E(i)}{E_{\text{local}}\left(i\right)}}. \tag{14}\]  
Among them, \(E(i)\) is the residual energy of the node \(i\), and \(E_{\text{local}}\left(i\right)\) is the average energy in the node \(i\) cluster. Based on the formula for the cluster head selection threshold in the LEACH protocol, the distance factor \(D_{f}\) and energy factor \(E_{f}\) are added for improvement, and the formula for the cluster head selection threshold in the SERP protocol for the perception layer of the Internet of Things with static nodes can be obtained:  
\[T(s_{i})= \begin{cases}\frac{p}{1-p\left(r\text{ mod }\frac{1}{p}\right)}*\left(\omega_{1}^{*}D_{f}+ \omega_{2}*E_{f}\right)&,i\in G\\ 0&,i\
otin G\end{cases}  \tag{15}\]  
where \(p\) denotes the optimal cluster head ratio, \(r\) denotes the number of running rounds, and \(G\) denotes the set of nodes that have not been selected for cluster heads in the most recent \(1/p\) round. \(\omega_{1}\) and \(\omega_{2}\) are adjustable parameters, indicating the weight of each parameter. By controlling the weight of each parameter, the clustering algorithm can be more inclined to a certain property, for example, the clustering algorithm is more inclined to energy, then \(W_{2}\) may be set larger. In the paper, it is expected that the weight of the energy factor will be lower at the beginning of clustering, and then gradually increase, so let  
\[\omega_{1}=\tanh 3\left(1-\frac{\sum_{i=1}^{n}E(i)}{nE_{0}}\right), \tag{16}\]  
\[\omega_{2}=\tanh 3\left(\frac{\sum_{i=1}^{n}E(i)}{nE_{0}}\right).\]  
In summary, \(T(s_{i})\) can be expressed as:  
\[T(s_{i})=