# An Efficient Resource Allocation Algorithm for Device-To-Device Communications
## 3 Proposed Algorithm  
In Section 2.2, the objective function and constraints defined by Equations (6)-(10) belong to the mixed-integer nonlinear optimization problem. The optimal solution needs to traverse all possible assignments with high complexity. Therefore, the complexity of this study is adopted to a lower, suboptimal approach to the optimal solution. This scheme first establishes a preference list of D2D users and channels, respectively. Each D2D user builds a preference list \(Due\_list\) based on system capacity on different channels, with the first value of each row in the preference list having the highest preference value. Table 1 shows a list of preferences for three D2D users. The preference list of the second D2D user is \(Due\_list\) (2) = (3,5,2,4,1), indicating that the channel resource that the second D2D user most wants to multiplex is 3. In a similar manner, each channel establishes a channel preference list \(Channel\_list\) based on the total system capacity achievable by different D2D user communications. The program also needs to define the following parameters:  
1. A collection Association of channels and D2D users, the Association(\(k\)) indicates that channel \(k\) contains already matched D2D users;
2. \(D\) list of channels that D2D users most want to multiplex, \(Pre=[\delta_{1},\delta_{2},\ldots,\delta_{k},\ldots,\delta_{D}]\), the user preference list shows that \(\delta_{k}\) is the first element of the \(Due\_list(k)\) list;
3. Define Cluster(\(k\)) as the set of D2D user pairs that currently want to multiplex channel \(k\). For example, Cluster(\(k\)) = {1, 3, 4} means that the current 1, 3, and 4 D2D user pairs most want to multiplex channel \(k\), i.e., \(\delta(\mathbf{d})\)=\(k\) (\(\forall\ \mathbf{d}\in\)) Cluster(\(k\));
4. No matching D2D user representation of the set as UNMATCH;
5. The total number of channels \(N\), the number of iterations is _Iteration_, and the maximum number of iterations is MAXGEN. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**D2D User Pair**} & \multicolumn{5}{c}{**Preference Level**} \\ \cline{2-6}  & **1** & **2** & **3** & **4** & **5** \\ \hline
3 & 1 & 2 & 3 & 5 & 4 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: D2D (device-to-device) user preference list. The pseudo-code of the algorithm is shown in Algorithm 1. ```
1:Initialization: Set system parameters such as the number of users, transmit power, path loss, etc., to allocate channels for macro cell users and micro cell users. 2: Establish user preference list \(Due\_list\), channel preference list \(Channel\_list\), initialization parameters Association, Cluster, UNMATCH. 3:While iteration \(<\) MAXGEN do
4:if UNMATCH = \(\mathcal{O}\)
5:for\(k=1\) to \(N\) do
6: Set D2D user \(k\) on current channel S = 0
7:if Cluster(\(k\)) \(\
eq\)\(\mathcal{O}\) and S \(\leq\) 2
8: Find from the set Cluster(\(k\)) according to the channel \(k\) preference list \(Channel\_list(k)\) to the highest priority D2D user \(d\)
9: Calculate the objective function of the macrocell, microcell and D2D users using Equation (6)
10: Determine the SINRs of the macrocell user, microcell and D2D user using Equation (7)-(9)
11: Assign the channel to the microcell user if Equations (10) is satisfied
12: Assign the channel to the D2D users if Equation (11) is satisfied
13:if the constraints of Equations (7)-(11) are satisfied
14: Association(\(k\)) = Association(\(k\)) \(\cup\) [\(d\)]
15: UNMATCH = UNMATCH\(-\)[d]
16: S = S + 1
17:else
18:\(Due\_list(d)=Due\_list(d)-\delta_{d}\), update \(Pre\) and Cluster(\(k\))
19:end
20: Cluster(\(k\))=Cluster(\(k\)) - [\(d\)]
21:end
22:for\(r\in\) Cluster(\(k\))
23:\(Due\_list(r)=Due\_list(r)-\delta_{r}\)
24:end
25:end
26:if\(Due\_list(w)=\mathcal{O}\) (\(w\in H\))
27:UNMATCH\(-\)[w]
28:end
29:end
30: Iteration = Iteration+1
31:End
32: Use the KM algorithm to achieve the optimal matching between D2D clusters and cellular users' channels [21]. ```  
**Algorithm 1** M2 IGS Algorithm  
The steps of Algorithm 1 are as follows:  
1.