Beispiel #1
0
        private void Relax(DirectedWeightedEdge edge)
        {
            int from = edge.From();
            int to   = edge.To();

            if (_distTo[to] > _distTo[from] + edge.Weight())
            {
                _distTo[to] = _distTo[from] + edge.Weight();
                _edgeTo[to] = edge;
            }
        }
Beispiel #2
0
        private void Relax(DirectedWeightedEdge edge, int target)
        {
            var u = edge.To();
            var v = edge.From();

            if (distTo[u] > distTo[v] + edge.Weight())
            {
                distTo[u] = distTo[v] + edge.Weight();
                edgeTo[u] = edge;

                if (pq.Contains(u))
                {
                    pq.DecreaseKey(u, heuristic(target, u) + distTo[u]);
                }
                else
                {
                    pq.Insert(u, heuristic(target, u) + distTo[u]);
                }
            }
        }