Skip to main content
. 2023 Jul 1;23(13):6088. doi: 10.3390/s23136088
Algorithm 2: ε–Greedy Solution
  • Input: 

    V (tasks), W (users), ε (probability of random selection), M (maximum number of episodes with no improvement)

  • Output: 

    R (greward of all episodes), {p,d,t} (profit of platform, travel distance of workers and workers’ response time), {Fj:wjW} (travelling trajectory of workers)

  • 1:

    R; // global maximum greward

  • 2:

    p,d,t0; // profit, distance and response time

  • 3:

    k0; // number of episodes with no improvement

  • 4:

    while k<M do

  • 5:

        Rk0; // local greward in current episode

  • 6:

        for viV do

  • 7:

            if there exist feasible users for task vi then

  • 8:

               Random selection with probability ε; otherwise, greedy selection (reward)

  • 9:

               Get reward of this assignment as Ri

  • 10:

               Rk=Rk+Ri; // update local greward

  • 11:

               if the task cannot be completed then

  • 12:

                   Tasks are not assigned to workers, update status of tasks and workers’ set

  • 13:

               else

  • 14:

                   Assign the task to worker, update status of tasks and workers’ set

  • 15:

               end if

  • 16:

            end if

  • 17:

        end for

  • 18:

        if Rk>R then

  • 19:

            R = Rk; // update global maximum greward

  • 20:

            Record p,d,t

  • 21:

            Record paths {Fj:wjW}

  • 22:

            k = 0; // reset k with improvement

  • 23:

        else

  • 24:

            k = k + 1; // increase k without improvement

  • 25:

        end if

  • 26:

    end while

  • 27:

    return R, {p,d,t} and {Fj:wjW}