Ejemplo n.º 1
0
        /// <summary>
        /// Relax the edge and update the priority queue if needed.
        /// </summary>
        /// <param name="edge">the edge</param>
        /// <param name="source">the source vertex where the edge leads from</param>
        private void Relax(WeightedGraphEdge edge, int source)
        {
            int v, w;

            if (source == edge.From)
            {
                v = edge.From;
                w = edge.To;
            }
            else
            {
                v = edge.To;
                w = edge.From;
            }
            if (distTo[w] > distTo[v] + edge.Cost)
            {
                distTo[w] = distTo[v] + edge.Cost;
                edgeTo[w] = edge;
                if (pq.Contains(w))
                {
                    pq.DecreaseKey(w, distTo[w]);
                }
                else
                {
                    pq.Insert(w, distTo[w]);
                }
            }
        }
Ejemplo n.º 2
0
        /**
         * Relax the edge and update the priority queue if needed.
         * @param edge the edge
         * @param source the source vertex where the edge leads from
         */
        private void Relax(WeightedGraphEdge edge, int source)
        {
            int v, w;

            if (source == edge.From)
            {
                v = edge.From;
                w = edge.To;
            }
            else
            {
                v = edge.To;
                w = edge.From;
            }
            // UnityEngine.Debug.Log("find distance from " + w+" to "+v);
            if (distTo[w] > distTo[v] + edge.Cost)
            {
                distTo[w] = distTo[v] + edge.Cost;
                edgeTo[w] = edge;
                if (pq.Contains(w))
                {
                    pq.DecreaseKey(w, distTo[w]);
                }
                else
                {
                    pq.Insert(w, distTo[w]);
                }
            }
        }