# Distributed Edge Computing to Assist Ultra-Low-Latency VANET Applications
## 4 Latency-Aware Offloading Algorithm for Multilevel MEC VANET System
### Annotation  
The abbreviations used for developing the offloading algorithm are introduced in Table 1. Algorithm 1 introduces the considered steps of the offloading algorithm for MEC based VANET. This algorithm is implemented in the decision engine of the OBU. This algorithm comprises the second algorithm (Algorithm 2) that introduces the required steps for accepting or rejecting offloading requests at the heterogeneous edge cloud servers. \begin{table}
\begin{tabular}{c c} \hline \hline
**Notation** & **Description** \\ \hline K & Total length of task input data \\ Q & QoS latency defined for input task \\ S & Number of CPU cycles required to process one bit of the input task \\ N\({}_{\text{CYC}}\) & Total number of CPU cycles required to process a task \\ I & Mode indicator \\ T\({}_{\text{ex-OBU}}\) & Total execution time of a task executed at the OBU \\ T\({}_{\text{ex-Micro-cloud}}\) & Total execution time of a task that is executed at the micro-cloud edge server \\ T\({}_{\text{ex-Mini-cloud}}\) & Total execution time of a task that is executed at the mini-cloud edge server \\ T\({}_{\text{T-Micro-cloud}}\) & Total time required to handle a task at a micro-cloud edge server \\ T\({}_{\text{T-Mini-cloud}}\) & Total time required to handle a task at a mini-cloud edge server \\ T\({}_{\text{Tx}}\) & Communication Latency for transmitting task data \\ T\({}_{\text{Rx}}\) & Feedback time delay of computation results \\ D\({}_{\text{0f-OBU}}\) & Binary decision variable of offloading decided by the OBU \\ D\({}_{\text{T-Micro-cloud-acc-off}}\) & Binary time decision variable of accepting offloading request decided by the micro-cloud edge server \\ D\({}_{\text{T-Mini-cloud-acc-off}}\) & Binary time decision variable of accepting offloading request decided by the mini-cloud edge server \\ R\({}_{\text{OBU}}\) & The processing resources of OBU allocated for an input task \\ R\({}_{\text{Micro-cloud}}\) & The processing resources of a micro-cloud edge server allocated for an input task \\ R\({}_{\text{Mini-cloud}}\) & The processing resources of a mini-cloud edge server allocated for an input task \\ F\({}_{\text{OBU}}\) & Total processing resources of OBU \\ F\({}_{\text{Micro-cloud}}\) & Total processing resources of micro-cloud edge server \\ F\({}_{\text{Mini-cloud}}\) & Total processing resources of mini-cloud edge server \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Key annotation. ```

**Algorithm 1** Latency-aware offloading algorithm for multilevel based VANET system. ### Offloading Model

For all input tasks, the OBU checks the availability of local execution at first. If it fails to execute within the QoS latency, Q, then it checks the possibility of offloading. At first, the decision engine of OBU calculates the total time required to execute the task locally, \(T_{ex\_OBU}\). This time is calculated based on the available processing resources of the OBU as illustrated in Equation (1). \[T_{ex\_OBU}=\frac{N_{\text{CYC}}}{R_{\text{OBU}}},\qquad R_{\text{OBU}}\in f_{ \text{OBU}} \tag{1}\]

\[N_{\text{CYC}}=K.S \tag{2}\]

Then, the OBU decides the local execution or the offloading by calculating the decision variable of offloading, \(D_{\text{off-OBU}}\). This can be calculated as following:

\[D_{\text{off-OBU}}=I(T_{ex\_OBU},\tau)=\left\{ \begin{array}{ll}0?&\text{If }\ (T_{\text{OBU}}\ \leq\ \tau)\\ 1?&\text{If }\ (T_{\text{OBU}}\ >\ \tau)\end{array} \right. \tag{3}\]For negative decision, the task is processed locally. Otherwise, the task is offloaded to the nearby micro-cloud edge server that decides whether to accept the offloading request or forward the request to the corresponding mini-cloud edge server. Once a micro-cloud edge server receives an offloading request from an OBU, it extracts the task information and starts to process the request. The decision engine of the micro-cloud edge server calculates the total time required to execute the task at the micro-cloud server, \(T_{ex\text{-}Micro\text{-}cloud}\), based on the current available resources.