## 3 Architecture
### Minimizing Energy Consumption  
The goal of using a combination of caching and an energy-saving strategy based on fine-grained task migration is to consider whether to cache the task on the edge cloud and refine the task into smaller-grained subtasks when the migration destination is uncertain. The migration optimization objective is to reduce the energy consumption of devices and save energy for these devices. At the same time, the user requested task delay time must be satisfied. Therefore, when we model minimizing energy consumption, the task completion time constraints must be ensured and the quality of user experience should be guaranteed. The transmission time \(T_{k}^{t}\) of the task \(k\) depends on the size of the data \(s_{km}\) transferred from the device to the edge cloud and the execution location \(D_{km}\) of the subtasks, which is calculated as the following:  
\[T_{k}^{t}=\sum_{m=1}^{p}D_{km}\frac{s_{km}}{B_{s}} \tag{9}\]  
The energy consumed by task \(k\) to transfer data to the edge cloud is denoted as \(E_{k}^{t}\), which is shown as the following:  
\[E_{k}^{t}=T_{k}^{t}p_{s} \tag{10}\]  
The execution time \(T_{km}^{x}\) of the subtask \(m\) of task \(k\) is related to the execution location and it can be calculated according to the following equation:  
\[T_{km}^{x}=(1-D_{km})T_{km}^{t}+D_{km}T_{km}^{e} \tag{11}\]  
The start time of subtask \(m\) of the task \(k\) is denoted as \(T_{km}^{b}\), which depends on the sum of its predecessors' completion time and the result data transmission delay between them. If the subtask \(m\) has multiple predecessors, the execution starts until the last predecessor subtask and all data transmission have been completed. The start time \(T_{km}^{b}\) of subtask \(m\) of task \(k\) is shown as follows:  
\[T_{km}^{b}=\underset{u\in V_{k}}{\max}R_{ku,m}(T_{ku}^{f}+|D_{ku}-D_{km}|T_{ku, m}) \tag{12}\]  
Then, the time when the subtask \(m\) is completed can be obtained according to the following equation using \(T_{km}^{b}\) and \(T_{km}^{x}\):  
\[T_{km}^{f}=T_{km}^{b}+T_{km}^{x} \tag{13}\]  
We define a variable \(x_{k}\in[0,1]\) to indicate whether task \(k\) is cached on the edge cloud (\(x_{k}=1\)) or not (\(x_{k}=0\)). The completion time of task \(k\) is the time when the last subtask is completed plus the data transmission time of task \(k\). The execution time of task \(k\) is presented in the following equation:  
\[T_{n,k}=x_{k}T_{k\
u}^{f}+(1-x_{k})(T_{k\
u}^{f}+T_{k}^{t}) \tag{14}\]  
The energy consumption of the mobile device is mainly composed of three parts: the task execution energy consumption, the result data transmission energy consumption and the task data transmission energy consumption. If the task data is cached on the edge cloud, we assume the data transmission energy consumption as \(E_{k}^{t}=0\). The execution energy \(E_{km}^{x}\) of the subtask \(m\) is related to the execution location \(D_{km}\), and it is calculated as follows:  
\[E_{km}^{x}=D_{km}E_{km}^{e}+(1-D_{km})E_{km}^{t} \tag{15}\]  
Therefore, the energy consumption of the mobile device when the entire task \(k\) is executed is shown as follows:  
\[E_{n,k}=(1-x_{k})E_{k}^{t}+\sum_{m=1}^{p}E_{km}^{x}+\sum_{(u,m)\in V_{k}}|D_{ku }-D_{km}|E_{ku,m} \tag{16}\]Based on the above analysis, a model for minimizing the energy consumption of mobile devices under the task completion time constraints is proposed, which can be expressed as follows:  
\[ \begin{array}{l}\text{minimize}\sum\limits_{n=1}^{N}E_{n,k}\\ \text{{subject}\;to}:\sum\limits_{k=1}^{K}x_{k}s_{k}\leq C_{e}\\ T_{n,k}\leq t_{n}\\ w_{k}=\sum\limits_{m=1}^{v}w_{km}\\ s_{k}=\sum\limits_{m=1}^{v}s_{km}\\ D_{km}\in\{0,1\},R_{ku,m}\in\{0,1\},x_{k}\in\{0,1\}\end{array}  \tag{17}\]  
The decision array \(D[N][v+1]\) is the solution of the optimization problem we introduced above, where \(N\) means a total of \(N\) users, and the first \(v\) variables are the subtask decision variables, and the last variable indicates whether the user task is cached on the edge cloud or not.