aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
PRM_tpl.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#pragma once
41
42
49#include <agrum/PRM/PRM.h>
50
51namespace gum {
52 namespace prm {
53
54 // Default constructor.
55 template < typename GUM_SCALAR >
57 GUM_CONSTRUCTOR(PRM);
59 }
60
61 // Destructor.
62 template < typename GUM_SCALAR >
64 GUM_DESTRUCTOR(PRM);
65 _classMap_.clear();
66 _typeMap_.clear();
67 _systemMap_.clear();
68
69 for (const auto sys: _systems_)
70 delete sys;
71
72 for (const auto cla: _classes_)
73 delete cla;
74
75 for (const auto inter: _interfaces_)
76 delete inter;
77
78 for (const auto typ: _types_)
79 delete typ;
80 }
81
82 // Add the built-in types in the PRM
83 template < typename GUM_SCALAR >
85 LabelizedVariable var("boolean", "built-in type", 0);
86 var.addLabel("false");
87 var.addLabel("true");
88 PRMType* boolean = new PRMType(var);
89 _types_.insert(boolean);
90 _typeMap_.insert("boolean", boolean);
91 }
92
93 template < typename GUM_SCALAR >
94 INLINE bool PRM< GUM_SCALAR >::isType(const std::string& name) const {
95 return _typeMap_.exists(name);
96 }
97
98 template < typename GUM_SCALAR >
99 INLINE bool PRM< GUM_SCALAR >::isClass(const std::string& name) const {
100 return _classMap_.exists(name);
101 }
102
103 template < typename GUM_SCALAR >
104 INLINE bool PRM< GUM_SCALAR >::isInterface(const std::string& name) const {
105 return _interfaceMap_.exists(name);
106 }
107
108 template < typename GUM_SCALAR >
109 INLINE bool PRM< GUM_SCALAR >::isSystem(const std::string& name) const {
110 return _systemMap_.exists(name);
111 }
112
113 template < typename GUM_SCALAR >
114 INLINE PRMType& PRM< GUM_SCALAR >::type(const std::string& name) {
115 return *(_typeMap_[name]);
116 }
118 template < typename GUM_SCALAR >
119 INLINE const PRMType& PRM< GUM_SCALAR >::type(const std::string& name) const {
120 return *(_typeMap_[name]);
121 }
122
123 template < typename GUM_SCALAR >
125 return _types_;
126 }
127
128 template < typename GUM_SCALAR >
129 INLINE PRMClass< GUM_SCALAR >& PRM< GUM_SCALAR >::getClass(const std::string& name) {
130 return *(_classMap_[name]);
131 }
132
133 template < typename GUM_SCALAR >
134 INLINE const PRMClass< GUM_SCALAR >&
135 PRM< GUM_SCALAR >::getClass(const std::string& name) const {
136 return *(_classMap_[name]);
137 }
138
139 template < typename GUM_SCALAR >
141 return _classes_;
142 }
143
144 template < typename GUM_SCALAR >
146 return *_interfaceMap_[name];
147 }
148
149 template < typename GUM_SCALAR >
150 INLINE const PRMInterface< GUM_SCALAR >&
151 PRM< GUM_SCALAR >::getInterface(const std::string& name) const {
152 return *_interfaceMap_[name];
153 }
154
155 template < typename GUM_SCALAR >
158 }
159
160 template < typename GUM_SCALAR >
161 INLINE PRMSystem< GUM_SCALAR >& PRM< GUM_SCALAR >::getSystem(const std::string& name) {
162 return *(_systemMap_[name]);
164
165 template < typename GUM_SCALAR >
166 INLINE const PRMSystem< GUM_SCALAR >&
167 PRM< GUM_SCALAR >::getSystem(const std::string& name) const {
168 return *(_systemMap_[name]);
169 }
170
171 template < typename GUM_SCALAR >
175
176 } /* namespace prm */
177} /* namespace gum */
Headers of PRM.
class LabelizedVariable
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
Representation of a set.
Definition set.h:131
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:75
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Definition PRMSystem.h:70
This is a decoration of the DiscreteVariable class.
Definition PRMType.h:78
HashTable< std::string, PRMType * > _typeMap_
Mapping of all PRMType given their name.
Definition PRM.h:235
Set< PRMType * > _types_
Set of all PRMType in this PRM.
Definition PRM.h:238
PRM()
Default constructor.
Definition PRM_tpl.h:56
HashTable< std::string, PRMClass< GUM_SCALAR > * > _classMap_
Mapping of all Class<GUM_SCALAR> given their name.
Definition PRM.h:223
PRMType & type(const std::string &name)
Returns a constant reference on a PRMType given it's name.
Definition PRM_tpl.h:114
Set< PRMSystem< GUM_SCALAR > * > _systems_
Set of all Systems in this PRM.
Definition PRM.h:244
HashTable< std::string, PRMInterface< GUM_SCALAR > * > _interfaceMap_
Mapping of all Class<GUM_SCALAR> given their name.
Definition PRM.h:229
PRMInterface< GUM_SCALAR > & getInterface(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it's name.
Definition PRM_tpl.h:145
Set< PRMInterface< GUM_SCALAR > * > _interfaces_
Set of all Class<GUM_SCALAR> in this PRM.
Definition PRM.h:232
~PRM()
Destructor.
Definition PRM_tpl.h:63
void _addBuiltInTypes_()
Add the built-in types in the PRM.
Definition PRM_tpl.h:84
PRMSystem< GUM_SCALAR > & getSystem(const std::string &name)
Returns a constant reference on a PRMSystem<GUM_SCALAR> given it's name.
Definition PRM_tpl.h:161
const Set< PRMType * > & types() const
Returns the Set of all PRMType in this PRM.
Definition PRM_tpl.h:124
bool isType(const std::string &name) const
Definition PRM_tpl.h:94
bool isSystem(const std::string &name) const
Definition PRM_tpl.h:109
const Set< PRMClass< GUM_SCALAR > * > & classes() const
Returns the Set of all Class<GUM_SCALAR> in this PRM.
Definition PRM_tpl.h:140
bool isClass(const std::string &name) const
Definition PRM_tpl.h:99
const Set< PRMInterface< GUM_SCALAR > * > & interfaces() const
Returns the Set of all Class<GUM_SCALAR> in this PRM.
Definition PRM_tpl.h:156
HashTable< std::string, PRMSystem< GUM_SCALAR > * > _systemMap_
Mapping of all Systems given their name.
Definition PRM.h:241
Set< PRMClass< GUM_SCALAR > * > _classes_
Set of all Class<GUM_SCALAR> in this PRM.
Definition PRM.h:226
PRMClass< GUM_SCALAR > & getClass(const std::string &name)
Returns a constant reference on a Class<GUM_SCALAR> given it's name.
Definition PRM_tpl.h:129
const Set< PRMSystem< GUM_SCALAR > * > & systems() const
Returns the Set of all Systems in this PRM.
Definition PRM_tpl.h:172
bool isInterface(const std::string &name) const
Definition PRM_tpl.h:104
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46