## 3 The Proposed Resource Allocation Scheme for D2D Communication
### Power Allocation with the Given D2D Pair  
Given the D2D pair \(k\) and the subcarriers \(m\) allocated to it, the binary variables \(\pi_{k,m}\) in (12) are identified as 0 or 1. In order to maximize the sum spectrum efficiency of overall heterogeneous network, the optimal transmission power allocated to each individual D2D pair \(k\) should be found. Note that the set \(\mathcal{M}_{k}\) represents subcarriers reused by the \(k\)th D2D pair; the optimization problem of solving the optimal power allocation for the D2D pair \(k\) can be expressed as:  
\[\begin{array}{ll}\max\limits_{p_{k,m}^{D},k,m}&\sum\limits_{m\in\mathcal{M} _{k}}\quad\Big{[}R_{k,m}^{D}(p_{k,m}^{D})+R_{k,m}^{C}(p_{k,m}^{D})\Big{]} \triangleq\sum\limits_{m\in\mathcal{M}_{k}}\mathcal{Q}(p_{k,m}^{D})\\ &s.t.\quad\quad\quad\quad\quad\quad\quad\quad\quad  
According to C1 in problem (12), we can easily get \(B_{1}/A_{1}\leq B_{3}/A_{3}\). By taking the second order derivative of the \(U(p_{k,m}^{D})\) versus \(p_{k,m}^{D}\), we have  
\[ \begin{array}{ll}\frac{\partial^{2}Q}{\partial p_{k,m}^{D}}&=\frac{1}{\ln 2} \cdot\left[-\frac{1}{(p_{k,m}^{D}+B_{1}/A_{1})^{2}}-\frac{1}{(p_{k,m}^{D}+B_{2} /A_{2})^{2}}\right.\\ &\left.+\frac{1}{(p_{k,m}^{D}+B_{3}/A_{3})^{2}}\right]\leq 0.\end{array}  \tag{26}\]  
indicating that \(Q(p_{k,m}^{D})\) is a concave function. Obviously, the optimization problem (25) is a standard convex optimization problem about variable \(p_{k,m}^{D}\) and can be solved by Lagrangian Dual method [23]. The Lagrangian associated the problem (25) is  
\[ \begin{array}{ll}L\Big{(}\Big{\{}p_{k,m}^{D}\Big{\}},\lambda,\mu,\
u\Big{)}= \sum\limits_{m\in\mathcal{M}_{k}}&\Big{[}R_{k,m}^{D}(p_{k,m}^{D})+R_{k,m}^{C} (p_{k,m}^{D})\Big{]}\\ &+\sum\limits_{m\in\mathcal{M}_{k}}\lambda_{m}\Big{(}p_{k,m}^{D}-p_{k,m}^{D \text{min1}}\Big{)}+\sum\limits_{m\in\mathcal{M}_{k}}\mu_{m}\Big{(}p_{k,m}^{D \text{max1}}-p_{k,m}^{D}\Big{)}\\ &+\
u\Bigg{(}p_{\text{thr}}^{D}-\sum\limits_{m\in\mathcal{M}_{k}}p_{k,m}^{D} \Bigg{)}\end{array}  \tag{27}\]  
where \(\lambda=\{\lambda_{m}\},\mu=\{\mu_{m}\},\
u\) are non-negative Lagrangian multipliers for the constraints C1\(\sim\)C3 in (25). The dual problem of the optimization primal problem is defined as:  
\[ \begin{array}{ll}\min\limits_{\{\lambda,\mu,\
u\}}&g(\lambda,\mu,\
u)=\max \limits_{\{p_{k,m}^{D}\}}L\Big{(}\Big{\{}p_{k,m}^{D}\Big{\}},\lambda,\mu,\
u \Big{)}\\ &s.t.\qquad\lambda_{m}\geq 0,\mu_{m}\geq 0,\
u\geq 0\end{array}  \tag{28}\]  
For any \(m\in\mathcal{M}_{k}\), \(p_{k,m}^{D\text{ }opt}\) is denoted as the optimal transmission power for D2D pair \(k\). Then, the corresponding Karush-Kuhn-Tucker (KKT) condition is as follows:  
\[ \begin{array}{ll}\frac{\partial g}{\partial p_{k,m}^{D}}=&\frac{1}{\ln 2} \cdot(\frac{1}{p_{k,m}^{D}+B_{1}/A_{1}}+\frac{1}{p_{k,m}^{D}+B_{2}/A_{2}}\\ &-\frac{1}{p_{k,m}^{D}+B_{3}/A_{3}})+\lambda_{m}^{*}-\mu_{m}^{*}-\
u^{*}=0, \end{array}  \tag{29}\]  
\[\lambda_{m}^{*}\Big{(}p_{k,m}^{Dopt}-p_{k,m}^{D\text{min1}}\Big{)}=0,\forall m \in\mathcal{M}_{k}, \tag{30}\]  
\[\mu_{m}^{*}\Big{(}p_{k,m}^{D\text{ max1}}-p_{k,m}^{D\text{ }opt}\Big{)}=0,\forall m\in\mathcal{M}_{k}, \tag{31}\]  
\[\
u^{*}\Bigg{(}p_{\text{thr}}^{D}-\sum\limits_{m\in\mathcal{M}_{k}}p_{k,m}^{D \text{ }opt}\Bigg{)}=0, \tag{32}\]  
where \(\lambda_{m}^{*}\), \(\mu_{m}^{*}\), and \(\
u^{*}\) are the optimal dual points. If \(p_{k,m}^{D\text{ }opt}>p_{k,m}^{D\text{ min1}}\) and \(p_{k,m}^{D\text{ }opt}<p_{k,m}^{D\text{ max1}}\), we have \(\lambda_{m}^{*}=0\) and \(\mu_{m}^{*}=0\). Furthermore, due to the fact that \(p_{k,m}^{D\text{ }opt}\) are optimal, the tendency to pursue the power maximization requires that the equation \(p_{\text{thr}}^{D}-\sum\limits_{m\in\mathcal{M}_{k}}p_{k,m}^{D\text{ }opt}=0\) always follows. By substituting \(\lambda_{m}^{*}=0,\mu_{m}^{*}=0\) into (29), the value of \(\
u^{*}\) can be obtained as follows.