Exemple #1
0
 protected virtual void Relax(EdgeWeightedDigraph digraph, int vertex)
 {
     foreach (var edge in digraph.Adjacent(vertex))
     {
         int w = edge.W;
         if (distanceTo[w] > distanceTo[vertex] + edge.Weight)
         {
             distanceTo[w] = distanceTo[vertex] + edge.Weight;
             edgeTo[w]     = edge;
         }
     }
 }
Exemple #2
0
        protected override void Relax(EdgeWeightedDigraph digraph, int vertex)
        {
            foreach (var edge in digraph.Adjacent(vertex))
            {
                int w = edge.W;
                if (distanceTo[w] > distanceTo[vertex] + edge.Weight)
                {
                    distanceTo[w] = distanceTo[vertex] + edge.Weight;
                    edgeTo[w]     = edge;

                    if (priorityQueue.Contains(w))
                    {
                        priorityQueue.Change(w, distanceTo[w]);
                    }
                    else
                    {
                        priorityQueue.Insert(w, distanceTo[w]);
                    }
                }
            }
        }