Ejemplo n.º 1
0
        private void Relax(Edge edge)
        {
            //get the source and target vertex of the edge
            int v = edge.Source, w = edge.Target;

            /*
             * _distTo[w] contains the shortest path so far to the
             * vertex w so we can compare it to the weight of of going through
             * v, if it is less use the new path instead
             * */
            if (_distanceTo[w] > _distanceTo[v] + edge.Weight)
            {
                //set the distance to w to the new(lower) weight
                _distanceTo[w] = _distanceTo[v] + edge.Weight;
                //add the edge to the list of edges in our shortest paths
                _edgeTo[w] = edge;
                if (_priorityQueue.Contains(w))
                {
                    /*
                     * if w is already in the priority que update its minimum path and re-order the que
                     * */
                    _priorityQueue.DecreaseKey(w, _distanceTo[w]);
                }
                else
                {
                    _priorityQueue.Insert(w, _distanceTo[w]);
                }
            }
        }