## 4 Combined Optimization of UAV Location, User Pairing, and Power Allocation
### User Pairing Optimization  
When the location and transmission power of UAV are determined, the NOMA user pairing subproblem can be represented as:  
\[\text{P4.2}\max_{g}U_{cache}+\sum_{m=1}^{M}\sum_{n=1}^{N_{m}} \left(1-\mu\right)T\cdot v_{char}-(\sum_{m=1}^{M}\sum_{n=1}^{N_{m}}p_{n,m}\tau_ {n,m}+P_{char}(1-\mu)T)\cdot v_{uav} \tag{41}\]  
where \(g=\{g_{1},g_{2},\ldots,g_{M}\}\) represents the user pairing status for \(M\) channels.  
This paper utilizes the simulated annealing (SA) algorithm to optimize NOMA user pairing. The SA algorithm is derived from the principles of solid annealing, where the fundamental concept begins with a relatively high initial temperature. As iterations progress, the temperature parameter continuously decreases. At each temperature, the algorithm adds a random perturbation to the feasible solution to generate a new solution and probabilistically accepts the current inferior new solution, thus avoiding falling into a local optimum, in order to find a globally optimal solution to the objective function.  
This paper regards the NOMA user pairing result \(g\) as the feasible solution of the algorithm, with the minimum user rate in the system serving as the objective function value for feasible solutions. The detailed procedures of the NOMA user pairing optimization algorithm are as follows. Initially, a random pairing method is employed for initializing the pairing. The initial pairing result is taken as the initial solution \(\mathbf{g}^{(0)}=\{g_{1},g_{2},\ldots,g_{M}\}\), which is then substituted into the objective function formula (40) to obtain the current minimum rate \(f(\mathbf{g}^{(0)})\). Subsequently, random perturbations are added to the current user pairing result by randomly selecting two user pairs and exchanging the users within each pair, thereby obtaining a new solution \(\mathbf{g}^{\prime}\) within the neighborhood, and computing the corresponding minimum user rate. Then, the difference \(\Delta f\) in minimum user rate between the new solution and the current optimal solution is calculated. When \(\Delta f>0\), the new solution is regarded as the optimal solution. When \(\Delta f\leq 0\), according to the _Metropolis_ criterion, the new solution is accepted as the current optimal solution with a probability of \(e^{\Delta f/T_{sa}}\). Through multiple iterations of the above process, the optimal pairing scheme under the current temperature is obtained. Subsequently, the temperature is reduced for further iterations until it reaches the minimum temperature and the change in the minimum transmission rate is less than the target tolerance \(\Delta R\). At this point, the optimal user pairing result \(\mathbf{g}^{*}\) is obtained.  
For the SA algorithm, it is assumed that the user pairs in the scenario are \(M\) pairs, the temperature drop times are cooled exponentially, that is, \(O(\log M)\), the number of iterations at each temperature \(L_{sa}=O(M)\), and each neighborhood operation is a user exchanging two user pairs, and the time complexity is \(O(1)\). Therefore, the total time complexity of SA is \(O(M\log M)\).