Пример #1
0
        void ProcessNeighbor(GenericBinaryHeapPriorityQueue <VisibilityVertex> pq, VisibilityEdge l,
                             VisibilityVertex v)
        {
            var len = l.Length;
            var c   = _current.Distance + len;

            if (c >= upperBound)
            {
                return;
            }
            if (targets.Contains(v))
            {
                upperBound    = c;
                closestTarget = v;
            }
            if (v != sources && _visGraph.PreviosVertex(v) == null)
            {
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                pq.Enqueue(v, c);
            }
            else if (c < v.Distance)
            {
                //This condition should never hold for the dequeued nodes.
                //However because of a very rare case of an epsilon error it might!
                //In this case DecreasePriority will fail to find "v" and the algorithm will continue working.
                //Since v is not in the queue changing its .Distance will not mess up the queue.
                //Changing v.Prev is fine since we come up with a path with an insignificantly
                //smaller distance.
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                pq.DecreasePriority(v, c);
            }
        }
        void ProcessBoneEdge(SdVertex v, SdVertex queueCandidate, SdBoneEdge boneEdge)
        {
            double newCost = GetEdgeAdditionalCost(boneEdge, v.Cost);

            if (queueCandidate.Cost <= newCost)
            {
                return;
            }
            queueCandidate.Cost     = newCost;
            queueCandidate.PrevEdge = boneEdge;
            if (Queue.ContainsElement(queueCandidate))
            {
                Queue.DecreasePriority(queueCandidate, newCost);
            }
            else
            {
                if (queueCandidate.IsTargetOfRouting)
                {
                    double costToTarget = 0;
                    if (CurrentEdgeGeometry.TargetPort is ClusterBoundaryPort)
                    {
                        costToTarget = LengthCoefficient * (queueCandidate.Point - CurrentEdgeGeometry.TargetPort.Location).Length;
                    }

                    if (newCost + costToTarget < LowestCostToTarget)
                    {
                        LowestCostToTarget  = newCost + costToTarget;
                        ClosestTargetVertex = queueCandidate;
                    }
                    return; //do not enqueue the target vertices
                }
                Enqueue(queueCandidate);
            }
        }
        void ProcessEdge(Edge edge, LgNodeInfo otherVert, double cost)
        {
            if (otherVert.Processed)
            {
                return;
            }
            var    len     = (edge.Source.Center - edge.Target.Center).Length;
            double newCost = len + cost;

            if (newCost >= otherVert.Cost)
            {
                return;
            }
            otherVert.Prev = edge;
            if (otherVert.Cost == double.PositiveInfinity)
            {
                otherVert.Cost = newCost;
                q.Enqueue(otherVert, newCost);
            }
            else
            {
                otherVert.Cost = newCost;
                q.DecreasePriority(otherVert, newCost);
            }
        }
        void ProcessNeighbor(GenericBinaryHeapPriorityQueue <VisibilityVertex> pq, VisibilityVertex u, VisibilityEdge l, VisibilityVertex v)
        {
            var len = l.Length;
            var c   = u.Distance + len;

            if (v != source && _visGraph.PreviosVertex(v) == null)
            {
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                if (v != target)
                {
                    pq.Enqueue(v, H(v));
                }
            }
            else if (c < v.Distance)     //This condition should never hold for the dequeued nodes.
            //However because of a very rare case of an epsilon error it might!
            //In this case DecreasePriority will fail to find "v" and the algorithm will continue working.
            //Since v is not in the queue changing its .Distance will not influence other nodes.
            //Changing v.Prev is fine since we come up with the path with an insignificantly
            //smaller distance.
            {
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                if (v != target)
                {
                    pq.DecreasePriority(v, H(v));
                }
            }
        }
        private void UpdateEntryToNeighborVertexIfNeeded(VertexEntry bestEntry, VertexEntry neigEntry, double weight)
        {
            int    numberOfBends;
            double length;
            var    dirToNeighbor = GetLengthAndNumberOfBendsToNeighborVertex(bestEntry, neigEntry.Vertex, weight, out numberOfBends, out length);

            if (CombinedCost(length, numberOfBends) < CombinedCost(neigEntry.Length, neigEntry.NumberOfBends))
            {
                var newCost = this.TotalCostFromSourceToVertex(length, numberOfBends) + HeuristicDistanceFromVertexToTarget(neigEntry.Vertex.Point, dirToNeighbor);
                neigEntry.ResetEntry(bestEntry, length, numberOfBends, newCost);
                queue.DecreasePriority(neigEntry, newCost);
            }
        }
        void ProcessNeighbor(GenericBinaryHeapPriorityQueue <VisibilityVertex> pq, VisibilityVertex u, VisibilityEdge l, VisibilityVertex v, int penalty)
        {
            var len = l.Length + penalty;
            var c   = u.Distance + len;

            /*
             * if (_visGraph.visVertexToId[l.Source] < _g.N || _visGraph.visVertexToId[l.Target] < _g.N)
             * {
             *  if (!(l.Source == _source || l.Target == _source || l.Source == _target || l.Target == _target))
             *  {
             *      c = 500;
             *  }
             * }
             */
            // (v != _source && _visGraph.PreviosVertex(v) == null)

            if (v != _source && _visGraph.PreviosVertex(v) == null)
            {
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                if (v != _target)
                {
                    pq.Enqueue(v, H(v));
                }
            }
            else if (v != _source && c < v.Distance)
            { //This condition should never hold for the dequeued nodes.
                //However because of a very rare case of an epsilon error it might!
                //In this case DecreasePriority will fail to find "v" and the algorithm will continue working.
                //Since v is not in the queue changing its .Distance will not influence other nodes.
                //Changing v.Prev is fine since we come up with the path with an insignificantly
                //smaller distance.
                var prevV = _visGraph.PreviosVertex(v);
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                if (v != _target)
                {
                    pq.DecreasePriority(v, H(v));
                }
            }
        }
 void ProcessNeighbor(GenericBinaryHeapPriorityQueue<VisibilityVertex> pq, VisibilityEdge l,
                      VisibilityVertex v) {
     var len = l.Length;
     var c = current.Distance + len;
     if (c >= upperBound)
         return;
     if (targets.Contains(v)) {
         upperBound = c;
         closestTarget = v;
     }
     if (v != source && _visGraph.PreviosVertex(v) == null) {
         v.Distance = c;
         _visGraph.SetPreviousEdge(v, l);
         pq.Enqueue(v, c);
     } else if (c < v.Distance) {
         //This condition should never hold for the dequeued nodes.
         //However because of a very rare case of an epsilon error it might!
         //In this case DecreasePriority will fail to find "v" and the algorithm will continue working.
         //Since v is not in the queue changing its .Distance will not mess up the queue.
         //Changing v.Prev is fine since we come up with a path with an insignificantly
         //smaller distance.
         v.Distance = c;
         _visGraph.SetPreviousEdge(v, l);
         pq.DecreasePriority(v, c);
     }
 }
        void ProcessNeighbor(GenericBinaryHeapPriorityQueue<VisibilityVertex> pq, VisibilityVertex u, VisibilityEdge l, VisibilityVertex v) {
            var len = l.Length;
            var c = u.Distance + len;

            // (v != _source && _visGraph.PreviosVertex(v) == null)

            if (v != _source && _visGraph.PreviosVertex(v) == null) {
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                if (v != _target) {
                    pq.Enqueue(v, H(v));
                }
            } else if (v != _source && c < v.Distance) { //This condition should never hold for the dequeued nodes.
                //However because of a very rare case of an epsilon error it might!
                //In this case DecreasePriority will fail to find "v" and the algorithm will continue working.
                //Since v is not in the queue changing its .Distance will not influence other nodes.
                //Changing v.Prev is fine since we come up with the path with an insignificantly
                //smaller distance.
                var prevV = _visGraph.PreviosVertex(v);
                v.Distance = c;
                _visGraph.SetPreviousEdge(v, l);
                if (v != _target)
                    pq.DecreasePriority(v, H(v));
            }
        }