## 3 D2D-Based Resource Allocation Algorithms
### Power and Delay Optimization Based Uplink Resource Allocation Algorithm
According to Lemma 1 in [32], if matrix \(G\) defined in Equation (11) satisfies Equation (15), then a unique lower bound for the power allocation is given by Equation (16), satisfying the condition \(p_{min}\preceq p_{max}\). Thus, \(p_{min}\) represents the optimal solution to the power allocation optimization problem. \[g_{i,i}>\gamma_{i}\sum_{j=1,j\
eq i}^{N+K}g_{i,j},\forall i=1,2,\cdots,N+K \tag{15}\]

\[p_{min}=G^{-1}n \tag{16}\]The proposed optimal power allocation and delay minimization based on the conflict graph algorithm for device-to-device communications approach is detailed in Algorithm 5. ```
\(M\) CUEs, \(N\) DUEs, \(K\) Idle Resource Blocks, \(Z\) Initial amount of CUEs; for\(j=1\) until\(Z+1\)do  Randomly Generates Locations of CUEs and DUEs;  Calculate the Gains \(g_{N,N}\), \(g_{b\times c_{k}}\), \(g_{b,N}\) and \(g_{N,c_{k}}\);  Calculate the Z-matrix using Equation (11);  Calculate the Power using Equation (16);  end for /* Find the optimal power: \(Pm\) /*; /* \(U\) is the set of unmarked groups */ \(U\leftarrow\{1,2,...,M\}\); /* \(\Gamma\) is the set of DUEs that join the group \(m\) */ \(\Gamma_{1},\Gamma_{2},...,\Gamma_{M}\gets 0\); for\(n\in\{1,2,...,N\}-\{\delta_{1},\delta_{2},...,\delta_{K}\}\)do /* Run Algorithm 2*/ \(m^{*}\gets OptimizeDelay(n,U)\); /* \(D_{n}\) join the group \(m^{*}\) */ \(\Gamma_{m^{*}}\gets\Gamma_{m^{*}}\cup\{n\}\);  end for while\(U\
eq 0\)do  Forms the conflict graph \(G_{m^{*}}\) for the largest group \(\Gamma_{m^{\prime}}\) in \(U\) \(\Delta_{m^{\prime}}\leftarrow\) set maximum weight independent of \(G_{m^{\prime}}\) for\(n^{\prime}\in\Delta_{m^{\prime}}\)do /* Checks if the DUE pair \(n^{\prime}\) meets the SINR requirement */ if\(P_{m^{\prime}}G_{m^{\prime}n^{\prime}}+\Sigma_{n\in\Delta_{m^{\prime}}-\{n^{ \prime}\}}P_{n}G_{m^{\prime}}\geq I_{n^{\prime}}\)then  Removes \(n^{\prime}\) from \(\Delta_{m^{\prime}}\)  end if  end for /*In descending order, sort the DUEs in \(\Delta_{m^{\prime}}\) by their interference in \(C_{m^{\prime}}\)*/ /* Removes one DUE from \(\Delta_{m^{\prime}}\) until the maximum tolerable interference constraint \(I_{m^{\prime}}\) is met */ while\(\Sigma_{n\in\Delta_{m^{\prime}}}P_{n}G_{n}\geq I_{n^{\prime}}\)do  Removes the first element from \(\Delta_{m^{\prime}}\)  end for for\(n\in\Gamma_{m^{\prime}}-\Delta_{m^{\prime}}\)do /* Run Algorithm 2*/ \(m^{*}\gets OptimizeDelay(n,U-\{m^{\prime}\})\); /* \(D_{n}\) join the group \(m^{*}\) */ \(\Gamma_{m^{*}}\leftarrow\Gamma_{m^{*}}\cup\{n\}\);  end for /* Group \(m^{\prime}\) is marked */ \(U\gets U-\{m^{\prime}\}\);  end for
```

**Algorithm 5**OP-DMCG

## 5 Simulation and Results

In this section, we present simulations and numerical results of the implemented scenario to evaluate the performance of the proposed optimal power allocation and delay minimization based on the conflict graph algorithm for device-to-device communications algorithm in maximizing the total throughput of both D2D and cellular users, while adhering to QoS requirements. In our research, we conduct a performance comparison of our algorithm against established methods from the existing literature, including the greedy throughput maximization plus, delay minimization conflict graph, and power and delay optimization based uplink resource allocation resource allocation techniques. We emphasize the significance of parameter tuning to ensure a fair and meaningful comparison across algorithms. The selected parameters align with the characteristics of 5G wireless networks and adhere to established practices in D2D multi-sharing communication [21; 34]. This tuning process enhances the relevance and validity of our comparative analysis, reflecting real-world scenarios in the context of evolving wireless communication technologies. The values for the parameters used in the simulations of this work are given in Table 1.

The computational complexity of algorithms has a direct impact on processing time. The proposed OP-DMCG algorithm has a complexity of \(O(n^{3})\) since it involves matrix inversion in its calculation.