Priority Queue (PQ) is an abstract data structure (ADS). They can be implemented a lot. Unfortunately, priority_queue, which comes with the C ++ standard library, is quite limited, while other implementations are much better suited to implement A *. Spoilers: you can use std :: set / multiset instead of std :: priority_queue. But read on:
So, what do you need from the priority queue for implementing A *:
- Get the least cost node
- Reduce the cost of custom elements
Any priority queue can do 1., but for 2. you need a “modified" priority queue. Standard Lieb cannot do this. In addition, you need an easy way to find entries in the priority queue to find out where to decrease keys (if A * finds the best path to an already open node). There are two main ways to do this: you store the handle of the priority queue element in your node graph (or use a map to store these descriptors for each node graph) - or you insert the graph nodes yourself.
In the first case, when you store descriptors for each node, you can use std :: multiset for your priority queue. std :: multiset :: first () will always be your "low cost" key, and you can reduce the key by removing it from the set, changing the value and reinserting it, and updating the descriptor. Alternatively, you can use the variable priority queues from Boost.Heap that directly support the reduce-key.
In the second case, you will need some kind of "intrusive" binary tree - since your search paths themselves should be in the priority queue. If you don't want to roll back your own, see Ordered Associative Containers in Boost.Intrusive.
ltjax
source share