# Enhanced Integrated Satellite-Terrestrial NOMA with Cooperative Device-to-Device Communication
## 3 Satellite-Aided NOMA with Cooperative D2D Communication
### SANOCO-D2D Operation
```
1 Input: Satellite CSI for each UE\({}_{i}\) and CSI between all the UE\({}_{i}\) and UE\({}_{j}\);
2 for\(i\gets 1\)to Ndo
3 for\(j\gets i+1\)to Ndo
4 Find which is the strong and the weak channel satellite user for each pair by comparing the corresponding channel gains \(\Gamma_{i}\) and \(\Gamma_{j}\);
5 Derive the power allocation factor \(\alpha_{t}\) for the strong channel satellite user through (12);
6 Calculate the achievable rate \(R_{strong}^{NOMA_{(ij)}}\) of the strong user using (6);
7 Calculate the achievable rate \(R_{weak}^{OMA}\) of the weak user using (8) which is achieved under the satellite NOMA optimal power allocation;
8 Calculate the rate \(R_{weak}^{D2D_{(ij)}}\) that the weak satellite user is able to achieve via the corresponding D2D link \(i\to j\) through (10);
9 Calculate the rate \(R_{weak}^{DECODED_{(ij)}}\) that the weak user is able to achieve in case that the strong user decode their signal using (13);
10 Calculate the achievable rate of the weak user regarding the D2D link, taking into account the rates \(R_{weak}^{D2D_{(ij)}}\) and \(R_{weak}^{DECODED_{(ij)}}\) from (14);
11 Derive the total sum rate \(R_{i,j}\) that this possible pair of users are able to achieve through (15);
12 Set the weight \(w_{i,j}\) of the edge \(e_{i,j}\in E\) of the graph \(G\) to \(w_{i,j}=R_{i,j}\);
13 end for
14
15 end for
16 Output: Optimal user pairing policy \(\mathbf{u}_{\text{i,j}}^{*}\) and the maximum sum rate \(R_{\text{max}}\)
```  
**Algorithm 2**SANOCO-D2D. Algorithm 2 presents the procedure SANOCO-D2D for maximizing the total sum rate of the system. The algorithm takes as an input the CSI of the satellite link of each user, and the CSI of each D2D link between the users. Next, it updates the weights of the edges of the graph \(G\) that has been created during the execution of Algorithm 1. Specifically, the algorithm visits each vertex \(v_{i}\) with \((1\leq i\leq N)\) of the graph representing each UE\({}_{i}\), and calculates and assigns an appropriate weight \(w_{i,j}\) to each edge \(e_{i,j}\) connecting this vertex with the vertex \(v_{j}\) of the graph with \((i<j\leq N)\). Obviously, when the algorithm visits vertex \(v_{N}\), the procedure of updating the weights of the edges of the graph immediately terminates, because all the weights of the edges connecting vertex \(v_{N}\) with all the other vertices of the graph \(G\) have been updated during the previous iterations. With the proposed algorithm, in order to calculate the weight \(w_{i,j}\) that should be assigned to the edge \(e_{i,j}\) connecting vertices \(v_{i}\) and \(v_{j}\) with \((i<j)\) and indicate a possible pair of users, the identification of the strong and the weak satellite users should be performed first, by comparing the corresponding channel gains \(\Gamma_{i}\) and \(\Gamma_{j}\) of \(\text{UE}_{i}\) and \(\text{UE}_{j}\) that are modeled as the vertices \(v_{i}\) and \(v_{j}\) of the graph \(G\). Then, the calculation of the power allocation factor of the strong satellite user takes place using (12). Subsequently, using (6) the achievable rate \(R_{strong}^{NOMA_{(i,j)}}\) of the strong satellite user is calculated in the context of NOMA optimal user pairing scheme. Thereafter, via (8), the achievable rate \(R_{weak}^{OMA}\) of the weak satellite user under the satellite NOMA optimal power allocation scheme should be calculated. Keep in mind that the achievable rate of the weak satellite user \(R_{weak}^{NOMA_{(i,j)}}\) under optimal power allocation is equal to \(R_{weak}^{OMA}\) because the power allocation factor that is assigned to the weak satellite user should satisfy the rate constraint for this user, while all the remaining power is allocated to the strong satellite user in order to maximize the achievable system sum rate.