# Social-Aware-Based Resource Allocation for NOMA-Enhanced D2D Communications
## 3 Social-Aware-Based Resource Allocation
### Cluster Formation  
\(N\) D2D content requesters are randomly distributed in the cell. They choose D2D content providers within their D2D communication range to join them and form D2D clusters. The utility function of D2D content requesters can be defined as  
\[U_{DR}^{m}=\omega_{1}\frac{\left(req_{n}\underset{k\in D_{n}}{\cap}cache_{k} \right)}{\left\|req_{n}\right\|_{1}}+\omega_{2}\frac{\underset{k\in D_{n}}{ \sum}d_{k,n}}{d_{th}*\left|D_{n}\right|}+\omega_{3}\frac{\underset{k\in D_{n}} {\sum}S_{k,n}}{\left|D_{n}\right|} \tag{1}\]  
Figure 2: System model (social domain).  
where \(req_{n}\) indicates the request content of D2D content requester \(DR_{n}\), \(cache_{k}\) indicates the cache content of D2D content provider \(DT_{k}\). \(d_{k,n}\) represents the distance between \(DT_{k}\) and \(DR_{n}\), whereas \(d_{th}\) indicates the D2D communication range. \(S_{k,n}\) denotes the social relationship between \(DT_{k}\) and \(DR_{n}\). (\(\bullet\)) represents the dot product between vectors and \(\|\bullet\|_{1}\) represents the 1-norm of a vector (the sum of all elements in the vector). \(\|\bullet\|\) represents the number of elements in \(\bullet\). The first term on the right side of Equation (1) indicates the degree of content matching between \(DT_{k}\) and \(DR_{n}\). The second term indicates their physical distance factor and the third term indicates their social relationship factor. All influencing factors are normalized according to other D2D content providers in the cluster \(D_{n}\).(\(\alpha_{1},\alpha_{2},\alpha_{3}\)) is the weighting factor which satisfies \(\omega_{1}+\omega_{2}+\omega_{3}=1\).  
According to the utility function in Equation (1), the D2D content requester selects the D2D content provider with the largest utility within the D2D communication range and adds it to his cluster until no D2D content provider nearby can increase his utility. If a D2D content provider is selected by several D2D content requesters, he will choose the one with the largest utility. After every D2D content requester has drawn up a shortlist for his cluster, the cluster formation is done. The proposed cluster formation algorithm is shown in Algorithm 1.  
```
1: For n = 1:\(N\)
2: For k = 1:\(K\)
3: If \(d_{k,n}<d_{th}\)
4: Calculate the utility \(U_{DR}^{n}\) of \(DT_{k}\) and \(DR_{n}\) according to Equation (1)
5: End if
6: End for
7: Compare and select \(DT_{k}\) who obtains the largest \(U_{DR}^{n}\) to join \(D_{n}\)
8: If \(DT_{k}\) has been selected by \(DR_{n^{\prime}}\)
9: Compare \(U_{DR}^{n}\) and \(U_{DR}^{n^{\prime}}\), select the one with larger utility and restart the loop
10: End if
11: While Equation (1)
12: For k = 1:K
13: If \(d_{k,n}<d_{th}\)
14: Calculate the increased utility \(\Delta U_{DR}^{n,k}\) according to Equation (1)
15: End If
16: End for
17: If \(\exists\Delta U_{DR}^{n,k}>0\)
18: Compare and select \(DT_{k}\) who obtains the largest \(\Delta U_{DR}^{n,k}\) to join \(D_{n}\)
19: If \(DT_{k}\) has been selected by \(DR_{n^{\prime}}\)
20: Compare \(U_{DR}^{n}\) and \(U_{DR}^{n^{\prime}}\)
21: Select the one with larger utility and restart the loop
22: End if
23: Else
24: Break
25: End while
26: End for
27: Output: {\(D\)}
```  
**Algorithm 1** D2D cluster formation algorithm.