Пример #1
0
        /// <summary>
        /// Returns  a  path
        /// </summary>
        /// <returns>a path or null if the target is not reachable from the source</returns>
        internal IEnumerable <VisibilityVertex> GetPath()
        {
            var pq = new GenericBinaryHeapPriorityQueue <VisibilityVertex>();

            foreach (var v in sources)
            {
                v.Distance = 0;
                pq.Enqueue(v, 0);
            }
            while (!pq.IsEmpty())
            {
                _current = pq.Dequeue();
                if (targets.Contains(_current))
                {
                    break;
                }

                foreach (var e in _current.OutEdges.Where(PassableOutEdge))
                {
                    ProcessNeighbor(pq, e, e.Target);
                }

                foreach (var e in _current.InEdges.Where(PassableInEdge))
                {
                    ProcessNeighbor(pq, e, e.Source);
                }
            }

            return(_visGraph.PreviosVertex(_current) == null ? null : CalculatePath());
        }
        List <SdBoneEdge> RouteOnKnownSourceTargetVertices(Point pathDirection, bool lookingForMonotonePath)
        {
            LowestCostToTarget  = Double.PositiveInfinity;
            ClosestTargetVertex = null;
            while (Queue.Count > 0)
            {
                double   hu;
                SdVertex bestNode = Queue.Dequeue(out hu);
                if (hu >= LowestCostToTarget)
                {
                    continue;
                }
                //update the rest
                for (int i = 0; i < bestNode.OutBoneEdges.Count; i++)
                {
                    var outBoneEdge = bestNode.OutBoneEdges[i];
                    if (outBoneEdge.IsPassable)
                    {
                        ProcessOutcomingBoneEdge(bestNode, outBoneEdge, pathDirection, lookingForMonotonePath);
                    }
                }

                for (int i = 0; i < bestNode.InBoneEdges.Count; i++)
                {
                    var inBoneEdge = bestNode.InBoneEdges[i];
                    if (inBoneEdge.IsPassable)
                    {
                        ProcessIncomingBoneEdge(bestNode, inBoneEdge, pathDirection, lookingForMonotonePath);
                    }
                }
            }

            return(GetPathAndUpdateRelatedCosts());
        }
Пример #3
0
        /// <summary>
        /// Grow hubs
        /// </summary>
        bool GrowHubs(bool useHalfEdgesAsIdealR)
        {
            var queue = new GenericBinaryHeapPriorityQueue <Station>();

            foreach (var v in metroGraphData.VirtualNodes())
            {
                queue.Enqueue(v, -CalculatePotential(v, useHalfEdgesAsIdealR));
            }

            bool progress = false;

            //choose a hub with the greatest potential
            while (!queue.IsEmpty())
            {
                double  hu;
                Station v = queue.Dequeue(out hu);
                if (hu >= 0)
                {
                    break;
                }

                //grow the hub
                if (TryGrowHub(v, useHalfEdgesAsIdealR))
                {
                    queue.Enqueue(v, -CalculatePotential(v, useHalfEdgesAsIdealR));
                    progress = true;
                }
            }
            return(progress);
        }
        /// <summary>
        /// Returns  a  path
        /// </summary>
        /// <returns>a path or null if the target is not reachable from the source</returns>
        internal IEnumerable<VisibilityVertex> GetPath(bool shrinkEdgeLength) {
            var pq = new GenericBinaryHeapPriorityQueue<VisibilityVertex>();

            _source.Distance = 0;
            _target.Distance = double.PositiveInfinity;
            pq.Enqueue(_source, H(_source));

            while (!pq.IsEmpty()) {
                double hu;
                var u = pq.Dequeue(out hu);
                if (hu >= _target.Distance)
                    break;

                foreach (var e in u.OutEdges) {
                    if (PassableOutEdge(e)) {
                        var v = e.Target;
                        ProcessNeighbor(pq, u, e, v);
                    }
                }

                foreach (var e in u.InEdges) {
                    if (PassableInEdge(e)) {
                        var v = e.Source;
                        ProcessNeighbor(pq, u, e, v);
                    }
                }

            }
            return _visGraph.PreviosVertex(_target) == null
                ? null
                : CalculatePath(shrinkEdgeLength);
        }
 internal void Run()
 {
     source.Cost      = 0;
     source.Processed = true;
     q.Enqueue(source, 0);
     while (q.Count > 0)
     {
         double cost;
         var    n = q.Dequeue(out cost);
         ProcessNode(n);
     }
 }
        /// <summary>
        /// Returns  a  path
        /// </summary>
        /// <returns>a path or null if the target is not reachable from the source</returns>
        internal IEnumerable <VisibilityVertex> GetPath(bool shrinkEdgeLength)
        {
            var pq = new GenericBinaryHeapPriorityQueue <VisibilityVertex>();

            _source.Distance = 0;
            _target.Distance = double.PositiveInfinity;
            pq.Enqueue(_source, H(_source));

            while (!pq.IsEmpty())
            {
                double hu;
                var    u = pq.Dequeue(out hu);
                if (hu >= _target.Distance)
                {
                    break;
                }

                foreach (var e in u.OutEdges)
                {
                    if (PassableOutEdge(e))
                    {
                        var v = e.Target;
                        if (u != _source && u.isReal)
                        {
                            ProcessNeighbor(pq, u, e, v, 1000);
                        }
                        else
                        {
                            ProcessNeighbor(pq, u, e, v);
                        }
                    }
                }

                foreach (var e in u.InEdges)
                {
                    if (PassableInEdge(e))
                    {
                        var v = e.Source;
                        ProcessNeighbor(pq, u, e, v);
                    }
                }
            }
            return(_visGraph.PreviosVertex(_target) == null
                ? null
                : CalculatePath(shrinkEdgeLength));
        }
Пример #7
0
        IEnumerable <Edge> SearchForPath()
        {
            while (queue.Count > 0)
            {
                double costPlus;
                var    node = queue.Dequeue(out costPlus);
                if (costPlus >= costToTarget)
                {
                    break;
                }
                double cost = node == source ? 0 : prev[node].Item2;
                ProcessVertex(node, cost);
            }
            IEnumerable <Edge> ret = RecoverPath();

            return(ret);
        }
        /// <summary>
        /// Returns  a  path
        /// </summary>
        /// <returns>a path or null if the target is not reachable from the source</returns>
        internal IEnumerable<VisibilityVertex> GetPath() {
            var pq = new GenericBinaryHeapPriorityQueue<VisibilityVertex>();
            source.Distance = 0;
            pq.Enqueue(source, 0);
            while (!pq.IsEmpty()) {
                current = pq.Dequeue();
                if (targets.Contains(current))
                    break;

                foreach (var e in current.OutEdges.Where(PassableOutEdge))
                    ProcessNeighbor(pq, e, e.Target);

                foreach (var e in current.InEdges.Where(PassableInEdge))
                    ProcessNeighbor(pq, e, e.Source);
            }

            return _visGraph.PreviosVertex(current) == null ? null : CalculatePath();
        }
        /// <summary>
        /// Grow hubs
        /// </summary>
        bool GrowHubs(bool useHalfEdgesAsIdealR) {
            var queue = new GenericBinaryHeapPriorityQueue<Station>();
            foreach (var v in metroGraphData.VirtualNodes()) {
                queue.Enqueue(v, -CalculatePotential(v, useHalfEdgesAsIdealR));
            }

            bool progress = false;
            //choose a hub with the greatest potential
            while (!queue.IsEmpty()) {
                double hu;
                Station v = queue.Dequeue(out hu);
                if (hu >= 0)
                    break;

                //grow the hub
                if (TryGrowHub(v, useHalfEdgesAsIdealR)) {
                    queue.Enqueue(v, -CalculatePotential(v, useHalfEdgesAsIdealR));
                    progress = true;
                }
            }
            return progress;
        }
        internal VertexEntry GetPathWithCost(VertexEntry[] sourceVertexEntries, VisibilityVertexRectilinear source, double adjustmentToSourceCost,
                                             VertexEntry[] targetVertexEntries, VisibilityVertexRectilinear target, double adjustmentToTargetCost,
                                             double priorBestCost)
        {
            this.upperBoundOnCost     = priorBestCost;
            this.sourceCostAdjustment = adjustmentToSourceCost;
            this.targetCostAdjustment = adjustmentToTargetCost;

            DevTracePrintSourceAndTarget(source, target);
            if (!InitPath(sourceVertexEntries, source, target))
            {
                this.DevTraceShowPath(source, null);
                return(null);
            }


            while (queue.Count > 0)
            {
                this.TestPreDequeue();
                var bestEntry  = queue.Dequeue();
                var bestVertex = bestEntry.Vertex;
                if (bestVertex == Target)
                {
                    this.DevTraceShowPath(source, bestEntry);
                    if (targetVertexEntries == null)
                    {
                        Cleanup();
                        return(bestEntry);
                    }

                    // We'll never get a duplicate entry direction here; we either relaxed the cost via UpdateEntryToNeighborIfNeeded
                    // before we dequeued it, or it was closed.  So, we simply remove the direction from the valid target entry directions
                    // and if we get to none, we're done.  We return a null path until the final stage.
#if SHARPKIT //http://code.google.com/p/sharpkit/issues/detail?id=368 property assignment not working with &= operator
                    this.EntryDirectionsToTarget = this.EntryDirectionsToTarget & ~bestEntry.Direction;
#else
                    this.EntryDirectionsToTarget &= ~bestEntry.Direction;
#endif
                    if (this.EntryDirectionsToTarget == Direction.None)
                    {
                        this.Target.VertexEntries.CopyTo(targetVertexEntries, 0);
                        Cleanup();
                        return(null);
                    }
                    this.upperBoundOnCost = Math.Min(this.MultistageAdjustedCostBound(bestEntry.Cost), this.upperBoundOnCost);
                    continue;
                }

                // It's safe to close this after removing it from the queue.  Any updateEntryIfNeeded that changes it must come
                // while it is still on the queue; it is removed from the queue only if it has the lowest cost path, and we have
                // no negative path weights, so any other path that might try to extend to it after this cannot have a lower cost.
                bestEntry.IsClosed = true;

                // PerfNote: Array.ForEach is optimized, but don't use .Where.
                foreach (var bendNeighbor in this.nextNeighbors)
                {
                    bendNeighbor.Clear();
                }
                var preferredBendDir = Right(bestEntry.Direction);
                this.ExtendPathAlongInEdges(bestEntry, bestVertex.InEdges, preferredBendDir);
                this.ExtendPathAlongOutEdges(bestEntry, bestVertex.OutEdges, preferredBendDir);
                foreach (var bendNeighbor in this.nextNeighbors)
                {
                    if (bendNeighbor.Vertex != null)
                    {
                        this.ExtendPathToNeighborVertex(bestEntry, bendNeighbor.Vertex, bendNeighbor.Weight);
                    }
                }
                this.DevTraceShowAllPartialPaths(source, bestEntry);
            }

            // Either there is no path to the target, or we have abandoned the path due to exceeding priorBestCost.
            if ((targetVertexEntries != null) && (this.Target.VertexEntries != null))
            {
                this.Target.VertexEntries.CopyTo(targetVertexEntries, 0);
            }
            this.DevTraceShowPath(source, null);
            Cleanup();
            return(null);
        }