# Secrecy Rate of Resource-Constrained Mobile Relay Model under Two-Way Wiretap Channel
## 2 Materials and Methods
### Local Optimal Solution to P1
#### 2.3.2 Optimal Solution of \((Z)\)(Namely \(\{Z_{m,j}\}\)) and \(\{t_{m},p_{m},q_{m}\}\)  
Given \(\mathbf{s}=\widetilde{\mathbf{s}}\), where \(\widetilde{\mathbf{s}}\) is any feasible solution to P1, the constraint (2e) of \(\mathcal{A}(\mathbf{s},\mathbf{Z})\) can be discarded since it only involves \(\mathbf{s}\). Combined with Equation (1) and (10c), it is proved in Appendix A that we can obtain the following equation:  
\[\sum_{m=1}^{M}\sum_{j=1}^{M}Z_{m,j}D_{m,j}=a(T-\sum_{m=1}^{M}t_{m}) \tag{22}\]  
Putting the above Equation (22) into Equation (13), we can obtain a new equal constraint of (10e),  
\[\sum_{m=1}^{M}P_{m}+\zeta(a)(T-\sum_{m=1}^{M}t_{m})\leq E \tag{23}\]  
Based on (13)-(15), (20)-(23), it is proved in Appendix B that P1 is equivalently transformed into the two-layer optimization problem shown below:  
\[\text{P2}: \max_{R^{Scc},\{t_{m},Q_{m},P_{m}\}}R^{Scc}\] s.t. \[TR^{Scc}-\sum_{m=1}^{M}f1(t_{m},Q_{m})+\sum_{m=1}^{M}\left[f2 (t_{m}^{0},Q_{m}^{0})+\frac{\partial f2(t_{m},Q_{m}^{0})}{\partial t_{m}} \Big{|}_{t_{m}=t_{m}^{0}}(t_{m}-t_{m}^{0})\right.\] \[+\left.\frac{\partial f2(t_{m},Q_{m}^{0})}{\partial Q_{m}}\Big{|} _{Q_{m}=Q_{m}^{0}}(Q_{m}-Q_{m}^{0})\right]\leq 0 \tag{24a}\] \[TR^{Scc}-\sum_{m=1}^{M}g1(t_{m},P_{m})+\sum_{m=1}^{M}\left[g2(t_ {m}^{0},P_{m}^{0})+\frac{\partial g2(t_{m},P_{m}^{0})}{\partial t_{m}}\Big{|} _{t_{m}=t_{m}^{0}}(t_{m}-t_{m}^{0})\right.\] \[+\left.\frac{\partial g2(t_{m}^{0},P_{m})}{\partial P_{m}}\Big{|} _{P_{m}=P_{m}^{0}}(P_{m}-P_{m}^{0})\right]\leq 0\] (24b) \[\sum_{m=1}^{M}t_{m}=\max_{\{Z_{m,j},Q_{m}\}}\left\{T-\frac{1}{a} \sum_{m=1}^{M}\sum_{j=1}^{M}Z_{m,j}D_{m,j}:\mathcal{A}(\widetilde{\mathbf{s}},\mathbf{Z})\right\}\] (24c) \[(1-\widetilde{s}_{m})(t_{m}^{2}+P_{m}+Q_{m})=0,\] \[t_{m}\geq 0,P_{m}\geq 0,Q_{m}\geq 0\quad\forall m=1,\cdots,M\] (24d) \[\sum_{m=1}^{M}P_{m}+\zeta(a)(T-\sum_{m=1}^{M}t_{m})\leq E\] (24e) \[\sum_{m=1}^{M}Q_{m}\leq Q \tag{24f}\]  
In P2, the right hand of (24c) is the crucial issue of the traveling salesman problem as shown below:  
\[\max_{\{Z_{m,j},\lambda_{m}\}}T-\frac{1}{a}\sum_{m=1}^{M}\sum_{j=1}^{M}Z_{m, j}D_{m,j}\quad s.t.\quad\mathcal{A}(\widetilde{\mathbf{s}},\mathbf{Z}) \tag{25}\]  
Problem (25) can be optimally solved via the software Mosek [23, 24]. \(\{\widehat{Z}_{m,j},\widehat{\lambda}_{m}\}\) are supposed to be the optimal solution to the problem (25), and the optimal objective value of problem (25) is given by \(T-(\sum_{m=1}^{M}\sum_{j=1}^{M}\widehat{Z}_{m,j}D_{m,j})/a\). Then, the (24c) constraint of P2 can be re-written as \(\sum_{m=1}^{M}t_{m}=T-(\sum_{m=1}^{M}\sum_{j=1}^{M}\widehat{Z}_{mj,j}D_{mj})/a\). Since other constraints of P2 are convex, P2 can be optimally solved by CVX. Denoting its solution as \(\{\widehat{R}^{Ssc},\widehat{t}_{m},\widehat{Q}_{m},\widehat{P}_{m}\}\), the optimal \(\{\widehat{q}_{m},\widehat{p}_{m}\}\) with fixed \(\mathbf{s}=\widehat{\mathbf{s}}\) can be obtained from \(\widehat{q}_{m}=\widehat{Q}_{m}/\widehat{t}_{m}\) and \(\widehat{p}_{m}=\widehat{P}_{m}/\widehat{t}_{m}\).