I am tasked with programming an A* Search Algorithm for an assignment that involves solving an '8-Puzzle'.
One of the algorithm's steps is to:
Add all the extended paths to Q. If the descendant state is already in Q, keep only the shorter path to state in Q (where Q is a Priority Queue (PQ)).
As such, I will need to search the PQ if an identical state exists but has a shorter path. If an identical state already exists but it has a longer path, I will need to delete this state from the PQ.
I have been directed to use an STL PQ, not my own implementation. I have managed to implement other types of searches using the below to create a Min PQ - which works as desired.
auto cmp = [](Puzzle* a, Puzzle* b) {
return a->getHCost() > b->getHCost();
};
std::priority_queue<Puzzle*, std::vector<Puzzle*>, decltype(cmp)> Q(cmp);
How can I extend my implementation so that...
- I can perform a brute force search - looping through each element of the STL PQ?
- I can delete an element somewhere in the STL PQ by its index? - shuffling elements 'upwards' if appropriate.