# Game-Theory-Based Task Offloading and Resource Scheduling in Cloud-Edge Collaborative Systems
## 5 Task Unloading Strategy
### GTPSO Algorithm
#### 5.2.1 Pre-Processing Offload Strategy  
1. Particle encoding  
Combined with the system in this paper, an integer encoding mechanism is used, and the particle swarm size is set to \(K\). Each particle represents a collection of offloading policies. The particle element represents the location of the edge server to be offloaded by the current computing task, and the number of particle elements is \(N\). The particle elements take the values of integers from \(1\sim M\). The velocity vector of particle \(k=\{task_{1},\cdots task_{n},\cdots task_{N}\}\) is \(V_{k}=\{v_{k1},v_{k2},\cdots,v_{kN}\}\); the position vector is \(X_{k}=\{x_{k1},x_{k2},\cdots,x_{kN}\}\); \(P_{best}\) denotes the individual optimal solution of the current particle; and \(G_{best}\) denotes the global optimal solution of all particles. 2. Fitness function  
The fitness function of a particle is typically the objective function of the problem being solved, and in this paper, the system overhead of offloading tasks to the edge servers for processing is used as the fitness function, i.e., the total system cost of assigning tasks to different edge servers, as in Equation (25). \[Fitness(V)=\min_{x_{n}}\sum_{m=1}^{M}\sum_{n=1}^{N}E_{n}^{m} \tag{25}\]  
\[ \begin{array}{l}s.t.\text{C1 : }0\leq E_{n}^{m}\leq E_{total}^{m}\leq E_{max}\\ \text{C2 : }0\leq f_{n}^{m}\leq f_{total}^{m}\leq f_{max}\end{array} \]  
where \(x_{n}\) denotes the server number specifically assigned to the task, C1 denotes the energy constraint offloaded to the task numbered \(m\) and C2 denotes the computing resource constraint assigned to the task numbered \(m\). Since we ignore task waiting time and consider the existence of load imbalance caused by multiple users offloading to an edge server, and since the edge server is rational, we can set the penalty function; therefore, the total system cost increases to relieve the load pressure when tasks are offloaded to the edge server with a high load. \[Fitness(V)=\min_{x_{n}}\sum_{m=1}^{M}\sum_{n=1}^{N}E_{n}^{m}+penalty(V) \tag{26}\]  
\[penalty(X)=g*\sum_{m=1}^{M}\sum_{n=1}^{N}(E^{m}-E_{max})\]  
Equation (26) indicates that, if the energy consumption of the task load offloaded to task number \(m\) is higher than the maximum energy consumption of the server, a penalty function is set to increase the system cost, where \(X\) denotes the offloading vector solved for and \(g\) denotes the penalty factor. 3. Algorithm Process  
Input:  
(1) User set \(N=\{1,2,\ldots N\}\), MEC server set \(M=\{1,2,\ldots M\}\), task set \(\tau_{n}=(D_{n},C_{n},T_{n})\). 2. Algorithm control parameters: maximum number of iterations \(maxGen\), velocity boundary \(v\in[-M,M]\), position boundary \(x\in[1,M]\), initial inertia factor \(w\) and penalty factor \(g\). Initialization: 1. The position vector \(X_{k}\) of each particle and the velocity vector \(V_{k}\). 2. The fitness function value \(Fitness(V)\) is initialized and updated as the iteration progresses. 3. Initialize the individual optimal solution and the global optimal solution of the particle, set the current position of the particle as the individual optimal solution \(P_{best}\) and set the position of the particle with the smallest fitness value as the global optimal solution \(G_{best}\). Iterative Process: 1. Let the number of iterations \(y=1\). 2. While \(y\leq maxGen\). 3. Update the velocity; each dimension in particle k independently goes to update the velocity \(V_{k}\). If \(|V_{k}|>M\). Then, when \(V_{k}>0\), let \(V_{k}=M\), and when \(V_{k}<0\), let \(V_{k}=-M\). The updated formula of particle velocity is: \[V_{k}=w_{max}*V_{k}+c_{1}*r_{1}(P_{best}-X_{k})+c_{2}*r_{2}(G_{best}-X_{k})\] (27) where \(c_{1}\) and \(c_{2}\) are learning factors and \(c_{1}=c_{2}=1.5\), and \(r_{1}\) and \(r_{2}\) are random numbers from 0-1. 4. Update the position. Particle \(k\) updates the position \(X_{k}\) independently based on the velocity information. If the value of \(X_{k}\) is greater than \(M\), then let \(X_{k}=M\).