# Bio-Inspired Algorithms for Efficient Clustering and Routing in Flying Ad Hoc Networks
## 4 HMAO Algorithms
### Clustering and CH Selection Phase  
The MGO algorithm is employed to identify the optimal CHs to efficiently establish clusters in highly dynamic FANETs. This selection process, which is vital for cluster stability, leverages local optimization metrics such as energy levels, mobility stability, and connectivity to ensure that the chosen CHs support sustainable and low-overhead network operations. In the initial phase, UAVs are assigned to clusters and the most suitable CHs are selected. Each UAV is evaluated based on key metrics such as the energy level, mobility, and distance to other UAVs in the cluster. The energy component of the fitness function is used to evaluate the residual energy of the UAV. A higher energy level is preferable because it ensures that the UAV can function longer as a CH without depleting its battery. The energy for UAV \(i\) is calculated as the normalized residual energy as follows  
\[E(i)=\frac{E_{residual,i}}{E_{max}}, \tag{7}\]  
where \(E_{residual,i}\) is the remaining energy of UAV \(i\) and \(E_{max}\) is the maximum energy capacity of a UAV. This normalization ensures that the energy values range between 0 and 1, where \(E=1\) means the UAV has full energy and \(E=0\) means the UAV has depleted its energy. Higher values of \(E\) indicate better energy efficiency, and CHs with higher energy are preferred because they can serve the cluster for a longer duration. Our approach also checks the stability of the UAV mobility patterns and CH selection. The one with minimal changes in velocity and consistent patterns of movement is selected  
Figure 2: Block diagram of proposed system. as the CH, thus ensuring that it may not move out of the cluster earlier. The UAV mobility pattern is defined as follows:  
\[MS\left(i\right)=\frac{1}{1+\sigma_{v}(i)}, \tag{8}\]  
where \(\sigma_{v}(i)\) defines the standard deviation of velocity of UAV over the timeframe. A low oscillation in the velocity indicates more stability. The distance \(D\) intra-cluster component considers the distance from the UAV to the other remaining UAVs that belong to its cluster. UAVs close to a cluster center are favored for the CH role because, consequently, communication costs at this point are reduced in all directions throughout the cluster. The formula to calculate \(D\) intra-cluster for UAV \(i\) is the average Euclidean distance between the UAV and every other UAV \(j\) in that same cluster as follows  
\[D(i)=\frac{1}{N_{cluster}}\sum_{j\in cluster}\sqrt{\left(x_{i}-x_{j}\right)^ {2}+\left(y_{i}-y_{j}\right)^{2}+\left(z_{i}-z_{j}\right)^{2}}, \tag{9}\]  
where \(N_{cluster}\) is the number of UAVs in the cluster. A lower value of \(D\) indicates that the UAV is closer to the CMs. The number of one-hop neighbors is defined as the number of UAVs within the communication range \(R_{max}\) of the UAV under evaluation. UAVs with more one-hop neighbors have a higher ability to facilitate communication within the cluster and are better placed to manage intra-cluster communication efficiently. The number of one-hop neighbors (\(NH\)) for UAV \(i\) is calculated as follows:  
\[NH(i)=\sum_{j=1}^{N}f\big{(}d_{ij}\big{)}, \tag{10}\]  
where \(NH(i)\) is the number of one-hop neighbors for UAV \(i\), \(N\) is the total number of UAVs in the network, and \(d_{ij}\) is the distance between UAV \(i\) and \(j\). Note that \(f\big{(}d_{ij}\big{)}=1\) if \(d_{ij}<R_{max}\) (i.e., UAV \(j\) is within the communication range of UAV \(i\)) and \(f\big{(}d_{ij}\big{)}=0\) otherwise. UAVs with a higher number of one-hop neighbors are more likely to be selected as CH because they can effectively communicate with and manage more UAVs within their cluster. This metric is often combined with other factors (such as energy, mobility stability, and intra-cluster distance) in the fitness function for CH selection to ensure a well-balanced and efficient clustering process.