knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
ReasonerManager.h
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 #ifndef KNOWROB_REASONER_MANAGER_H_
7 #define KNOWROB_REASONER_MANAGER_H_
8 
9 #include "knowrob/plugins/PluginManager.h"
10 #include "knowrob/storage/StorageManager.h"
11 #include "knowrob/KnowledgeBase.h"
12 #include "knowrob/reasoner/GoalDrivenReasoner.h"
13 #include "knowrob/reasoner/DataDrivenReasoner.h"
14 
15 namespace knowrob {
19  class ReasonerManager : public PluginManager<Reasoner> {
20  public:
26  ReasonerManager(KnowledgeBase *kb, const std::shared_ptr<StorageManager> &backendManager);
27 
28  ~ReasonerManager() override;
29 
33  auto kb() const { return kb_; }
34 
38  auto backendManager() const { return backendManager_; }
39 
43  auto &goalDriven() const { return goalDriven_; }
44 
48  auto &dataDriven() const { return dataDriven_; }
49 
54  std::vector<DefiningReasoner> findDefiningReasoner(const PredicateIndicator &indicator) const;
55 
61  std::shared_ptr<Storage> getReasonerStorage(const std::shared_ptr<NamedReasoner> &reasoner);
62 
63  // override PluginManager
64  std::shared_ptr<NamedReasoner> loadPlugin(const boost::property_tree::ptree &config) override;
65 
66  // override PluginManager
67  std::shared_ptr<NamedReasoner>
68  addPlugin(std::string_view reasonerID, PluginLanguage language, const std::shared_ptr<Reasoner> &reasoner) override;
69 
78  const GoalDrivenReasonerPtr &reasoner,
79  const std::vector<FirstOrderLiteralPtr> &literals,
80  const QueryContextPtr &ctx);
81 
82  private:
83  KnowledgeBase *kb_;
84  std::shared_ptr<StorageManager> backendManager_;
85  // maps reasoner to their backends
86  std::map<std::string_view, StoragePtr, std::less<>> reasonerBackends_;
87  std::map<std::string_view, DataDrivenReasonerPtr> dataDriven_;
88  std::map<std::string_view, GoalDrivenReasonerPtr> goalDriven_;
89 
90  void setReasonerStorage(const std::shared_ptr<NamedPlugin<Reasoner>> &plugin, const std::shared_ptr<Storage> &dataBackend);
91 
92  void initPlugin(const std::shared_ptr<NamedReasoner> &namedReasoner);
93 
94  static bool initializeReasoner(const std::shared_ptr<NamedReasoner> &namedReasoner, PropertyTree &config);
95  };
96 }
97 
98 // a macro for static registration of a reasoner type.
99 // reasoner types registered with this macro are builtin reasoners that are not
100 // loaded from a plugin.
101 #define KNOWROB_BUILTIN_REASONER(Name, Type) class Type ## _Registration{ static bool isRegistered; }; \
102  bool Type ## _Registration::isRegistered = knowrob::PluginManager<knowrob::Reasoner>::addFactory<Type>(Name);
103 
104 #endif //KNOWROB_REASONER_MANAGER_H_
std::shared_ptr< NamedReasoner > addPlugin(std::string_view reasonerID, PluginLanguage language, const std::shared_ptr< Reasoner > &reasoner) override
std::shared_ptr< NamedReasoner > loadPlugin(const boost::property_tree::ptree &config) override
static TokenBufferPtr evaluateQuery(const GoalDrivenReasonerPtr &reasoner, const std::vector< FirstOrderLiteralPtr > &literals, const QueryContextPtr &ctx)
std::vector< DefiningReasoner > findDefiningReasoner(const PredicateIndicator &indicator) const
ReasonerManager(KnowledgeBase *kb, const std::shared_ptr< StorageManager > &backendManager)
std::shared_ptr< Storage > getReasonerStorage(const std::shared_ptr< NamedReasoner > &reasoner)
PluginLanguage
Definition: NamedPlugin.h:16
std::shared_ptr< TokenBuffer > TokenBufferPtr
Definition: TokenBuffer.h:43
std::shared_ptr< const QueryContext > QueryContextPtr
Definition: QueryContext.h:41
std::shared_ptr< GoalDrivenReasoner > GoalDrivenReasonerPtr