# An IoT-Based Fog Computing Model
## 3 Fog Computing Layer Design of Proposed Model
### The Proposed Optimization Framework for IoT-Based Fog Computing Environments  
The fog computing layer model, which is constructed in this paper, focuses on three target parameter that decide it comprehensive performance. These parameters are: delay, energy and distance. Delay means the response time that users (sink nodes) have to wait after they submit their tasks. Energy is the total energy the target \(FN\) needs to finish its allocated tasks, while distance means the total distance of each user to their corresponding \(FN\) according to scheduling result. Suppose the fog computing system consists of the fog nodes, which can be represented as a set \(FN=FN_{1},FN_{2},\ldots,FN_{N}\), and the application tasks which are going to be scheduled can be represented as a set \(T=t_{1},t_{2},\ldots t_{n}\). Delay is the main factor which can affect execution time \(ExeT_{ij}\), where i = 1,..., n and j = 1,..., N. \(ExeE_{ij}\) is the energy consumption of \(t_{i}\) by \(FN_{j}\). Figure 2: The architecture of the internet of things-based fog computing model (IoT-FCM). The first quality factor considered is the total distance \(TD\), which is the distance from users to their corresponding \(FN\). This can be calculated by traversing all the tasks in set T. If (\(T_{iX}\), \(T_{iY}\)) and (\(FN_{jX}\), \(FN_{jY}\)), denote the coordinates of user \(i\) and \(FN_{j}\), respectively, then \(TD\) can be determined by using  
\[TD=\sum_{i=1}^{n}\sqrt{(T_{iX}-FN_{jX})^{2}+(T_{iY}-FN_{jY})^{2}},TD<TDL, \tag{1}\]  
where \(T\) is the task set, n is the number of tasks in set \(T\), while connected to the \(j\)-th \(FN\), and \(TDL\) is the total distance limitation. From the fog computing characteristics, delay should be kept as low as possible. Task scheduling strategy therefore must aim at minimizing task completing time (execution time). \(FN\)s can hold more than one task at a time, the completing time is thus the execution time of such a task running on a \(FN\) whose execution time is the longest. The execution time \(ExeT\) of a task \(T\) by the \(FN\) can be described by using  
\[ExeT=\max\sum_{i=1}^{n}ExeT_{ij};j\in N,ExeT(T,FN)<DL, \tag{2}\]  
where \(DL\) is the delay limitation, the summation of all the execution times \(ExeT_{ij}\) of the various tasks \(T_{i}(i\in n)\) running on a \(FN\) gives the completion time of each \(FN_{j}\), \(j\in N\). The delay is obtained from the last \(FN_{j}\) to finish its tasks. Energy saving is also a very important factor that needs to be considered while building fog computing models. Therefore, fog computing system should keep the energy consumption as low as possible. In addition, the scheduling energy consumption \(ExeE\) cannot be greater than the upper limit of electricity supply. The energy consumption for executing task set \(T\) by set \(FN\) is given by  
\[ExeE=\sum_{i=1}^{n}\sum_{j=1}^{N}ExeE_{ij},ExeE(T,FN)<EL, \tag{3}\]  
where \(ExeE_{ij}\) is the energy consumed by \(FN_{j}\), \(j\in N\) to execute task \(T_{i}\), \(i\in n\) and \(ExeE\) is the energy consumed by all the FNs in executing their allocated tasks; \(EL\) is the energy limitation. The three equations can be integrated into a fitness function which is defined by using  
\[F(C)=\left\{ \begin{array}{c}\alpha*\left(1-\frac{ExeT(C)}{DL}\right)+\beta* \left(1-\frac{ExeE(C)}{EL}\right)+\gamma*\left(1-\frac{TD(C)}{TDL}\right),\\ \text{if }\text{ExeT(C)}\leq\text{DL},\text{ExeE(C)}\leq\text{EL },\text{TD(C)}>\text{TDL}\\ 0,\end{array} \right., \tag{4}\]  
where C is the vector of the special individual which includes one match between tasks and fog nodes \((T,FN)\), \(F(C)\) is the fitness function means the fitness value of the vector C, which is used for measuring the score of the individual in the population, (\(1-\text{ExeT(C)}\)/DL) is the benefit of execution time which is considered as delay in the paper when finished the task scheduling, so the same (\(1-\text{ExeE(C)}\)/EL) is the benefit of energy and (\(1-\text{TD(C)}\)/TDL) is the benefit of distance.