## 4 Distributed Computation Offloading and Resource Allocation
### Distributed Computing Resource Allocation  
To overcome the resource limitation of E-APs, we analyzed the distributed computing scheme, where the available E-APs participate in executing the computing tasks and tackle the immense computation demand. In the dynamic computation offloading process, we exploited the greedy algorithm to allocate computing resources at the edge to avoid the rigorous time consumption of DRL training. The distributed computing resource allocation problem is considered a binary problem where the number of computing resources can overcome this challenge. Therefore, the simplified form of the original computing resource allocation problem can be stated as  
\[\min_{\{f_{l,k}\}} p_{l,k}\frac{C_{k}}{\sum_{l=1}^{L}f_{l,k}},\] s.t. \[(\ref{eq:E-AP}),\] \[E_{i,j}\leq\delta_{E},\] \[E_{k}^{edge}\leq\varphi_{E} \tag{17}\]  
where the constraint (17) illustrates that the energy between the assistive E-AP and primary E-AP must be less than \(\delta_{E}\) and the computation energy at the edge cannot go beyond the threshold delay of \(\varphi_{E}\), as depicted by (17). In Algorithm 1, we further elaborate on our concept of maximizing the processing capacity at the edge and how to lessen the intervention of cloud computing in serving the computing demand. At steps 8 and 9, we calculate the requested computing task of users \(K\) and available computing resources at the edge, respectively. Hereafter, the computation energy is calculated according to (9), where the available computing resources are distributed to satisfy the computing demand. At steps 11 to 20, we allocate the computing resources and evaluate the energy at the edge based on \(E_{i,j}\leq\delta_{E}\) and \(E_{k}^{edge}\leq\varphi_{E}\)[38]. We accept the result and consider the edge to be a suitable mode for offloading the task of the user \(k\). Finally, the algorithm sends the edge, status to the DQN for evaluation and future decisions.  
```
1:Input:
2:Set of users: \(\mathcal{K}=\{1,2,3,\dots,K\}\)
3:Set of E-APs: \(\mathcal{L}=\{1,2,3,\dots,L\}\)
4:Generated task for each user: \(M_{k}\)
5:Computing capacity of each E-AP:\(f_{l}\)
6:Tolerable computing energy is set to \(\varphi_{E}\)
7:Tolerable transmission energy from primary E-AP \(i\) to assistive E-AP \(j\) is set to \(\delta_{E}\);
8:Determine the total number of tasks requested by user \(K\) as \(\sum_{k=1}^{K}M_{k}\);
9:Calculate the total available computing resources at the edge as \(\sum_{l=1}^{L}f_{l}\)
10:Output:
11:The selected offloading mode for each user's tasks that meet the specified energy and resource constraints
12:Iteration:
13:foruser k: K do
14:while\(f_{l}\leq\sum_{l=1}^{L}f_{l}\)do
15:if\(E_{i,j}\leq\delta_{E}\)then
16: Select the E-AP \(j\) as the suitable assistive E-AP for offloading the task of \(k\)
17: Calculate computing energy at the edge according to (10)
18:if\(E_{k}^{edge}\leq\varphi_{E}\)then
19: break
20: Select edge is the suitable mode for offloading the task of \(k\)
21:endif
22:endif
23:\(f_{l}=f_{l}+1\)
24:endwhile
25:endfor
26:Return result
```  
**Algorithm 1** A3C Algorithm for Distributed Computation