Exemplo n.º 1
0
  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)
Exemplo n.º 2
0
    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)