def test_viztracing_vertex_only(self):
     self.vertices = {
         0: [1],
         1: [2, 3],
         2: [3],
         3: [4, 6],
         4: [5, 6],
         5: [5],
         6: [6]
     }
     self.directed_graph = DirectedGraph(self.vertices)
     vertex_1 = self.directed_graph.get_vertex(1)
     vertex_1.set_attr("activated", True)
     vertex_2 = self.directed_graph.get_vertex(2)
     vertex_2.set_attr("in_cycle", True)
     pt.create_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH)
     VizTracing.enable(pt.get_dir_in_user_home(
         TestDirectedGraph.RESOURCES_PATH),
                       self.directed_graph,
                       vertex_states=[{
                           VizTracing.ACTIVATED: {
                               "fillcolor": "red",
                               "style": "filled"
                           }
                       }, {
                           VizTracing.IN_CYCLE: {
                               "fillcolor": "blue",
                               "style": "filled"
                           }
                       }])
     VizTracing.snapshot()
     self.assertTrue(True)
def viztrace(vertices, resource_path):
    """ Main function that takes a number of vertices (of a directed graph),
    invokes the cycle check functionality (which in turn creates the traced images),
    and converts the images to a video
    
    Args:
        vertices(dict): a dictionar with vertices and for each vertex its destination
            vertices
        resource_path: the path that should contain the generated resources

    """

    directed_graph = DirectedGraph(vertices)
    work_path = path.join(RESOURCES_PATH, resource_path)
    pt.create_dir_in_user_home(work_path)
    VizTracing.enable(
        pt.get_dir_in_user_home(work_path), 
        directed_graph,
        vertex_states=[
                    {VizTracing.ACTIVATED: {"fillcolor":"red", "style": "filled"}}, 
                    {VizTracing.IN_CYCLE: {"fillcolor":"blue", "style": "filled"}},
                    {VizTracing.VISISTED: {"fillcolor":"gray", "style": "filled"}}])
    directed_graph.is_cyclic()
    viztrace_log_finish(directed_graph)
    vt.convert_images_to_video(pt.get_dir_in_user_home(work_path))
 def test_viztracing_activate_vertex(self):
     self.vertices = {
         0: [1],
         1: [2, 3],
         2: [3],
         3: [4, 6],
         4: [5, 6],
         5: [5],
         6: [6]
     }
     self.directed_graph = DirectedGraph(self.vertices)
     vertex_1 = self.directed_graph.get_vertex(1)
     pt.create_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH)
     VizTracing.enable(pt.get_dir_in_user_home(
         TestDirectedGraph.RESOURCES_PATH),
                       self.directed_graph,
                       vertex_states=[{
                           VizTracing.ACTIVATED: {
                               "fillcolor": "red",
                               "style": "filled"
                           }
                       }, {
                           VizTracing.IN_CYCLE: {
                               "fillcolor": "blue",
                               "style": "filled"
                           }
                       }])
     VizTracing.change_activated_vertex(self.directed_graph, vertex_1)
     for label, vertex in self.directed_graph.get_vertices().items():
         if vertex_1.get_label() == label:
             self.assertTrue(vertex.get_attr(VizTracing.ACTIVATED))
         else:
             self.assertFalse(vertex.get_attr(VizTracing.ACTIVATED))
 def test_viztracing_default(self):
     pt.create_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH)
     VizTracing.enable(
         pt.get_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH),
         self.directed_graph)
     VizTracing.snapshot()
     self.assertTrue(True)
def viztrace_log_finish(directed_graph):
    """ Viz traces the first vertex 

    Args:
        directed_graph(DirectedGraph): the directed graph in question

    """

    starting_vertex = next(iter(directed_graph.get_vertices().items()))[1]
    VizTracing.change_activated_vertex(directed_graph, starting_vertex)    
    VizTracing.snapshot()
def viztrace_vertex(directed_graph, vertex):
    """ Changes focus to the vertex and takes a snapshot

    Args:
        directed_graph (DirectedGraph): The directed graph
        vertex: the vertex that should get the status activated

    """

    VizTracing.change_activated_vertex(directed_graph, vertex)
    VizTracing.snapshot()
Exemplo n.º 7
0
 def test_viztracing_cyclic(self):
     Logging.enable()
     self.vertices = {0: [1], 1: [2, 3], 2: [3],
                      3: [4, 6], 4: [5, 6], 5: [7, 8], 6:[7, 8], 
                      7: [9, 10, 11], 8: [3], 9: [], 
                      10: [11], 11: [12], 12: []}
     self.directed_graph = DirectedGraph(self.vertices)        
     pt.create_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH)
     VizTracing.enable(
         pt.get_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH), 
         self.directed_graph,
         vertex_states=[
                 {VizTracing.ACTIVATED: {"fillcolor":"red", "style": "filled"}}, 
                 {VizTracing.IN_CYCLE: {"fillcolor":"blue", "style": "filled"}},
                 {VizTracing.VISISTED: {"fillcolor":"gray", "style": "filled"}}])
     self.assertTrue(self.directed_graph.is_cyclic())       
Exemplo n.º 8
0
 def test_viztracing_snapshot(self):
     pt.create_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH)
     VizTracing.enable(pt.get_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH), self.directed_graph)
     VizTracing.snapshot() 
     self.assertTrue(os.path.exists(path.join(pt.get_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH),
         VizTracing.IMAGE_NAME_PREFIX + ("{:04d}".format(VizTracing.snapshot_no - 1)) + "." + 
         VizTracing.IMAGE_TYPE)))
     VizTracing.snapshot() 
     self.assertTrue(os.path.exists(path.join(pt.get_dir_in_user_home(TestDirectedGraph.RESOURCES_PATH),
         VizTracing.IMAGE_NAME_PREFIX + ("{:04d}".format(VizTracing.snapshot_no - 1)) + "." + 
         VizTracing.IMAGE_TYPE)))
def viztrace_cycle_found(directed_graph, tail, head):
    """ Changes the state of a vertex when the vertex is part of a cycle

    Args:
        directed_graph (DirectedGraph): The directed graph
        tail: the tail vertex that should get the status activated
        head: the head vertex that should get the in_cycle status

    """
        
    VizTracing.set_status(directed_graph, head, VizTracing.IN_CYCLE)
    VizTracing.change_activated_vertex(directed_graph, head)    
    VizTracing.snapshot()
def viztrace_visit_tail(directed_graph, vertex):
    """ Function that is used to tag vertices with the state "visisted", 
    if these vertices have been visited once. So next time, when another predecessor
    of a tagged vertex is being considered, it is skipped

    Args:
        directed_graph (DirectedGraph): The directed graph
        vertex: the vertex that should get the status "visited"

    """
    VizTracing.change_activated_vertex(directed_graph, vertex)
    VizTracing.set_status(directed_graph, vertex, VizTracing.VISISTED)
    VizTracing.snapshot()
def viztrace_cycle_reported(directed_graph, vertex):
    """ Function that is used along the way back from the origin
    of the cycle detection to the initial state. Along the way,
    all vertices are tagged with the state in_cycle

    Args:
        directed_graph (DirectedGraph): The directed graph
        vertex: the vertex that should get the status activated

    """    
    VizTracing.set_status(directed_graph, vertex, VizTracing.IN_CYCLE)
    VizTracing.change_activated_vertex(directed_graph, vertex)    
    VizTracing.snapshot()