Skip to main content
. 2025 Mar 30;25(7):2197. doi: 10.3390/s25072197
Algorithm 2 Task Offloading Algorithm
Input: Workload matrix W(t) representing the resource requirements of tasks over time and Edge server information matrix EdgeServerInfo
Output: Predicted data, Energy consumption matrix, Delay matrix, Cost matrix
  •  1:

    Initialize Counter=0

  •  2:

    Load a pre-trained model for predicting task resource requirements

  •  3:

    for each edge server i do

  •  4:

     Calculate Pi=Predict(Di)

  •  5:

    end for

  •  6:

    for each edge server i do

  •  7:

     Calculate Fi=Combine(Pi,Ei,Δi,Ci)

  •  8:

    end for

  •  9:

    Sort edge servers based on the decision factor: SortedServers=Sort(Fi)

  • 10:

    for each service do

  • 11:

    if Fi<Threshold then

  • 12:

      Process the service locally

  • 13:

    else

  • 14:

      Migrate the service to the selected edge server

  • 15:

    end if

  • 16:

    end for

  • 17:

    for each edge server i in SortedServers do

  • 18:

    if the edge server has enough capacity to host the current service and the service is not already hosted then

  • 19:

      Provision(i)

  • 20:

      Increment Counter

  • 21:

      Exit the loop to ensure the service is migrated only once

  • 22:

    end if

  • 23:

    end for

  • 24:

    if Counter=N then

  • 25:

     Halt the process

  • 26:

    end if