knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
ModalFormula.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #include <utility>
7 
8 #include "knowrob/formulas/ModalFormula.h"
9 #include "knowrob/integration/python/utils.h"
10 #include "knowrob/terms/Numeric.h"
11 
12 using namespace knowrob;
13 
16  modalOperator_(std::move(modalOperator)) {
17 }
18 
19 bool ModalFormula::isEqual(const Formula &other) const {
20  const auto &x = static_cast<const ModalFormula &>(other); // NOLINT
21  return (*modalOperator() == *x.modalOperator()) && (*modalFormula()) == (*x.modalFormula());
22 }
23 
25  return modalOperator_->isModalNecessity();
26 }
27 
28 const char *ModalFormula::operator_symbol() const {
29  return modalOperator_->symbol();
30 }
31 
32 void ModalFormula::write(std::ostream &os) const {
33  modalOperator_->write(os);
34  os << *(formulae_[0].get());
35 }
36 
37 namespace knowrob::modals {
38  std::shared_ptr<ModalFormula> B(const FormulaPtr &phi) {
39  return std::make_shared<ModalFormula>(B(), phi);
40  }
41 
42  std::shared_ptr<ModalFormula> K(const FormulaPtr &phi) {
43  return std::make_shared<ModalFormula>(K(), phi);
44  }
45 
46  std::shared_ptr<ModalFormula> P(const FormulaPtr &phi) {
47  return std::make_shared<ModalFormula>(P(), phi);
48  }
49 
50  std::shared_ptr<ModalFormula> H(const FormulaPtr &phi) {
51  return std::make_shared<ModalFormula>(H(), phi);
52  }
53 
55  static auto k_withoutArgs = std::make_shared<ModalOperator>(ModalType::KNOWLEDGE);
56  return k_withoutArgs;
57  }
58 
59  ModalOperatorPtr K(std::string_view perspective) {
60  auto op = std::make_shared<ModalOperator>(ModalType::KNOWLEDGE);
61  op->setPerspective(perspective);
62  return op;
63  }
64 
66  static auto beliefOperator = std::make_shared<ModalOperator>(ModalType::BELIEF);
67  return beliefOperator;
68  }
69 
70  ModalOperatorPtr B(std::string_view perspective) {
71  auto op = std::make_shared<ModalOperator>(ModalType::BELIEF);
72  op->setPerspective(perspective);
73  return op;
74  }
75 
76  ModalOperatorPtr B(std::string_view perspective, double confidence) {
77  auto op = std::make_shared<ModalOperator>(ModalType::BELIEF);
78  op->setPerspective(perspective);
79  op->setConfidence(confidence);
80  return op;
81  }
82 
83  ModalOperatorPtr B(double confidence) {
84  auto op = std::make_shared<ModalOperator>(ModalType::BELIEF);
85  op->setConfidence(confidence);
86  return op;
87  }
88 
90  static auto op = std::make_shared<ModalOperator>(ModalType::SOMETIMES);
91  return op;
92  }
93 
94  ModalOperatorPtr P(const TimeInterval &timeInterval) {
95  auto op = std::make_shared<ModalOperator>(ModalType::SOMETIMES);
96  op->setTimeInterval(timeInterval);
97  return op;
98  }
99 
101  static auto op = std::make_shared<ModalOperator>(ModalType::ALWAYS);
102  return op;
103  }
104 
105  ModalOperatorPtr H(const TimeInterval &timeInterval) {
106  auto op = std::make_shared<ModalOperator>(ModalType::ALWAYS);
107  op->setTimeInterval(timeInterval);
108  return op;
109  }
110 } // knowrob::modals
111 
112 namespace knowrob::py {
113  template<>
115  using namespace boost::python;
116  class_<ModalFormula, std::shared_ptr<ModalFormula>, bases<CompoundFormula>>
117  ("ModalFormula", init<const ModalOperatorPtr &, const FormulaPtr &>())
118  .def("modalOperator", &ModalFormula::modalOperator, return_value_policy<copy_const_reference>())
119  .def("modalFormula", &ModalFormula::modalFormula, return_value_policy<copy_const_reference>())
120  .def("isModalPossibility", &ModalFormula::isModalPossibility)
121  .def("isModalNecessity", &ModalFormula::isModalNecessity);
122  }
123 }
const std::vector< FormulaPtr > formulae_
bool isModalPossibility() const
Definition: ModalFormula.h:39
void write(std::ostream &os) const override
const ModalOperatorPtr & modalOperator() const
Definition: ModalFormula.h:29
bool isEqual(const Formula &other) const override
bool isModalNecessity() const
const char * operator_symbol() const override
const ModalOperatorPtr modalOperator_
Definition: ModalFormula.h:53
ModalFormula(ModalOperatorPtr modalOperator, const FormulaPtr &formula)
const FormulaPtr & modalFormula() const
Definition: ModalFormula.h:34
std::shared_ptr< ModalFormula > K(const FormulaPtr &phi)
std::shared_ptr< ModalFormula > P(const FormulaPtr &phi)
std::shared_ptr< ModalFormula > B(const FormulaPtr &phi)
std::shared_ptr< ModalFormula > H(const FormulaPtr &phi)
FormulaRule & formula()
Definition: formula.cpp:283
void createType< ModalFormula >()
std::shared_ptr< Formula > FormulaPtr
Definition: Formula.h:99
std::shared_ptr< const ModalOperator > ModalOperatorPtr
FormulaType
Definition: Formula.h:17