symbolic
planner.h
1 
10 #ifndef SYMBOLIC_PLANNING_PLANNER_H_
11 #define SYMBOLIC_PLANNING_PLANNER_H_
12 
13 #include <functional> // std::hash
14 #include <iostream> // std::ostream
15 #include <memory> // std::shared_ptr
16 
17 #include "symbolic/pddl.h"
18 
19 namespace symbolic {
20 
21 class Planner {
22  public:
23  class Node {
24  struct NodeImpl;
25 
26  public:
27  class iterator;
28  class reverse_iterator;
29 
30  Node() = default;
31  Node(const Pddl& pddl, const State& state, size_t depth = 0);
32  Node(const Node& parent, const Node& sibling, State&& state,
33  std::string&& action);
34 
35  const std::string& action() const;
36  const State& state() const;
37  size_t depth() const;
38 
39  // Iterate over children
40  iterator begin() const;
41  iterator end() const;
42 
43  // Evaluate goal condition
44  explicit operator bool() const;
45 
46  // Compare states for caching
47  bool operator<(const Node& rhs) const;
48  bool operator==(const Node& rhs) const;
49 
50  friend std::ostream& operator<<(std::ostream& os,
51  const symbolic::Planner::Node& node);
52 
53  private:
54  NodeImpl* operator->() { return impl_.get(); }
55  const NodeImpl* operator->() const { return impl_.get(); }
56 
57  std::shared_ptr<NodeImpl> impl_;
58  };
59 
68  explicit Planner(const Pddl& pddl) : Planner(pddl, pddl.initial_state()) {}
69 
79  Planner(const Pddl& pddl, const State& state)
80  : root_(pddl, pddl.ConsistentState(state)) {}
81 
82  const Node& root() const { return root_; }
83 
84  private:
85  const Node root_;
86 };
87 
89  public:
90  using iterator_category = std::input_iterator_tag;
91  using value_type = Node;
92  using difference_type = ptrdiff_t;
93  using pointer = const value_type*;
94  using reference = const value_type&;
95 
96  explicit iterator(const Node& parent);
97 
98  iterator& operator++();
99  iterator& operator--();
100  bool operator==(const iterator& other) const;
101  bool operator!=(const iterator& other) const { return !(*this == other); }
102  reference operator*() const { return child_; }
103 
104  private:
105  const Pddl& pddl_;
106 
107  const Node& parent_;
108  Node child_;
109 
110  std::vector<Action>::const_iterator it_action_;
111  ParameterGenerator::const_iterator it_param_;
112 
113  friend class Node;
114 };
115 
116 } // namespace symbolic
117 
118 namespace std {
119 
120 template <>
121 struct hash<symbolic::Planner::Node> {
122  size_t operator()(const symbolic::Planner::Node& node) const noexcept;
123 };
124 
125 } // namespace std
126 
127 #endif // SYMBOLIC_PLANNING_PLANNER_H_
symbolic::Planner::Node
Definition: planner.h:23
symbolic
Definition: action.cc:329
symbolic::Planner
Definition: planner.h:21
symbolic::Planner::Planner
Planner(const Pddl &pddl)
Definition: planner.h:68
symbolic::Pddl
Definition: pddl.h:40
symbolic::Planner::Planner
Planner(const Pddl &pddl, const State &state)
Definition: planner.h:79
symbolic::Planner::Node::NodeImpl
Definition: planner.cc:22
symbolic::State
Definition: state.h:40
symbolic::Planner::Node::iterator
Definition: planner.h:88