symbolic
normal_form.h
1 
10 #ifndef SYMBOLIC_NORMAL_FORM_H_
11 #define SYMBOLIC_NORMAL_FORM_H_
12 
13 #include <functional> // std::function
14 #include <ostream> // std::ostream
15 #include <set> // std::set
16 #include <utility> // std::pair
17 #include <vector> // std::vector
18 
19 #include "symbolic/action.h"
20 #include "symbolic/formula.h"
21 #include "symbolic/state.h"
22 
23 namespace symbolic {
24 
25 struct ConjunctiveFormula;
26 
28  using Conjunction = PartialState;
29 
30  DisjunctiveFormula() = default;
31 
32  explicit DisjunctiveFormula(std::vector<Conjunction>&& conjunctions)
33  : conjunctions(std::move(conjunctions)) {}
34 
35  DisjunctiveFormula(std::initializer_list<Conjunction> l) : conjunctions(l) {}
36 
37  DisjunctiveFormula(const Pddl& pddl, const Formula& formula,
38  const std::vector<Object>& parameters,
39  const std::vector<Object>& arguments)
40  : DisjunctiveFormula(pddl, formula.symbol(), parameters, arguments) {}
41 
42  DisjunctiveFormula(const Pddl& pddl, const VAL::goal* symbol,
43  const std::vector<Object>& parameters,
44  const std::vector<Object>& arguments)
46  Create(pddl, symbol, parameters, arguments).value()) {}
47 
48  DisjunctiveFormula(const Pddl& pddl, const VAL::effect_lists* symbol,
49  const std::vector<Object>& parameters,
50  const std::vector<Object>& arguments)
52  Create(pddl, symbol, parameters, arguments).value()) {}
53 
54  DisjunctiveFormula(const Pddl& pddl, ConjunctiveFormula&& cnf)
55  : DisjunctiveFormula(Create(pddl, std::move(cnf)).value()) {}
56 
57  bool empty() const { return conjunctions.empty(); }
58 
59  static std::optional<DisjunctiveFormula> Create(
60  const Pddl& pddl, const Formula& formula,
61  const std::vector<Object>& parameters,
62  const std::vector<Object>& arguments, bool apply_axioms = false) {
63  return Create(pddl, formula.symbol(), parameters, arguments, apply_axioms);
64  }
65 
66  static std::optional<DisjunctiveFormula> Create(
67  const Pddl& pddl, const VAL::goal* symbol,
68  const std::vector<Object>& parameters,
69  const std::vector<Object>& arguments, bool apply_axioms = false);
70 
71  static std::optional<DisjunctiveFormula> Create(
72  const Pddl& pddl, const VAL::effect_lists* symbol,
73  const std::vector<Object>& parameters,
74  const std::vector<Object>& arguments, bool apply_axioms = false);
75 
76  static std::optional<DisjunctiveFormula> Create(const Pddl& pddl,
77  ConjunctiveFormula&& cnf,
78  bool apply_axioms = false);
79 
93  static std::optional<std::pair<DisjunctiveFormula, DisjunctiveFormula>>
94  NormalizeConditions(const Pddl& pddl, const std::string& action_call,
95  bool apply_axioms = false);
96 
97  static std::optional<DisjunctiveFormula> NormalizePreconditions(
98  const Pddl& pddl, const std::string& action_call,
99  bool apply_axioms = false);
100 
101  static std::optional<DisjunctiveFormula> NormalizePostconditions(
102  const Pddl& pddl, const std::string& action_call,
103  bool apply_axioms = false);
104 
105  static std::optional<DisjunctiveFormula> NormalizeGoal(
106  const Pddl& pddl, bool apply_axioms = false);
107 
108  friend bool operator==(const DisjunctiveFormula& lhs,
109  const DisjunctiveFormula& rhs) {
110  return lhs.conjunctions == rhs.conjunctions;
111  }
112 
113  friend std::ostream& operator<<(std::ostream& os,
114  const DisjunctiveFormula& dnf);
115 
116  std::vector<Conjunction> conjunctions;
117 };
118 
120  using Disjunction = PartialState;
121 
122  ConjunctiveFormula() = default;
123 
124  // ConjunctiveFormula(const Pddl& pddl, const Formula& formula,
125  // const std::vector<Object>& parameters,
126  // const std::vector<Object>& arguments);
127 
128  // ConjunctiveFormula(const DisjunctiveFormula& dnf);
129 
130  friend std::ostream& operator<<(std::ostream& os,
131  const ConjunctiveFormula& cnf);
132 
133  std::vector<Disjunction> disjunctions;
134 };
135 
136 // bool Simplify(DisjunctiveFormula* dnf);
137 
138 // DisjunctiveFormula Disjoin(std::vector<DisjunctiveFormula>&& dnfs);
139 
140 // DisjunctiveFormula Conjoin(const std::vector<DisjunctiveFormula>& dnfs);
141 
142 std::optional<DisjunctiveFormula> Negate(const Pddl& pddl,
143  DisjunctiveFormula&& dnf);
144 
145 // ConjunctiveFormula Flip(DisjunctiveFormula&& cnf);
146 
147 } // namespace symbolic
148 
149 #endif // SYMBOLIC_NORMAL_FORM_H_
symbolic
Definition: action.cc:329
symbolic::DisjunctiveFormula::NormalizeConditions
static std::optional< std::pair< DisjunctiveFormula, DisjunctiveFormula > > NormalizeConditions(const Pddl &pddl, const std::string &action_call, bool apply_axioms=false)
Definition: normal_form.cc:481
symbolic::Pddl
Definition: pddl.h:40
symbolic::DisjunctiveFormula
Definition: normal_form.h:27
symbolic::ConjunctiveFormula
Definition: normal_form.h:119
symbolic::Formula
Definition: formula.h:36
symbolic::PartialState
Definition: state.h:126