symbolic
action.h
1 
10 #ifndef SYMBOLIC_ACTION_H_
11 #define SYMBOLIC_ACTION_H_
12 
13 #include <functional> // std::function
14 #include <ostream> // std::ostream
15 #include <string> // std::string
16 #include <utility> // std::pair
17 #include <vector> // std::vector
18 
19 #include "symbolic/formula.h"
20 #include "symbolic/object.h"
21 #include "symbolic/proposition.h"
22 #include "symbolic/state.h"
23 #include "symbolic/utils/parameter_generator.h"
24 
25 namespace VAL {
26 
27 class operator_;
28 class effect_lists;
29 
30 } // namespace VAL
31 
32 namespace symbolic {
33 
34 class Pddl;
35 
36 class Action {
37  public:
38  Action() = default;
39 
40  Action(const Pddl& pddl, const VAL::operator_* symbol);
41 
42  // action_call can be action(params) or action name
43  Action(const Pddl& pddl, const std::string& action_call);
44 
45  bool IsValid(const State& state, const std::vector<Object>& arguments) const {
46  return Preconditions_(state, arguments);
47  }
48 
49  std::optional<bool> IsValid(const PartialState& state,
50  const std::vector<Object>& arguments) const {
51  return Preconditions_(state, arguments);
52  }
53 
54  State Apply(const State& state, const std::vector<Object>& arguments) const;
55 
56  bool Apply(const std::vector<Object>& arguments, State* state) const {
57  return static_cast<bool>(Apply_(arguments, state));
58  }
59 
60  PartialState Apply(const PartialState& state,
61  const std::vector<Object>& arguments) const;
62 
67  int Apply(const std::vector<Object>& arguments, PartialState* state) const {
68  return ApplyPartial_(arguments, state);
69  }
70 
71  const VAL::operator_* symbol() const { return symbol_; }
72 
73  const Pddl& pddl() const { return *pddl_; }
74 
75  const std::string& name() const { return name_; }
76 
77  const std::vector<Object>& parameters() const { return parameters_; }
78 
79  const ParameterGenerator& parameter_generator() const { return param_gen_; }
80 
81  const Formula& preconditions() const { return Preconditions_; }
82 
83  const VAL::effect_lists* postconditions() const;
84 
85  std::string to_string() const;
86 
87  std::string to_string(const std::vector<Object>& arguments) const;
88 
89  static std::pair<Action, std::vector<Object>> Parse(
90  const Pddl& pddl, const std::string& action_call);
91 
92  friend bool operator<(const Action& lhs, const Action& rhs) {
93  return lhs.name() < rhs.name();
94  }
95 
96  friend bool operator==(const Action& lhs, const Action& rhs) {
97  return lhs.name() == rhs.name();
98  }
99 
100  friend std::ostream& operator<<(std::ostream& os, const Action& action);
101 
102  protected:
103  const VAL::operator_* symbol_ = nullptr;
104  const Pddl* pddl_ = nullptr;
105  std::string name_;
106  std::vector<Object> parameters_;
107  ParameterGenerator param_gen_;
108 
109  Formula Preconditions_;
110  std::function<int(const std::vector<Object>&, State*)> Apply_;
111  std::function<int(const std::vector<Object>&, PartialState*)> ApplyPartial_;
112 };
113 
114 } // namespace symbolic
115 
116 #endif // SYMBOLIC_ACTION_H_
VAL
Definition: pddl.cc:27
symbolic
Definition: action.cc:329
symbolic::Pddl
Definition: pddl.h:40
symbolic::Action
Definition: action.h:36
symbolic::State
Definition: state.h:40
symbolic::PartialState
Definition: state.h:126
symbolic::Action::Apply
int Apply(const std::vector< Object > &arguments, PartialState *state) const
Definition: action.h:67