Skip to main content
. 2021 Oct 25;21(21):7053. doi: 10.3390/s21217053
Algorithm 2: Second-level algorithm of the learning hierarchy.
1. Initialization
2. While not converged, do
 1. For each element i of the learner’s flag, do
  1. If flag(i) is converted from 1 to 0, do
    Find device u that helped device i among all devices, including neighbors’ helpers, and return the borrowed bandwidth from di to du
  2. Else if flag(i) is converted from 0 to 1, do
   a. Make a feasible device set, including the nodes’ own feasible devices and neighbors’ feasible help lists.
   b. With probability ɛ, randomly choose device k among the feasible device set, otherwise:
      ai=argmaxj∈ feasible(Q(i,zn,zm,Thnew,j)), where j is the index of the selected.
   c. Increase the bandwidth of di and decrease the bandwidth of dj, as much as di needs.
   d. Calculate penalty or punish(i) or blame(i) based on the learner’s action and then calculate RnQ:
      RnQ=operation−punish(i)−penalty−blame
   e. Update Q matrix:
      Qnew(i,zn,zm,Thnew,ai)=(1−α)Qold(i,zn,zm,Thnew,ai)+
      α (RnQ+γ(maxk′ϵ feasible (Qold(i′,zn,zm,Thnew,ai’))))
  3. End if
 2. End for
 3. Make the next flag based on the learner’s device priorities.
 4. Repeat lines 3 to 26 for neighboring fog nodes
 5. Calculate SBMn using countpun considering all fragments
 6. Calculate the average SBM
 7. Increase the time step n by 1
3. End while