Пример #1
0
        public static void Main()
        {
            // 1.
            var priorityQueue = new PriorityQueue<int>();
            priorityQueue.Enqueue(2);
            priorityQueue.Enqueue(7);
            priorityQueue.Enqueue(17);
            priorityQueue.Enqueue(19);
            priorityQueue.Enqueue(26);
            priorityQueue.Enqueue(29);
            priorityQueue.Dequeue();
            priorityQueue.Enqueue(3);
            priorityQueue.Enqueue(1);
            priorityQueue.Dequeue();
            priorityQueue.Enqueue(25);
            priorityQueue.Enqueue(36);
            priorityQueue.Dequeue();

            Console.WriteLine();

            // 2.
            PrintFirst20Products();

            Console.WriteLine();

            // 3.
            CountWords();
        }
Пример #2
0
        public int[] makeNextMove(Grid board)
        {
            PriorityQueue<MoveNode> q = new PriorityQueue<MoveNode>();
              	q.initialize(expandNodes(board, null, 1));
               	MoveNode current = q.Dequeue();

              	while ((current.Ply < depth) && !(q.isEmpty))
              	{
               		MoveNode next = q.Dequeue();
               	if(next.Rank> current.Rank)
               	{
                    current = next;
                    MoveNode[] expnd = expandNodes(current.Board, current, (current.Ply + 1));
                    if(expnd.Length > 0)
                        q.EnqueueArray(expnd);
                }
             	}

              	while(current.Ply > 1)
              	{
               		current = current.PreviousMove;
              	}
             	//this will be the best move to make after expanding down to depth plys.
              	int[] result = { current.Group.X, current.Group.Y };
              	Console.WriteLine("rank: " + current.Rank);

               	return result;
        }
        static void Main(string[] args)
        {
            var queue = new PriorityQueue<int>();

            queue.Enqueue(5);
            queue.Enqueue(8);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(11);

            foreach (var i in queue)
            {
                Console.WriteLine(i);
            }


            Console.WriteLine("*******Removed value:{0}",queue.Dequeue());
            foreach (var i in queue)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("*******Removed value:{0}", queue.Dequeue());
            foreach (var i in queue)
            {
                Console.WriteLine(i);
            }
        }
Пример #4
0
        public void Remove()
        {
            PriorityQueue<int> p = new PriorityQueue<int>(delegate(int i, int j) { return i - j; });
            Random r = new Random();
            for(int i = 0; i < 10000; ++i) {
                p.Enqueue(r.Next(1000));
            }

            int removed = 0;
            while(removed < 100) {
                int count = p.Count;
                p.Remove(r.Next(1000));
                if(count > p.Count) {
                    ++removed;
                }
            }

            int item = p.Dequeue();
            while(p.Count > 0) {
                int next = p.Dequeue();
                if(next < item) {
                    Assert.Fail("bad order detected");
                }
            }
        }
Пример #5
0
        public void TestBasicFunctionality()
        {
            var q = new PriorityQueue<int>();
            Assert.AreEqual(0, q.Count);
            Assert.AreEqual(0, q.Capacity);
            Assert.Throws<InvalidOperationException>(() => q.Peek());
            Assert.Throws<InvalidOperationException>(() => q.Dequeue());

            q.Enqueue(5);
            q.Enqueue(2);
            q.Enqueue(4);

            Assert.AreEqual(3, q.Count);
            Assert.IsTrue(q.Capacity >= 3);

            Assert.IsTrue(q.Contains(2));
            Assert.IsFalse(q.Contains(3));

            Assert.AreEqual(3, q.ToArray().Length);
            CollectionAssert.AreEqual(q.ToArray(), q);

            Assert.AreEqual(2, q.Peek());

            Assert.AreEqual(2, q.Dequeue());
            Assert.AreEqual(4, q.Dequeue());
            Assert.AreEqual(5, q.Dequeue());
        }
Пример #6
0
        public async void OnTick(IWeiboAccessToken at)
        {
            if (_tick++%57 != 0)
                return;
            var resp = await WeiboClient.suggestions_statuses_hot_async(at.get(), 20, true, 1, _type);
            if(++_type == hot_status_type.count)
                _type = hot_status_type.musement;

            if (resp.Failed() || resp.Value.Length == 0)
                return;
            var queue = new PriorityQueue<long, Status>();
            foreach(var s in resp.Value)
            {
                queue.Enqueue(EvalMark(s),s);
            }
            while (queue.Size > 5)
                queue.Dequeue();
            while(!queue.IsEmpty)
            {
                var s = queue.Dequeue();
                var ws = new WeiboStatus();
                ws.assign_sina(s);
                await DispatcherHelper.UIDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) (() =>
                {
                    if(statuses.Count > 10)
                        statuses.RemoveAt(0);
                    statuses.Add(ws);
                }));
            }
        }
Пример #7
0
        public void PriorityQueue()
        {
            PriorityQueue<int> pq = new PriorityQueue<int>(LinqExt.TakeMore);
            pq.Enqueue(1, 1);
            pq.Enqueue(9, 9);
            pq.Enqueue(2, 2);
            pq.Enqueue(5, 5);

            Assert.IsTrue(pq.First() == 9, "Wrong Priority");
            Assert.IsTrue(pq.Dequeue() == 9, "Wrong Priority");
            Assert.IsTrue(pq.Dequeue() == 5, "Wrong Priority");

            pq.ChangePriority(1, 29);
            Assert.IsTrue(pq.First() == 1, "Wrong Priority, 1 should be first priority now with priority 29");

            pq.Enqueue(3, 2); //add item with same priority
            pq.Enqueue(4, 2); //add item with same priority

            Assert.IsTrue(pq.Last() == 4, "Wrong Priority, 4 should be last");

            pq.Enqueue(30, 30); // mix case
            Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should be first priority");

            pq.Enqueue(31, 30); // mix case
            Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should still be first priority");

            pq.Enqueue(5, 2); //add item with same priority
            pq.Enqueue(6, 2); //add item with same priority

            Assert.IsTrue(pq.Last() == 6, "Wrong Priority, 6 should be last");
        }
Пример #8
0
 public void EnqDeq()
 {
     var pq = new PriorityQueue<string>();
     pq.Enqueue(1, "world");
     pq.Enqueue(2, "hello");
     Assert.AreEqual("hello", pq.Dequeue());
     Assert.AreEqual("world", pq.Dequeue());
 }
Пример #9
0
 public void ConstructFromSequence()
 {
     var pq = new PriorityQueue<int>(new int[] { 1, 4, 2, 10, -10 });
     Assert.AreEqual(-10, pq.Dequeue());
     Assert.AreEqual(1, pq.Dequeue());
     Assert.AreEqual(2, pq.Dequeue());
     Assert.AreEqual(4, pq.Dequeue());
     Assert.AreEqual(10, pq.Dequeue());
 }
Пример #10
0
        public void TestOrder()
        {
            PriorityQueue<int, string> q = new PriorityQueue<int, string>();
            q.Enqueue(0, "a");
            q.Enqueue(-1, "b");
            q.Enqueue(1, "c");

            Assert.AreEqual("b", q.Dequeue());
            Assert.AreEqual("a", q.Dequeue());
            Assert.AreEqual("c", q.Dequeue());

            q.Enqueue(0, "a");
            q.Enqueue(0, "b");
            q.Enqueue(0, "c");

            q.Enqueue(1, "c");
            q.Enqueue(1, "d");
            q.Enqueue(1, "e");

            Assert.AreEqual("a", q.Dequeue());
            Assert.AreEqual("b", q.Dequeue());
            Assert.AreEqual("c", q.Dequeue());

            Assert.AreEqual("c", q.Dequeue());
            Assert.AreEqual("d", q.Dequeue());
            Assert.AreEqual("e", q.Dequeue());
        }
Пример #11
0
 public void BasicTest()
 {
     var pq = new PriorityQueue<int>();
     pq.Enqueue(5);
     pq.Enqueue(3);
     pq.Enqueue(10);
     pq.Enqueue(1);
     Assert.AreEqual(1, pq.Dequeue());
     Assert.AreEqual(3, pq.Dequeue());
     Assert.AreEqual(5, pq.Dequeue());
     Assert.AreEqual(10, pq.Dequeue());
 }
Пример #12
0
        public void TestConstructWithComparer()
        {
            var q = new PriorityQueue<int>(Comparer<int>.Create((a, b) => -a.CompareTo(b)));

            q.Enqueue(5);
            q.Enqueue(2);
            q.Enqueue(4);

            Assert.AreEqual(5, q.Dequeue());
            Assert.AreEqual(4, q.Dequeue());
            Assert.AreEqual(2, q.Dequeue());
        }
Пример #13
0
        public void New_highest_prio_is_added_at_head()
        {
            var sut = new PriorityQueue<string>();

            sut.Enqueue("0");
            sut.Enqueue(1, "1");
            sut.Enqueue(2, "2");

            Assert.AreEqual("2", sut.Dequeue());
            Assert.AreEqual("1", sut.Dequeue());
            Assert.AreEqual("0", sut.Dequeue());
        }
Пример #14
0
 public void CustomComparer()
 {
     var pq = new PriorityQueue<int>(
         (lhs, rhs) => (10 - lhs).CompareTo(10 - rhs)
     );
     pq.Enqueue(5);
     pq.Enqueue(3);
     pq.Enqueue(10);
     pq.Enqueue(1);
     Assert.AreEqual(10, pq.Dequeue());
     Assert.AreEqual(5, pq.Dequeue());
     Assert.AreEqual(3, pq.Dequeue());
     Assert.AreEqual(1, pq.Dequeue());
 }
Пример #15
0
 static void Main(string[] args)
 {
     PriorityQueue<int> heap = new PriorityQueue<int>();
     heap.Enqueue(1);
     heap.Enqueue(2);
     heap.Enqueue(3);
     heap.Enqueue(4);
     heap.Dequeue();
     heap.Enqueue(3);
     heap.Enqueue(5);
     Console.WriteLine(heap.Dequeue());
     heap.ToString();
     heap.Enqueue(2);
     heap.ToString();
 }
Пример #16
0
        public PathFinder(Grid graph, Cell start, Cell goal)
        {
            //  Priority Queue which contains cells that are candidates for examining, lowest priority to the node with the lowest f value
            var frontier = new PriorityQueue<Cell>();
            frontier.Enqueue(start, 0);

            cameFrom[start] = start;
            costSoFar[start] = 0;

            while (frontier.Count > 0)
            {
                var current = frontier.Dequeue();

                // Exit the search if goal have discovered
                if (current.Equals(goal)) { break; }

                // discovers the neighbours
                foreach (var next in graph.Neighbors(current))
                {
                    int newCost = costSoFar[current] + graph.Cost(current, next);

                    if (!costSoFar.ContainsKey(next) || newCost < costSoFar[next])
                    {
                        costSoFar[next] = newCost;

                        // f = g + h
                        int priority = newCost + Heuristic(next, goal);

                        frontier.Enqueue(next, priority);
                        cameFrom[next] = current;
                    }
                }
            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            PriorityQueue<int> queue = new PriorityQueue<int>();
            queue.Enqueue(5);
            queue.Enqueue(3);
            queue.Enqueue(16);
            queue.Enqueue(4);
            queue.Enqueue(8);
            queue.Enqueue(10);
            queue.Enqueue(20);
            queue.Enqueue(33);
            queue.Enqueue(6);
            queue.Enqueue(24);
            queue.Enqueue(68);
            queue.Enqueue(19);
            queue.Enqueue(61);
            queue.Enqueue(638);
            queue.Enqueue(213);
            queue.Enqueue(2132);

            int count = queue.Count;
            Console.WriteLine("Get elements from Priority queue one by one:");
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(queue.Dequeue());
            }
        }
Пример #18
0
        static void Solve(Dictionary<int, Node> allNodes, Node startNode)
        {
            foreach (var node in allNodes.Values)
            {
                node.Distance = int.MaxValue;
            }

            startNode.Distance = 0;

            PriorityQueue<Node> nodes = new PriorityQueue<Node>();
            nodes.Enqueue(startNode);

            while (nodes.Count > 0)
            {
                var node = nodes.Dequeue();

                if (node.Distance == int.MaxValue)
                {
                    break;
                }

                for (int i = 0; i < node.Connections.Count; i++)
                {
                    var newDistance = node.Distance + node.Connections[i].Distance;
                    if (newDistance < node.Connections[i].ToNode.Distance)
                    {
                        node.Connections[i].ToNode.Distance = newDistance;
                        nodes.Enqueue(node.Connections[i].ToNode);
                    }
                }
            }
        }
Пример #19
0
        public static void Main(string[] args)
        {
            PriorityQueue<Student> payQueue = new PriorityQueue<Student>();

            for (int i = 0; i < 5; i++)
            {
                payQueue.Enqueue(new Student("Student" + i, 12, true));
            }

            for (int i = 5; i < 10; i++)
            {
                payQueue.Enqueue(new Student("Student" + i, 12, false));
            }

            for (int i = 0; i < 5; i++)
            {
                payQueue.Enqueue(new Student("StudentVer2" + i, 12, true));
            }

            int payQueueLength = payQueue.Count;

            for (int i = 0; i < payQueueLength; i++)
            {
                Console.WriteLine(payQueue.Dequeue().ToString());
            }
        }
Пример #20
0
        static void Main(string[] args)
        {
            //var queue = new PriorityQueue<int>();
            //queue.Enqueue(99);
            //queue.Enqueue(2);
            //queue.Enqueue(10);
            //queue.Enqueue(25);
            //queue.Enqueue(11);
            //queue.Enqueue(3);
            //queue.Enqueue(7);
            //queue.Enqueue(22);
            //queue.Enqueue(5);
            //queue.Enqueue(1);
            //queue.Enqueue(45);
            //queue.Enqueue(31);

            var queue = new PriorityQueue<Student>();

            queue.Enqueue(new Student() { Name = "Ivan", Age = 27 });
            queue.Enqueue(new Student() { Name = "Pesho", Age = 21 });
            queue.Enqueue(new Student() { Name = "Dragan", Age = 24 });
            queue.Enqueue(new Student() { Name = "Gosho", Age = 18 });
            queue.Enqueue(new Student() { Name = "Todor", Age = 25 });

            while (queue.Count > 0)
            {
                Console.WriteLine(queue.Dequeue().ToString());
            }
        }
Пример #21
0
        public static void Main()
        {
            //Heap test

            //Heap<int> testHeap = new Heap<int>();
            //testHeap.Push(3);
            //testHeap.Push(4);
            //testHeap.Push(5);
            //testHeap.Push(1);
            //testHeap.Push(6);

            //while (testHeap.Count > 0)
            //{
            //    testHeap.Pop();
            //    testHeap.Print();
            //}

            //Queue test
            PriorityQueue<int> queue = new PriorityQueue<int>();
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);
            queue.Enqueue(1);
            queue.Enqueue(6);

            queue.Print();

            while (queue.Count > 0)
            {
                queue.Dequeue();
                queue.Print();
            }
        }
        public static void DijkstraAlgorithm(Dictionary<Node, List<Connection>> graph, Node source)
        {
            PriorityQueue<Node> queue = new PriorityQueue<Node>();

            foreach (var item in graph)
            {
                item.Key.DijkstraDistance = long.MaxValue;
            }

            queue.Enqueue(source);
            source.DijkstraDistance = 0;

            while (queue.Count != 0)
            {
                var currentNode = queue.Dequeue();

                foreach (var connection in graph[currentNode])
                {
                    var dist = connection.Distance + currentNode.DijkstraDistance;

                    if (dist < connection.ToNode.DijkstraDistance)
                    {
                        connection.ToNode.DijkstraDistance = dist;
                        queue.Enqueue(connection.ToNode);
                    }
                }
            }
        }
        public static void DijkstraAlgorithm(Dictionary<Node, List<Connection>> graph, Node source)
        {
            PriorityQueue<Node> queue = new PriorityQueue<Node>();
            foreach (var node in graph)
            {
                node.Key.DijkstraDistance = long.MaxValue;
            }

            source.DijkstraDistance = 0;
            queue.Enqueue(source);

            while (queue.Count != 0)
            {
                Node currentNode = queue.Dequeue();
                if (currentNode.DijkstraDistance == long.MaxValue)
                {
                    break;
                }

                foreach (var connection in graph[currentNode])
                {
                    var potDistance = currentNode.DijkstraDistance + connection.Distance;
                    if (potDistance < connection.ToNode.DijkstraDistance)
                    {
                        connection.ToNode.DijkstraDistance = potDistance;
                        queue.Enqueue(connection.ToNode);
                    }
                }
            }
        }
        // Dijkstra's shortest paths algorithm, implemented
        // with priority queue. Running time: O(M * log M)
        // Learn more at: https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm#Using_a_priority_queue
        public static void DijkstraAlgorithm(
            Dictionary<Node, List<Edge>> graph,
            Node sourceNode)
        {
            var queue = new PriorityQueue<Node>();

            foreach (var node in graph)
            {
                node.Key.Distance = double.PositiveInfinity;
            }
            sourceNode.Distance = 0.0d;
            queue.Enqueue(sourceNode);

            while (queue.Count != 0)
            {
                var currentNode = queue.Dequeue();

                if (double.IsPositiveInfinity(currentNode.Distance))
                {
                    // All nodes processed --> algorithm finished
                    break;
                }

                foreach (var childEdge in graph[currentNode])
                {
                    var newDistance = currentNode.Distance + childEdge.Distance;
                    if (newDistance < childEdge.Node.Distance)
                    {
                        childEdge.Node.Distance = newDistance;
                        childEdge.Node.PreviousNode = currentNode;
                        queue.Enqueue(childEdge.Node);
                    }
                }
            }
        }
Пример #25
0
        private static void Dijkstra(Graph<int> graph, Node<int> source)
        {
            var queue = new PriorityQueue<Node<int>>();
            foreach (var node in graph.NodesCollection.Keys)
            {
                node.DijkstraDistance = double.PositiveInfinity;
            }

            source.DijkstraDistance = 0.0d;
            queue.Enqueue(source);

            while (queue.Count != 0)
            {
                var currentNode = queue.Dequeue();

                if (double.IsPositiveInfinity(currentNode.DijkstraDistance))
                {
                    break;
                }

                foreach (var neighbor in currentNode.Collection)
                {
                    var potDistance = currentNode.DijkstraDistance + neighbor.Distance;
                    if (potDistance < neighbor.Target.DijkstraDistance)
                    {
                        neighbor.Target.DijkstraDistance = potDistance;
                        queue.Enqueue(neighbor.Target);
                    }

                }
            }
        }
Пример #26
0
        public static void FindMinimalPaths(Dictionary<Node, List<Street>> graph, Node source)
        {
            PriorityQueue<Node> queue = new PriorityQueue<Node>();

            foreach (var node in graph)
            {
                if (source.ID != node.Key.ID)
                {
                    node.Key.DijkstraDistance = ulong.MaxValue;
                }
            }

            source.DijkstraDistance = 0;
            queue.Enqueue(source);

            while (queue.Count != 0)
            {
                Node currentNode = queue.Dequeue();

                foreach (var neighbour in graph[currentNode])
                {
                    ulong potDistance = currentNode.DijkstraDistance + neighbour.Distance;

                    if (potDistance < neighbour.Node.DijkstraDistance)
                    {
                        neighbour.Node.DijkstraDistance = potDistance;
                        // adds only modified elements in the queue
                        // thus reordering the queue after each iteration is avoided
                        queue.Enqueue(neighbour.Node);
                    }
                }
            }
        }
Пример #27
0
        public static Path<Node> FindPath(
            Node start,
            Node destination,
            Func<Node, Node, double> distance,
            Func<Node, double> estimate)
        {
            var closed = new HashSet<Vector2>();
            var queue = new PriorityQueue<double, Path<Node>>();
            queue.Enqueue(0, new Path<Node>(start));

            while (!queue.IsEmpty)
            {
                var path = queue.Dequeue();
                if (closed.Contains(path.LastStep.Point))
                {
                    continue;
                }

                if (path.LastStep.Point.Equals(destination.Point))
                    return path;

                closed.Add(path.LastStep.Point);
                foreach (Node n in path.LastStep.Neightbours)
                {
                    double d = distance(path.LastStep, n);
                    var newPath = path.AddStep(n, d);
                    queue.Enqueue(newPath.TotalCost + estimate(n), newPath);
                }
            }

            return null;
        }
Пример #28
0
        public void Insert_before_entry_with_lower_prio()
        {
            var sut = new PriorityQueue<string>();

            sut.Enqueue("0");
            sut.Enqueue(2, "2");
            sut.Enqueue(4, "4");
            sut.Enqueue(1, "1");
            sut.Enqueue(3, "3");

            Assert.AreEqual("4", sut.Dequeue());
            Assert.AreEqual("3", sut.Dequeue());
            Assert.AreEqual("2", sut.Dequeue());
            Assert.AreEqual("1", sut.Dequeue());
            Assert.AreEqual("0", sut.Dequeue());
        }
Пример #29
0
        public static void DijkstraAlgorithm(Dictionary<Node, List<Connection>> graph, Node source)
        {
            var queue = new PriorityQueue<Node>();

            foreach (var node in graph)
            {
                node.Key.DijkstraDistance = double.PositiveInfinity;
            }

            source.DijkstraDistance = 0.0d;
            queue.Enqueue(source);

            while (queue.Count != 0)
            {
                var currentNode = queue.Dequeue();

                if (double.IsPositiveInfinity(currentNode.DijkstraDistance))
                {
                    break;
                }

                foreach (var neighbor in graph[currentNode])
                {
                    var potDistance = currentNode.DijkstraDistance + neighbor.Distance;
                    if (potDistance < neighbor.Node.DijkstraDistance)
                    {
                        neighbor.Node.DijkstraDistance = potDistance;
                        queue.Enqueue(neighbor.Node);
                    }
                }
            }
        }
Пример #30
0
 public void PriorityQueueDequeueOneElementDecrementsCount()
 {
     var q = new PriorityQueue<int>();
     q.Enqueue(AnyInt);
     var count = q.Count;
     q.Dequeue();
     Assert.Equal(count - 1, q.Count);
 }
Пример #31
0
            /// <summary>
            /// Returns all nodes in this quadrant that are fully contained within the given bounds.
            /// The nodes are returned in order of descending priority.
            /// </summary>
            /// <param name="bounds">The bounds that contains the nodes you want returned.</param>
            /// <returns>A lazy list of nodes along with the new potential of this quadrant.</returns>
            internal IEnumerable <Tuple <QuadNode, double> > GetNodesInside(Rect bounds)
            {
                double w = _bounds.Width / 2;
                double h = _bounds.Height / 2;

                // assumption that the Rect struct is almost as fast as doing the operations
                // manually since Rect is a value type.
                Rect topLeft     = new Rect(_bounds.Left, _bounds.Top, w, h);
                Rect topRight    = new Rect(_bounds.Left + w, _bounds.Top, w, h);
                Rect bottomLeft  = new Rect(_bounds.Left, _bounds.Top + h, w, h);
                Rect bottomRight = new Rect(_bounds.Left + w, _bounds.Top + h, w, h);

                // Create a priority queue based on the potential of our nodes and our quads.
                var queue = new PriorityQueue <IEnumerator <Tuple <QuadNode, double> >, double>(true);

                if (_nodes != null)
                {
                    queue.Enqueue(_nodes.GetNodesInside(bounds).GetEnumerator(), _nodes.Next.Priority);
                }

                if (_topLeft != null && topLeft.Intersects(bounds))
                {
                    queue.Enqueue(_topLeft.GetNodesInside(bounds).GetEnumerator(), _topLeft._potential);
                }

                if (_topRight != null && topRight.Intersects(bounds))
                {
                    queue.Enqueue(_topRight.GetNodesInside(bounds).GetEnumerator(), _topRight._potential);
                }

                if (_bottomLeft != null && bottomLeft.Intersects(bounds))
                {
                    queue.Enqueue(_bottomLeft.GetNodesInside(bounds).GetEnumerator(), _bottomLeft._potential);
                }

                if (_bottomRight != null && bottomRight.Intersects(bounds))
                {
                    queue.Enqueue(_bottomRight.GetNodesInside(bounds).GetEnumerator(), _bottomRight._potential);
                }

                // Then just loop through the queue.
                while (queue.Count > 0)
                {
                    // Grab the enumerator with the highest potential.
                    var enumerator = queue.Dequeue().Key;
                    if (enumerator.MoveNext())
                    {
                        // Get the current node and its new potential from the enumerator.
                        var current   = enumerator.Current;
                        var node      = current.Item1;
                        var potential = current.Item2;

                        // Determine our new potential.
                        var newPotential = queue.Count > 0 ? !potential.IsNaN() ? Math.Max(potential, queue.Peek().Value) : queue.Peek().Value : potential;

                        // It might be the case that the actual intersecting node has less priority than our remaining potential.
                        if (newPotential > node.Priority)
                        {
                            // Store it for later in a container containing only it with no further potential.
                            var store = Enumerable.Repeat(Tuple.Create(node, double.NaN), 1).GetEnumerator();

                            // Enqueue the container at the correct position.
                            queue.Enqueue(store, node.Priority);
                        }
                        else
                        {
                            // Return it to our parent along with our new potential.
                            yield return(Tuple.Create(node, newPotential));
                        }

                        // If this enumerator has some more potential then re-enqueue it.
                        if (!potential.IsNaN())
                        {
                            queue.Enqueue(enumerator, potential);
                        }
                    }
                }
            }