# Game-Theory-Based Task Offloading and Resource Scheduling in Cloud-Edge Collaborative Systems
## 4 Computing Resource Allocation  
We propose a game-theoretic-based resource allocation and task offloading scheme for users who choose to offload and solve their resource allocation problem. According to the given task offloading policy \(S\) that satisfies the constraints, the utility of the set of users offloading to MEC, \(U_{m}(\mathcal{F},S)\), is obtained using the expression \(u_{n}^{m}\) for the utility function, denoted as  
\[U_{m}(\mathcal{F},S)=\underset{\mathcal{F}}{\text{min}}\sum_{n\in N_{off}} \left[\beta_{n}^{t}\frac{(T_{n}-t_{n}^{m})}{T_{n}}+\beta_{n}^{e}\frac{(e_{n}^{ l}-e_{n}^{m})}{e_{n}^{l}}\right] \tag{14}\]  
To maximize the utility function \(U_{m}(\mathcal{F},S)\), which is equivalent to minimizing the unloading overhead, it can be expressed as  
\[\underset{\mathcal{F}}{\text{min}}\sum_{n\in N_{off}}\left(\beta_{n}^{t}t_{n} ^{m}+\beta_{n}^{e}e_{n}^{m}\right) \tag{15}\]  
When a user offloads its computational tasks to the MEC server, the computational resource allocation problem is expressed as  
\[\underset{\mathcal{F}}{\text{min}}\sum_{n\in N_{off}}\left\{\beta_{n}^{t}( \frac{I_{n}}{r_{c}}+\frac{D_{n}}{r_{n}}+\frac{C_{n}}{f^{c}}+\frac{C_{n}}{f_{n} ^{m}})+\beta_{n}^{e}[p_{n}(\frac{I_{n}}{r_{c}}+\frac{D_{n}}{r_{n}})+C_{n} \theta_{n}^{m}]\right\} \tag{16}\]  
\[s.t.\text{ C1}:\text{ }0<f_{n}^{m}\leq F,\forall n\in N_{off}\] \[\text{ C2}:\text{ }\sum_{n\in N_{off}}f_{n}^{m}\leq F^{total}, \forall n\in N_{off}\]  
The objective function in Problem (15) is denoted as \(\varphi(\mathcal{F},S)\), and the first and second-order derivatives of \(\varphi(\mathcal{F},S)\) with respect to \(f_{n}^{m}\) are obtained. \[\frac{\partial\varphi(\mathcal{F},S)}{\partial f_{n}^{m}}=-\frac{\beta_{n}^{ t}C_{n}}{\left(\frac{f_{n}^{m}}{f_{n}^{m}}\right)^{2}}\text{, }\forall n\in N_{off} \tag{17}\]  
\[\frac{\partial^{2}\varphi(\mathcal{F},S)}{\partial(f_{n}^{m})^{2}}\text{=} \frac{2\beta_{n}^{t}C_{n}}{\left(f_{n}^{m}\right)^{3}}\text{, }\forall n\in N_{off} \tag{18}\]  
The second-order derivative of \(\varphi(\mathcal{F},S)\) with respect to \(f_{n}^{m}\) is constantly greater than zero, and the constraints C1 and C2 are both convex. Therefore, Problem (16) is a convex optimization problem satisfying the Slater condition, and the KKT condition can be used to find the optimal computational resource allocation \(\mathcal{F}^{*}\). Formulating Problem (16) as a Lagrange function results in:\[L(f_{n}^{m},\lambda,\eta)=\sum_{n\in N_{off}}\left\{\beta_{n}^{t}(\frac{I_{n}}{r_{ c}}+\frac{D_{n}}{r_{n}}+\frac{C_{n}}{f^{c}}+\frac{C_{n}}{f_{n}^{m}})+\beta_{n}^{c}[p_{n} (\frac{I_{n}}{r_{c}}+\frac{D_{n}}{r_{n}})+C_{n}\theta_{n}^{m}]\right\}+\lambda (f_{n}^{m}-F)+\eta(\sum_{n\in N_{off}}f_{n}^{m}-MF) \tag{19}\]  
where \(\lambda\) and \(\eta\) are Lagrange multipliers associated with computational resource constraints satisfying \(\lambda\geq 0\) and \(\eta\geq 0\). Solving for the first-order derivative of \(L(f_{n}^{m},\lambda,\eta)\) with respect to \(f_{n}^{m}\) yields  
\[f_{n}^{m^{*}}=\sqrt{\frac{\beta_{n}^{t}C_{n}}{\lambda^{*}+\eta^{*}}},\ \forall n\in N_{off} \tag{20}\]  
Since \(f_{n}^{m^{*}}\) is coupled with Lagrange multipliers \(\lambda^{*}\) and \(\eta^{*}\), the gradient descent method is used to iteratively update \(\lambda\), \(\eta\) until the computational resource constraints C1 and C2 are satisfied, and the optimal computational resource allocation solution \(f_{n}^{m^{*}}\) is obtained. The process is shown in Algorithm 1. ```
1:Initialization: very small tolerance \(\varepsilon>0\), \(\lambda=\lambda^{max}\), \(\eta=\eta^{max}\)
2:While\(f_{n}^{m^{*}}-f_{n}^{m}>\varepsilon\) do
3: set \(f_{n}^{m}=f_{n}^{m^{*}}\)
4: compute \(f_{n}^{m}\) according to substitute \(\lambda\), \(\eta\) into (20). 5:if\(f_{n}^{m}<F\), update \(\lambda=\lambda-\Delta\lambda\) \(\sum_{n\in N_{off}}f_{n}^{m}<MF\), update \(\eta=\eta-\Delta\eta\)
6:endwhile
7: The optimal computation resource allocation scheme can be derived by substituting \(\lambda,\eta\) into (20).