5.1. Load Balancing between Nodes
When a task is uploaded to the FC system, the optimal load balancing is computed to minimize the computation time and the energy consumption when each task is processed by each fog cluster.
The initial load allocation of a task is represented for
N q-dimensional random arrays, where
q represents the number of fog nodes in the fog cluster. The traditional PSO is used to find the best load-balancing scheme. The particle search formula is as follows:
where
xp(
i,:) represents the position of the current
ith particle,
yp(
i,:) represents the position of the
ith particle after searching,
pp(
i,:) represents the current extremum position of the
ith particle, and
gbestp represents the optimal value position of all of the current particles.
The mass of the particles is represented by Equation (6), and the particles with preferable quality are selected according to the greedy criterion. The above operation is repeated until the maximum period is reached, and the desired allocation result is output.
The pseudocode for the load-balancing Algorithm 1 in this article is as follows:
Algorithm 1: Load balancing based on PSO |
Input: resource set {z1, z2, …, zq}, task set X, N, MP |
Output: Processing time (t), energy consumption (e), load balancing solutions |
1: initialize particle position, particle velocity |
2: calculate the fitness value of the particle and record it as the best fitness value for each particle |
3: obtain the current global best fitness value and global best particle position |
4: for tm = 1→MP do |
5: for i = 1→N do |
6: update particle velocity and position |
7: calculate the fitness value of the new particle |
8: if (new particle fitness value < particle best fit value s) then |
9: The new particle position becomes the best position for the particle |
10: end |
11: if (particle best fit value < global best fit value) then |
12: The best position of this particle becomes the current global best particle position |
13: end |
14: end |
15: obtain the global best particle position |
16: end |
17: calculate processing time (t) and energy consumption (e) |
18: return Load Balancing Solutions |
5.2. Task-Scheduling Optimization Based on PGABC
In order to address the shortcomings of the traditional ABC, such as its poor convergence and optimization ability, and the way in which it falls into the local optimum in task-scheduling problems, we introduced the concept of chromosome coding from the genetic algorithm into the initial stage of the traditional ABC. Thus, the initialization of the bee colony is represented by chromosome coding. The chromosome crossover of the genetic algorithm was introduced into the employed bee phase. The global optimal value was introduced into each generation of the observation bee iteration stage of the ABC. The concept of variation was introduced into the scout bee phase. On the basis of the ABC, the PSO was introduced for deep optimization. Thus, an ABC optimized with PSO and the genetic algorithm (PGABC) is proposed.
The modified artificial bee colony algorithm consists of five main phases: bee colony initialization, the improved employed bee stage, the observation bee stage, the improved reconnaissance peak stage, and the particle swarm optimization stage.
(1) The bee colony initialization stage
The initial solution set is composed of
D-dimensional numbers. Each number is represented by the value
r (0 ≤
r ≤ 1). Each
r represents a gene, and several genes form a chromosome. The chromosome represents the location information of the nectar source in the ABC. Each nectar source represents a solution,
task represents the quantity of tasks input, and
gene represents the quantity of genes per chromosome. The dimension of the particle is equal to the quantity of tasks multiplied by the quantity of genes in each chromosome.
The quantity of nectar sources is set to
nPop, i.e., the quantity of employed bees and scout bees is also
nPop, the number of observer bees is
n0nlooker, the maximum number of searches for nectar sources is
Limit, and the maximum quantity of iterations is
Maxcycle. In the initial stage, all of the bees are scout bees, and random searching produces
nPop nectar sources. The solution groups are represented by
nPop D-dimensional vectors. The nectar source generation formula is as follows:
where
xij represents the
jth dimension value of the
ith nectar source,
,
,
xmaxj and
xminj represent the maximum 1 and the minimum 0 in the
jth dimension space, respectively, and
denotes random numbers between 0 and 1;
(2) The improved employed bee stage
The employed bees search for new nectar sources in the vicinity of the initial nectar sources and update them according to the greedy rule. If the fitness value of the new nectar source is higher than that of the original nectar source, then the original nectar source is replaced by a new one. As a result of the large quantity of variables that is used in the destination algorithm, in order to increase the effort that is put into the search for the solution, the chromosome crossover in the genetic algorithm is combined with the neighborhood search in the traditional ABC in order to obtain the latest solution. The specific operation scheme is shown in
Figure 5.
(3) The observation bee phase
When the nectar source is discovered by the bee colony, the quality of the honey source is measured by its fitness. The fitness calculation formula is as follows:
where
Fi represents the objective function value of
xi,
Fi is obtained by transforming
xi into the mapping matrix that is shown in Equation (10) using Equation (24), and
fiti represents the fitness value of
xi.
In the observation bee stage, the observing bees select the honey source by observing the quality of the honey source. In this paper, the smaller the objective function value, the better the quality of the honey source, and the more observation bees will convene. The observing bee selects a source of honey via roulette probability. The selection probability formula is as follows:
where
pi represents the probability that
xi is selected. Then, because of the slow convergence of the algorithm, the global optimal honey source position is introduced to accelerate the convergence of the algorithm. The location update formula is as follows:
where
yij is the new nectar source that is identified by the employed bees;
xij is the current nectar source;
xkj is the other nectar source that is selected, which is different from the current nectar source;
;
k ≠
I;
xbest is the best nectar source position among all of the current nectar sources; and
is a random number between −1 and 1;
(4) The improved scout bee stage
Because the number of genes is too large and the traditional ABC reconnaissance peak phase is not suitable, the mutation rate was introduced by referring to the variation in the genetic algorithm. Given a value Var (Var < 1) as the mutation rate, all of the nectar sources are traversed during the reconnaissance peak phase, and each nectar source randomly generates a random value rand (0,1). When Var < rand (0,1), the nectar source is mutated to obtain a new nectar source in order to avoid the algorithm solution falling into the local optimum;
(5) The particle swarm optimization stage
The current optimal solution is introduced into the PSO, and each nectar source position is used as the initial position of the particles. With the particle swarm velocity update formula and the position update formula, a new nectar source is identified near to the original nectar source. The particle velocity update formula and the position update formula are as follows:
where
x(
i,:) represents the location information of the current
ith particle (the honey source),
p(
i,:) represents the individual extremum position of the
ith particle (the honey source), and
gbest represents the optimal value position of all of the current particles.
The pseudocode for Algorithm 2 task scheduling is as follows:
Algorithm 2: Task scheduling based on PGABC |
Input: resource set {F1, F2, …, FM}, task set {r1, r2, …, rn}, nPop, n0nlooker, MaxIt, em, tm, Var |
Output: Total time delay, total energy consumption, scheduling results |
1: initialize the nectar source location, calculate the fitness value of each nectar source |
2: obtain the nectar source with the best fitness value at present |
3: for it = 1→MaxIt do |
4: for i = 1→nPop do |
5: generation of new nectar positions according to chromosome crossover |
6: calculate the fitness value for the new nectar source location |
7: if (new nectar source adaptation value < old nectar source adaptation value) then |
8: new nectar source replaces old one |
9: end |
10: end |
11: calculate the probability of fitness for each nectar source |
12: for i = 1→n0nlooker do |
13: honey source selection by roulette with the following bees |
14: search for new honey sources near the selected honey source |
15: calculate the fitness value for the new nectar source location |
16: if (new nectar source adaptation value < old nectar source adaptation value) then |
17: new nectar source replaces old one |
18: end |
19: end |
20: for i = 1→nPop do |
21: generate a random number between 0 and 1 represented by rand |
22: if (rand < Var) then |
23: local variation of location information in nectar sources |
24: the new nectar source obtained replaces the original one |
25: end |
26: update the global best honey source |
27: for i = 1→nPop do |
28: search for new nectar source locations using the particle swarm algorithm search method |
29: calculate the fitness value for the new nectar source location |
30: if (new nectar source adaptation value < old nectar source adaptation value) then |
31: new nectar source replaces old one |
32: end |
33: end |
34: obtain the location of the nectar source with the best fitness value |
35: end |
36: calculate the total time delay and energy consumption |
37: return task scheduling solutions |
5.3. Resource Scheduling Based on PGABC–PSO
Firstly, the PSO is used to determine the load balancing in the same fog cluster, and then PGABC is used to determine the resource-scheduling scheme (PGABC–PSO) of the task-scheduling problem between the fog clusters, as shown in
Figure 6.
The overall algorithm steps are as follows:
(1) Input the fog node parameters and the task parameters;
(2) The fog nodes are simply clustered according to the geographical location, and the parameters of each cluster are output;
(3) Use the classical PSO to calculate the time and the energy consumption that are required for processing all of the input fog layer tasks in each fog cluster, which are then saved in a matrix;
(4) Input the matrix that was calculated in step (1); initialize the nectar sources, the employed bees, the observed bees, and the iterations; and input the values of c, w, etc.;
(5) Calculate the objective function value of each nectar source individual, identify the current optimal nectar source position and the optimal function value, and record them;
(6) Use the employed bees after the genetic optimization to generate a new solution and calculate the fitness value;
(7) The employed bees update the nectar source according to the greedy strategy;
(8) Use Equation (29) to calculate the fitness value of the honey source according to the objective function value of the honey source and calculate the selection probability of the honey source by using Equation (30);
(9) Use the genetic optimized reconnaissance peak stage to locally mutate and update the honey source;
(10) Update the optimal nectar source position and the optimal function value;
(11) Perform further optimizations in the PSO stage to improve the computational accuracy of the proposed algorithm. Take the optimal position of the nectar source obtained in step (10) as the global optimal particle of the particle swarm, and take the latest position of all of the nectar sources obtained in step (9) as the initial particle position and the local optimal position of the particle swarm. Update the positions according to the particle swarm algorithm;
(12) Calculate the objective function value of each individual nectar source again, and update and identify the current optimal nectar source position and optimal function value;
(13) If the iteration end condition is reached, stop the iteration to output the optimal honey source position and fitness value; if not, return to step (6).
5.4. Time and Resource Complexities
In
Table 2,
q represents the number of fog nodes in the fog cluster,
Np represents the number of particles in the particle swarm,
Mp represents the total number of cycles of the particle swarm,
m represents the total number of fog nodes,
n represents the number of tasks,
M represents the number of fog clusters in the system,
nPop represents the number of employed bees,
n0nlooker represents the amount of following bees,
gene represents the number of genes per chromosome in the PGABC, and
Maxcycle represents the total number of cycle iterations in the PGABC.
In the FC system, the number of fog nodes m and the number of fog clusters M are generally fixed, and only the number of input tasks n is variable. The other parameters in the above table are all inherent parameters of the algorithm itself. It can be seen that the data variation in the method is only related to the number of tasks n, and the other parameters can be neglected; therefore, the final time complexity is O(n) and the resource complexity is O(n). The performance of the method that was proposed in this section is good, and it does not become computationally intractable as the amount of data increases.