# DD-FoG: Intelligent Distributed Dynamic FoG Computing Framework
## 4 Proposed Algorithms of Monitoring and Control
### Service Time Providing through Device Selection (SWARM-Based Algorithm)  
One of the sub-processes is the process of determining those fog-nodes that have free computing capabilities and satisfy the conditions for migrating microservices to them with subsequent deployment. Within the framework of this sub-process, it is necessary to solve the optimization problem: for a given function (describing the state of the fog-node through a set of parameters), among all possible values of this function, find a value at which this function takes max values (min values are discarded). There are many algorithms that are guaranteed to find the extremum of a function, which is a local minimum or maximum near a given starting point. \(x_{0}\). Such algorithms include, for example, gradient descent algorithms. However, in this problem, it is necessary to find the global maximum of a function that, in a given range of parameters, in addition to one global extremum, has many local extrema. Gradient algorithms cannot cope with the optimization of such a function, because their solution converges to the nearest extremum near the starting point. For issues of finding the global maximum or minimum, so-called global optimization algorithms are used. Swarm intelligence algorithms are one of the classes of these algorithms. In this work, it is proposed to use PSO (practicle swarm optimization). The original PSO algorithm was inspired by the social behavior of biological organisms, specifically the ability of groups of some species of animals to work as a whole in locating desirable positions in a given area, e.g., birds flocking to a food source. This seeking behavior was associated with that of an optimization search for solutions to non-linear equations in a real-valued search space. Thus, this algorithm is described as follows:  
An individual particle \(i\) is composed of three vectors: its position in the D-dimensional search space \(\underline{x_{i}}=(x_{i1},x_{i2},\ldots,x_{iD})\), the best position that it has individually found \(p_{i}=(p_{i1},p_{i2},\ldots,p_{iD})\), and its velocity \(\underline{v_{i}}=(x_{i1},v_{i2},\ldots,v_{iD})\). Particles were originally initialized in a uniform random manner throughout the search space; velocity is also randomly initialized. These particles then move throughout the search space by a fairly simple set of update equations. The algorithm update the entire swarm at each time step by updating the velocity (Equation (3)) and position (Equation (4)) of each particle in every dimension by the following rules [22]:  
\[v_{id}=v_{id}+c\epsilon_{1}(p_{id}-x_{id})+c\epsilon_{2}(p_{gd}-x_{id}) \tag{3}\]  
\[x_{id}=x_{id}+v_{id} \tag{4}\]  
where in the original equations \(c\) is a acceleration constant, \(\epsilon_{1}\) and \(\epsilon_{2}\) are independent random numbers in the follow limits [0, 1], \(p_{i_{j}}\) is the best position passed by all particles, \(p_{S_{d}}\) is the position found by any neighbor of the particle. The update process is summarized in Algorithm 1. ```
1:for each time step \(t\)do
2:for each particle \(i\) in the swarm do
3: Update position \(\underline{x_{t}}\) using Equations (3) and (4). 4: Calculate particle fitness \(f(\underline{x_{t}})\)
5: Update \(\underline{p_{i}}\), \(\underline{p_{g}}\). 6:endfor
7:endfor
```  
**Algorithm 1** PSO Update Process  
Particle velocities in this original algorithm were clamped at a maximum value \(vmax\). Without the clamping in place the system was prone to entering a state of explosion, wherein the random weighting of the \(\epsilon_{1}\) and \(\epsilon_{2}\) values caused velocities and thus particle positions to increase rapidly, approaching infinity. The \(v_{m}ax\) parameter prevented the system from entering this state by limiting the velocity of all particles to that value. Thus, it is necessary to define the parameters describing each of the investigated fog-nodes.