def __init__(self, G): super(Topological, self).__init__() cyclefinder = DirectedCycle(G) if not cyclefinder.has_cycle(): dfo = DepthFirstOrder(G) self.order = dfo.get_reversePost() else: self.order = []
def __init__(self, G): self.orders = [] cyclefinder = DirectedCycle(G) if not cyclefinder.hasCycle(): dfs = DepthFirstOrder(G) self.orders = dfs.reversePost() else: print("G hasCycle:", end=' ') print(cyclefinder.cycle())
def __init__(self, G): self.counts = 0 self.markeds = [False] * G.V() self.ids = [0] * G.V() order = DepthFirstOrder(G.reverse()) for s in order.reversePost(): if not self.markeds[s]: self.dfs(G, s) self.counts += 1
def topological_order(sg): graph = sg.graph() finder = DirectedCycle(graph) if finder.has_cycle(): yield 'has_cycle' return dfs = DepthFirstOrder(graph) for v in dfs.reverse_post: yield (sg.name(v))
def __init__(self, G): super(KosarajuSCC, self).__init__() self.marked = [0 for i in xrange(G.Vcount())] self.id = [-1 for i in xrange(G.Vcount())] self.count = 0 order = DepthFirstOrder(G.reverse()) for s in order.get_reversePost()[::-1]: # pop the reverse post stack if not self.marked[s]: self.dfs(G, s) self.count += 1
def __init__(self, G): finder = DirectedCycle(G) if finder.has_cycle() is False: dfo = DepthFirstOrder(G) self.__order = dfo.reverse_post() self.__rank = [0] * G.V() for index, v in enumerate(self.__order): self.__rank[v] = index else: self.__order = None
def __init__(self, G): # count is the number of connected coponents in the digraph self._depth_first_order = DepthFirstOrder(G.reverse()) self._count = 0 self._marked = [False] * G.V() self._id = [0] * G.V() # size of each component self._size = [0] * G.V() for v in self._depth_first_order.reverse_postorder(): if not self._marked[v]: self._dfs(G, v) self._count += 1