# Joint Resource Allocation in Secure OFDMA-Based Networks Taking a Base Station as a Two-Way Relay
## 3 Problem Solution  
After relaxing \(\rho\in[0,1]\) and \(\eta\in[0,1]\), we can see that all constraints of problem (19) are affine and the target function is concave, therefore the Slater's condition is satisfied. This optimization problem can be solved by the Lagrange dual method with a zero duality gap [27]. Because the dual function is always concave and the constraints are convex [27], the primary problem is transformed into convex optimization. \(\lambda\) is the dual variable associated with the total power constraints at the base station. The Lagrange dual function for (19) is:  
\[g(\lambda)=\underset{\boldsymbol{\pi},\boldsymbol{\rho},\boldsymbol{P}}{ \text{maximize}}L(\boldsymbol{\pi},\boldsymbol{\eta},\boldsymbol{\rho}, \boldsymbol{P},\lambda) \tag{20}\]  
This is a maximization problem, and is solved in three phases step-by-step using convex optimization. \[ \begin{array}{l}L(\boldsymbol{\pi},\boldsymbol{\eta},\boldsymbol{\rho}, \boldsymbol{P},\lambda)\\ =\sum\limits_{k=1}^{K}\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{N}\pi_{i,j}\rho_ {k}^{i,j}R_{\text{sec},T_{k}}^{i,j}+\sum\limits_{m=1}^{M}\sum\limits_{i=1}^{N} \sum\limits_{j=1}^{N}\eta_{i,j}p_{m}^{i,j}R_{\text{sec},m}^{i,j}-\lambda\cdot \sum\limits_{j=1}^{N}\left(\sum\limits_{m=1}^{M}P_{R,(A_{m},B_{m})}^{j}+\sum \limits_{k=1}^{K}P_{R,T_{k}}^{j}\right)+\lambda P_{totalB}\\ =\sum\limits_{j=1}^{N}\sum\limits_{k=1}^{K}\sum\limits_{i=1}^{N}\left(\pi_{i,j} \rho_{k}^{i,j}R_{\text{sec},T_{k}}^{i,j}-\lambda\cdot P_{R,T_{k}}^{i,j}\right) +\sum\limits_{j=1}^{N}\sum\limits_{m=1}^{M}\sum\limits_{i=1}^{N}\left(\eta_{i,j} \rho_{m}^{i,j}R_{\text{sec},m}^{i,j}-\lambda\cdot P_{R,(A_{m},B_{m})}^{j}+ \lambda P_{totalB}\\ =\sum\limits_{j=1}^{N}L_{j,k}(\pi_{i,j},\rho_{k}^{i,j},P_{R,T_{k}}^{i,j})+\sum \limits_{j=1}^{N}L_{j,m}(\eta_{i,j},\rho_{m}^{i,j},P_{R,(A_{m},B_{m})}^{j})+ \lambda P_{totalB}\\ \end{array}  \tag{21}\]  
\[L_{j,k}(\pi_{i,j},\rho_{k}^{i,j},P_{R,T_{k}}^{j},\lambda)=\sum\limits_{i=1}^{N} \sum\limits_{k=1}^{K}\left(\pi_{i,j}\rho_{k}^{i,j}R_{\text{sec},T_{k}}^{i,j}- \lambda\cdot P_{R,T_{k}}^{j}\right) \tag{22}\]  
\[L_{j,m}(\eta_{i,j},\rho_{m}^{i,j},P_{R,(A_{m},B_{m})}^{j},\lambda)=\sum\limits_{i=1 }^{N}\sum\limits_{m=1}^{M}\left(\eta_{i,j}\rho_{m}^{i,j}R_{\text{sec},m}^{i,j}- \lambda\cdot P_{R,(A_{m},B_{m})}^{j}\right). \tag{23}\]The dual problem can be expressed as:  
\[\underset{\lambda}{\text{minimizeg}}(\lambda).\] (24) s.t. \[\lambda\geq 0\]  
This is a convex optimization problem, which can be solved by the sub-gradient method with guaranteed convergence [28]. The derived sub-gradient of \(g(\lambda)\) is:  
\[\Delta\lambda=P_{totalB}-\sum_{j=1}^{N}\Biggl{(}\sum_{m=1}^{M} \widehat{P}_{R,(A_{m},B_{m})}^{j}+\sum_{k=1}^{K}\widehat{P}_{R,T_{k}}^{j} \Biggr{)} \tag{25}\] \[\lambda^{(l+1)}=\lambda^{(l)}+\varepsilon^{(l)}\Delta\lambda\]  
\(\varepsilon\) is the step size in the \(l\)-th iteration; \(\widehat{\rho}_{k}^{i,j}\) and \(\widehat{\rho}_{m}^{i,j}\) are the optimal power allocations at the dual point, which can be found in the following step. Step 1. For fixed \(\pi_{i,j}=1\) and \(\rho_{k}^{i,j}=1\), according to Karush-Kuhn-Tucker condition, the solution is the non-negative real root of the quadratic function. \[\begin{array}{l}\left[4\lambda(\ln 2)|g_{R,T_{k}}^{j}|^{2}|g_{R,E}^{j}| ^{2}\right]\left(P_{R,T_{k}}^{j}\right)^{2}+\left[4\lambda\sigma^{2}(\ln 2)|[g_{R,T_{k}}^{  
\[e=2\lambda(\ln 2)[2\sigma^{8}\alpha^{6}|g^{j}_{B_{m}}|^{2}+\sigma^{6} \alpha^{6}P^{i}_{A_{m}}|h^{i}_{A_{m},R}|^{2}|g^{j}_{B_{m}}|^{2}+2\sigma^{8}\alpha ^{6}|g^{j}_{A_{m}}|^{2}+\sigma^{6}\alpha^{6}P^{i}_{B_{m}}|h^{i}_{B_{m},R}|^{2}|g^ {j}_{A_{m}}|^{2}]\] \[-\sigma^{6}\alpha^{6}P^{i}_{B_{m}}|h^{i}_{B_{m},R}|^{2}|g^{j}_{A_{m }}|^{2}-\sigma^{6}\alpha^{6}P^{i}_{A_{m}}|h^{i}_{A_{m},R}|^{2}|g^{j}_{B_{m}}|^{2}\]  
Step 2. In the above step, we achieve the optimal \(\widehat{P}^{j}_{R,T_{k}}\) and \(\widehat{P}^{j}_{R,(A_{m},B_{m})}\).