aGrUM 3.1.1
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-2026 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-2026 *
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 GUM_O3PRMR_CONTEXT_H
50#define GUM_O3PRMR_CONTEXT_H
51
52#include <map>
53#include <string>
54#include <vector>
55
57
58#include <string_view>
59
60namespace gum {
61 namespace prm {
62 namespace o3prmr {
63
70 public:
71 int line;
73
74 explicit O3prmrCommand(int line);
75
77
78 virtual ~O3prmrCommand() = default;
79
80 virtual RequestType type() const = 0;
81 virtual std::string toString() const = 0;
82 };
83
86 public:
87 ImportCommand(int line, std::string_view value, std::string_view alias);
88
90
91 int line;
92 std::string value;
93 std::string alias;
94
95 std::string toString() const;
96 };
97
100 public:
101 SetEngineCommand(int line, std::string_view value);
102
104
105 std::string value;
106
107 RequestType type() const override;
108
109 std::string toString() const override;
110 };
111
114 public:
115 SetGndEngineCommand(int line, std::string_view value);
116
118
119 std::string value;
120
121 RequestType type() const override;
122
123 std::string toString() const override;
124 };
125
127 template < GUM_Numeric GUM_SCALAR >
129 public:
130 ObserveCommand(int line, std::string_view leftValue, std::string_view rightValue);
131
133
134 std::string leftValue;
135 std::string rightValue;
138 Tensor< GUM_SCALAR > potentiel;
139
140 RequestType type() const override;
141
142 std::string toString() const override;
143 };
144
146 template < GUM_Numeric GUM_SCALAR >
148 public:
149 std::string value;
152
153 UnobserveCommand(int line, std::string_view value);
154
156
157 RequestType type() const override;
158
159 std::string toString() const override;
160 };
161
163 template < GUM_Numeric GUM_SCALAR >
165 public:
166 QueryCommand(int line, std::string_view val);
167
168 std::string value;
171
172 RequestType type() const override;
173
174 std::string toString() const override;
175 };
176
181 template < GUM_Numeric GUM_SCALAR >
184 std::string m_name;
186 std::vector< O3prmrCommand* > m_commands;
187 std::map< const PRMSystem< GUM_SCALAR >*, PRMInference< GUM_SCALAR >* > m_infEngineMap;
188
189 public:
190 explicit O3prmrSession(std::string_view name = "");
192 virtual ~O3prmrSession();
193
194 std::string name() const;
195
196 std::vector< O3prmrCommand* > commands() const;
197 void addObserve(int line, std::string_view leftValue, std::string_view rightValue);
198 void addUnobserve(int line, std::string_view value);
199 void addQuery(int line, std::string_view value);
200 void addSetEngine(int line, std::string_view value);
201 void addSetGndEngine(int line, std::string_view value);
202 void addCommand(const O3prmrCommand* command);
203
204 virtual std::string toString() const;
206
207 private:
208 void addCommand(O3prmrCommand* command);
209 };
210
215 template < GUM_Numeric GUM_SCALAR >
217 std::string m_filename;
218 std::string m_package;
219 std::vector< O3prmrSession< GUM_SCALAR >* > m_sessions;
220 std::vector< ImportCommand* > m_imports;
222
223 public:
224 explicit O3prmrContext(std::string_view filename = "");
226 virtual ~O3prmrContext();
227
228 const ImportCommand* mainImport() const;
229
230 std::string filename() const;
231
232 std::string package() const;
233 void setPackage(std::string_view package);
234
235 std::string aliasToImport(std::string_view alias);
236 std::vector< ImportCommand* > imports() const;
237 void addImport(int line, std::string_view import, std::string_view alias);
238 void addImport(int line, std::string_view import, bool ismain);
239
240 void addImport(const ImportCommand& i);
241
242 std::vector< O3prmrSession< GUM_SCALAR >* > sessions() const;
243 void addSession(const O3prmrSession< GUM_SCALAR >& session);
244
245 virtual std::string toString() const;
247 };
248
249
250#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
251# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
252# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
253# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
254# ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
255 extern template class ObserveCommand< double >;
256# endif
257# endif
258# endif
259# endif
260#endif
261#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
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 extern template class UnobserveCommand< double >;
267# endif
268# endif
269# endif
270# endif
271#endif
272#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
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 extern template class QueryCommand< double >;
278# endif
279# endif
280# endif
281# endif
282#endif
283#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
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 extern template class O3prmrSession< double >;
289# endif
290# endif
291# endif
292# endif
293#endif
294#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
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 extern template class O3prmrContext< double >;
300# endif
301# endif
302# endif
303# endif
304#endif
305
306
307 } // namespace o3prmr
308 } // namespace prm
309} // namespace gum
310
311#ifndef GUM_NO_INLINE
313#endif // GUM_NO_INLINE
314
316
317#endif // GUM_O3PRMR_CONTEXT_H
Inline implementation of non-template classes in O3prmrContext.
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:72
ImportCommand(int line, std::string_view value, std::string_view alias)
ImportCommand(const ImportCommand &c)
This is an abstract class.
virtual ~O3prmrCommand()=default
O3prmrCommand(const O3prmrCommand &c)
virtual RequestType type() const =0
virtual std::string toString() const =0
std::vector< ImportCommand * > m_imports
void addImport(int line, std::string_view import, std::string_view 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
O3prmrContext(std::string_view filename="")
const ImportCommand * mainImport() const
std::string aliasToImport(std::string_view alias)
void setPackage(std::string_view package)
O3prmrContext & operator+=(const O3prmrContext &c)
This class contains a o3prmr session.
O3prmrSession & operator+=(const O3prmrSession &c)
O3prmrSession(std::string_view name="")
std::vector< O3prmrCommand * > commands() const
void addSetEngine(int line, std::string_view value)
void addUnobserve(int line, std::string_view value)
std::string m_name
The session name;.
virtual std::string toString() const
void addObserve(int line, std::string_view leftValue, std::string_view rightValue)
void addQuery(int line, std::string_view value)
void addSetGndEngine(int line, std::string_view value)
std::vector< O3prmrCommand * > m_commands
A sequence of commands.
std::map< const PRMSystem< GUM_SCALAR > *, PRMInference< GUM_SCALAR > * > m_infEngineMap
void addCommand(const O3prmrCommand *command)
std::string toString() const override
RequestType type() const override
PRMInference< GUM_SCALAR >::Chain chain
const PRMSystem< GUM_SCALAR > * system
ObserveCommand(int line, std::string_view leftValue, std::string_view rightValue)
const PRMSystem< GUM_SCALAR > * system
PRMInference< GUM_SCALAR >::Chain chain
RequestType type() const override
std::string toString() const override
QueryCommand(int line, std::string_view val)
SetEngineCommand(const SetEngineCommand &c)
std::string toString() const override
RequestType type() const override
SetEngineCommand(int line, std::string_view value)
SetGndEngineCommand(const SetGndEngineCommand &c)
RequestType type() const override
std::string toString() const override
SetGndEngineCommand(int line, std::string_view value)
UnobserveCommand(int line, std::string_view value)
PRMInference< GUM_SCALAR >::Chain chain
const PRMSystem< GUM_SCALAR > * system
std::string toString() const override
RequestType type() const override
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46