Пример #1
0
 def __call__(self):
     if self.length_limit is None:
         can_extend = self.is_acyclic
     else:
         can_extend = lambda path: len(path) < self.length_limit
     v = self.PathBuilderVisitor(self.graph.roots, can_extend=can_extend)
     r = graph.DFS(self.graph).scan(v)
     while r.dirty:
         r.accept()
         r = graph.DFS(self.graph).scan(v)
     return r
Пример #2
0
 def __call__(self):
     nodes = graph.DFS(self.graph).scan(graph.CollectNodesVisitor())
     partition = Partition(self.graph)
     for component in self.collapsing:
         partition.add_component(Partition.Component(component))
         nodes.difference_update(component)
     for node in nodes:
         partition.add_component(Partition.Component([node]))
     return partition
Пример #3
0
 def __init__(self, g, scan=None):
     """
     @param g the graph
     @param scan a GraphScan object; the scanning method may
       yield different path-finding algorithms. The default is DFS(g).
     """
     if scan is None: scan = graph.DFS(g)
     self.graph = g
     self.scan = scan
Пример #4
0
 def clone_with_visitor(cls, g, roots=None, without=set(), visitor=None):
     cloned = copy.copy(g)
     if roots is None: roots = g.roots
     scan = graph.DFS(g, roots)
     if visitor is None:
         visitor = CloneVisitor(without=without)
     scan.scan(visitor)
     cloned.roots = visitor.clone_roots(roots)
     if isinstance(g, AttributesClone):
         cloned.clone_attributes_from(g, visitor.cloned_nodes)
     return cloned, visitor
Пример #5
0
 def __call__(self):
     visitor = self.Visitor(self.graph, self.connect_criterion)
     return graph.DFS(self.graph).scan(visitor)
Пример #6
0
 def __call__(self):
     colormap = graph.DFS(self.g).scan(self.Visitor(self.coloring))
     partition = Partition(self.g)
     for component in colormap.values():
         partition.add_component(component)
     return partition
Пример #7
0
 def dump(cls, g):
     roots = [id(node) for node in g.roots]
     return (roots, ) + graph.DFS(g).scan(cls.StoreVisitor())
Пример #8
0
 def get_crossing_edges(self, g):
     scan = graph.DFS(g)
     visitor = CutVisitor(self)
     scan.scan(visitor)
     return visitor.crossing