aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
O3prmrContext.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48
49#ifndef SKOORSYNTAXTREE_H
50#define SKOORSYNTAXTREE_H
51
52#include <map>
53#include <string>
54#include <vector>
55
57
58namespace gum {
59 namespace prm {
60 namespace o3prmr {
61
68 public:
69 int line;
71
72 explicit O3prmrCommand(int line) : line(line) {}
73
75
76 virtual ~O3prmrCommand() {}
77
78 virtual RequestType type() const = 0;
79 virtual std::string toString() const = 0;
80 };
81
84 public:
85 ImportCommand(int line, const std::string& value, const std::string& alias) :
87
89
90 int line;
91 std::string value;
92 std::string alias;
93
94 std::string toString() const {
95 return "import " + value + (alias.empty() ? "" : "as " + alias) + ";";
96 }
97 };
98
101 public:
102 SetEngineCommand(int line, const std::string& value) : O3prmrCommand(line), value(value) {}
103
105
106 std::string value;
107
109
110 std::string toString() const { return "engine " + value + ";"; }
111 };
112
115 public:
116 SetGndEngineCommand(int line, const std::string& value) :
118
120
121 std::string value;
122
124
125 std::string toString() const { return "grd_engine " + value + ";"; }
126 };
127
129 template < typename GUM_SCALAR >
131 public:
132 ObserveCommand(int line, const std::string& leftValue, const std::string& rightValue) :
134
138
139 std::string leftValue;
140 std::string rightValue;
143 Tensor< GUM_SCALAR > potentiel;
144
146
147 std::string toString() const { return leftValue + " = " + rightValue + ";"; }
148 };
149
151 template < typename GUM_SCALAR >
153 public:
154 std::string value;
157
158 UnobserveCommand(int line, const std::string& value) :
160
163
165
166 std::string toString() const { return "unobserve " + value + ";"; }
167 };
168
170 template < typename GUM_SCALAR >
172 public:
173 QueryCommand(int line, const std::string& val) :
174 O3prmrCommand(line), value(val), system(nullptr) {}
175
176 std::string value;
179
181
182 std::string toString() const { return "? " + value + ";"; }
183 };
184
189 template < typename GUM_SCALAR >
192 std::string m_name;
194 std::vector< O3prmrCommand* > m_commands;
195 std::map< const PRMSystem< GUM_SCALAR >*, PRMInference< GUM_SCALAR >* > m_infEngineMap;
196
197 public:
198 explicit O3prmrSession(const std::string& name = std::string());
200 virtual ~O3prmrSession();
201
202 std::string name() const;
203
204 std::vector< O3prmrCommand* > commands() const;
205 void addObserve(int line, const std::string& leftValue, const std::string& rightValue);
206 void addUnobserve(int line, const std::string& value);
207 void addQuery(int line, const std::string& value);
208 void addSetEngine(int line, const std::string& value);
209 void addSetGndEngine(int line, const std::string& value);
210 void addCommand(const O3prmrCommand* command);
211
212 virtual std::string toString() const;
214
215 private:
216 void addCommand(O3prmrCommand* command);
217 };
218
223 template < typename GUM_SCALAR >
225 std::string m_filename;
226 std::string m_package;
227 std::vector< O3prmrSession< GUM_SCALAR >* > m_sessions;
228 std::vector< ImportCommand* > m_imports;
230
231 public:
232 explicit O3prmrContext(const std::string& filename = std::string());
234 virtual ~O3prmrContext();
235
236 const ImportCommand* mainImport() const { return m_mainImport; }
237
238 std::string filename() const;
239
240 std::string package() const;
241 void setPackage(const std::string& package);
242
243 std::string aliasToImport(const std::string& alias);
244 std::vector< ImportCommand* > imports() const;
245 void addImport(int line, const std::string& import, const std::string& alias);
246 void addImport(int line, const std::string& import, bool ismain);
247
248 void addImport(const ImportCommand& i) {
249 m_imports.push_back(new ImportCommand(i.line, i.value, i.alias));
250
251 if (i.alias == "default") m_mainImport = m_imports.back();
252 }
253
254 std::vector< O3prmrSession< GUM_SCALAR >* > sessions() const;
255 void addSession(const O3prmrSession< GUM_SCALAR >& session);
256
257 virtual std::string toString() const;
259 };
260
261
262#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
263# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
264# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
265# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
266# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
267 extern template class ObserveCommand< double >;
268# endif
269# endif
270# endif
271# endif
272#endif
273#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
274# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
275# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
276# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
277# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
278 extern template class UnobserveCommand< double >;
279# endif
280# endif
281# endif
282# endif
283#endif
284#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
285# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
286# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
287# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
288# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
289 extern template class QueryCommand< double >;
290# endif
291# endif
292# endif
293# endif
294#endif
295#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
296# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
297# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
298# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
299# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
300 extern template class O3prmrSession< double >;
301# endif
302# endif
303# endif
304# endif
305#endif
306#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
307# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
308# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
309# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
310# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
311 extern template class O3prmrContext< double >;
312# endif
313# endif
314# endif
315# endif
316#endif
317
318
319 } // namespace o3prmr
320 } // namespace prm
321} // namespace gum
322
324
325#endif // SKOORSYNTAXTREE_H
Implementation of O3prmReader.
Headers of PRMInference.
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
ImportCommand(const ImportCommand &c)
ImportCommand(int line, const std::string &value, const std::string &alias)
This is an abstract class.
virtual RequestType type() const =0
virtual std::string toString() const =0
O3prmrCommand(const O3prmrCommand &c)
Represent a o3prmr context, with an import, and some sequencials commands.
std::vector< ImportCommand * > m_imports
std::string aliasToImport(const std::string &alias)
std::vector< O3prmrSession< GUM_SCALAR > * > sessions() const
void addSession(const O3prmrSession< GUM_SCALAR > &session)
virtual std::string toString() const
std::vector< ImportCommand * > imports() const
std::vector< O3prmrSession< GUM_SCALAR > * > m_sessions
void addImport(int line, const std::string &import, const std::string &alias)
const ImportCommand * mainImport() const
void addImport(const ImportCommand &i)
void setPackage(const std::string &package)
O3prmrContext(const std::string &filename=std::string())
O3prmrContext & operator+=(const O3prmrContext &c)
This class contains a o3prmr session.
void addSetEngine(int line, const std::string &value)
O3prmrSession & operator+=(const O3prmrSession &c)
std::vector< O3prmrCommand * > commands() const
O3prmrSession(const std::string &name=std::string())
std::string m_name
The session name;.
void addQuery(int line, const std::string &value)
virtual std::string toString() const
std::vector< O3prmrCommand * > m_commands
A sequence of commands.
void addUnobserve(int line, const std::string &value)
void addSetGndEngine(int line, const std::string &value)
std::map< const PRMSystem< GUM_SCALAR > *, PRMInference< GUM_SCALAR > * > m_infEngineMap
void addCommand(const O3prmrCommand *command)
void addObserve(int line, const std::string &leftValue, const std::string &rightValue)
ObserveCommand(const ObserveCommand &c)
PRMInference< GUM_SCALAR >::Chain chain
const PRMSystem< GUM_SCALAR > * system
ObserveCommand(int line, const std::string &leftValue, const std::string &rightValue)
QueryCommand(int line, const std::string &val)
const PRMSystem< GUM_SCALAR > * system
PRMInference< GUM_SCALAR >::Chain chain
SetEngineCommand(int line, const std::string &value)
SetEngineCommand(const SetEngineCommand &c)
SetGndEngineCommand(int line, const std::string &value)
SetGndEngineCommand(const SetGndEngineCommand &c)
UnobserveCommand(int line, const std::string &value)
PRMInference< GUM_SCALAR >::Chain chain
const PRMSystem< GUM_SCALAR > * system
UnobserveCommand(const UnobserveCommand &c)
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46