Example #1
0
 def test_acyclic_graph(self):
     v1 = 'vertex 1'
     v2 = 'vertex 2'
     v3 = 'vertex 3'
     graph = {v1: [v2, v3], v2: [v3], v3: []}
     sorted_vertices = topological_sort(graph)
     self.assertTrue(len(sorted_vertices) == len(graph))
     self.assertTrue(v3 is sorted_vertices[0])
Example #2
0
 def test_disconnected_graph(self):
     v1 = 'vertex 1'
     v2 = 'vertex 2'
     v3 = 'vertex 3'
     graph = {v1: [], v2: [], v3: []}
     sorted_vertices = topological_sort(graph)
     for v in (v1, v2, v3):
         self.assertTrue(v in sorted_vertices, v)
     self.assertTrue(len(sorted_vertices) == len(graph))
 def test_acyclic_graph(self):
     v1 = 'vertex 1'
     v2 = 'vertex 2'
     v3 = 'vertex 3'
     graph = {v1: [v2, v3],
              v2: [v3],
              v3: []}
     sorted_vertices = topological_sort(graph)
     self.assertTrue(len(sorted_vertices) == len(graph))
     self.assertTrue(v3 is sorted_vertices[0])
 def test_disconnected_graph(self):
     v1 = 'vertex 1'
     v2 = 'vertex 2'
     v3 = 'vertex 3'
     graph = {v1: [],
              v2: [],
              v3: []}
     sorted_vertices = topological_sort(graph)
     for v in (v1, v2, v3):
         self.assertTrue(v in sorted_vertices, v)
     self.assertTrue(len(sorted_vertices) == len(graph))
Example #5
0
 def _analyze_dependencies(self, task_list):
     # build a dependency graph to check the user-defined dependencies
     call_request_map = dict((task.call_request.id, task) for task in task_list)
     dependency_graph = {}
     for task in task_list:
         dependency_graph[task] = [call_request_map[id] for id in task.call_request.dependencies]
     # check the dependencies with a topological sort
     try:
         sorted_task_list = topological_sort(dependency_graph)
     except NoTopologicalOrderingExists:
         raise dispatch_exceptions.CircularDependencies(), None, sys.exc_info()[2]
     # add the dependencies as actual blocking tasks
     for task in sorted_task_list:
         dependency_tasks = [call_request_map[id].id for id in task.call_request.dependencies]
         task.blocking_tasks.update(dependency_tasks)
     return sorted_task_list
Example #6
0
    def _analyze_dependencies(self, task_list):
        """
        Analyze and validate the user-defined dependencies among a list of tasks.
        @param task_list: list of tasks
        @type task_list: list
        @return: sorted task list
        @rtype: list
        """

        call_request_map = dict((task.call_request.id, task) for task in task_list)
        dependency_graph = dict((task.call_request.id, task.call_request.dependencies.keys()) for task in task_list)

        # check the dependencies with a topological sort and get a valid order
        # in which to enqueue the tasks

        sorted_call_request_ids = topological_sort(dependency_graph)

        sorted_task_list = [call_request_map[id] for id in sorted_call_request_ids]
        return sorted_task_list
Example #7
0
    def _analyze_dependencies(self, task_list):
        """
        Analyze and validate the user-defined dependencies among a list of tasks.
        @param task_list: list of tasks
        @type task_list: list
        @return: sorted task list
        @rtype: list
        """

        call_request_map = dict(
            (task.call_request.id, task) for task in task_list)
        dependency_graph = dict(
            (task.call_request.id, task.call_request.dependencies.keys())
            for task in task_list)

        # check the dependencies with a topological sort and get a valid order
        # in which to enqueue the tasks

        sorted_call_request_ids = topological_sort(dependency_graph)

        sorted_task_list = [
            call_request_map[id] for id in sorted_call_request_ids
        ]
        return sorted_task_list