# Joint User Pairing, Channel Assignment and Power Allocation in NOMA based CR Systems
## 2 System Model and Problem Formulation
The problem can be decomposed into following \(\dfrac{W^{3}}{8}\) sub-problems:  
\[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}x_{n,i,c}(P_{n,i,c}+S_{n,i,c})|f_{ c}|^{2}\leq I_{th},\forall c,n\in\mathcal{A},i\in\mathcal{B},\]8 \[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}x_{n,i,c}(P_{n,i,c}+S_{n,i,c})|f_{ c}|^{2}\leq I_{th},\forall c,n\in\mathcal{A},i\in\mathcal{B},\]9 \[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]0  
As the problem is convex, we can apply Karush-Kuhn-Tucker (KKT):  
\[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]1 \[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]2  
Simplifying Equation (32), we get:  
\[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]3  
where  
\[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]4 \[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]5 \[\sum_{n=1}^{W/2}\sum_{i=1}^{W/2}\sum_{c=1}^{W/2}x_{n,i,c}(P_{n,i,c }+S_{n,i,c})\leq P_{T},\forall n\in\mathcal{A},i\in\mathcal{B},\]6  
To solve the problem, we propose the technique provided in Algorithm 1. 1. **Initialize**\(x=zero\left(\dfrac{W}{2},\dfrac{W}{2},\dfrac{W}{2}\right)\)
2. **Pair**\(\mathcal{A}_{n}\) with \(\mathcal{B}_{(W/2)+1-n},\forall n=1,2,3...\dfrac{W}{2}\), where \(\mathcal{A}_{n}\) represents the \(n\)th user in the set of strong users sorted in descending order of channel gains and \(\mathcal{B}_{z}\) denotes the \(z\)th user in the sorted set of all the weak users. Then, the \(n\)th user pair is given as \(\xi_{n}\). 3. **Set**\(P_{\mathcal{A}_{n}}\)=\(P_{\mathcal{B}_{n}}\)=\(\dfrac{P_{T}}{W},\quad\forall n=1,2,3,...\dfrac{W}{2}\). 4. **Calculate** the rate of each user pair (\(\xi_{n}\)) for every channel as \(\theta_{\xi_{n},c}=\log_{2}\Bigg{(}1+\dfrac{P_{\mathcal{A}_{n}}|h_{\mathcal{A }_{n},c}|^{2}}{\sigma^{2}}\Bigg{)}+\log_{2}\Bigg{(}1+\dfrac{P_{\mathcal{B}_{W +1-n}}|h_{\mathcal{B}_{W+1-n}}|^{2}}{P_{\mathcal{A}_{n}}|h_{\mathcal{B}_{W+1- n}}|^{2}+\sigma^{2}}\Bigg{)}\). 5. **Find**\(l\) such that \(\theta_{\xi_{n},l}==\max(\theta_{\xi_{n},c})\forall c=1,2,3...\dfrac{W}{2}\). 6. **Set**\(x_{\xi_{n},l}\)=1. 7. **Remove** user pair \(\xi_{n}\) and channel \(l\) from the search. 8. **Repeat** steps 2-7, \(\dfrac{W}{2}-1\) times. 9. **Return**\(x_{n,i,c}^{*}\). **Algorithm 1** User pairing and channel allocation. We know that a user with better channel conditions requires less power to achieve the required rate as compared to the user with bad channel conditions. Thus, if the very weak user is paired with a very strong user, the strong user would only require a little power to satisfy its rate, thus leaving large amount of available energy for the weak user. In this scheme, we pair the users such that the strongest user is paired with the weakest user. In Step 1, we initialize a three-dimensional matrix \(x\) having size \(\dfrac{W}{2}\) in all dimensions. Then, in Step 2, we pair the users together such that the strongest user is paired with the weakest user, the second strongest user is paired with the second weakest and so on. In Step 3, to find the channel allocation, we first decide the available power equally among all the users. In Step 4, we calculate the rate of each user pair. Then, in Steps 5 and 6, we find the channels for which each respective pair provides maximum rate and assign that channel to the user pair, respectively. The user pair that has been allocated a channel is removed from the allocation process along with the allocatedchannel. As there are \(\dfrac{W}{2}\) user pairs and channels, Steps 2-7 are repeated \(\dfrac{W}{2}-1\) times because the last user pair is automatically assigned the last remaining channel.