aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
PRMClassElement.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 GUM_CLASS_ELEMENT_H
50#define GUM_CLASS_ELEMENT_H
51
52#include <sstream>
53
54#include <agrum/agrum.h>
55
56#include <agrum/PRM/utils_prm.h>
57
58namespace gum {
59 namespace prm {
60 template < typename GUM_SCALAR >
61 class PRMAttribute;
62
74 template < typename GUM_SCALAR >
75 class PRMClassElement: public PRMObject {
76 public:
77 // ========================================================================
79 // ========================================================================
81
91 explicit PRMClassElement(const std::string& name);
92
97
101 virtual ~PRMClassElement();
102
104 // ========================================================================
106 // ========================================================================
108
116
117 static std::string enum2str(ClassElementType type) {
118 switch (type) {
119 case prm_attribute : return "prm_attribute";
120
121 case prm_aggregate : return "prm_aggregate";
122
123 case prm_refslot : return "prm_refslot";
124
125 case prm_slotchain : return "prm_slotchain";
126
127 case prm_parameter : return "prm_parameter";
128
129 default : return "unknown";
130 }
131 }
132
134 static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR >& elt) {
135 return elt.elt_type() == prm_refslot;
136 }
137
139 static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR >& elt) {
140 return elt.elt_type() == prm_attribute;
141 }
142
144 static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR >& elt) {
145 return elt.elt_type() == prm_aggregate;
146 }
147
149 static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR >& elt) {
150 return elt.elt_type() == prm_slotchain;
151 }
152
154 static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR >& elt) {
155 return elt.elt_type() == prm_parameter;
156 }
157
159 // ========================================================================
161 // ========================================================================
163
165 NodeId id() const;
166
168 virtual void setId(NodeId id);
169
176 virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt) = 0;
177
184 virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt) = 0;
185
187 virtual typename PRMObject::prm_type obj_type() const;
188
190 virtual ClassElementType elt_type() const = 0;
191
193 // ========================================================================
195 // ========================================================================
197
204 virtual PRMType& type() = 0;
205
213 virtual const PRMType& type() const = 0;
214
232
243 const std::string& safeName() const;
244
251 virtual std::string cast(const PRMType& t) const;
252
253 // /**
254 // * Return a reference over the gum::Tensor of this class element.
255 // * @throw OperationNotAllowed Raised if this class element doesn't have
256 // * any gum::Tensor (like a
257 // gum::PRMReferenceSlot).
258 // */
259 // virtual Tensor<GUM_SCALAR>& cpf() = 0;
260
268 virtual const Tensor< GUM_SCALAR >& cpf() const = 0;
269
271
272 protected:
274 std::string safeName_;
275
276 private:
279 };
280
281
282#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
283 extern template class PRMClassElement< double >;
284#endif
285
286 } /* namespace prm */
287} // namespace gum
288
290
291#endif /* GUM_CLASS_ELEMENT_H */
Inline implementation of gum::PRMClassElement.
PRMAttribute is a member of a Class in a PRM.
static INLINE bool isParameter(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMParameter.
static INLINE bool isSlotChain(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMSlotChain.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)=0
Add a parent to this element.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)=0
Add a child to this element.
virtual PRMObject::prm_type obj_type() const
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
virtual const Tensor< GUM_SCALAR > & cpf() const =0
Return a constant reference over the gum::Tensor of this class element.
static std::string enum2str(ClassElementType type)
Returns true if obj_ptr is of type PRMReferenceSlot.
NodeId _id_
The node's id of this element.
PRMClassElement(const std::string &name)
Default constructor of a PRMClassElement.
virtual void setId(NodeId id)
Used to assign the id of this element.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const =0
Returns a proper cast descendant of this PRMAttribute.
static INLINE bool isReferenceSlot(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMReferenceSlot.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
virtual const PRMType & type() const =0
Return a constant reference over the gum::PRMType of this class element.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
virtual ~PRMClassElement()
Destructor of this class.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
std::string safeName_
The safe name of this PRMClassElement.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition PRMObject.h:88
PRMObject(const std::string &name)
Constructor.
Definition PRMObject.cpp:62
This is a decoration of the DiscreteVariable class.
Definition PRMType.h:78
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46