示例#1
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);
        }
示例#2
0
 public ShortestPartRouterForLg(Node source, Node target, Func <Node, LgNodeInfo> geomNodeToLgNode)
 {
     this.source           = source;
     this.target           = target;
     this.geomNodeToLgNode = geomNodeToLgNode;
     queue.Enqueue(source, 0);
     pathDirection         = target.Center - source.Center;
     costToTarget          = double.PositiveInfinity;
     EdgeIsInterestingFunc = MonotonicityFunc;
 }
 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);
     }
 }
 void InitEventQueue()
 {
     Queue = new GenericBinaryHeapPriorityQueue <LinkedPoint>();
     foreach (var vertPoint in VerticalPoints)
     {
         Queue.Enqueue(vertPoint, Low(vertPoint));
     }
     //a horizontal point will appear in the queue after a vertical point
     // with the same coordinate low coorinate
     foreach (var horizPoint in HorizontalPoints)
     {
         Queue.Enqueue(horizPoint, horizPoint.Point.Y);
     }
 }
        /// <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);
        }
示例#6
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 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));
                }
            }
        }
示例#8
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());
        }
 void Cleanup() {
     costToTarget = double.PositiveInfinity;
     bestEdgeIntoTarget = null;
     prev.Clear();
     queue = new GenericBinaryHeapPriorityQueue<Node>();
     queue.Enqueue(source, 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 != 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);
     }
 }
示例#11
0
 void Cleanup()
 {
     costToTarget       = double.PositiveInfinity;
     bestEdgeIntoTarget = null;
     prev.Clear();
     queue = new GenericBinaryHeapPriorityQueue <Node>();
     queue.Enqueue(source, 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;
                        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();
        }
        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 Enqueue(SdVertex simpleSdVertex)
 {
     Queue.Enqueue(simpleSdVertex, H(simpleSdVertex));
 }
        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));
            }
        }
 void InitEventQueue() {
     Queue = new GenericBinaryHeapPriorityQueue<LinkedPoint>();
     foreach (var vertPoint in VerticalPoints)
         Queue.Enqueue(vertPoint, Low(vertPoint));
     //a horizontal point will appear in the queue after a vertical point 
     // with the same coordinate low coorinate
     foreach (var horizPoint in HorizontalPoints)
         Queue.Enqueue(horizPoint, horizPoint.Point.Y);
 }