## 5 The _DeepFogSim_ Toolkit: Software Architecture and Supported Resource Allocation Strategies
### The General SW Architecture of DeepFogSim  
The main functionalities of _DeepFogSim_ are implemented by the functions listed in Table 2. In the following of the paper, these functions are briefly described. A detailed explanation about the usage of such functions is found in the _DeepFogSim_ User Guide, which can be downloaded along with the software package (see Section 9). The main functions in Table 2 use some auxiliary functionalities implemented by the set of additional routines listed in Table 3.  
To describe the general software architecture of the simulator, we note that _DeepFogSim_ acts as the main program that:  
1. allows the user to setup 34 input parameters (refer to Table 10), which characterize the scenario to be simulated by the user (see Figure 3);
2. optionally calls the _Static_Allocation_ function to simulate the same scenario where all the resources are set to their maximum values \(\left\{\vec{f}^{(MAX)},\ \overrightarrow{\vec{f}}^{(MAX)},\ \overrightarrow{R}^{(MAX)}\right\}\) (bit/s);
3. optionally, calls the _DynDeFog_TRACKER_ function. It returns the time plots over the interval: \([1,\ iteration\_number]\) of the: (a) total energy \(\mathcal{E}_{TOT}\) consumed by the overall proposed platform of Figure 3; (b) the corresponding energy \(\mathcal{E}_{COM}\) consumed by the convolutional and classifier processors of Figure 3; (c) the corresponding energy \(\mathcal{E}_{NET}\) consumed by the network connections of Figure 3; and (d) the behavior of the first and last (\(M\)-th) _lambda_ multipliers in (25) associated to the constraints in Equation (23),  
when unpredicted and abrupt changes in the operating conditions of the simulated Fog platform of Figure 3 occur. The user may set the magnitude of these changes, in order to test various time-fluctuations of the simulated environment of Figure 3 (see Section 5.4 for a deeper description of the _DynDeFog_TRACKER_ function and its supported options).  
The current version of the _DeepFogSim_ simulator is equipped with a (rich) _Graphical User Interface_ (GUI) that displays:  
1. the numerical values of the best optimized frequencies for the convolutional and classifier processors and the network throughputs; and
2. the numerical values of the optimal energy consumption, which are returned by the _DynDeF_RAS_ function.  
\begin{table}
\begin{tabular}{p{142.3 pt} p{142.3 pt}} \hline \hline
**Function** & **Description** \\ \hline DynDeF\_RAS\(\left(\vec{f}_{0},\ \overline{\vec{f}}_{0},\ \vec{R}_{0},\ \vec{\lambda}_{0}\right)\) & Implements the Resource Allocation Strategy to solve the optimization problem in Equation (23). \\ \hline DynDeFog\_TRACKER\(\left(\vec{f}_{0},\ \overline{\vec{f}}_{0},\ \vec{R}_{0},\ \vec{\lambda}_{0}\right)\) & Tests the convergence rate at the steady state and the steady-state stability of the primal-dual iterations performed by the _RAS_ function when abrupt changes happen. \\ \hline Static\_Allocation\(()\) & Runs the Static Allocation strategy. \\ \hline \hline \end{tabular}
\end{table}
Table 2: Main functions implemented by _DeepFogSim_.  
\begin{table}
\begin{tabular}{p{142.3 pt} p{142.3 pt}} \hline \hline
**Function** & **Description** \\ \hline Check\_convexity\(()\) & Checks the strict convexity of the underlying optimization problem in Equation (23). \\ \hline Check\_feasibility\(()\) & Checks the feasibility of the underlying optimization problem in Equation (23). \\ \hline Check\_input\(()\) & Checks the correct value ranges of the input parameters. \\ \hline \(\left[\vec{f}_{0},\ \vec{f}_{0},\ \vec{R}_{0},\ \vec{\lambda}_{0}\right]=\text{init\_other\_global}()\) & Initializes all the remaining variables. \\ \hline \(\left[tier,\ column\right]=\text{oneDottwoD}(oneDindex)\) & Converts the 1D indexing of a Fog node to the corresponding 2D row/column one. \\ \hline \(oneDindex=\text{twoDotoneD}(tier,\ column)\) & Evaluates the 1D equivalent index of the 2D indexing of a Fog node. \\ \hline \hline \end{tabular}
\end{table}
Table 3: Auxiliary functions implemented by _DeepFogSim_.