aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
O3prmrInterpreter.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of O3prmInterpreter
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6), Ni NI, Lionel TORTI & Vincent RENAUDINEAU
27  */
28 
29 #ifndef SKOORINTERPRETER_H
30 #define SKOORINTERPRETER_H
31 
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 # include <agrum/PRM/inference/PRMInference.h>
34 # include <agrum/PRM/o3prm/O3prmReader.h>
35 # include <agrum/PRM/o3prmr/O3prmrContext.h>
36 
37 # include <agrum/tools/core/errorsContainer.h>
38 #endif // DOXYGEN_SHOULD_SKIP_THIS
39 
40 namespace gum {
41 
42  namespace prm {
43 
44  namespace o3prmr {
45 
46  /**
47  *
48  * */
49  class SingleResult {
50  public:
52  float p;
53  };
54 
55  /**
56  *
57  * */
58  class QueryResult {
59  public:
60  double time;
63  };
64 
65  /**
66  * @brief Represents a O3PRMR context.
67  * O3prmr use the @<double@> version of the O3PRM templatized ecosystem
68  */
70  public:
71  /// This constructor create an empty context.
73  /// Destructor. Delete current context.
75 
76  /**
77  * Interpret the file or the command line.
78  * If syntax mode is activated, check only syntax and semantic.
79  * If errors occured, return false. Errors messages can be retrieve be
80  * errorsContainer() methods.
81  * If any errors occured, return true.
82  * Requests results can be retrieve be results() methods.
83  * */
84  bool interpretFile(const std::string& filename);
85  bool interpretLine(const std::string& line);
86 
87  /// Retrieve prm object.
88  const gum::prm::PRM< double >* prm() const;
89  /// Retrieve inference motor object.
90  const gum::prm::PRMInference< double >* inference() const;
91  /// Return a vector of QueryResults.
92  /// Each QueryResults is a struct with query command, time and values,
93  /// a vector of struct SingleResult, with pair label/value.
94  const std::vector< QueryResult >& results() const;
95  /// Return container with all errors.
97 
98  /// Getter and setter for the context.
99  O3prmrContext< double >* getContext() const;
100  void setContext(O3prmrContext< double >* context);
101 
102  /// Root paths to search from there packages.
103  /// Default are working dir, request file dir if any
104  /// and one is calculate from package if any.
105  std::vector< std::string > getPaths() const;
106  void addPath(std::string path);
107  void clearPaths();
108 
109  /// syntax mode don't process anything, just check syntax. Default is
110  /// false.
111  bool isInSyntaxMode() const;
112  void setSyntaxMode(bool f);
113 
114  /// verbose mode show more details on the program execution. Default is
115  /// false.
116  bool isVerboseMode() const;
117  void setVerboseMode(bool f);
118 
119  /**
120  * En cas d'échec, l'API de gestion d'erreurs est présente.
121  * */
122  /// # of errors + warnings
123  Size count() const;
124  /// # of errors
125  Size errors() const;
126  /// # of warnings
127  Size warnings() const;
128  /// throw a string error if i >= count
129  ParseError error(Idx i) const;
130  /// send on std::cerr the list of errors
131  void showElegantErrors(std::ostream& o = std::cerr) const;
132  /// send on std::cerr the list of errors or warnings
133  void showElegantErrorsAndWarnings(std::ostream& o = std::cerr) const;
134  /// send on std::cerr the number of errors and the number of warnings
135  void showErrorCounts(std::ostream& o = std::cerr) const;
136 
137  private:
138  bool checkSemantic(O3prmrContext< double >* context);
139  bool checkSetEngine(SetEngineCommand* command);
140  bool checkSetGndEngine(SetGndEngineCommand* command);
141  bool checkObserve(ObserveCommand< double >* command);
142  bool checkUnobserve(UnobserveCommand< double >* command);
143  bool checkQuery(QueryCommand< double >* command);
144 
145  bool interpret(O3prmrContext< double >* c);
146  bool import(O3prmrContext< double >* context, std::string import);
147  bool observe(const ObserveCommand< double >* command);
148  bool unobserve(const UnobserveCommand< double >* command);
149  void query(const QueryCommand< double >* command);
150  void setEngine(const SetEngineCommand* command);
151  void setGndEngine(const SetGndEngineCommand* command);
152 
154  std::string findInstanceName(std::string& s, const gum::prm::PRMSystem< double >& sys);
156  const gum::prm::PRMInstance< double >& instance);
157  const PRMSystem< double >& system(std::string& ident);
158  void generateInfEngine(const gum::prm::PRMSystem< double >& sys);
159 
160  void addError(std::string msg);
161  void addWarning(std::string msg);
162 
163  std::string _readFile_(const std::string& file);
164 
168  gum::BayesNet< double >* m_bn;
169  // Don't delete this, the m_inf_map will do it
170  gum::prm::PRMInference< double >* m_inf;
171  HashTable< const PRMSystem< double >*, PRMInference< double >* > m_inf_map;
177  bool m_verbose;
180 
181  //// We need this when using grounded inference
182  // gum::BayesNetInference<gum::prm::prm_float>* bn;
183 
184  }; // class O3prmrInterpreter
185 
186  } // namespace o3prmr
187  } // namespace prm
188 } // namespace gum
189 
190 #endif // GUM_SKOORINTERPRETER_H
void showElegantErrors(std::ostream &o=std::cerr) const
send on std::cerr the list of errors
bool observe(const ObserveCommand< double > *command)
void addPath(std::string path)
Root paths to search from there packages. Default are &#39;./&#39; and one is calculate from request package ...
void generateInfEngine(const gum::prm::PRMSystem< double > &sys)
const gum::prm::PRM< double > * prm() const
Retrieve prm object.
void query(const QueryCommand< double > *command)
bool checkSetEngine(SetEngineCommand *command)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
bool checkSemantic(O3prmrContext< double > *context)
Check semantic validity of context.
bool isVerboseMode() const
verbose mode show more details on the program execution. Default is false.
bool checkSetGndEngine(SetGndEngineCommand *command)
const gum::prm::PRMInference< double > * inference() const
Retrieve inference motor object.
bool checkQuery(QueryCommand< double > *command)
bool checkUnobserve(UnobserveCommand< double > *command)
std::string findSystemName(std::string &s)
gum::prm::o3prm::O3prmReader< double > * m_reader
void showElegantErrorsAndWarnings(std::ostream &o=std::cerr) const
send on std::cerr the list of errors or warnings
ParseError error(Idx i) const
throw a string error if i >= count
bool import(O3prmrContext< double > *context, std::string import)
std::string _readFile_(const std::string &file)
std::vector< SingleResult > values
bool interpret(O3prmrContext< double > *c)
Crée le prm correspondant au contexte courant.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
std::string findAttributeName(const std::string &s, const gum::prm::PRMInstance< double > &instance)
gum::prm::PRMInference< double > * m_inf
std::vector< std::string > m_paths
bool interpretLine(const std::string &line)
void clearPaths()
Root paths to search from there packages. Default are &#39;./&#39; and one is calculate from request package ...
void setSyntaxMode(bool f)
syntax mode don&#39;t process anything, just check syntax.
ErrorsContainer errorsContainer() const
Return container with all errors.
bool interpretFile(const std::string &filename)
Interpret the file or the command line.
bool checkObserve(ObserveCommand< double > *command)
void setGndEngine(const SetGndEngineCommand *command)
void setEngine(const SetEngineCommand *command)
std::vector< std::string > getPaths() const
Root paths to search from there packages. Default are working dir, request file dir if any and one is...
~O3prmrInterpreter()
Destructor. Delete current context.
bool unobserve(const UnobserveCommand< double > *command)
bool isInSyntaxMode() const
syntax mode don&#39;t process anything, just check syntax. Default is false.
O3prmrContext< double > * getContext() const
Getter and setter for the context.
void showErrorCounts(std::ostream &o=std::cerr) const
send on std::cerr the number of errors and the number of warnings
Size count() const
En cas d&#39;échec, l&#39;API de gestion d&#39;erreurs est présente.
HashTable< const PRMSystem< double > *, PRMInference< double > *> m_inf_map
const PRMSystem< double > & system(std::string &ident)
const std::vector< QueryResult > & results() const
Return a vector of QueryResults. Each QueryResults is a struct with query command, time and values, a vector of struct SingleResult, with pair label/value.
void setContext(O3prmrContext< double > *context)
Setter for the context.
O3prmrInterpreter()
This constructor create an empty context.
std::vector< QueryResult > m_results
std::string findInstanceName(std::string &s, const gum::prm::PRMSystem< double > &sys)
void setVerboseMode(bool f)
verbose mode show more details on the program execution.
O3prmrContext< double > * m_context