# Routing Protocol for Heterogeneous Wireless Sensor Networks Based on a Modified Grey Wolf Optimizer
## 3 Grey Wolf Optimizer  
The GWO algorithm is designed from the social hierarchy and hunting behavior of grey wolf groups [50]. Grey wolves are gregarious animals with an average population of five to 12. Wolves are classified into four categories: leader wolves (\(\alpha\)), the second-best wolves (\(\beta\)), the third-best wolves (\(\delta\)), and other wolves (\(\alpha\)), as shown in Figure 1. Among them, \(\alpha\) wolves make decisions about their daily activities, such as how to hunt, when to rest, when to wake up and how to distribute food. The main task of \(\beta\) wolves are not only to assist \(\alpha\) wolves in making decisions on the daily behavior of the wolves, but also to report the performance of other wolves to \(\alpha\) wolves. \(\delta\) wolves are the followers of \(\alpha\) and \(\beta\) wolves, mainly following the orders of \(\alpha\) and \(\beta\) wolves, but can command the lower \(\omega\) wolves. \(\omega\) wolves mainly obey the orders of the higher wolves. Figure 1: Grey wolf social hierarchy. During hunting, the location of the prey is assessed by \(\alpha\), \(\beta\), and \(\delta\) wolves, and the remaining wolves calculate the distance between themselves and the prey; then, the wolves encircle the prey. The following is the calculational formula of the wolf's position  
\[\overset{\rightarrow}{X}^{t+1}=\overset{\rightarrow}{X_{p}}-\overset{ \rightarrow}{A}\times\overset{\rightarrow}{D}. \tag{1}\]  
\[\overset{\rightarrow}{A}=2\times\overset{\rightarrow}{\alpha}\times \overset{\rightarrow}{r_{1}}-\overset{\rightarrow}{\alpha}. \tag{2}\]  
where \(\overset{\rightarrow}{X}^{t+1}\) is the wolf's position in the \((t+1)^{th}\) iteration, and \(\overset{\rightarrow}{X_{p}}^{t}\) is the prey's position at the \(t^{th}\) iteration. \(\overset{\rightarrow}{A}\) is the convergence factor. \(\overset{\rightarrow}{\alpha}\) linearly decreases from 2 to 0 over the course of iterations, and \(\overset{\rightarrow}{r_{1}}\) is a random vector in the range [0,1]. \(\overset{\rightarrow}{D}\) is the distance from the wolves to the prey, and is calculated as follows:  
\[\overset{\rightarrow}{D}=\left|\overset{\rightarrow}{C}\times\overset{ \rightarrow}{X_{p}}-\overset{\rightarrow}{X}^{t}\right|. \tag{3}\]  
\[\overset{\rightarrow}{C}=2\times\overset{\rightarrow}{r_{2}}, \tag{4}\]  
where \(\overset{\rightarrow}{X_{p}}\) and \(\overset{\rightarrow}{X}^{t}\) are, respectively, the prey's position and the wolf's position in the \(t^{th}\) iteration, \(\overset{\rightarrow}{C}\) is the coefficient vectors calculated in (4), and \(\overset{\rightarrow}{r_{2}}\) is a random vector between 0 and 1. In GWO, the \(\alpha\), \(\beta\), and \(\delta\) wolves are thought to be closest to the prey. They also have the most extensive hunting experience, and thus can determine where the prey is located. Therefore, the prey's location can be calculated as follows  
\[\overset{\rightarrow}{X_{p}}^{t+1}=(\overset{\rightarrow}{X_{\alpha}}^{t+1 }+\overset{\rightarrow}{X_{\beta}}^{t+1}+\overset{\rightarrow}{X_{\delta}}^ {t+1})/3, \tag{5}\]  
where \(\overset{\rightarrow}{X_{\alpha}}^{t+1}\), \(\overset{\rightarrow}{X_{\beta}}^{t+1}\), and \(\overset{\rightarrow}{X_{\delta}}^{t+1}\) are the positions of the \(\alpha\) wolves, the \(\beta\) wolves and the \(\delta\) wolves in the \((t+1)^{th}\) iteration, respectively. They are all calculated according to Equation (1). In addition, other wolves will update their positions around the prey, according to Formula (1). At the end of the iteration times, \(\alpha\) wolves have the highest fitness value. Therefore, \(\alpha\) wolves are considered as the optimal solution of the function. Algorithm 1 describes the GWO pseudo-code. In GWO, the end of the iteration indicates the best time for the wolves to capture their prey, and that all wolves are closest to their prey. In the routing protocol of the clustering algorithm, the node with the smallest distance in the cluster should be selected as the CH.