# Energy-Efficient Subcarrier Pairing and Power Allocation for DF Relay Networks with an Eavesdropper
## 3 Energy-Efficient Subcarrier Pairing and Power Allocation Algorithm
### Solution of the Subproblem  
By employing the Karush-Kuhn-Tucker (KKT) conditions, we can find the optimal power allocation for a given subcarrier pairing \(\left(i,j\right)\). To find the optimal \(P_{R,j}^{\left(t+1\right)^{*}}\) and \(\Omega_{i}^{\left(t+1\right)^{*}}\) in iteration \(\left(t+1\right)\), we take the partial derivative of (18) with respect to \(P_{R,j}\) and \(\Omega_{i}\) and equate the results to zero as  
\[P_{R,j}^{\left(t+1\right)^{*}} = \left[\left(\frac{\
u_{j}\varepsilon^{\Omega_{j}}\sigma_{D,j}^{2} }{\left|h_{RD,j}\right|^{2}\left(\frac{\alpha_{j}^{\epsilon}}{\ln 2}-\left( \Psi+\lambda\right)\sum\limits_{i=1}^{K}\rho_{i,j}\right)}\right)\right]^{+} \tag{21}\] \[\Omega_{i}^{\left(t+1\right)^{*}} = \left[\frac{\frac{\alpha_{i}^{d}}{2\ln 2}\sum\limits_{j=1}^{K}\rho_{i,j} }{\frac{\mu_{i}\sigma_{R,j}^{2}}{\frac{\mu_{i}\sigma_{R,j}^{2}}{e^{\beta_{S,i }}\left|h_{SR,i}\right|^{2}}-\frac{v_{i}\sigma_{D,i}^{2}}{e^{\beta_{R,i}}\left| h_{RD,j}\right|^{2}}}}\right]^{+} \tag{22}\]  
The source power at the \(\left(t+1\right)^{th}\) iteration, \(P_{S,i}^{\left(t+1\right)}\), can be updated through the subgradient method as  
\[P_{S,i}^{\left(t+1\right)^{*}}=\left[P_{S,i}^{\left(t\right)}+\varepsilon_{1} ^{\left(t\right)}\left(\frac{\mu_{i}^{\left(t\right)^{\sigma_{R,i}^{\left(t \right)^{2}}}}}{\left|h_{SR,i}\right|^{\left(t\right)^{2}}}+\left(\Psi^{\left(t \right)}+\lambda^{\left(t\right)}\right)\sum\limits_{j=1}^{K}\rho_{i,j}^{\left( t\right)}\right)\right]^{+} \tag{23}\]  
where \(\varepsilon_{1}^{\left(t\right)}\) is a positive step size. To determine the optimal subcarrier pairing, we put (23) and (21) into (18), yielding  
\[\mathcal{L}\left(\mathbf{P}_{S}^{\star},\mathbf{P}_{R}^{\star},\rho,\mathbf{ \Omega}^{\star},\lambda,\mu,\
u\right)=\sum\limits_{i=1}^{K}\sum\limits_{j=1}^ {K}\rho_{i,j}Y_{i,j}+Z\left(\lambda,\mu,\
u\right) \tag{24}\]  
where  
\[Y_{i,j}=\frac{\alpha_{i}^{d}}{2\ln 2}\ln\Omega_{i}^{\star}+\frac{\beta_{i}^{d }}{2}-\left(\Psi+\lambda\right)\left(P_{S,i}^{\star}+P_{R,j}^{\star}\right) \tag{25}\]  
\[Z\left(\lambda,\mu,\
u\right)= -\sum\limits_{j=1}^{K}\frac{\alpha_{j}^{\epsilon}}{\ln 2}\left(\ln P_{R,j}^ {\star}+\ln\left(\left|h_{RE,j}\right|^{2}\right)-\ln\left(\sigma_{E,j}^{2} \right)\right)-\beta_{j}^{\epsilon}-\Psi P_{SC}+\lambda P_{max}\] \[-\sum\limits_{i=1}^{K}\mu_{i}\left(\frac{\Omega_{i}^{\star}\sigma_ {R,i}^{2}}{P_{S,i}^{\star}\left|h_{SR,i}\right|^{2}}-1\right)-\sum\limits_{j=1} ^{K}v_{j}\left(\frac{\Omega_{j}^{\star}\sigma_{D,j}^{2}}{P_{R,j}^{\star}\left| h_{RD,j}\right|^{2}}-1\right) \tag{26}\]The first term in \(Y_{i,j}\) denotes the sum rate obtained for the given subcarrier pairing \((i,j)\), while the remaining term \(Z\left(\lambda,\mathbf{\mu},\mathbf{\
u}\right)\), which is always independent of \(\rho_{i,j}\), works as a penalty for the power dissipation.  
As a result, for the optimal power allocation \(\left(\mathbf{P}_{R}^{\star},\mathbf{P}_{S}^{\star}\right)\) derived in (21) and (23), the optimal subcarrier pairing \(\mathbf{\rho}^{\star}\) can be found by solving the problem (P.4) as follows:  
\[\mathrm{(P.4)} \max_{\mathbf{\rho}}\ \sum_{i=1}^{K}\sum_{j=1}^{K}\rho_{i,j}Y_{i,j}\] (27) s.t. \[\mathrm{(C.2)}\ \&\ \mathrm{(C.3)}\]  
Define a \(K\times K\) matrix \(\mathbf{Y}\) as follows:  
\[\mathbf{Y}=\begin{bmatrix}Y_{1,1}&\cdots&Y_{1,K}\\ \vdots&\ddots&\vdots\\ Y_{K,1}&\cdots&Y_{K,K}\end{bmatrix} \tag{28}\]  
The optimal subcarrier pairing \(\mathbf{\rho}^{\star}\) can be determined by choosing exactly one value in each row and column of the matrix \(\mathbf{Y}\) with the help of the Hungarian method [20] such that the sum of these \(K\) values is maximized.