/// <summary> /// Merges two priority queues /// </summary> /// <param name="pq1">first priority queue</param> /// <param name="pq2">second priority queue</param> /// <returns>resultant priority queue</returns> /// <remarks> /// source priority queues must have equal comparers, /// otherwise <see cref="InvalidOperationException"/> will be thrown /// </remarks> public static MyPriorityQueue <TPriority, TValue> MergeQueues(MyPriorityQueue <TPriority, TValue> pq1, MyPriorityQueue <TPriority, TValue> pq2) { if (pq1 == null || pq2 == null) { throw new ArgumentNullException(); } if (pq1._comparer != pq2._comparer) { throw new InvalidOperationException("Priority queues to be merged must have equal comparers"); } return(MergeQueues(pq1, pq2, pq1._comparer)); }
/// <summary> /// Merges two priority queues and sets specified comparer for resultant priority queue /// </summary> /// <param name="pq1">first priority queue</param> /// <param name="pq2">second priority queue</param> /// <param name="comparer">comparer for resultant priority queue</param> /// <returns>resultant priority queue</returns> public static MyPriorityQueue <TPriority, TValue> MergeQueues(MyPriorityQueue <TPriority, TValue> pq1, MyPriorityQueue <TPriority, TValue> pq2, IComparer <TPriority> comparer) { if (pq1 == null || pq2 == null || comparer == null) { throw new ArgumentNullException(); } // merge data MyPriorityQueue <TPriority, TValue> result = new MyPriorityQueue <TPriority, TValue>(pq1.Count + pq2.Count, pq1._comparer); result._baseHeap.AddRange(pq1._baseHeap); result._baseHeap.AddRange(pq2._baseHeap); // heapify data for (int pos = result._baseHeap.Count / 2 - 1; pos >= 0; pos--) { result.HeapifyFromBeginningToEnd(pos); } return(result); }
/// <summary> /// constructor of best first /// search /// </summary> public BestFS() { openList = new MyPriorityQueue <State <Position> >(); evaluatedNodes = 0; }
public PrioritySearcher() { openList = new MyPriorityQueue <State <T>, double>(); evaluatedNodes = 0; }