# Resource Allocation in Uplink NOMA-IoT Based UAV for URLLC Applications
## 5 Proposed Algorithm
### Frequency Domain Packet Scheduling (FDPS)  
The main purpose of FDPS is allocating resources for IoT devices based on channel conditions (CQI) to increase spectral efficiency [32]. FDPS allocates resources to the IoT devices chosen by TDPS. Thus, the optimization problem of FDPS could be formulated as  
\[\underset{\{b_{k,l}(t)\}}{\text{Max}}\sum_{k=1}^{K}\sum_{l=1}^{N\_sel}\text{ R}_{k,l}(t) \tag{29}\]  
\[s.t\ C1:\sum_{k=1}^{K}b_{k,l}(t)R_{k,l}(t)\ \geq\ R_{min,l} \tag{30}\]  
\[C3:\ b_{k,l}(t)\ \in\{0,1\} \tag{31}\]  
\[C5:\sum_{l=1}^{N\_sel}b_{k,l}(t)\ \leq\ L \tag{32}\]  
In the proposed algorithm in FDPS each of the selected users prioritizes the RBs, where each IoT device sorts the RBs in descending order of CQI. The CQI value is an indication for the channel quality of each user on each subchannel. CQI value ranges from 0 to 15. The higher the value, the better the channel quality and vice versa. The CQI value is determined according to the estimated value of SINR [33]. Therefore, a preference matrix is formed containing the CQI values of all users on all RBs such that \(CQI_{i,k}\) is the CQI value of user \(i\) on RB \(k\); where the rows correspond to the IoT devices and the columns are related to the RBs. Each IoT device's preferences (CQI values) are listed in a row in this matrix; such that a higher CQI value indicates that the IoT device prefers this RB. A weighted preference matrix is then formed which is based on the weighted metrics (27) computed in TDPS and the preferences determined in FDPS, and can be given by  
\[f_{obj}=Diag(M_{1 xN\_sel})\ CQI_{N\_sel\ xK} \tag{33}\]  
where \(M_{1 xN\_sel}\) is a row vector of the metrics of the selected devices and \(\ CQI_{N\_sel\ xK}\) is the preference matrix which contains the CQI values of the selected devices on all RBs. Hence, the problem in (29) can be easily modified to  
\[\underset{\{b_{kJ}(t)\}}{\text{Max}}-Diag\big{(}M_{1 xN\_sel}\big{)}\ CQI_{N\_sel xK}b_{kJ}(t) \tag{34}\]  
\[s.t\ C3:\ b_{kJ}(t)\ \in\{0,1\} \tag{35}\]  
\[C5:\ \sum_{l=1}^{N\_sel}b_{kJ}(t)\ \leq\ L \tag{36}\]  
The problem in (34) can be solved using binary integer programming which is used to solve the constrained problem to maximize \(f_{obj}\) The algorithm (Algorithm 1) to find the optimum allocation matrix is listed in detail as shown in the pseudo code. ```
1:Input:\(T\), \(K\), \(N\), \(A\), \(P_{min}\) & \(P_{max}\), \(j\), \(L\)
2:Output:\(\{s\}\)\(b_{k,j}\)
3: Initialize: \(N_{max}=L^{*}K\)
4: Step 1: chooses the \(N_{max}\) devices with the highest metrics in TDPS. 5: Arrange IoT devices in \(j\) groups according to the application type. 6: For\(T_{s}=1\) to \(T_{s}=T\)do
7:\(R=\) IoT devices send scheduling requests
8:if\(R=<N_{max}\) go to Label
9:else,do
10: For\(i=1\) to \(i=R\)do
11: Compute the weight of device \(i\) (27): \(M_{i}=\alpha_{i}\ w_{i,j}d_{av,i}\)
12:Endfor
13: Arrange IoT devices of each group in descending order of the weight (\(M_{i}\))
14: Choose the \(N\_max\) nodes which have the maximum weight to be scheduled in this TTI. 15: Label:  Choose the R nodes to be scheduled in this TTI. 16: End If
17:\(N\_sel=\) the selected nodes to be scheduled
18:Step 2: assign each IoT device a resource block
19: For\(i=1\) to \(i=N\_sel\)do
20: Form the preference matrix for each device \(i\) to all available RBs based on the CQI value. 21: Form the objective function which is the weighted preference matrix \(f_{obj}\). 22: Initialize \(\hat{k}=1\), correspondingly set \(f_{max}=f_{obj}\). 23:if a solution \(ke\Big{\{}\ kk\Big{|}\ f_{obj}\Big{\}}\Big{/}f_{max}\Big{\}}\) can be found: update \(\hat{k}=k\), and \(f_{max}=f_{obj}\). 24: Endfor
25: Delay of the scheduled nodes is cleared, but that of waiting nodes is incremented. 26: Rejected nodes send scheduling requests in the next TTI. 27:EndFor
```  
**Algorithm 1** Joint Delay-Rate Optimization Scheduler  
In the Joint Delay-Rate Optimization Scheduler, the UAV receives scheduling requests in every TTI. In TDPS, the UAV classifies the requests to groups according to the application.