## 3 D2D-Based Resource Allocation Algorithms
### Power and Delay Optimization Based Uplink Resource Allocation Algorithm
\[\zeta(\phi,w)\triangleq\frac{N_{FFT}}{N_{FFT}+L+L_{CH}-2}\frac{N_{p}}{N_{u}}rm _{mod}[1-\Phi(\gamma_{eff})] \tag{8}\]  
The goodput power allocation algorithm, as presented in Algorithm 4, aims to minimize network delay by taking into consideration the queue buffer of cellular users and implementing an optimal throughput optimization policy. The algorithm ensures efficient allocation of resources by maximizing the network throughput while minimizing delay. The power allocation is calculated based on the current state of the system and the estimated channel quality. This allows for adaptability to changing network conditions and ensures efficient utilization of available resources. Hence, the simulations presented in Section 5 integrate the goodput power allocation (Algorithm 4) and the resource allocation method (Algorithms 1 and 2) composing the PDO-URA approach (Algorithm 3). ```
Calculate the previous average arrival rate \(\overline{a}\)  Define \(\mu_{m}^{\{0\}}=\frac{1}{\overline{a}_{m}}\)  Calculate \(r^{(0)}=argmax_{r\in C}h^{(0)T}\cdot r\)  Initialize the non-idle state size \(\eta_{m}^{(0)}=min_{m\in M}\frac{\delta_{m}^{1}}{r_{m}^{(0)}}\)  Initialize the constellation size \(m_{mod}=0\) and \(\xi_{max}=0\)  Define the order so that \(\frac{q_{m}^{1}}{r_{\pi(1)}^{(0)}}\geq\frac{\delta_{m}^{1}}{r_{\pi(2)}^{(0)} }\geq\cdots\geq\frac{q_{\pi(M)}^{1}}{r_{\pi(M)}^{(0)}}\)  Define \(u=0\)
```  
**Algorithm 4**Goodput Algorithm  
```
Calculate the previous average arrival rate \(\overline{a}\)  Define \(\mu_{m}^{\{0\}}=\frac{1}{\overline{a}_{m}}\)  Calculate \(r^{(0)}=argmax_{r\in C}h^{(0)T}\cdot r\)  Initialize the non-idle state size \(\eta_{m}^{(0)}=min_{m\in M}\frac{\delta_{m}^{1}}{r_{m}^{(0)}}\)  Initialize the constellation size \(m_{mod}=0\) and \(\xi_{max}=0\)  Define the order so that \(\frac{q_{m}^{1}}{r_{\pi(1)}^{(0)}}\geq\frac{\delta_{m}^{1}}{r_{\pi(2)}^{(0)} }\geq\cdots\geq\frac{q_{\pi(M)}^{1}}{r_{\pi(M)}^{(0)}}\)  Define \(u=0\)
```  
**Algorithm 5**Goodput Algorithm  
```
Calculate the previous average arrival rate \(\overline{a}\)  Define \(\mu_{m}^{\{0\}}=\frac{1}{\overline{a}_{m}}\)  Calculate \(r^{(0)}=argmax_{r\in C}h^{(0)T}\cdot r\)  Initialize the non-idle state size \(\eta_{m}^{(0)}=min_{m\in M}\frac{\delta_{m}^{1}}{r_{m}^{(0)}}\)  Initialize the constellation size \(m_{mod}=0\) and \(\xi_{max}=0\)  Define the order so that \(\frac{q_{m}^{1}}{r_
```
repeat  Define \(\eta^{(u+1)}=\eta^{(u)}\) for\(m=1\) until\(M\)do \(\eta^{*}=\eta^{(u+1)}\); repeat  Increases \(\eta^{*}_{\pi(m)}\) repeat \(m_{mod}=m_{mod}+2\); for\(b=0:B-1\)do  Calculates \(\tilde{w}_{b}(m_{mod})\)  end for  Collect \(\tilde{w}(m_{mod})=\left[\tilde{w}_{0}(m_{mod}),\cdots,\tilde{w}_{B-1}(m_{ mod})\right]^{T}\)  Select \(r^{\prime}=argmax_{r\in\mathbb{C}\mathbb{C}}(r,m_{mod},\tilde{w}(m_{mod}))\) if\(\varsigma(r,m_{mod},\tilde{w}(m_{mod}))\geq\varsigma_{max}\)then  Define \(m^{*}=m_{mod}\) \(r^{*}=r^{\prime}\); \(w^{*}=\tilde{w}(m_{mod})\); \(\varsigma_{max}=\varsigma(r,m_{mod},\tilde{w}(m_{mod}))\);  end for until\(m_{mod}=m_{mod_{max}}\);  Return \(\phi^{*}=\left\{m^{*}_{mod},r^{*}\right\}\) and \(w^{*}\)  Solves the maximization problem and calculates the evolution of the queue state if\(q^{\eta^{*}_{\pi(m)}}_{\pi(m)}\geq 0\)then \(\eta^{(u+1)}_{\pi(m)}=\eta^{*}_{\pi(m)}\);  end if until\(q^{\eta^{*}_{\pi(m)}}_{\pi(m)}<0\);  end for \(u=u+1\); until\(\eta^{(u)}_{\pi}-\eta^{(u-1)}_{m}<\epsilon,\forall m\in M\); \(\eta^{*}=\eta^{(u)}\);  Calculates the current weight vector \(\mu^{t}\)  Calculates the current allocation rate: \(r^{*}=argmax_{r\in\mathbb{C}}\left(\mu^{t}\right)^{T}\cdot r\)
```
**Algorithm 4**_Cont._

## 4 Optimal Power Allocation and Delay Minimization Conflict Graph Algorithm for D2D Communications

In this section, we introduce the proposed algorithm for maximizing the total throughput of D2D and cellular users while meeting their respective QoS requirements.