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_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()
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()
Esempio n. 4
0
 def test_viztracing_set_status(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_5 = self.directed_graph.get_vertex(5)
     vertex_6 = self.directed_graph.get_vertex(6)
     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.set_status(self.directed_graph, vertex_5, VizTracing.IN_CYCLE)
     VizTracing.set_status(self.directed_graph, vertex_6, VizTracing.IN_CYCLE)
     for label, vertex in self.directed_graph.get_vertices().items():
         if vertex_5.get_label() == label or vertex_6.get_label() == label:
             self.assertTrue(vertex.get_attr(VizTracing.IN_CYCLE))
         else:
             self.assertFalse(vertex.get_attr(VizTracing.IN_CYCLE))