## 5 Joint Optimization of Resource Allocation and Computation-Offloading Decisions
### Computation-Offloading Decision  
When computational resource allocation is provided (i.e., \(\mathbf{F}=\mathbf{F^{*}}\)), Equation (16) can be simplified as follows:  
\[\underset{\mathbf{Y},\mathbf{Z}}{\text{minimize}} \sum_{m=1}^{M}(\lambda_{m}^{t}E_{m}+\lambda_{m}^{t}T_{m})\] (21) subject to C1, C2, C3 and C4. Here, we applied PSO to solve the subproblem in Equation (21) in order to obtain the solution to offloading decisions \(\mathbf{Y}\) and \(\mathbf{Z}\). In particular, the binary version of PSO (BPSO) is applied to solve the offloading-decision problem in Equation (21). First, we introduce the standard continuous PSO algorithm and the BPSO algorithm. PSO is a natural optimization method bio-inspired by the behavior of bird flocking [44], where each particle (individual) in a swarm searches for food in a search space. An effective way to locate food is to follow the bird closest to the food. By mimicking bird-foraging behavior, a variety of optimization problems can be solved by the PSO algorithm with highly competitive performance, including joint problems of power control and channel allocation in device-to-device communications [28; 29]. In the PSO algorithm, a fitness function is defined to assess solution feasibility. The algorithm is initialized with random population-candidate solutions (particles), with each candidate solution represented by the position of a particle for the optimization problem. With each iteration, the position of each particle in the swarm changes within the search space in order to obtain a good solution based on the best individual position and the best position of all particles. After numerous iterations, the best solution will be found corresponding to the optimal position of all particles. Applicationof the PSO algorithm requires mapping the problem solution onto the particle space, which directly effects feasibility and performance. We considered a swarm involving \(K\) particles and assumed that the particle position \(k\)th of the swarm was represented by \(\mathbf{X}_{k}=(X_{m1},X_{k2},\dots,X_{km},\dots,X_{kM})\) with a particle velocity \(k\)th of \(\mathbf{V}_{k}=(V_{k1},V_{k2},\dots,V_{kn},\dots,V_{kM})\), where \(M\) is the total number of MDs. According to a previous study [44], the particle updates its velocity and changes to a new position via the following two equations:  
\[\mathbf{V}_{k} =w\mathbf{V}_{k}+c_{1}r_{1}(\mathbf{L}_{k}-\mathbf{X}_{k})+c_{2}r_{2}(\mathbf{G}- \mathbf{X}_{k}), \tag{22}\] \[\mathbf{X}_{k} =\mathbf{X}_{k}+\mathbf{V}_{k}, \tag{23}\]  
where \(\mathbf{L}_{k}\) and \(\mathbf{G}\) represent the best individual position of the \(m\)th particle and the global best position, respectively; \(w\) denotes a constant inertia weight; \(c_{1}\) and \(c_{2}\) are two acceleration coefficients; and \(r_{1}\) and \(r_{2}\) are two random variables in (0, 1). Because the offloading decision and location are discrete values (i.e., either 0 or 1), the problem cannot be solved using the continuous standard PSO algorithm; therefore, we used the BPSO [45]. The main differences between the PSO and BPSO involve the position-updating procedure and the transfer function [45]. The position \(\mathbf{X}_{k}\) is based on toggling between the values 1 and 0, with the velocity of the particle used to update the position. Therefore, we converted the velocity values to probabilities within the interval [0, 1] using the sigmoid function, as follows [45]:  
\[Sig(V_{km})=\frac{1}{1+e^{-V_{km}}}, \tag{24}\]  
where \(V_{km}\) is the velocity of the \(k\)th particle at the \(m\)th element, with the position of this particle updated to a binary variable according to the following rule:  
\[X_{km}= \begin{cases}0,&\text{if }rand<Sig(V_{km}),\\ 1,&\text{otherwise},\end{cases}  \tag{25}\]  
where \(rand\) is a uniformly random number within [0, 1]. Algorithm 1 shows the pseudo-code for the standard BPSO, which is similar to the standard continuous PSO algorithm, except that updating each particle position occurs using Equation (25).