## 4 Joint Task Offloading, Resource Allocation, and Security Assurance Algorithm
### Joint Task Offloading and Resource Allocation
#### 4.3.1 Optimization of Resource Allocation  
Given \(\mathbf{x}\) and \(\lambda\), the resource allocation problem can be written as  
\[ \begin{split}\text{P7}:&\min_{\mathbf{f}}T( \mathbf{f})\!\!=\!\!\min_{\mathbf{f}}\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}x _{i,j}\lambda_{i,j}\Big{(}\frac{c_{i}}{f_{i}}\!+\!\!\varsigma_{i,j}\Big{)}+x_{i,j}\kappa_{i,j}\\ s.t.&\text{C7}.1:\sum\limits_{j=1}^{M}x_{i,j}\Big{[} \lambda_{i,j}\Big{(}\frac{c_{i}}{f_{i}}\!+\!\varsigma_{i,j}\Big{)}+\kappa_{i,j }\Big{]}\leq T^{th},\ \forall i\in\mathbf{N}\\ &\text{C7}.2:0\leq\sum\limits_{i=1}^{N}x_{i,j}f_{i,j}\leq F_{j}, \ \forall j\in\mathbf{M}\\ &\text{C7}.3:0\leq f_{i,j}\leq F_{i},\ \forall i\in\mathbf{N},\ \forall j\in \mathbf{M}\\ &\text{C7}.4:R_{e}\leq R_{th},\ \forall i\in\mathbf{N},\ \forall j\in \mathbf{M}.\end{split}  \tag{25}\]  
As \(\frac{\partial^{2}T(\lambda,\mathbf{f})}{\partial\mathbf{f}^{2}}\geq 0\) and C7.1-C7.4 are linear constraints, the optimization problem P7 is a convex optimization problem. We use the Lagrangian method to solve this optimization problem P7. Let \(\Theta(\mathbf{f},\theta,\psi,\rho,\omega,\chi)\) denote the Lagrangian function of the optimization problem P7, which can be given by  
\[ \begin{split}\Theta(\mathbf{f},\theta,\psi,\rho,\omega,\chi)& =\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}x_{i,j}\lambda_{i,j} \Big{(}\frac{c_{i}}{f_{i}}\!+\!\varsigma_{i,j}\Big{)}+x_{i,j}\kappa_{i,j}\\ &-\sum\limits_{i=1}^{N}\theta_{i}\sum\limits_{j=1}^{M}x_{i,j} \Big{[}\lambda_{i,j}\Big{(}\frac{c_{i}}{f_{i}}\!+\!\varsigma_{i,j}\Big{)}+ \kappa_{i,j}\Big{]}-T^{th}\Bigg{\}}\\ &-\sum\limits_{j=1}^{M}\psi_{j}\left(\sum\limits_{i=1}^{N}x_{i,j }f_{i,j}-F_{j}\right)-\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}\rho_{i,j} \big{(}f_{i,j}-F_{j}\big{)}\\ &+\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}\omega_{i,j}f_{i,j} -\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{M}\chi_{i,j}(R_{e}-R_{th}),\end{split}  \tag{26}\]  
where \(\theta_{i}\), \(\psi_{j}\), \(\rho_{i,j}\), \(\omega_{i,j}\), and \(\chi_{i,j}\) are Lagrangian multipliers, respectively. We have  
\[\mathbf{D}(\theta,\psi,\rho,\omega,\chi)=\min\Theta(\mathbf{f},\theta,\psi, \rho,\omega,\chi). \tag{27}\]  
Thus, the dual problem of optimization problem P7 can be expressed as  
\[ \begin{split}\max\mathbf{D}(\theta,\psi,\rho,\omega,\chi)\\ s.t.&\ \theta<0,\psi\leq 0,\rho\leq 0,\omega\leq 0, \chi\leq 0.\end{split}  \tag{28}\]  
As the above problem is convex, we adopt the gradient descent method to solve (28). As the Lagrange function is differentiable, the gradients of Lagrangian multipliers can be expressed as  
\[\frac{\partial\Theta}{\partial\theta_{i}}=-\sum\limits_{j=1}^{M}x_{i,j} \bigg{[}\lambda_{i,j}\bigg{(}\frac{c_{i}}{f_{i}}\!+\!\varsigma_{i,j}\bigg{)}+ \kappa_{i,j}\bigg{]}+T^{th}, \tag{29}\]  
\[\frac{\partial\Theta}{\partial\psi_{j}}\!\!=-\sum\limits_{i=1}^{N}x_{i,j}f_{i, j}\!+\!F_{j}, \tag{30}\]  
\[\frac{\partial\Theta}{\partial\rho_{i,j}}=-f_{i,j}+F_{j}, \tag{31}\]\[\frac{\partial\Theta}{\partial\omega_{i,j}}=f_{i,j}, \tag{32}\]  
\[\frac{\partial\Theta}{\partial\chi_{i,j}}=-R_{e}+R_{th}. \tag{33}\]  
The Lagrangian multipliers can be calculated iteratively as follows:  
\[\theta_{i}(t+1)=\bigg{[}\theta_{i}(t)+\iota_{1}\frac{\partial\Theta}{\partial \theta_{i}}\bigg{]}^{+},\iota_{1}>0, \tag{34}\]  
\[\psi_{j}(t+1)=\bigg{[}\psi_{j}(t)+\iota_{2}\frac{\partial\Theta}{\partial\psi_ {i}}\bigg{]}^{+},\iota_{2}>0, \tag{35}\]  
\[\rho_{i,j}(t+1)=\bigg{[}\rho_{i,j}(t)+\iota_{3}\frac{\partial\Theta}{\partial \rho_{i,j}}\bigg{]}^{+},\iota_{3}>0, \tag{36}\]  
\[\omega_{i,j}(t+1)=\bigg{[}\omega_{i,j}(t)+\iota_{4}\frac{\partial\Theta}{ \partial\omega_{i,j}}\bigg{]}^{+},\iota_{4}>0, \tag{37}\]  
\[\chi_{i,j}(t+1)=\bigg{[}\chi_{i,j}(t)+\iota_{5}\frac{\partial\Theta}{\partial \chi_{i,j}}\bigg{]}^{+},\iota_{5}>0, \tag{38}\]  
where \(t\) represents the gradient number; \([\cdot]^{+}\) represents \(\max(0,\cdot)\); and \(\iota_{1}\), \(\iota_{2}\), \(\iota_{3}\), \(\iota_{4}\), and \(\iota_{5}\) are gradient iteration steps.