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