## 5 Joint Optimization of Resource Allocation and Computation-Offloading Decisions
### The Proposed Algorithm JROPSO  
As noted, the proposed algorithm JROPSO uses PSO to jointly find optimal solutions to problems concerning computation-offloading decisions in Equation (21) and computational resource allocation in Equation (20). The JROPSO algorithm is illustrated in Algorithm 2. ```
Input: The size (\(K\)) of the particle population (\(k=\{1,\dots,K\}\)), the maximum number of iterations \(T_{\max}\), the convergence criteria \(\zeta\), and the parameter \(w,c_{1}\), and \(c_{2}\). Output: The best fitness values and global best position. Initialization: population of \(K\) particles with random positions \(\mathbf{X}_{k}\) and velocities \(\mathbf{V}_{k}\). Set the iteration index as \(t=1\). Compute the resource allocation according to Equation (20). Calculate the fitness value of each particle according to Equation (27). repeat for each the number of particles \(K_{m}\)do  Update the velocity \(\mathbf{V}_{k}\) and position \(\mathbf{X}_{k}\) according to Equations (22) and (26),  respectively. end for  Update the resource allocation according to Equation (20). Calculate the fitness of each particle solution according to Equation (27). Update the best individual value if the new fitness is better than the current value. Update the global best solution among \(K\) particles. Increase the iteration index: \(t=t+1\). until\(t>T_{\max}\) or Fit(t)-Fit(t-\(t\)) \(\leq\zeta\);
```  
**Algorithm 2**PSO-based joint resource allocation and computational offloading decision algorithm (JROPSO)  
```
Input: The size (\(K\)) of the particle population (\(k=\{1,\dots,K\}\)), the maximum number of iterations \(T_{\max}\), the convergence criteria \(\zeta\), and the parameter \(w,c_{1}\), and \(c_{2}\). Output: The best fitness values and global best position. Initialization: population of \(K\) particles with random positions \(\mathbf{X}_{k}\) and velocities \(\mathbf{V}_{k}\). Set the iteration index as \(t=1\). Compute the resource allocation according to Equation (20). Calculate the fitness value of each particle according to Equation (27). repeat for each the number of particles \(K_{m}\)do  Update the velocity \(\mathbf{V}_{k}\) and position \(\mathbf{X}_{k}\) according to Equations (22) and (26),  respectively. end for  Update the resource allocation according to Equation (20). Calculate the fitness of each particle solution according to Equation (27). Update the best individual value if the new fitness is better than the current value. Update the global best solution among \(K\) particles. Increase the iteration index: \(t=t+1\). until\(t>T_{\max}\) or Fit(t)-Fit(t-\(t\)) \(\leq\zeta\);
```  
**Algorithm 3**PSO-based joint resource allocation and computational offloading decision algorithm (JROPSO)  
### The Proposed Algorithm JROPSO  
As noted, the proposed algorithm JROPSO uses PSO to jointly find optimal solutions to problems concerning computation-offloading decisions in Equation (21) and computational resource allocation in Equation (20). The JROPSO algorithm is illustrated in Algorithm 2. ``` Input: The size (\(K\)) of the particle population (\(k=\{1,\dots,K\}\)), the maximum number of iterations \(T_{\max}\), the convergence criteria \(\zeta\), and the parameter \(w,c_{1}\), and \(c_{2}\). Output: The best fitness values and global best position. Initialization: population of \(K\) particles with random positions \(\mathbf{X}_{k}\) and velocities \(\mathbf{V}_{k}\). Output: the resource allocation according to Equation (20). Calculate the fitness value of each particle according to Equation (27). repeat for each the number of particles \(K_{m}\)do  Update the velocity \(\mathbf{V}_{k}\) and position \(\mathbf{X}_{k}\) according to Equations (22) and (26),  respectively. end for  Update the resource allocation according to Equation (20). Calculate the fitness of each particle solution according to Equation (27). Update the best individual value if the new fitness is better than the current value. Update the global best solution among \(K\) particles. Increase the iteration index: \(t=t+1\).