## 4 Combined Optimization of UAV Location, User Pairing, and Power Allocation
### UAV Location Optimization  
In the UAV location optimization subproblem, considering the given UAV caching strategy, UAV transmit power allocation, and NOMA user pairing, the optimization of UAV location is formulated as follows:  
\[\text{P4.3}\max_{d_{uav}}U_{cache}+\sum_{m=1}^{M}\sum_{n=1}^{N_{m}}T(1-\mu)v_{ char}-(\sum_{m=1}^{M}\sum_{n=1}^{N_{m}}p_{n,m}\tau_{n,m}+P_{char}(1-\mu)T)v_{ uav} \tag{42}\]Particle swarm optimization (PSO) is an heuristic optimization algorithm based on swarm intelligence, inspired by the social behavior of biological groups such as birds or schools of fish. PSO seeks the optimal solution by simulating the cooperation and competition among individuals in a group. Each particle represents a potential solution, which is searched by iteratively updating its own speed and position, tracking individual historical optimal and group global optimal. The UAV position problem often involves high-dimensional continuous space optimization and complex constraints. Due to the continuous space optimization capability of PSO, it is not necessary to discretize the UAV coordinates when optimizing the UAV position, but to directly optimize the continuous variables, which is more in line with the actual scenario and brings the location accuracy. Therefore, this paper adopts PSO to solve the optimization problem of UAV position. This paper employs the PSO algorithm to optimize the location of the UAV, utilizing the minimum user rate within the system as the fitness value for the particles. By optimizing the UAV location, the optimal deployment location for the UAV is obtained. Assume there are \(N_{pso}\) particles, where each particle's location \(d_{particle}^{(i)}\) represents the three-dimensional location \(d_{uav}^{(i)}=(x_{uav},y_{uav},h)\) of a UAV and the fitness value of a particle represents the minimum user rate within that location in the system. The particle's velocity \(v_{particle}^{(i)}\) denotes the distance and direction for the UAV's next iterative movement. Defining the historical best location of individual UAV and the population as \(d_{pbest}\) and \(d_{gbest}\), respectively, the update formulas for the velocity and location vectors of UAV particles are given as follows:  
\[v_{particle}^{(i+1)}=\omega\mathbf{v}_{particle}^{(i)}+c_{1}r_{1}(d_{pbest}^{(i)}- \mathbf{d}_{particle}^{(i)})+c_{2}r_{2}(d_{gbest}-\mathbf{d}_{particle}^{(i)}) \tag{43}\]  
\[\mathbf{d}_{particle}^{(i+1)}=\mathbf{d}_{particle}^{(i)}+\mathbf{v}_{particle}^{(i+1)} \tag{44}\]  
where \(\omega\) represents inertia weight, \(c_{1}\) represents individual learning factor, and \(c_{2}\) represents group learning factor. \(r_{1}\) and \(r_{2}\) are randomly generated numbers within the range [0, 1] to enhance the randomness of the search. According to the particle swarm optimization algorithm, after \(L_{pso}\) iterations, the global optimal value of the whole particle swarm, \(d_{gbest}\), which is the optimal position of the UAV, \(d_{uav}^{*}\), is obtained. For the PSO algorithm, suppose the number of particles is \(N_{pso}\), the number of iterations is \(L_{pso}\), and the space dimension is \(D\). The time complexity of a single iteration of each particle is \(O(D)\), the total time complexity of each iteration is \(O(D\cdot N_{pso})\), and the total time complexity is \(O(D\cdot N_{pso}L_{pso})\). Therefore, for the single UAV position optimization problem, \(D=2\) is fixed, so the time complexity of this paper is \(O(N_{pso}L_{pso})\). In summary, the solution algorithms for the combined optimization of content providers and UAV location, transmission power, and user group for the two subproblems of file pricing and UAV cache placement have been provided. The specific steps of the joint optimization algorithm for UAV cache and charging services are outlined in Algorithm 2. Firstly, each content provider provides the initial pricing of the file, which is then substituted into Algorithm 1. After conducting a Stackelberg-Bertrand game, the optimal caching strategy and caching revenue of the UAV are determined.