def tasks_in_interval(resources=CostAwareResources([], [], [], 0), r=-1, t=-1): timeslot_len = resources.timeslot[r] t += float(timeslot_len / 2) tasks_in_resource = resources.tasksOfResource[r] length_r = len(tasks_in_resource) start_task_index = 0 end_task_index = length_r - 1 if length_r == 0: return [] t0 = tasks_in_resource[start_task_index].EST x = float(t - t0) / timeslot_len if x < 0: return [] start_time_of_timeslot = math.floor(x) * timeslot_len + t0 end_time_of_timeslot = math.ceil(x) * timeslot_len + t0 if start_time_of_timeslot == end_time_of_timeslot: end_time_of_timeslot += timeslot_len task_list = [] for i in range(start_task_index, end_task_index + 1): # find the task ids within the timeslot (each portion of them) task_start_time = tasks_in_resource[i].EST task_finish_time = tasks_in_resource[i].EFT if start_time_of_timeslot <= task_finish_time <= end_time_of_timeslot or \ start_time_of_timeslot <= task_start_time <= end_time_of_timeslot: task_list.append(tasks_in_resource[i].task.id) return task_list
def assign_cost_for_each_task(g, resources=CostAwareResources([], [], [], 0)): for r in range(0, resources.len): resource_cost = resources.resource_cost(r) if resource_cost == 0: continue scheduled_task_in_resource = resources.tasksOfResource[r] sum_weight = sum( map(lambda t: t.task.weight, scheduled_task_in_resource)) for schedule in scheduled_task_in_resource: g.tasks[ schedule.task. id].cost = resource_cost * schedule.task.weight / sum_weight g.tasks[schedule.task.id].eft = schedule.EFT
def __init__(self, g=Graph(), constraint_type=Constraint.none, constraint=0, resources=CostAwareResources([], [], [], 0), reference_graph=None, reference_resources=None): if constraint_type is Constraint.none: raise Exception('Constraint type must be defined') elif constraint <= 0: raise Exception('Constraint must be a non-zero positive value') self.g = copy.deepcopy(g) self.type = constraint_type self.constraint = constraint self.reference_graph = reference_graph if constraint_type is Constraint.budget: if self.reference_graph is None: self.reference_graph = copy.deepcopy(g) resources_copy = copy.deepcopy(resources) Scheduler.BHEFT.schedule(self.reference_graph, resources_copy, constraint) self.reference_graph.resources = resources_copy # verbose: # resources_copy.show_schedule(self.reference_graph.name, # '--' + str(resources_copy.makespan) + ', ' # + str(resources_copy.plan_cost)) self.reference_graph.cost = resources_copy.plan_cost self.reference_graph.budget = constraint self.reference_graph.critical_first = self.reference_graph.budget / self.reference_graph.cost self.critical_first = self.reference_graph.critical_first # self.scheduler = Scheduler.BHEFT.SchedulerClass(self.g, resources, constraint) # reference_resources = reference_graph.resources # it is moved to method parameters for t in reference_graph.tasks.values(): t.lft = reference_resources.job_task_schedule[ reference_graph.name][t.id].EFT Multi_Workflow.assign_sub_deadlines(self.reference_graph, self.g, asap=False) Multi_Workflow.assign_sub_budgets(self.reference_graph, self.g, reference_resources) self.scheduler = Scheduler.DeadlineOptimisticAlpha.SchedulerClass( self.g, resources, reference_graph.makespan) elif constraint_type is Constraint.deadline: if self.reference_graph is None: self.reference_graph = copy.deepcopy(g) resources_copy = copy.deepcopy(resources) Scheduler.ICPCP.schedule(self.reference_graph, resources_copy, constraint) self.reference_graph.resources = resources_copy # resources_copy.show_schedule(self.reference_graph.name, # '--' + str(resources_copy.makespan) + ', ' # + str(resources_copy.plan_cost)) self.reference_graph.makespan = resources_copy.makespan self.reference_graph.deadline = constraint self.reference_graph.critical_first = self.reference_graph.deadline / self.reference_graph.makespan self.critical_first = self.reference_graph.critical_first Multi_Workflow.assign_sub_deadlines(self.reference_graph, self.g, asap=True) Multi_Workflow.assign_sub_budgets(self.reference_graph, self.g, reference_resources) self.scheduler = Scheduler.DeadlineOptimisticAlpha.SchedulerClass( self.g, resources, constraint) else: raise Exception("Define a constraint!") Multi_Workflow.assign_cost_for_each_task(self.reference_graph, reference_resources) # print('', end='') self.sum_w = sum( map(lambda task: task.weight, self.reference_graph.tasks.values())) self.overall_budget = reference_resources.plan_cost self.scheduler.set_budget(reference_resources.plan_cost)
def compute_gap_rate(resources=CostAwareResources([], [], [], 0), r=-1, t=-1, list_is_required=False): timeslot_len = resources.timeslot[r] t += float(timeslot_len / 2) tasks_in_resource = resources.tasksOfResource[r] length_r = len(tasks_in_resource) try: start_task_index = 0 while tasks_in_resource[start_task_index].task.dummy_task: start_task_index += 1 end_task_index = length_r - 1 while tasks_in_resource[end_task_index].task.dummy_task: end_task_index -= 1 if end_task_index < start_task_index: if list_is_required: return 0, -1, -1, [] else: return 0, -1, -1 except LookupError: if list_is_required: return 0, -1, -1, [] else: return 0, -1, -1 t0 = tasks_in_resource[start_task_index].EST x = float(t - t0) / timeslot_len if x < 0: if list_is_required: return 0, -1, -1, [] else: return 0, -1, -1 start_time_of_timeslot = math.floor(x) * timeslot_len + t0 end_time_of_timeslot = math.ceil(x) * timeslot_len + t0 if start_time_of_timeslot == end_time_of_timeslot: end_time_of_timeslot += timeslot_len sum_gap = 0 gap_list = [] for i in range(start_task_index + 1, end_task_index + 1): # find the gap between "i"th and "i-1"th tasks: gap_start = tasks_in_resource[i - 1].EFT gap_end = tasks_in_resource[i].EST if end_time_of_timeslot <= gap_start: break if gap_end <= start_time_of_timeslot: continue if gap_start < start_time_of_timeslot: gap_start = start_time_of_timeslot if end_time_of_timeslot < gap_end: gap_end = end_time_of_timeslot sum_gap += gap_end - gap_start if not list_is_required or gap_end == gap_start: continue gap_list.append((gap_start, gap_end)) if start_time_of_timeslot < tasks_in_resource[ end_task_index].EFT < end_time_of_timeslot: sum_gap += end_time_of_timeslot - tasks_in_resource[end_task_index].EFT if list_is_required: gap_list.append( (tasks_in_resource[end_task_index].EFT, end_time_of_timeslot)) if list_is_required: return float( sum_gap ) / timeslot_len, start_time_of_timeslot, end_time_of_timeslot, gap_list else: return float( sum_gap ) / timeslot_len, start_time_of_timeslot, end_time_of_timeslot