## 4 Joint Task Offloading, Resource Allocation, and Security Assurance Algorithm
### Joint Task Offloading and Resource Allocation
#### 4.3.2 Optimization of Task Offloading  
Given \(\mathbf{x}\) and \(\mathbf{f}\), the offload ratio problem can be written as  
\[\begin{split}\text{P8}:&\min_{\lambda}T(\lambda) \mathbf{=}\min_{\lambda}\sum_{i=1}^{N}\sum_{j=1}^{M}x_{i,j}\lambda_{i,j} \Big{(}\frac{c_{i}}{f_{i}}\mathbf{+}\xi_{i,j}\Big{)}+x_{i,j}\kappa_{i,j}\\ s.t.&\text{C8.1}:\sum\limits_{j=1}^{M}x_{i,j}\Big{[} \lambda_{i,j}\Big{(}\frac{c_{i}}{f_{i}}\mathbf{+}\xi_{i,j}\Big{)}+\kappa_{i,j} \Big{]}\leq T^{th},\ \forall i\in\mathbf{N}\\ &\text{C8.2}:0\leq\lambda_{i,j}\leq 1,\ \forall i\in\mathbf{N},\ \forall j\in\mathbf{M}\\ &\text{C8.3}:R_{e}\leq R_{th},\ \forall i\in\mathbf{N},\ \forall j\in\mathbf{M}.\end{split} \tag{41}\]  
As \(\frac{\hat{\beta}^{2}T(\lambda I)}{\hat{\alpha}\lambda^{2}}\)\(=\)0 and C8.1-C8.3 are linear constraints, the optimization problem P8 is a convex optimization problem. We use the Lagrangian method to solve this optimization problem P8. Let \(\Lambda(\lambda,\
u,\mu,\eta,\varpi)\) denote the Lagrangian function of the optimization problem for P8, which can be given by  
\[\begin{split}\Lambda(\lambda,\
u,\mu,\eta,\varpi)&= \sum\limits_{j=1}^{M}x_{ij}\lambda_{ij}\bigg{(}\frac{\varsigma_{i}}{\bar{\eta}_{ i}}\!+\!\varsigma_{i,j}\bigg{)}+x_{ij}\kappa_{i,j}\\ &-v_{i}\left\{\sum\limits_{j=1}^{M}x_{ij}\bigg{[}\lambda_{i,j} \bigg{(}\frac{\varsigma_{i}}{\bar{\eta}_{i}}\!+\!\varsigma_{i,j}\bigg{)}+ \kappa_{i,j}\bigg{]}-T^{th}\right\}\\ &-\sum\limits_{j=1}^{M}\mu_{i}\big{(}\lambda_{i,j}-1\big{)}+\sum \limits_{j=1}^{M}\eta_{i}\lambda_{i,j}\\ &-\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}\varpi_{i,j}(R_{e}- R_{th}),\end{split} \tag{42}\]  
where \(v_{i}\), \(\mu_{i,j}\), \(\eta_{i,j}\), and \(\varpi_{i,j}\) are Lagrangian multipliers, respectively. Due to the Lagrange function is differentiable, the gradients of Lagrangian multipliers can be expressed as  
\[\frac{\partial\Lambda}{\partial v_{i}}\!=\!-\sum\limits_{j=1}^{M}x_{ij}\bigg{[} \lambda_{i,j}\bigg{(}\frac{\varsigma_{i}}{\bar{f}_{i}}\!+\!\varsigma_{i,j} \bigg{)}+\kappa_{i,j}\bigg{]}-T^{th}, \tag{43}\]  
\[\frac{\partial\Lambda}{\partial\mu_{i}}\!=\!1-\lambda_{i,j}, \tag{44}\]  
\[\frac{\partial\Lambda}{\partial\eta_{i}}\!=\!\lambda_{i,j}, \tag{45}\]  
\[\frac{\partial\Lambda}{\partial\varpi_{i,j}}\!=\!-R_{e}+R_{th}. \tag{46}\]  
Similarly, we iterate computation the Lagrangian multipliers \(v_{i}\), \(\mu_{i,j}\), \(\eta_{i,j}\), and \(\varpi_{i,j}\), which can be calculated as  
\[v_{i}(l+1)=\bigg{[}v_{i}(l)+\iota_{6}\frac{\partial\Lambda}{\partial v_{i}} \bigg{]}^{+}, \tag{47}\]  
\[\mu_{i}(l+1)=\bigg{[}\mu_{i}(l)+\iota_{7}\frac{\partial\Lambda}{\partial\mu_{ i}}\bigg{]}^{+}, \tag{48}\]  
\[\eta_{i}(l+1)=\bigg{[}\eta_{i}(l)+\iota_{8}\frac{\partial\Lambda}{\partial\eta _{i}}\bigg{]}^{+}, \tag{49}\]  
\[\varpi_{i,j}(l+1)=\bigg{[}\varpi_{i,j}(l)+\iota_{9}\frac{\partial\Lambda}{ \partial\varpi_{i}}\bigg{]}^{+}, \tag{50}\]  
where \(l\) represents the gradient number; \([\cdot]^{+}\) represents \(\max(0,\cdot)\); and \(\iota_{6}\), \(\iota_{7}\), \(\iota_{8}\), and \(\iota_{9}\) are gradient iteration steps.  
Let \(\frac{\partial\Lambda}{\partial\lambda_{i,j}}\!=\!0\), we have the optimal solution \(\lambda_{i,j}^{*}\), which can be calculated as  
\[\lambda_{i,j}^{*}=\frac{f_{i}\big{[}x_{i,j}\varsigma_{i,j}(v_{i}-1)+\mu_{i}- \eta_{i}\big{]}}{c_{i}x_{i,j}(1-v_{i})}. \tag{51}\]