10 #ifndef SYMBOLIC_PLANNING_A_STAR_H_
11 #define SYMBOLIC_PLANNING_A_STAR_H_
20 template <
typename NodeT>
22 SearchNode(
const NodeT& node,
const std::vector<NodeT>& ancestors)
23 : node(node), ancestors(ancestors) {}
25 SearchNode(NodeT&& node, std::vector<NodeT>&& ancestors)
26 : node(std::move(node)), ancestors(std::move(ancestors)) {}
29 std::vector<NodeT> ancestors;
32 template <
typename NodeT,
typename Compare>
37 AStar(
const Compare& compare,
const NodeT& root,
size_t max_depth)
38 : kMaxDepth(max_depth), compare_(compare), root_(root) {}
41 iterator it(compare_, root_, kMaxDepth);
47 const size_t kMaxDepth;
49 const Compare& compare_;
53 template <
typename NodeT,
typename Compare>
56 using iterator_category = std::input_iterator_tag;
57 using value_type = std::vector<NodeT>;
58 using difference_type = ptrdiff_t;
59 using pointer =
const value_type*;
60 using reference =
const value_type&;
62 explicit iterator(
const Compare& compare) : queue_(compare) {}
63 iterator(
const Compare& compare,
const NodeT& root,
size_t max_depth)
64 : queue_(compare), kMaxDepth(max_depth) {
65 queue_.emplace(root, std::vector<NodeT>());
69 bool operator==(
const iterator& other)
const {
70 return queue_.empty() && other.queue_.empty();
72 bool operator!=(
const iterator& other)
const {
return !(*
this == other); }
73 reference operator*()
const {
return ancestors_; }
76 const size_t kMaxDepth = 0;
78 std::priority_queue<SearchNode<NodeT>, std::vector<SearchNode<NodeT>>,
81 std::vector<NodeT> ancestors_;
84 template <
typename NodeT,
typename Compare>
87 while (!queue_.empty()) {
91 ancestors_.swap(top.ancestors);
92 ancestors_.push_back(std::move(top.node));
96 const NodeT& node = ancestors_.back();
100 if (ancestors_.size() > kMaxDepth)
continue;
103 for (
const NodeT& child : node) {
104 queue_.emplace(child, ancestors_);
112 #endif // SYMBOLIC_PLANNING_A_STAR_H_