def prepare(self, simulation):
num_tasks = len(self.tasks)
# build ECT matrix
ECT = np.zeros((num_tasks, len(self.hosts)))
for t, task in enumerate(self.tasks):
stage_in = task.parents[0]
for h, host in enumerate(self.hosts):
if stage_in.amount > 0:
ect = stage_in.get_ecomt(self.master, host) + task.get_eet(host)
else:
ect = task.get_eet(host)
ECT[t][h] = ect
# print(ECT)
# build schedule
task_idx = np.arange(num_tasks)
for _ in range(0, len(self.tasks)):
min_hosts = np.argmin(ECT, axis=1)
min_times = ECT[np.arange(ECT.shape[0]), min_hosts]
if self.strategy == ListHeuristic.MIN_FIRST:
t = np.argmin(min_times)
elif self.strategy == ListHeuristic.MAX_FIRST:
t = np.argmax(min_times)
elif self.strategy == ListHeuristic.SUFFERAGE:
if ECT.shape[1] > 1:
min2_times = np.partition(ECT, 1)[:,1]
sufferages = min2_times - min_times
t = np.argmax(sufferages)
else:
t = np.argmin(min_times)
task = self.tasks[int(task_idx[t])]
h = int(min_hosts[t])
host = self.hosts[h]
ect = min_times[t]
self.host_tasks[host.name].append(task)
logging.debug("%s -> %s" % (task.name, host.name))
task_idx = np.delete(task_idx, t)
ECT = np.delete(ECT, t, 0)
stage_in = task.parents[0]
if stage_in.amount > 0:
task_ect = stage_in.get_ecomt(self.master, host) + task.get_eet(host)
else:
task_ect = task.get_eet(host)
ECT[:,h] += task_ect
# print(ECT)
评论列表
文章目录