# Efficient Dynamic Deployment of Simulation Tasks in Collaborative Cloud and Edge Environments
## 4 Design of Pool
### Reassigning of Tasks
In this part, we will introduce how to reassign the tasks based on both the optimal flow \(f^{\tau+1}\) and the assignment solution \(\mathcal{F}^{\tau}\) at time \(\tau\). The detailed procedures are presented in Algorithm 1. ``` Input: The optimal flow \(f^{\tau+1}\) at time \(\tau+1\)  The assignment solution \(\mathcal{F}^{\tau}\) at time \(\tau\) Output: Assignment solution \(\mathcal{F}^{\tau+1}\) at time \(\tau+1\)
1 sortTasksByMigraCost() unScheList.clear() fortask \(t\) in \(\mathbb{T}\)do
2 if\(t\).isAssigned then
3\(h=\) getAssignment(\(t,\mathcal{F}^{\tau}\))
4 else
5 unScheList.push_back(\(t\)) continue
6
7 end if
8
9 end if
10 if!\(h\).isDeletedthen
11 ifhasFeasibleFlow(\(t\), \(h\), \(f^{\tau+1}\)) then
12 setAssignment(\(t,h\), \(f^{\tau+1}\))
13 updateFlow(\(t\), \(h\), \(f^{\tau+1}\))
14
15 else
16 ifhasEfficientResource(\(t\), \(h\), \(f^{\tau+1}\)) then
17 c_migra = getMigrationCost(\(t\))
18 c_curr = getCurrentCost(\(t\))
19 c_mini = getMinimumCost(\(t\))
20 ifc_migra \(\geq\) c_curr - c_mini then
21 setAssignment(\(t,h,\mathcal{F}^{\tau+1}\))
22 updateFlow(\(t\), \(h\), \(f^{\tau+1}\))
23
24 else
25\(t\).isAssigned = False
26
27



54 return\(\mathcal{F}^{\tau}\)
53



265



As tasks are processed sequentially when determining their assignments based on the optimal flow, tasks with larger migration cost should be considered first. In our algorithm, we first calculate the migration cost of each task based on Equation (2), and then sort all tasks in a descending order. Each task has an attribute called _isAssigned_ to indicate whether this task has been assigned to some host at time \(\tau\). For a newly added task, this value is set at false. There exists two ways to express the migration cost of task \(i\). On the one hand, a new arc from task \(i\) to its corresponding host \(h\) can be added to indicate the preference of task \(i\) for staying in \(h\). However, it can increase the complexity of flow network markedly. On the other hand, the migration cost of task \(i\) can be calculated and taken into consideration when assigning tasks based on optimal flow \(f\). In this case, the structure of flow network needs not to be modified. In Pool, the second strategy is adopted for simplicity. For task \(t\) which has been assigned at time \(\tau\), if its corresponding host \(h\) is deleted at time \(\tau+1\), it must be migrated to other hosts and its value of _isAssigned_ is reset at false. Otherwise, we need to justify whether there exists a feasible path between the corresponding task node of \(t\) and host node of \(h\) in \(f^{\tau+1}\). If true, it means that assigning \(t\) to \(h\) confronts to the optimal flow and incurs the least communication cost. In this case, the assignment of \(t\) keeps unchanged and the optimal flow \(f^{\tau+1}\) is updated. However, the non-existence of feasible path between \(t\) and \(h\) does not mean that task \(t\) must be migrated. On the one hand, the reason may be that host \(h\) can provide adequate resources while assigning \(t\) to some other hosts may incur smaller cost. On the other hand, it can be attributed to that \(h\) cannot provide enough resources to process \(t\) due to resource competition from other tasks. For the first situation, we need to further verify whether the gain obtained from migrating \(t\) can make up the migration cost of \(t\). Communication cost of current assignment and the migration cost for task \(t\) can be easily calculated based on Equations (1) and (2), respectively. To be simplified, the minimum communication cost for \(t\) in all possible assignments is calculated heuristically to obtain the migration gain (see Lines 14-16 in Algorithm 1). If the gain is less than migration cost, task \(t\) is still assigned to host \(h\). Otherwise, value of _isAssigned_ for \(t\) is set at false (see Lines 17-22 in Algorithm 1). For the second situation, we just need to set _isAssigned_ at false. After processing all the tasks, those whose value on _isAssigned_ is false are all stored in list _unScheList_.