c++ - Should I use mutable priority queue for dikjstra/A* algorithm? -
i trying implement a* algorithm , dikjstra algorithm special case of a* (just pass h(x){return 0;}
a*), when choosing priority_queue, have 2 choices
- use empty priority_queue, , push start point when initializing, , "pop u, push neighbors of u satisfying conditions", in way, 1 node might pushed twice if common neighbor of 2 other nodes.
- use mutable priority queue supports
update()/decreasekey()/increasekey()
, choose data structures inboost::heap
or (actually have) implement priority_queue myself, in way, nodes needed pushed container when initializing , handles them need kept.
what pros , cons of these 2 strategies , 1 more practical?
a common implementation of priority queue dijkstra's in c++ uses std::set
, smallest item set.begin()
, , can find
exact item , erase
it. can define facade allows access std::set
priority queue-like interface , support additional update/erase/increasekey/decreasekey methods.
look here code samples dijkstra's implementations both std::set
, std::priority_queue
: https://www.topcoder.com/community/data-science/data-science-tutorials/power-up-c-with-the-standard-template-library-part-2/#dijkstra2
this article makes claim, performance naturally same, whether use std::priority_queue
, discard stale items you've popped, or use std::set
, erase old item immediately.
Comments
Post a Comment