## 5 The _DeepFogSim_ Toolkit: Software Architecture and Supported Resource Allocation Strategies
### Supported Resource Allocation Strategies
\(\triangleright\)**Begin DynDeF_RAS function**
```
1:for\(m=1:M\)do
2:for\(j=1:m_{m}\)do
3: Compute \(v_{I}(j,m)\) with Equation (1)
4: Compute \(v_{O}(j,m)\) with Equation (2)
5:endfor
6:endfor
7:for\(t=1:I_{MAX}\)do\(\triangleright\)**RAS iterations**
8:for\(m=1:M\)do
9:for\(j=1:m_{m}\)do
10: Compute the \(T_{EXE}(j,m)\) with Equations (3) and (4)
11:endfor
12: Compute \(T_{EXE}(m)\) with Equation (5)
13:endfor
14: Compute \(T_{EXE}^{(1,m)}\) with Equation (6)
15: Compute \(\mathcal{E}_{COP}\) with Equations (9), (11), and (21)
16: Compute \(\mathcal{E}_{NET}\) with Equation (22)
17: Compute \(\mathcal{E}_{TOT}\) with Equation (20)
18: Compute all the derivatives of the Lagrangian function
19: Update \(\widetilde{f}\), \(\widetilde{\overline{f}}\), and \(\overline{R}\) with Equations (24) and (25)
20: Update \(\overline{\mathcal{\lambda}}\), \(\overline{\mathcal{\kappa}}\), and \(\overline{\mathcal{\xi}}\) with Equations (26) and (27)
21:endfor
22: Obtain \(\widetilde{f}^{(best)}\), \(\widetilde{\overline{f}}^{(best)}\), and \(\overline{R}^{(best)}\)
23: Compute \(\mathcal{E}_{COP}^{(best)}\) with Equations (9), (11), and (21)
24: Compute \(\mathcal{E}_{NET}^{(MAX)}\) with Equation (22)
25: Compute \(\mathcal{E}_{TOT}^{(MAX)}\) with Equation (20)
26:return\(\Big{[}\widetilde{f}^{(best)}\), \(\widetilde{\overline{f}}^{(best)}\), \(\overline{R}^{(best)}\), \(\mathcal{E}_{TOT}^{(best)}\), \(\mathcal{E}_{COP}^{(best)}\), \(\mathcal{E}_{NET}^{(best)}\Big{]}\). \(\triangleright\)**End DynDeF_RAS function**(b) The Static Allocation strategy  
The Static Allocation strategy, implemented by the _Static_Allocation_ function, calculates the computing, networking, and total energy consumed by the simulated Fog platform of Figure 3 for sustaining the delay-constrained inference phase of the considered CDNN under the (static) maximal allocation vectors: \(\left\{\vec{f}^{(MAX)},\overrightarrow{\vec{f}}^{(MAX)},\overrightarrow{R}^{( MAX)}\right\}\). Hence, the _Static_Allocation_ function returns:  
1. \(\mathcal{E}_{TOT}^{(MAX)}\): the maximum total energy consumed by the the simulated Fog platform of Figure 3 under the maximal resource vectors;
2. \(\mathcal{E}_{COP}^{(MAX)}\): the maximum computing energy consumed by the the simulated Fog platform of Figure 3 under the maximal resource vectors; and
3. \(\mathcal{E}_{NET}^{(MAX)}\): the maximum network energy consumed by the the simulated Fog platform of Figure 3 under the maximal resource vectors. Algorithm 2 presents a pseudo-code of the implemented _Static_Allocation_ function. An examination of this code points out that the asymptotic computational complexity of the _Static_Allocation_ function scales linearly with the sum of \(M\) of tiers and the total number \(Q\) of Fog nodes, i.e., \(M+Q\). ```
1:\(Static\_Allocation()\). 2:\(FanIn(j,m)\), \(FanOut(j,m)\), \(\vec{f}^{(MAX)}\), \(\overrightarrow{\vec{f}}^{(MAX)}\), and \(\overrightarrow{R}^{(MAX)}\). 3:\(\text{scalar total energy }\mathcal{E}_{TOT}^{(MAX)}\) (Joule), scalar computing energy \(\mathcal{E}_{COP}^{(MAX)}\) (Joule), and network energy \(\mathcal{E}_{NET}^{(MAX)}\) (Joule) consumed under the maximal allocation vectors. 4:\(\triangleright\)Begin Static_Allocation function
5:for\(m=1:M\)do
6:for\(j=1:m_{m}\)do
7: Compute \(v_{I}(j,m)\) with Equation (1)
8: Compute \(v_{O}(j,m)\) with Equation (2)
9: Compute \(T_{EXE}(j,m)\) with Equations (3) and (4)
10:endfor
11: Compute \(T_{EXE}(m)\) with Equation (5)
12:endfor
13: Compute \(T_{EXE}^{(1,m)}\) with Equation (6)
14: Compute \(\mathcal{E}_{COP}^{(MAX)}\) with Equations (9), (11), and (21)
15: Compute \(\mathcal{E}_{NET}^{(MAX)}\) with Equation (22)
16: Compute \(\mathcal{E}_{TOT}^{(MAX)}\) with Equation (20)
17:return\(\left[\mathcal{E}_{TOT}^{(MAX)},\,\mathcal{E}_{COP}^{(MAX)},\,\mathcal{E}_{NET}^{( MAX)}\right]\). \(\triangleright\)End Static_Allocation function
```  
**Algorithm 2**_Static_Allocation_ function