# Trust-Aware Routing Mechanism through an Edge Node for IoT-Enabled Sensor Networks
## 4 Proposed Trust-Aware Routing Mechanism
### Clustering through Modified GWO  
The modified GWO [15] is employed to elect the cluster head (CH) in every cluster. The distance, CH balancing factor, and residual energy are the primary factors to identify the best CH in a cluster. The positions of the nodes are sent to the BS after the network deployment. The BS implements a modified GWO algorithm (Algorithm 1) using the objective function based on the above parameters. Initially, for the sensor nodes whose residual energy is higher by 10% compared with average energy, those nodes are considered to be CHs. Based on the hierarchy of dominance of gray wolves (high-energy nodes), \(\alpha\) is considered the best solution, (with the least value of fitness) followed by \(\beta\) (higher value than the least) and then \(\delta\). Apart from those, \(\omega\) is taken as the least optimal solution calculated by the objective function given below:  
\[ \begin{split}\mathcal{F}=(t-z)\times O_{1}+(1-x+t)\times O_{2}\\ +(1-t)O_{3}+(t-y)\times O_{4}\end{split}  \tag{1}\]  
where \(t=y+z,x+t=1\)  
\[O_{1}=\frac{1}{\sum_{a=1}^{b}{(E_{CH_{a}})}} \tag{2}\]  
The above equation represents the total energy of all CHs. A minimum value of this factor denotes less energy usage, where \(a\) is the cluster number and \(b\) denotes total CHs. \(CH_{a}\) represents cluster head in cluster \(a\). \[O_{2}=\sum_{a=1}^{b}{\frac{n}{b}-c_{a}} \tag{3}\]  
\(O_{2}\) is the balancing factor. To avoid the formation of some huge and small clusters, this parameter is defined to balance the cluster size to minimize power consumption. \(n\) is the total number of sensor nodes and \(c_{a}\) represents the number of sensor nodes in cluster \(a\). \[O_{3}=\sum_{a=1}^{b}{\frac{1}{c_{a}}-dist(CH_{a},\ S)} \tag{4}\]  
\(O_{3}\) is the average sink distance from each CH. \(S\) is the base station position. \[O_{4}=\sum_{a=1}^{b}{\frac{1}{c_{a}}\sum_{k=1}^{c_{a}}dist(sn_{k},CH_{a})} \tag{5}\]  
\(O_{4}\) is the average intra-cluster distance and dist(\(sn_{k}\), \(CH_{a}\)) is the total intra-cluster distance of each node from its CH. \(sn_{k}\) are '\(k\)' sensors that are in a communication range. The above equation must evaluate the minimum value. The overall fitness function defined in Equation (1) needs to be minimized. For an optimal selection of CH, the above objective function is evaluated for each CH. The node with the least value of fitness in that cluster is selected as CH. While hunting, gray wolves surround their prey and then attack it. Initially, the location of the prey is unknown. The hunting process is governed by best solutions alpha, beta, and omega and they upgrade their positions using the search agents beta and alpha, shown in Equations (6)-(12). \[\vec{A}_{\alpha}=\left|\vec{B}_{1}\cdot\vec{B}_{\alpha}-\vec{P}\right| \tag{6}\]  
\[\vec{A}_{\beta}=\left|\vec{B}_{2}\cdot\vec{P}_{\beta}-\vec{P}\right| \tag{7}\]\[\vec{A}_{\delta}=\left|\vec{B}_{3}\cdot\vec{P}_{\delta}-\vec{P}\right| \tag{8}\] \[\vec{P}_{1}=\vec{P}_{\alpha}-\vec{C}_{1}\cdot(\vec{A}_{\alpha})\] (9) \[\vec{P}_{2}=\vec{P}_{\beta}-\vec{C}_{2}\cdot(\vec{A}_{\beta})\] (10) \[\vec{P}_{3}=\vec{P}_{\delta}-\vec{C}_{3}\cdot(\vec{A}_{\delta})\] (11) \[O_{2}=\sum_{a=1}^{b}{\frac{n}{b}-c_{a}} \tag{3}\]0  
where \(\vec{P}_{n}\) is the position of CH; \(n=1,2\ldots,\vec{P}_{\alpha}\), \(\vec{P}_{\beta}\), \(\vec{P}_{\delta}\) are the positions of gray wolves (best optimal solutions); \(p\) is the ongoing iteration; \(\vec{B}_{n}\), \(\vec{C}_{n}\) are coefficient vectors for various prey positions, where \(\vec{B}=2\cdot\vec{m}_{1}\) and \(\vec{C}=2\vec{a}\cdot\vec{m}_{2}-\vec{a}\). Here, \(\vec{m}_{1}\) and \(\vec{m}_{2}\) are vectors randomly picked between \([0,1]\).