Exemplo n.º 1
0
 private void Visit(EdgeWeightedGraph graph, int v)
 {
     _marked[v] = true;
     foreach (Edge edge in graph.Adj(v))
     {
         int w = edge.Other(v);
         if (_marked[w])
         {
             continue;
         }
         if (edge.Weight < _distTo[w])
         {
             _edgeTo[w] = edge;
             _distTo[w] = edge.Weight;
             if (_pq.contains(w))
             {
                 _pq.change(w, _distTo[w]);
             }
             else
             {
                 _pq.insert(w, _distTo[w]);
             }
         }
     }
 }
Exemplo n.º 2
0
        private void visit(EdgeWeightedGraph G, int v)
        {
            mark[v] = true;
            foreach (Edge e in G.adj(v))
            {
                int w = e.other(v);

                if (mark[w])
                {
                    continue;
                }
                if (e.getWeight() < distTo[w])
                {
                    edgeTo[w] = e;
                    distTo[w] = e.getWeight();
                    if (pq.contains(w))
                    {
                        pq.change(w, distTo[w]);
                    }
                    else
                    {
                        pq.insert(w, distTo[w]);
                    }
                }
            }
        }
Exemplo n.º 3
0
 private void scan(EdgeWeightedGraph G, int v)
 {
     marked[v] = true;
     foreach (Edge e in G.Adj(v))
     {
         int w = e.other(v);
         if (marked[w])
         {
             continue;                    // v-w is obsolete edge
         }
         if (e.Weight() < distTo[w])
         {
             distTo[w] = e.Weight();
             edgeTo[w] = e;
             if (pq.contains(w))
             {
                 pq.decreaseKey(w, distTo[w]);
             }
             else
             {
                 pq.insert(w, distTo[w]);
             }
         }
     }
 }
Exemplo n.º 4
0
 // relax edge e and update pq if changed
 private void relax(Edge e, int v) {
     int w = e.other(v);
     if (distTo[w] > distTo[v] + e.weight()) {
         distTo[w] = distTo[v] + e.weight();
         edgeTo[w] = e;
         if (pq.contains(w)) pq.decreaseKey(w, distTo[w]);
         else                pq.insert(w, distTo[w]);
     }
 }
Exemplo n.º 5
0
 // relax edge e and update pq if changed
 private void relax(DirectedEdge e) {
     int v = e.from(), w = e.to();
     if (distTo[w] > distTo[v] + e.weight()) {
         distTo[w] = distTo[v] + e.weight();
         edgeTo[w] = e;
         if (pq.contains(w)) pq.decreaseKey(w, distTo[w]);
         else                pq.insert(w, distTo[w]);
     }
 }
Exemplo n.º 6
0
 // scan vertex v
 private void scan(EdgeWeightedGraph G, int v) {
     marked[v] = true;
     for (Edge e : G.adj(v)) {
         int w = e.other(v);
         if (marked[w]) continue;         // v-w is obsolete edge
         if (e.weight() < distTo[w]) {
             distTo[w] = e.weight();
             edgeTo[w] = e;
             if (pq.contains(w)) pq.decreaseKey(w, distTo[w]);
             else                pq.insert(w, distTo[w]);
         }
     }
 }