symbolic
pddl.h
1 
10 #ifndef SYMBOLIC_PDDL_H_
11 #define SYMBOLIC_PDDL_H_
12 
13 #include <iostream> // std::cout, std::ostream
14 #include <memory> // std::shared_ptr, std::weak_ptr
15 #include <set> // std::set
16 #include <string> // std::string
17 #include <unordered_map> // std::unordered_map
18 #include <utility> // std::pair
19 #include <vector> // std::vector
20 
21 #include "symbolic/action.h"
22 #include "symbolic/axiom.h"
23 #include "symbolic/derived_predicate.h"
24 #include "symbolic/formula.h"
25 #include "symbolic/object.h"
26 #include "symbolic/predicate.h"
27 #include "symbolic/proposition.h"
28 
29 namespace VAL {
30 
31 class analysis;
32 
33 } // namespace VAL
34 
35 namespace symbolic {
36 
40 class Pddl {
41  public:
42  using ObjectTypeMap = std::unordered_map<std::string, std::vector<Object>>;
43  using AxiomContextMap =
44  std::unordered_map<std::string, std::vector<std::weak_ptr<Axiom>>>;
45 
55  Pddl(const std::string& domain_pddl, const std::string& problem_pddl,
56  bool apply_axioms = true);
57 
65  explicit Pddl(const std::string& domain_pddl);
66 
76  bool IsValid(bool verbose = false, std::ostream& os = std::cout) const;
77 
90  State NextState(const State& state, const std::string& action_call) const;
91 
104  State ApplyActions(const State& state, const std::vector<std::string>& action_calls) const;
105 
109  State DerivedState(const State& state) const;
110 
119  State ConsistentState(const State& state) const;
120 
129  PartialState ConsistentState(const PartialState& state) const;
130 
140  bool IsValidAction(const State& state, const std::string& action) const;
141 
150  bool IsValidState(const State& state) const;
151 
165  bool IsValidState(const PartialState& state) const;
166 
170  bool IsValidTuple(const State& state, const std::string& action_call,
171  const State& next_state) const;
172  bool IsValidTuple(const std::set<std::string>& state,
173  const std::string& action_call,
174  const std::set<std::string>& next_state) const;
175 
179  bool IsGoalSatisfied(const State& state) const { return goal_(state); }
180  bool IsGoalSatisfied(const std::set<std::string>& state) const;
181 
185  bool IsValidPlan(const std::vector<std::string>& action_skeleton) const;
186 
190  std::vector<std::vector<Object>> ListValidArguments(
191  const State& state, const Action& action) const;
192  std::vector<std::vector<std::string>> ListValidArguments(
193  const std::set<std::string>& state, const std::string& action_name) const;
194 
198  std::vector<std::string> ListValidActions(const State& state) const;
199  std::vector<std::string> ListValidActions(
200  const std::set<std::string>& state) const;
201 
202  void AddObject(const std::string& name, const std::string& type);
203  void RemoveObject(const std::string& name);
204 
205  const VAL::analysis* symbol() const { return analysis_.get(); }
206 
210  const std::string& name() const;
211 
215  const std::string& domain_pddl() const { return domain_pddl_; }
216 
220  const std::string& problem_pddl() const { return problem_pddl_; }
221 
225  const State& initial_state() const { return initial_state_; }
226  void set_initial_state(State&& state) { initial_state_ = std::move(state); }
227 
228  const ObjectTypeMap& object_map() const { return object_map_; }
229 
230  const std::vector<Object>& constants() const { return constants_; }
231  const std::vector<Object>& objects() const { return objects_; }
232 
233  const std::vector<Action>& actions() const { return actions_; }
234 
235  const std::vector<Predicate>& predicates() const { return predicates_; }
236 
237  const std::vector<std::shared_ptr<Axiom>>& axioms() const { return axioms_; }
238 
242  const AxiomContextMap& axiom_map() const { return axiom_map_; }
243 
244  const std::vector<DerivedPredicate>& derived_predicates() const {
245  return derived_predicates_;
246  }
247 
248  const StateIndex& state_index() const { return state_index_; }
249 
250  const Formula& goal() const { return goal_; }
251 
252  private:
253  std::shared_ptr<VAL::analysis> analysis_;
254  std::string domain_pddl_;
255  std::string problem_pddl_;
256 
257  std::vector<Object> constants_;
258  std::vector<Object> objects_;
259  ObjectTypeMap object_map_;
260 
261  AxiomContextMap axiom_map_;
262  std::vector<Action> actions_;
263  std::vector<std::shared_ptr<Axiom>> axioms_;
264 
265  std::vector<Predicate> predicates_;
266  std::vector<DerivedPredicate> derived_predicates_;
267 
268  StateIndex state_index_;
269 
270  State initial_state_;
271  Formula goal_;
272 };
273 
274 std::set<std::string> Stringify(const State& state);
275 std::pair<std::set<std::string>, std::set<std::string>> Stringify(
276  const PartialState& state);
277 std::vector<std::string> Stringify(const std::vector<Action>& actions);
278 std::vector<std::vector<std::string>> Stringify(
279  const std::vector<std::vector<Object>>& arguments);
280 std::vector<std::string> Stringify(const std::vector<Object>& objects);
281 
282 std::ostream& operator<<(std::ostream& os, const Pddl& pddl);
283 
284 } // namespace symbolic
285 
286 #endif // SYMBOLIC_PDDL_H_
symbolic::Pddl::IsValid
bool IsValid(bool verbose=false, std::ostream &os=std::cout) const
Definition: pddl.cc:304
symbolic::Pddl::NextState
State NextState(const State &state, const std::string &action_call) const
Definition: pddl.cc:322
symbolic::Pddl::name
const std::string & name() const
Definition: pddl.cc:545
symbolic::Pddl::IsValidAction
bool IsValidAction(const State &state, const std::string &action) const
Definition: pddl.cc:401
symbolic::Pddl::problem_pddl
const std::string & problem_pddl() const
Definition: pddl.h:220
VAL
Definition: pddl.cc:27
symbolic
Definition: action.cc:329
symbolic::Pddl::ListValidArguments
std::vector< std::vector< Object > > ListValidArguments(const State &state, const Action &action) const
Definition: pddl.cc:471
symbolic::Pddl::ConsistentState
State ConsistentState(const State &state) const
Definition: pddl.cc:359
symbolic::Pddl::Pddl
Pddl(const std::string &domain_pddl, const std::string &problem_pddl, bool apply_axioms=true)
Definition: pddl.cc:250
symbolic::Pddl
Definition: pddl.h:40
symbolic::Pddl::initial_state
const State & initial_state() const
Definition: pddl.h:225
symbolic::Action
Definition: action.h:36
symbolic::Pddl::ListValidActions
std::vector< std::string > ListValidActions(const State &state) const
Definition: pddl.cc:499
symbolic::State
Definition: state.h:40
symbolic::Pddl::IsValidTuple
bool IsValidTuple(const State &state, const std::string &action_call, const State &next_state) const
Definition: pddl.cc:429
symbolic::Pddl::domain_pddl
const std::string & domain_pddl() const
Definition: pddl.h:215
symbolic::Pddl::DerivedState
State DerivedState(const State &state) const
Definition: pddl.cc:355
symbolic::Pddl::IsValidState
bool IsValidState(const State &state) const
Definition: pddl.cc:418
symbolic::Pddl::ApplyActions
State ApplyActions(const State &state, const std::vector< std::string > &action_calls) const
Definition: pddl.cc:341
symbolic::Pddl::IsGoalSatisfied
bool IsGoalSatisfied(const State &state) const
Definition: pddl.h:179
symbolic::Pddl::axiom_map
const AxiomContextMap & axiom_map() const
Definition: pddl.h:242
symbolic::PartialState
Definition: state.h:126
symbolic::Pddl::IsValidPlan
bool IsValidPlan(const std::vector< std::string > &action_skeleton) const
Definition: pddl.cc:456