aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
PRMClass.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_H
50#define GUM_CLASS_H
51
52#include <utility>
53
54#include <agrum/agrum.h>
55
58
59namespace gum {
60 namespace prm {
61
62 template < typename GUM_SCALAR >
63 class PRMInterface;
64
74 template < typename GUM_SCALAR >
75 class PRMClass: public PRMClassElementContainer< GUM_SCALAR > {
76 friend class PRMInterface< GUM_SCALAR >;
77
78 public:
81
86 explicit PRMClass(const std::string& name);
87
94 PRMClass(const std::string& name,
96 bool delayInheritance = false);
97
106 PRMClass(const std::string& name,
107 const Set< PRMInterface< GUM_SCALAR >* >& set,
108 bool delayInheritance = false);
109
118 PRMClass(const std::string& name,
120 const Set< PRMInterface< GUM_SCALAR >* >& set,
121 bool delayInheritance = false);
122
124 PRMClass(const PRMClass< GUM_SCALAR >& source) = delete;
125
127 PRMClass(const PRMClass< GUM_SCALAR >&& source) = delete;
128
131
134
136 virtual ~PRMClass();
137
139 virtual PRMObject::prm_type obj_type() const;
141 // ========================================================================
143 // ========================================================================
145
148
151
153 // ========================================================================
155 // ========================================================================
157
163 virtual bool isOutputNode(const PRMClassElement< GUM_SCALAR >& elt) const;
164
177 bool isCastDescendant(const std::string& safe_name) const;
178
181 PRMClassElement< GUM_SCALAR >& get(const std::string& name);
182
185 const PRMClassElement< GUM_SCALAR >& get(const std::string& name) const;
186
189
192
194 virtual void addArc(const std::string& tail, const std::string& head);
195
202
208
214
221
229
236
238 // ========================================================================
240 // ========================================================================
242
263 virtual bool isSubTypeOf(const PRMClassElementContainer< GUM_SCALAR >& cec) const;
264
270 const PRMClass< GUM_SCALAR >& super() const;
271
281
284 const Set< PRMClass< GUM_SCALAR >* >& extensions() const;
285
287 // ========================================================================
289 // ========================================================================
291
295
299
302 PRMClassElement< GUM_SCALAR >& operator[](const std::string& name);
303
306 const PRMClassElement< GUM_SCALAR >& operator[](const std::string& name) const;
307
309
313 void inheritParameters();
314 void inheritAttributes();
315 void inheritAggregates();
316 void inheritSlotChains();
318 void completeInheritance(const std::string& attr);
320
321 protected:
323 virtual const DAG& dag_() const;
324
327 virtual DAG& dag_();
328
331
335
336 private:
338 // void _copyClass_<GUM_SCALAR>(const Class<GUM_SCALAR>& c);
339
340 // ========================================================================
342 // ========================================================================
344
348
352
354 // ========================================================================
356 // ========================================================================
358
362
365
368
371
374
377
380
384
386 // ========================================================================
388 // ========================================================================
390
396
399
403
408
411
412
415
417 void _implementInterfaces_(bool delayInheritance);
418
421
424
427
430
434
444
447 const PRMClassElement< GUM_SCALAR >* overloader);
448
451 PRMAttribute< GUM_SCALAR >* overloaded);
452
456
460
463 PRMParameter< GUM_SCALAR >* overloaded);
464
466 };
467
468
469#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
470 extern template class PRMClass< double >;
471#endif
472
473
474 } /* namespace prm */
475
476} // namespace gum
477
479
480namespace gum {
481
482 namespace prm {} /* namespace prm */
483
484} // namespace gum
485
486
487#endif /* GUM_CLASS_H */
Inline implementation of gum::Class.
Headers of gum::PRMParameter.
Headers of gum::PRMSlotChain.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for dag.
Definition DAG.h:121
This class should be useless as only its specializations should be used.
Definition hashFunc.h:487
The class for generic Hash Tables.
Definition hashTable.h:637
Representation of a set.
Definition set.h:131
PRMAttribute is a member of a Class in a PRM.
PRMClassElementContainer(const std::string &name)
Default constructor.
Abstract class representing an element of PRM class.
void _addExtension_(PRMClass< GUM_SCALAR > *c)
This method is called when a sub-Class<GUM_SCALAR> of this Class<GUM_SCALAR> is created.
Set< PRMReferenceSlot< GUM_SCALAR > * > _referenceSlots_
The sequence of PRMReferenceSlot<GUM_SCALAR>.
Definition PRMClass.h:367
void _overloadReference_(PRMReferenceSlot< GUM_SCALAR > *overloader, PRMReferenceSlot< GUM_SCALAR > *overloaded)
Overloads a reference slot.
bool _checkOverloadLegality_(const PRMClassElement< GUM_SCALAR > *overloaded, const PRMClassElement< GUM_SCALAR > *overloader)
Return true of overloaded can be overload by overloader.
const Set< PRMReferenceSlot< GUM_SCALAR > * > & referenceSlots() const
Returns the set of PRMReferenceSlot<GUM_SCALAR> of this Class<GUM_SCALAR>.
virtual bool isSubTypeOf(const PRMClassElementContainer< GUM_SCALAR > &cec) const
Test if this Class<GUM_SCALAR> is a subclass of cec.
PRMClass< GUM_SCALAR > * _superClass_
The alternate PRMClassElementContainer<GUM_SCALAR> searched for elements defined in this....
Definition PRMClass.h:395
virtual void addArc(const std::string &tail, const std::string &head)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::addArc().
void _addCastDescendants_(PRMClassElement< GUM_SCALAR > *attr)
Recursively adds cast descendant of attr in this Class<GUM_SCALAR>.
void _checkInterfaces_(PRMClassElement< GUM_SCALAR > *elt)
Check that a given element respects all the class interfaces.
PRMClass(const std::string &name)
Default constructor.
void _overloadAggregate_(PRMAggregate< GUM_SCALAR > *overloader, PRMClassElement< GUM_SCALAR > *overloaded)
Overloads an aggregate.
void findAllSubtypes_(Set< PRMClassElementContainer< GUM_SCALAR > * > &set)
Fills set with all the subtypes of this Class<GUM_SCALAR>.
Bijection< const DiscreteVariable *, const DiscreteVariable * > * _bijection_
The bijection between variables in super and variables in this The bijection's firsts are attributes ...
Definition PRMClass.h:407
PRMClass(const PRMClass< GUM_SCALAR > &&source)=delete
Move constructor.
Set< PRMSlotChain< GUM_SCALAR > * > _slotChains_
The set of gum::PRMSlotChain<GUM_SCALAR>s.
Definition PRMClass.h:373
void _checkInterface_(PRMClassElement< GUM_SCALAR > *elt, PRMInterface< GUM_SCALAR > *i)
Check that a given element respects a specific interface.
virtual ~PRMClass()
Destructor.
virtual PRMObject::prm_type obj_type() const
Implementation of pure virtual method of PRMObject.
PRMClassElement< GUM_SCALAR > & get(NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
void _implementInterfaces_(bool delayInheritance)
Proceed with the implementation of interfaces.
HashFunc< PRMClassElementContainer< GUM_SCALAR > * > _dummy_hashfunc_
a dummy member used to fix a compilation issue in clang4
Definition PRMClass.h:410
DAG _dag_
The dag representing dependencies between formal attributes and slots.
Definition PRMClass.h:347
void _checkRefInterface_(PRMReferenceSlot< GUM_SCALAR > *elt, PRMInterface< GUM_SCALAR > *i)
Check that a given element respects a specific interface.
virtual const DAG & dag_() const
returns a constant reference over this interface's dag.
PRMClass(const PRMClass< GUM_SCALAR > &source)=delete
Copy constructor.
PRMClass< GUM_SCALAR > & operator=(const PRMClass< GUM_SCALAR > &&source)=delete
Move operator. Don't use it.
NodeProperty< PRMClassElement< GUM_SCALAR > * > _nodeIdMap_
Mapping between node's id and their name (being an attribute or a slot). Used for fast access to a me...
Definition PRMClass.h:351
Set< PRMAggregate< GUM_SCALAR > * > _aggregates_
The sequence of aggregate.
Definition PRMClass.h:370
void _overloadParameter_(PRMParameter< GUM_SCALAR > *overloader, PRMParameter< GUM_SCALAR > *overloaded)
Overloads a parameter.
const Set< PRMParameter< GUM_SCALAR > * > & parameters() const
Returns the set of parameters of this Class<GUM_SCALAR>.
void _inheritClass_(const PRMClass< GUM_SCALAR > &c)
Proceed with the copy when this inherits c.
const Set< PRMClass< GUM_SCALAR > * > & extensions() const
Returns the set of Class<GUM_SCALAR> which are direct sub-Class<GUM_SCALAR> of this Class<GUM_SCALAR>...
const Set< PRMAttribute< GUM_SCALAR > * > & attributes() const
Returns the set of PRMAttribute<GUM_SCALAR> of this Class<GUM_SCALAR>.
HashTable< std::string, const PRMParameter< GUM_SCALAR > * > scope() const
Returns all the parameters in the scope of this class.
virtual NodeId add(PRMClassElement< GUM_SCALAR > *elt)
See gum::prm::add(PRMClassElement<GUM_SCALAR>*).
virtual bool isOutputNode(const PRMClassElement< GUM_SCALAR > &elt) const
Returns true if elt is an output node.
Set< PRMParameter< GUM_SCALAR > * > _parameters_
The Set of parameters in this Class<GUM_SCALAR>.
Definition PRMClass.h:376
PRMClassElement< GUM_SCALAR > & operator[](NodeId id)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::operator[](NodeId).
void _addIOInterfaceFlags_(PRMClassElement< GUM_SCALAR > *elt)
Check if elt is present in an implementation. If it is, its IO flags are updated.
Set< PRMClass< GUM_SCALAR > * > _extensions_
The set of Class<GUM_SCALAR> which are extension of this Class<GUM_SCALAR> (i.e. direct subtypes).
Definition PRMClass.h:402
HashTable< std::string, PRMClassElement< GUM_SCALAR > * > _nameMap_
Mapping between a member's name and itself. Used for fast access to a member given it's name.
Definition PRMClass.h:361
friend class PRMInterface< GUM_SCALAR >
Definition PRMClass.h:76
const Set< PRMAggregate< GUM_SCALAR > * > & aggregates() const
Returns the set of PRMAggregate<GUM_SCALAR> of this Class<GUM_SCALAR>.
void completeInheritance(const std::string &attr)
const Set< PRMInterface< GUM_SCALAR > * > & implements() const
Returns the Set of PRMInterface<GUM_SCALAR> implemented by this Class<GUM_SCALAR>.
const Set< PRMSlotChain< GUM_SCALAR > * > & slotChains() const
Returns the set of PRMSlotChain<GUM_SCALAR> of this Class<GUM_SCALAR>.
void _overloadAttribute_(PRMAttribute< GUM_SCALAR > *overloader, PRMAttribute< GUM_SCALAR > *overloaded)
Overloads an attribute.
PRMClass< GUM_SCALAR > & operator=(const PRMClass< GUM_SCALAR > &source)=delete
Copy operator. Don't use it.
const PRMClass< GUM_SCALAR > & super() const
Returns the super Class<GUM_SCALAR> of this Class<GUM_SCALAR>.
Set< PRMAttribute< GUM_SCALAR > * > _attributes_
The sequence of PRMAttribute<GUM_SCALAR>s.
Definition PRMClass.h:364
void updateDescendants_(const PRMClassElement< GUM_SCALAR > &elt)
See gum::prm::PRMClassElementContainer<GUM_SCALAR>(constPRMClassElement<GUM_SCALAR>&).
virtual NodeId overload(PRMClassElement< GUM_SCALAR > *elt)
See gum::prm::overload(PRMClassElement<GUM_SCALAR>*).
void _checkRefInterfaces_(PRMReferenceSlot< GUM_SCALAR > *elt)
Check that a given element respects all the class interfaces.
Set< PRMInterface< GUM_SCALAR > * > * _implements_
The Set of implemented interface of this.
Definition PRMClass.h:398
bool isCastDescendant(const std::string &safe_name) const
Return true if the attribute named safe_name is a cast descendant.
An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALA...
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
PRMParameter is a member of a Class in a PRM.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46