Beispiel #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());
        }
Beispiel #2
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);
        }
        /// <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));
        }
        /// <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;
        }