## 4 Cooperative Resource Management Algorithm
### Cooperative Resource Management Algorithm
\(L5\): if any required parameters of C changes then  C sends the new value of the parameter to MEC-BS; endif \(L6\): if\(r_{j}\) is decided to be offloaded to C then  C executes \(r_{j}\);  C returns the offloading response of \(r_{j}\) to MEC-BS; endif \(L7\): if the data required by \(r_{j}\) should be cached in MEC-BS from C then  MEC-BS sends the data caching request of \(r_{j}\) to C;  C returns the data caching response of \(r_{j}\) to MEC-BS; endif \(L8\): if the data required by \(r_{j}\) should be cached in \(n_{k}\) from C then \(n_{k}\) sends the data caching request of \(r_{j}\) to C;  C returns the data caching response of \(r_{j}\) to \(n_{k}\); endif
```  
**Algorithm 3** Cooperative Resource Management Algorithm at C side  
```
Initial: send \(\phi_{k}\), \(s_{k}^{\text{NBS2 BS}}\) and \(s_{k}^{\text{BS2 NBS}}\) to MEC-BS. \(L9\): if any required parameters of \(n_{k}\) changes then \(n_{k}\) sends the new value of the parameter to MEC-BS; endif \(L10\): if\(r_{j}\) is decided to be offload to \(n_{k}\) and \(n_{k}\) cached the data of \(r_{j}\) in advance then \(n_{k}\) executes \(r_{j}\); \(n_{k}\) returns the offloading response of \(r_{j}\) to MEC-BS; elseif\(r_{j}\) is decided to be offload to \(n_{k}\) and \(n_{k}\) did not cache the data of \(r_{j}\) in advance then \(n_{k}\) sends the data request of \(r_{j}\) to C;  C returns the data response of \(r_{j}\) to \(n_{k}\); \(n_{k}\) executes \(r_{j}\); \(n_{k}\) sends the offloading response of \(r_{j}\) to MEC-BS; endif endif
```  
**Algorithm 4** Cooperative Resource Management Algorithm at \(n_{k}\) side (\(k\in\mathcal{K}\))  
```
Initial: send \(\phi_{k}\), \(s_{k}^{\text{NBS2 BS}}\) and \(s_{k}^{\text{BS2 NBS}}\) to MEC-BS. \(L9\): if any required parameters of \(n_{k}\) changes then \(n_{k}\) sends the new value of the parameter to MEC-BS; endif \(L10\): if\(r_{j}\) is decided to be offload to


```
Initial: collect required parameters from MTs, MEC-NBS, C, and itself, then store their values. \(L11\) (runs periodically): if MEC-BS receives a new value of the required parameters then  MEC-BS runs Algorithm 1 and get optimal result \(\mathbf{H}\); for each \(\mathbf{H}_{i}\) in \(\mathbf{H}\)do if the value of \(\mathbf{H}_{i}\) is updated then  MEC-BS sends the new value of \(\mathbf{H}_{i}\) to \(m_{i}\); endif endfor \(L12\): if MEC-BS receives the offloading request of \(r_{j}\) from \(m_{i}\)then if\(r_{j}\) is decided to be offload to MEC-BS and MEC-BS cached the data of \(r_{j}\) in advance then  MEC-BS executes \(r_{j}\);  MEC-BS sends the offloading response of \(r_{j}\) to \(m_{i}\); elseif\(r_{j}\) is decided to be offload to MEC-BS and MEC-BS did not cache the data of \(r_{j}\) in advance then  MEC-BS sends the data request of \(r_{j}\) to C;  C returns the data response of \(r_{j}\) to MEC-BS;  MEC-BS executes \(r_{j}\);  MEC-BS sends the offloading response of \(r_{j}\) to \(m_{i}\); endif endif \(L13\): if MEC-BS receives the offloading response of \(r_{j}\) sent from C then  MEC-BS forwards the offloading response to \(m_{i}\); endif \(L14\): if MEC-BS receives the offloading response of \(r_{j}\) sent from \(n_{k}\) (\(\forall k\in\mathcal{K}\)) then  MEC-BS forwards the offloading response to \(m_{i}\); endif
```
**Algorithm 5** Cooperative Resource Management Algorithm at MEC-BS side
``` Initial: collect required parameters from MTs, MEC-NBS, C, and itself, then store their values.