## 3 VirtFogSim: A View of the Simulated Formal Models
### Supported Task Allocation Strategies and Adaptive Resource Allocation
The resulting asymptotic computational complexity scales up as: \(\mathcal{O}\left(\left(3^{(V-2)}\times 8\times G_{MAX}\right)/n_{core}\right)\). The parallel Genetic Task Allocation (_GeneticTA_par_) function assumes that all the global variables of parallel _VirtFogSim_ are already setup. The _GeneticTA_par_ function jointly optimizes the task allocation and the resource allocation in an adaptive way. It returns:  
1. the \((0,1,2)\)-ternary \(V\)-long vector \(\vec{x}_{\textit{best}}\) of the best searched task allocation;
2. the corresponding \((1\times 7)\) vector: \(\overline{RS}_{\textit{best}}=\left[f_{M}^{*},f_{F}^{*},f_{C}^{*},R_{U}^{*},R_{D} ^{*},B_{U}^{*},B_{D}^{*}\right]\) (bit/s), of the optimal resource allocation computed by the _RAP_p_ function under the best task allocation vector \(\vec{x}_{\textit{best}}\);
3. the total and network energies: \(\mathcal{E}_{\textit{best}}\), \(\mathcal{E}_{\textit{best}}^{NET}\) (Joule) that are consumed under the returned \(\overline{RS}_{\textit{best}}\);
4. the actual transmission rate: \(RB_{\textit{best}}\) (bit/s) of the two-way Fog \(\leftrightarrow\) Cloud backhaul connection. Task allocation is performed by _GeneticTA_par_ by running a genetic algorithm. For this purpose,  
_GeneticTA_par_ calls the _Crossover_ and _Mutation_ functions. Resource allocation is performed by _GeneticTA_par_ in an adaptive way. For this purpose, at each parallel iteration called by a parfor-cycle, _GeneticTA_par_ calls the _RAP_p_ function. Afterward, _GeneticTA_par_ picks up and stores:  
1. the best (that is, the minimum energy) task allocation vector \(\vec{x}_{\textit{best}}\);
2. the corresponding resource allocation vector \(\overline{RS}_{\textit{best}}\);
3. the total consumed energy \(\mathcal{E}_{\textit{best}}\) and the corresponding network energy \(\mathcal{E}_{\textit{best}}^{NET}\) computed up to the current generation. \(PS\) is the size of each generation of task allocation vectors; \(G_{MAX}\) is the number of carried out generations; \(CF\) is the fraction of crossover elements of the current generation; and \(MN\) is the number of mutated locations on a per-task-allocation basis. Let \(n_{\textit{core}}\geq 1\) be the number of parallel cores (e.g., parallel workers) managed by the _Parallel Toolbox_ of MATLAB, in order to support the execution of the _VirtFogSim_ package. Hence, the resulting asymptotic implementation complexity scales as in: \(\mathcal{O}\left(\left(PS\times G_{MAX}\times 8\times I_{MAX}\right)/\left(n_{ \textit{core}}\right)\right)\). The _Only Mobile Strategy_ (_OM_S_) function assumes that all the \(V\) tasks of the assigned application DAG are executed at the Mobile device. Then, it returns the \((1\times 7)\) vector \(\overline{RS}_{\textit{OM}}^{\lambda}=\left[f_{M},f_{F},f_{C},R_{U},R_{D},B_{U},B_{D}\right]\) (bit/s) of the corresponding resource allocation, the corresponding total computing-plus-communication consumed energy \(\mathcal{E}_{\textit{OM}}\) (Joule), and the (vanishing) network energy: \(\mathcal{E}_{\textit{NET}}^{\textit{OM}}\) (Joule). It is expected that the returned \(f_{M}\) is not zero, while the returned \(f_{C}\), \(f_{F}\), \(R_{U}\), \(R_{D}\), \(B_{U}\), \(B_{D}\), and \(\mathcal{E}_{\textit{NET}}^{\textit{OM}}\) vanish. The asymptotic complexity of the _OM_S_ function scales up as in: \(\mathcal{O}\left(8\times I_{MAX}\right)\). The _Only Fog Strategy_ (_OF_S_) function assumes that the first and last tasks of the assigned application DAG are executed at the Mobile device, while all the remaining inner \((V-2)\) tasks are executed at the Fog clone. Then, _OF_S_ returns the \((1\times 7)\) vector \(\overrightarrow{RS}_{OF}=[f_{M},f_{F},f_{C},R_{U},R_{D},B_{U},B_{D}]\) (bit/s) of the corresponding resource allocation, the corresponding total computing-plus-networking consumed energy \(\mathcal{E}_{OF}\), and the network energy \(\mathcal{E}_{NET}^{OF}\) (Joule).