| Algorithm 2: Initial Task Scheduling |
| Input: vi:task to schedule |
| 1 PList[vi ∈ N, j ∈ M]; |
| 2 begin |
| 3 Qvm ←Sort the fog serves by the cij with the descending order; |
| 4 V ← NULL; |
| 5 foreach Vj ∈ Qvm do |
| 6 Tj,0 ← 0; |
| 7 foreach Vj ∈ Qvm do |
| 8 Calculate the Tie of Vj by the Equation (4); |
| 9 if Tj,i -1 + < di then |
| 10 Calculate the Tj,i of Vj by the Equation (3); |
| 11 Z ← Vj; |
| 12 break; |
| 13 Calculate cost of Z by the Equation (1); |
| 14 PList[vi ∈ N, j ∈ M] ← Z; |
| 15 return Z, V; |