## 3 Secure Rate Maximization Scheme
### K-Means Cluster Pair Algorithm
The secure rate in the first phase of a NOMA pair \(\hat{R}_{p}^{1,\text{sec}}\) can be expressed as

\[\hat{R}_{p}^{1,\text{sec}}= \left(r_{a}^{D\to l}-r_{a}^{D\to E}\right)+\left(r_{d}^{D\to l}-r_{d}^{D \to E}\right)\] \[= B_{p}\text{log}_{2}\left(\frac{T(d,U)+\sigma_{1}^{2}+T(a,U)}{T( d,U)+\sigma_{1}^{2}}\right)\] \[- B_{p}\text{log}_{2}\left(\frac{T(d,E)+\sigma_{1}^{2}+T(a,E)}{T( d,E)+\sigma_{1}^{2}}\right) \tag{16}\] \[+ B_{p}\text{log}_{2}\left(\frac{\sigma_{1}^{2}+T(d,U)}{\sigma_{1} ^{2}}\right)-B_{p}\text{log}_{2}\left(\frac{\sigma_{1}^{2}+T(d,E)}{\sigma_{1} ^{2}}\right)\] \[= B_{p}\text{log}_{2}\left(T(d,U)+\sigma_{1}^{2}+T(a,U)\right)\] \[- B_{p}\text{log}_{2}\left(T(d,E)+\sigma_{1}^{2}+T(a,E)\right),\]

where \(T(x,Y)=P_{x}G_{x}^{D\to Y}\) is the product of signal power and channel gain. Due to the non-convex nature of the above equation, the successive convex approximation (SCA) method is applied to obtain a convergent solution. The solution at \((l-1)\)-th iteration is regarded as the local solution of the \(l\)-th iteration. Then, we use first-order Taylor expansion to obtain its lower bound as

\[\text{s.t.}(8),(9),(10),(11),(12),\]0 \[\text{s.t.}(8),(9),(10),(11),(12),\]1 \[\text{s.t.}(8),(9),(10),(11),(12),\]2

where \(l\) represents the \(l\)-th iteration. Then, the original problem can be converted into the following convex problem

\[\text{s.t.}(8),(9),(10),(11),(12),\]3 (18) s.t. (10), (11),

where \(\hat{R}_{p}^{2,\text{sec}}\) is the secure rate in second phase of a NOMA pair. Hence, such a problem can be solved using the CVX toolbox in MATLAB. #### 3.2.3 Height Optimization

With fixed channel and power allocation, the height optimization problem can be converted to

\[\text{s.t.}(8),(9),(10),(11),(12),\]4 (19) s.t. (12). The UAVs' height affects the total secure rate in both time slots. The influence can be interpreted as: \(r_{x}^{D\to U}\) increases when UAV is closer to the ground and \(r^{U\to H}\) decreases at the second phase. Here the ant colony optimization (ACO) algorithm is applied to address the optimal height of UAVs [29]. The ACO algorithm has three important parameters which are pheromone volatile factor \(\rho\), transfer probability constant \(P_{0}\), and local search step size \(\mu\). In order to obtain the optimum altitude by using ACO, the procedures are as follows. Firstly, the height optimization range of the UAV is divided into \(t\) discrete points, denoted by \(h_{j}\), \(j=\{1,2,\ldots,t\}\), which are considered as the initial position of the ants. Then, the secure rate calculated at \(h_{j}\) is regarded as the pheromone left by the ant, denoted by \(R_{j}\). The state transition probability value is obtained from Equation (20), which is given by

\[\text{s.t.}(8),(9),(10),(11),(12),\]5

where \(R_{\max}\) is the maximum value in the pheromone matrix \(\mathbf{R},\mathbf{R}=[R_{1},R_{2},\ldots,R_{t}]\). When \(P\) is less than \(P_{0}\), a local search is performed, otherwise, a global search is performed. Finally, the optimal height of \(m\)-th UAV \(h_{m}\) can be addressed accordingly. Specific process is shown in Algorithm 2, where \(r_{1}\) and \(r_{2}\) are random numbers for location searches. ```
1:Initializing: \(t\), \(\rho\), \(P_{0}\), \(\mu\), \(h_{\max}\), \(h_{\min}\), \(iter_{\max}\). 2:Generate random heights \(h_{j}\), calculate secure rate \(R_{j}\). 3:\(iter=0\). 4:repeat
5:if\(P<P_{0}\)then
6:\(h_{j}=h_{j}+\left(r_{1}\times\mu\times\frac{1}{iter}\right)\), \(r_{1}\in[-1,1]\). 7:else
8:\(h_{j}=h_{j}+\left(r_{2}\times\left(h_{\max}-h_{\min}\right)\right)\), \(r_{2}\in[-0.5,0.5]\). 9:endif
10:update pheromone: \(R_{j}=(1-\rho)\times R_{j}+R\left(h_{j}\right)\). 11:\(iter=iter+1\). 12:until\(iter=iter_{\max}\). 13:Output the optimal height \(h_{m}\). ```

**Algorithm 2** Height optimization based on ACO algorithm

### Iterative Algorithm

The iterative procedure can be found in \[\text{s.t.}(8),(9),(10),(11),(12),\]6 Firstly, we use the K-means cluster pair algorithm to obtain the UAV's 2D coordinates \(\mathbf{Q}^{*}\).