# Bio-Inspired Algorithms for Efficient Clustering and Routing in Flying Ad Hoc Networks
## 4 HMAO Algorithms
### Routing Phase
The congestion level \(CL_{net}\) is determined by combining the queue length, packet loss rates, and UAV density in a certain area as \(CL_{net}=f(QL,\ PL,\ UD)\), where \(QL\) is the queue length, \(PL\) is the packet loss, and \(UD\) is the UAV density in a network. The value of the C threshold determines the degree of congestion to tolerate the primary path. As soon as congestion exceeds this value, it activates a redundant secondary path. The threshold value can be empirically derived from data or network conditions as \(CL_{th}=(\varphi_{1}\max QL+\varphi_{2}\max PL+\varphi_{3}\max\ UD)\), where values of \(\varphi_{1}\), \(\varphi_{2}\), and \(\varphi_{3}\) are 0.5, 0.3, and 0.2, respectively. The proposed method activates the secondary routing path when congestion exceeds the threshold as follows:  
\[ARP=f(x)=\left\{ \begin{array}{ll}1,&if\ CL_{net}>CL_{th}\\ 0,&otherwise\end{array} \right., \tag{23}\]  
where \(ARP\) represents the activate secondary path. If congestion is detected on the primary path, the UAV from the secondary list should be chosen based on its geographical position. The UAV provides a geographically unique direction from the path taken by the primary node, measured by the angle between the paths as follows:  
\[A_{s}>A_{th}=\cos^{-1}\left(\frac{V_{pri}\cdot V_{sec}}{|V_{pri}|\,|V_{sec}|} \right), \tag{24}\]  
where \(A_{s}\) and \(A_{th}\) represent the angle of secondary path and angle of threshold, respectively. The threshold angle indicates the minimum angle between the primary and secondary paths. \(V_{pri}\) and \(V_{sec}\) are the direction vectors of the primary and secondary paths. The final fitness value used to select the next-hop UAV for either the primary or secondary path considers both the mobility prediction and congestion control. The fitness function is defined as  
\[FF_{j}=(\delta_{1}\times MS_{j})+\left(\delta_{2}\times L_{j}\right)+\left( \delta_{2}\times\frac{1}{CL_{j}}\right), \tag{25}\]  
where the values of \(\delta_{1}\), \(\delta_{2}\), and \(\delta_{3}\) are 0.5, 0.3, and 0.2, respectively. Algorithm 4 implements a congestion-aware fault-tolerant routing mechanism for UAV networks that incorporates energy constraints, mobility prediction, load balancing, and congestion control. Initially, each UAV gathers position, velocity, energy, queue length, and packet rate data from its neighbors through periodic Hello Messages. In the eligibility phase, it filters out only those UAVs that have residual energy higher than a certain threshold value, and discards low-energy UAVs well in advance to prevent premature network depletion. During the fitness evaluation phase, eligible UAVs are scored for the mobility and load balancing criteria. Mobility is scored with a view of predicted future position, distance towards the destination, and directionality of motion, giving preference to the UAV moving toward the destination. The load is determined by the queue length and packet processing rate, and the combined fitness score of the mobility and load is used to select the optimal next-hop UAV. Congestion monitoring is conducted by ferry nodes, which assess network density, queue lengths, and packet loss rates. The second path is dynamically activated. It selects nodes that meet geographical separation, load, and energy requirements such that interference with the primary path is avoided when congestion exceeds a certain threshold. Data packets are forwarded through primary or both paths according to real-time network conditions to ensure efficient load distribution and high fault tolerance. Our proposed approach is inspired by the principles of AO, where ferry nodes act as global information hubs, sharing network-wide congestion and load conditions with the UAVs. This allows UAVs to dynamically adjust routing decisions based on a real-time overview of network conditions, thereby enhancing their robustness and adaptability in high-mobility environments.