class TestHeftMethods(unittest.TestCase): """ This class test HEFT on the same example graph presented by Topcuoglu et al """ def setUp(self): self.workflow = Workflow("{0}/{1}".format( current_dir, cfg.test_heuristic_data['topcuoglu_graph_nocalc'])) env = Environment("{0}/{1}".format( current_dir, cfg.test_workflow_data['topcuoglu_graph_system'])) self.workflow.add_environment(env) # self.workflow.load_attributes(cfg.test_heuristic_data['heft_attr'],calc_time=False) def test_rank(self): rank_values = [108, 77, 79, 80, 69, 63, 42, 35, 44, 14] # for task in self.workflow.tasks: # task.rank = rank_up(self.workflow, task) task_ranks = calculate_upward_ranks(self.workflow) # upward_rank(self.workflow) for task in self.workflow.tasks: task.rank = task_ranks[task] sorted_tasks = self.workflow.sort_tasks('rank') for node in sorted_tasks: self.assertTrue(rank_values[node.tid] == int(node.rank)) def test_schedule(self): solution = heft(self.workflow) self.assertEqual(80, solution.makespan)
class TestPHeftMethods(unittest.TestCase): def setUp(self): self.workflow = Workflow(cfg.test_heuristic_data['pheft_graph']) env = Environment(cfg.test_workflow_data['topcuoglu_graph_system']) self.workflow.add_environment(env) self.up_oct_rank_values = [72, 41, 37, 43, 31, 41, 17, 20, 16, 0] self.up_rank_values = [169, 114, 102, 110, 129, 119, 52, 92, 42, 20] def tearDown(self): return -1 def test_up_rank(self): task_ranks = calculate_upward_ranks(self.workflow) # upward_rank(self.workflow) for task in self.workflow.tasks: task.rank = task_ranks[task] sorted_tasks = self.workflow.sort_tasks('rank') for node in sorted_tasks: self.assertTrue(int(node.rank) == self.up_rank_values[node.tid]) def test_oct_rank(self): oct_rank_matrix = generate_ranking_matrix(self.workflow) # upward_oct_rank(self.workflow, oct_rank_matrix) for task in self.workflow.tasks: sum = 0 for (t, p) in oct_rank_matrix: if t is task: sum += oct_rank_matrix[(t, p)] rank = int(sum / len(self.workflow.env.machines)) task.rank = rank sorted_tasks = self.workflow.sort_tasks('rank') for node in sorted_tasks: self.assertEqual(self.up_oct_rank_values[node.tid], node.rank) def test_heft_schedule(self): # upward_rank(self.workflow) solution = heft(self.workflow) self.assertTrue(solution.makespan == 133) def test_pheft_schedule(self): # upward_rank(self.workflow) solution = pheft(self.workflow) self.assertTrue(solution.makespan == 122)
class TestWorkflowSorting(unittest.TestCase): def setUp(self) -> None: self.workflow = Workflow("{0}/{1}".format(current_dir, cfg.test_workflow_data['topcuoglu_graph'])) def test_topological_sort(self): task_list = list(self.workflow.sort_tasks("topological")) task_order = [t.tid for t in task_list] self.assertSequenceEqual([0, 5, 4, 3, 2, 6, 1, 8, 7, 9], task_order)