## 4 Problem Solution
### Device Association Strategy
Next, the fitness function (lines 5-7) is calculated for the population individuals, and their fitness degree is calculated separately using the fitness function (12). Then, the population individual selection operation (line 8) is performed, and the elitist retention strategy is used to select the individuals with the largest fitness function values to be retained, called elite individuals, and then, the roulette strategy is used to determine the level of selection probability according to the fitness function values, where individuals with high fitness have a higher chance of being selected, while individuals with low fitness are more likely to be eliminated in the offspring population, so that a certain number of individuals can be selected to be retained, and the rest of the individuals with low fitness can be eliminated. In the replication process (line 9), elite individuals are replicated into the next generation population. Then, the crossover process (line 10) is carried out, setting a certain crossover probability \(p_{Crossover}\). For the parent chromosomes to be crossed, a set of two is used, and each set is subjected to a single-point crossover operation: a random crossover point is set in the individual chromosome, thus dividing the chromosome into two parts, with the left and right sides of the offspring chromosome coming from the parent chromosome, respectively. For the newly generated offspring individuals, it is necessary to determine whether they satisfy the \(C_{1}\)-\(C_{5}\) constraints, and if so, they are retained; otherwise, the new individuals need to be discarded. The next mutation is performed (line 11), setting a certain mutation probability of \(p_{Mutation}\). Since each gene position is a binary variable, the mutation of gene positions is achieved by inverting the variables from 0 to 1. In addition, it should be noted that each device is associated with at most one location in the same time slot, i.e., a UAV or a ground 5G base station, and thus, the gene position which is already '1' needs to be '0' subsequently before flipping for the mutation process. Similarly, the new individual after mutation also needs to be judged whether it meets the \(C_{1}\)-\(C_{5}\) constraints. By the above operation, the next generation population can be obtained (line 12) and then return to line 5 for a loop until convergence or the maximum number of iterations is reached. ```
1:Input: Device set \(\mathcal{I}\), UAV set \(\mathcal{U}\), ground 5G base station set \(\mathcal{B}\) and channel state information. Output: Optimal device association strategy \(\{\mathbf{x}_{\text{u}}(t),\mathbf{x}_{\text{b}}(t)\}\). 2:Initialize: Population size \(N_{number}\), crossover probability \(p_{Crossover}\), mutation probability \(p_{Mutation}\), maximum number of iterations \(N_{iteration}\) and \(f=1\). 3:Random generate initial population \(f_{f}\). 4:repeat
5:for each population individual in \(f_{f}\)do
6: Calculate the fitness function using (12). 7:endfor
8: Selective manipulation of individuals using elitist retention strategies and roulette wheel strategies. 9: Replication of elite individuals into the next generation of populations. 10: For all parental chromosomes that are selected, a set of two is used, and each set is crossed over according to the crossover probability \(p_{Crossover}\) to generate new offspring to be added to the next generation population. 11: According to \(p_{Mutation}\), genes in the chromosomes of non-elite individuals of the parent are mutated, and the mutated individuals are inserted into the next generation population. 12: Combining lines 8-11 yields the new generation of populations \(f_{f+1}\). 13:\(f=f+1\). 14:until\(f>N_{iteration}\). 15:Return\(\{\mathbf{x}_{\text{u}}(t),\mathbf{x}_{\text{b}}(t)\}\). ```  
**Algorithm 1**Genetic algorithm-based device association strategy  
By performing Algorithm 1 within each time slot, the optimal device association strategy can be obtained with equal power allocation for each device.