# Bio-Inspired Algorithms for Efficient Clustering and Routing in Flying Ad Hoc Networks
## 4 HMAO Algorithms
### Cluster Maintenance Phase  
Dynamical cluster maintenance is required to ensure network-wide efficient and balanced operation of UAVs in cases of high mobility. The clusters may also be overcrowded or skewed because UAVs move over time. This can cause performance degradation of the entire network. The goal of the second phase is to shift UAVs between their respective clusters in a manner that minimizes congestion, along with overall performance optimization and reduced-cost communications. Each CH periodically calculates the local congestion factor (LCF) every \(t\) second to assess the level of congestion in its cluster. Congestion is determined based on the density of UAVs within the total area of the cluster. The LCF for cluster \(i\) is calculated as follows:  
\[LCF_{i}=\frac{N_{cluster,\,i}}{A_{cluster,\,i}}, \tag{12}\]  
where \(N_{cluster,\,i}\) is the number of UAVs in cluster \(i\) and \(A_{cluster,\,i}\) is the area of cluster \(i\). This formula directly measures the UAV density in a cluster. If \(LCF_{i}\) is high, the cluster must be more congested because more UAVs are confined to a smaller area. Each CH compares its calculated \(LCF_{i}\) with a given threshold value, representing the allowed maximum UAV density as follows:  
\[LCF_{th}=\frac{Max\;acceptable\;UAVs}{Area}. \tag{13}\]  
If the LCF of a cluster exceeds this threshold, it indicates that the cluster is congested and requires reformation. When the LCF of a cluster exceeds a threshold value, the CH initiates dynamic UAV reassignment to alleviate the congestion. This is done by finding neighbor clusters with lower LCF values and sufficient capacity to accommodate more UAVs. The CH of the congested cluster searches for neighboring clusters within a specified distance threshold. Only clusters within this distance are considered, ensuring minimal communication costs and energy consumption during reassignment. For each neighboring cluster \(j\), the CH determines the number of additional UAVs that the cluster can handle without exceeding the LCF threshold. The maximum number of UAVs \(N_{max,j}\) that a neighboring cluster \(j\) can accommodate is calculated as follows:  
\[N_{max,j}=LCF_{th}\times A_{cluster,\;j}. \tag{14}\]  
The available capacity \(N_{ava}\) of neighboring cluster \(j\) is defined as  
\[N_{ava}=N_{max,j}-N_{current,\;j}, \tag{15}\]  
where \(N_{current,\;j}\) is the current number of UAVs in cluster \(j\) and only clusters with \(N_{ava}>0\) are eligible to receive the UAVs. The number of UAVs \(M\) to be moved from congested cluster \(i\) to neighboring cluster \(j\) is calculated based on the difference between the congested cluster's LCF and the threshold as follows:  
\[M=\min(\alpha\times(LCF_{i}-LCF_{th})\times A_{cluster,\;i},N_{ava}), \tag{16}\]  
where \(\alpha\) is a scaling factor (typically \(0<\alpha\leq 10\)) to control reassignment rate, \(LCF_{i}\) is the current LCF of congested cluster \(i\), \(LCF_{th}\) is the threshold LCF value that represents the maximum acceptable density for efficient communication, \(A_{cluster,\;i}\) is the area of congested cluster \(i\), and \(N_{ava}\) is the available capacity of neighboring cluster \(j\). When the energy level of a CH drops below a predefined threshold \(E_{th}\) (\(E_{CH}<E_{th}\)), the CH sends a control message to all its CMs, informing them about its low-energy status. This proactive notification ensures that the re-election process begins before the CH completely depletes its energy, thereby allowing for a smooth transition to a new CH. Once the notification is sent, the CMs participate in the voting process to elect a new CH. Adaptive cluster maintenance refers to the process of dynamically adjusting and maintaining clusters of nodes within a network. Algorithm 2 aims to balance UAV density across clusters by dynamically reassigning UAVs when a cluster becomes congested. Each CH periodically calculates its LCF by dividing the number of UAVs by their cluster area.