# DD-FoG: Intelligent Distributed Dynamic FoG Computing Framework
## 4 Proposed Algorithms of Monitoring and Control
### Determination of the Central Load Point of Users (K-Means-Based Algorithm)  
One of the sub-processes is the periodic determination of the epicenter of users of a service. To search for the epicenter, it is proposed to use the k-means clustering algorithms. This algorithm is characterized by simplicity of implementation and speed of execution. The a priori data is the number of clusters (set in advance before the start of the clustering process, and its value has a high impact on the final result). Regarding the specifics of the application of the algorithm in the current task, the number of specified clusters is affected by the metrics collected by the mobile network operator (the number of connections, the average number of connections to the base station per day, etc.) Determining the exact formula, which is describing the dependence of these metrics with the parameter of the number of clusters is not a priority task in this research work. The cluster radii can differ from each other, even if the clusters of service consumers were formed in the same fog-zone, as a result of the execution of the same process with a given number of clusters.  
Within one fog-zone, there will be areas with different density of congestion of service consumers [20; 21]. Moreover, the sizes of such clusters are also not the same. If we consider the FORELL formal element algorithm as a clustering algorithm, with a predetermined cluster size, then there is a probability that the formed cluster will not completely cover such an area (or the coverage area will be significantly larger than the area of congestion of service consumers). Therefore, the k-means clustering algorithm is used to find user centers. One of the initial conditions within the framework of this article is also the static nature of IoT devices, smartphones and other devices that form fog regions. The radius of the cluster will be the distance between the center and the farthest point in the cluster. In this work, coordinates x, y, z are measured in meters. Three positioning planes were selected in order to take into account the height of the user device in order to correctly form the corresponding clusters. In real conditions, the coordinates of user devices and fog-nodes are proposed to be determined using GPS. The GPS receiver determines the coordinates  
Figure 7: Framework algorithm.  
(latitude and longitude) of the location of three satellites relative to each other and the distance between them and the receiver (determined through the time of transmission of the radio original from the satellites to the receiver).  
The algorithm is executed in five stages:  
1. Input data are set: x, y and z coordinates of points. The number of clusters and their initial centers are also set.
2. Assigning users (user devices) to the nearest cluster centers. For this, the Euclidean metric of the distance between points in space is used: \[\sqrt{(x-x_{k})^{2}+(y-y_{k})^{2}+(z-z_{k})^{2}}\] (1) where x, y and z are the coordinates of the point itself. Determination of centers of mass (the center of mass is determined separately for coordinates x, y, z): \[C_{mx}=\frac{\sum_{i=0}^{l}x_{i}}{l},C_{my}=\frac{\sum_{i=0}^{l}y_{i}}{l},C_{ mz}=\frac{\sum_{i=0}^{l}z_{i}}{l}\] (2) where \(l\) denotes the number of fog-nodes included in the cluster.
3. Comparison of centers of mass and assumed centers of clusters.
4. If the centers of mass and the assumed centers of the clusters are equal, then the centers of the clusters are considered finally determined and all users assigned to them are marked as members of this cluster. If they are not equal, then steps 2-4 are repeated anew, but with the assumed centers of the clusters equal to the centers of mass determined at this iteration.  
It should be noted that in this article (at the current stage of the project), when implementing the mathematical model of the algorithm, the mobility of users of services and fog-nodes was not taken into account.