## 4 Dynamic Weighted Clustering Algorithm with Dual Cluster Heads
### Weight Factor  
When selecting a cluster head, on the one hand, it is necessary to ensure that the number of cluster members is not too large or too small, resulting in low efficiency or a waste of resources. On the other hand, the cluster head needs not only to ensure good communication quality with the cluster members, but also to ensure the connection with the gBS. Therefore, degree, distance, and communication quality are introduced as weight factors. In addition, due to the characteristics of strong mobility and limited energy of a UAV, in order to avoid frequent replacement of cluster heads caused by this, the relative mobility and remaining service time of a UAV should be taken into account in the calculation of cluster head weight in addition to the size of the cluster, communication quality within cluster, and communication quality with gBS. Detailed weight factor calculations are shown below. * Degree. If the cluster is too large, the load of the cluster head will be too high and the system efficiency will be degraded. If the clustering is too small, too few nodes in the cluster will result in resource waste. In order to realize balanced clustering, the concept of degree \(\triangle_{i}\) is introduced to measure the difference between the number of neighbor nodes and the size of the ideal cluster, which is denoted by: \[\triangle_{i}=|n_{i}-\delta|\] (1) where \(\delta\) is the ideal cluster size, \(n_{i}\) is the number of neighbor nodes of UAV \(i\) in set \(\mathcal{U}\), \(\mathcal{U}\) is the set of unclustered nodes during the initial clustering stage and the node set of the currently maintained cluster during the dynamic maintenance stage. \(n_{i}\) is expressed as \(n_{i}=\sum\limits_{\textit{f}\in\mathcal{U},\textit{f}^{\prime}\
eq i}\{dist(i,i^{\prime})<range\}\), where \(dist(i,i^{\prime})\) represents the distance between UAV \(i\) and \(i^{\prime}\), \(range\) represents the signal receiving distance of the UAV, which is the distance between the transmitter and the receiver when the receiving power is greater than the threshold. According to the free space propagation model, \(range=\sqrt{\frac{P_{T}G_{T}G_{R}\lambda^{2}}{(4\pi)^{2}PL_{th}}}\)[24], where \(P_{T}\) is the transmit power of the UAV, \(G_{T}\) and \(G_{R}\) are the antenna gains at the transmitter and the receiver, respectively. In addition, \(\lambda\) is the wavelength, \(L\) is the loss factor independent of propagation, and \(P_{th}\) is the threshold of receiving power. * Distance. The signal intensity between two UAV nodes is affected by the distance between them [25]. When a node in a cluster is far away from the cluster head, the communication efficiency will be degraded due to signal attenuation. According to [25], air-to-air (A2A) channels obey line of sight (LoS) fading, and signal attenuation is proportional to the square of the distance. The distance factor \(D_{i}\) represents the sum of the distance between node \(i\) to all its neighbors, which can be expressed as: \[D_{i}=\sum\limits_{\textit{f}^{\prime}\in(N_{i}\cap\mathcal{U}),\textit{f}^{ \prime}\
eq i}((X_{i}-X_{i^{\prime}})^{2}+(Y_{i}-Y_{i^{\prime}})^{2})\] (2) where \(X_{i}\) and \(Y_{i}\) are the horizontal and vertical coordinates of UAV \(i\), respectively. \(N_{i}\) is the set of neighbor nodes of UAV \(i\). * Communication quality. In order to ensure the communication connection between air network and gBS, the cluster head node needs to ensure good quality of the air-to-ground channel. The path loss factor \(PL_{i}\) is utilized for the air-to-ground path loss of node \(i\), the lower the \(PL_{i}\) is, the better the communication is between the node \(i\) and the gBS.