# Bio-Inspired Algorithms for Efficient Clustering and Routing in Flying Ad Hoc Networks
## 4 HMAO Algorithms
### Routing Phase
Moreover, the algorithm ensures that the UAVs move in the correct direction (toward the destination). For each UAV, the directionality and speed relative to the destination are computed as \(\overrightarrow{V_{j}}\cdot\overrightarrow{U_{dest}}\)where \(\overset{\rightarrow}{V_{j}}\) is the velocity of UAV \(j\) and \(\overset{\rightarrow}{V_{dest}}\) is the velocity toward the destination. The effective range \(R_{eff}\) is the predicted distance between the sender and forwarder UAV after \(\Delta t\). By ensuring that the selected forwarder node stays within the effective range most of the time, the algorithm prevents a situation in which the chosen forwarder moves out of range too quickly, disrupting the communication link. The mobility score for each neighboring UAV is computed by combining the directionality, proximity, remaining connectivity, and communication range stability, as follows:  
\[MS_{j}=\left(\overset{\rightarrow}{V_{j}}\overset{\rightarrow}{V_{dest}} \right)+\lambda_{1}\left(\frac{1}{d_{dest,\,j}^{future}}\right)+\lambda_{2} \left(\frac{R_{eff}}{R_{max}}\right), \tag{20}\]  
where the values of \(\lambda_{1}\) and \(\lambda_{2}\) are 0.6 and 0.4, respectively, \(\frac{1}{d_{dest,\,j}^{future}}\) indicates the rewards for UAVs that will be closer to the destination in the future, and \(\left(\frac{R_{eff}}{R_{max}}\right)\) measures the proportion of the communication range that will remain between the sender and forwarder nodes over time \(\Delta t\). Load balancing ensures that data are distributed efficiently across UAVs, thereby preventing certain nodes from becoming overloaded. Load balancing in UAV networks is useful for delay reduction because it selects nodes with shorter queue lengths and higher packet processing rates to minimize the waiting time for packets and network latency. It allows the efficient utilization of resources because traffic spreads evenly across the network, thus preventing bottlenecks. Using this method helps prevent the overloading of certain UAVs, resulting in a more stable network that is not subject to node failures due to congestion. For each neighboring UAV \(j\), load \(L_{j}\) is calculated using both its queue length and packet rate, as follows:  
\[L_{j}=\beta_{1}\times\left(QL_{j}\right)+\ \beta_{2}\left(\frac{1}{PR_{j}} \right), \tag{21}\]  
where \(\beta_{1}\) and \(\beta_{2}\) are weighting factors that balance the importance of the queue length versus the packet rate and values of \(\beta_{1}\) and \(\beta_{2}\) are 0.6 and 0.4, respectively. \(QL_{j}\) is the number of packets waiting in queue \(j\) of UAV node and \(PR_{j}\) is the rate at which UAV \(j\) processes the packets (packets/s). The UAV with the lowest load is the most appropriate forwarding hop, as \(FH_{j}=\text{min}\left\{L_{j}\right\}\). If there is no congestion on the secondary path, the secondary path is turned off and the system selects the next-hop UAV based on the load on each UAV. In this scenario, the fitness function focuses on minimizing the loads on the selected nodes to determine efficient data routing. To determine the next-hop UAV \(j\), the fitness value is calculated as follows:  
\[FV_{j}=\text{min}\big{(}\left(\delta_{1}\times MS_{j}\right)+\left(\delta_{2} \times\ L_{j}\right)\big{)}, \tag{22}\]  
where the values of \(\delta_{1}\) and \(\delta_{2}\) are 0.7 and 0.3, respectively. Fault-tolerant secondary path routing for congestion avoidance is a strategy that improves the reliability and efficiency of packet delivery in FANETs. The system eradicates the priority-based mechanism and incorporates network conditions to dynamically tune routing such that packets bypass congested areas and reach their destination in time. The use of ferry nodes to monitor network congestion adds an adaptive element to the routing strategy, thus making it resilient against fluctuating network conditions, ensuring better load distribution, and minimizing the chances of packet loss or delays.