def main(prt=sys.stdout): filename = sys.argv[1] delimiter = sys.argv[2] sg = SymbolDigraph(filename, delimiter) topological = Topological(sg.G()) for v in topological.order(): prt.write(sg.name(v))
def __init__(self, G, s): # G=DAG, v=source vertex O(V+E) self._distTo = [self.Inf for i in range(G.V())] # distance of shortest s->v path self._edgeTo = [None for i in range(G.V())] # last edge on shortest s->v path self._distTo[s] = 0.0 # visit vertices in toplogical order topological = Topological(G) if not topological.hasOrder(): raise Exception("Digraph is not acyclic.") for v in topological.order(): for e in G.adj(v): self.relax(e)
def __init__(self, G, s): # G=DAG, v=source vertex O(V+E) self._distTo = [self.Inf for i in range(G.V()) ] # distance of shortest s->v path self._edgeTo = [None for i in range(G.V()) ] # last edge on shortest s->v path self._distTo[s] = 0.0 # visit vertices in toplogical order topological = Topological(G) if not topological.hasOrder(): raise Exception("Digraph is not acyclic.") for v in topological.order(): for e in G.adj(v): self.relax(e)