aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::prm::ClassDependencyGraph< GUM_SCALAR > Class Template Reference

This class represent the dependencies of all classes in a PRM<GUM_SCALAR>. More...

#include <agrum/PRM/classDependencyGraph.h>

+ Collaboration diagram for gum::prm::ClassDependencyGraph< GUM_SCALAR >:

Public Member Functions

Constructors and Destructor.
 ClassDependencyGraph (const PRM< GUM_SCALAR > &prm)
 Default constructor. More...
 
 ClassDependencyGraph (const ClassDependencyGraph< GUM_SCALAR > &source)
 Copy constructor. More...
 
 ~ClassDependencyGraph ()
 Destructor. More...
 
Getters & setters.
const DAGdag () const
 Returns a constant reference over the graph of the DAG representing the ClassDependencyGraph<GUM_SCALAR>. More...
 
const EltPairget (NodeId id) const
 Returns a constant reference over the element assiociated with the node id in the ClassDependencyGraph<GUM_SCALAR>. More...
 
NodeId get (const PRMClassElementContainer< GUM_SCALAR > &c, const PRMClassElement< GUM_SCALAR > &elt) const
 Returns the NodeId assign to the given PRMClassElement<GUM_SCALAR> of a given Class. Is is necessary to give both Class and PRMClassElement<GUM_SCALAR> because inherited PRMClassElement<GUM_SCALAR> are shared in the inheritance hierarchy. More...
 
const NodeProperty< Size > & modalities () const
 Returns a mapping between the ClassDependencyGraph<GUM_SCALAR>'s nodes and their modalities. More...
 

Public Types

typedef std::pair< const PRMClassElementContainer< GUM_SCALAR > *, const PRMClassElement< GUM_SCALAR > *> EltPair
 Association between a class element and it's holding class. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::ClassDependencyGraph< GUM_SCALAR >

This class represent the dependencies of all classes in a PRM<GUM_SCALAR>.

A Class Dependency Graph does listen to changes in it's PRM<GUM_SCALAR>.

Definition at line 46 of file classDependencyGraph.h.

Member Typedef Documentation

◆ EltPair

template<typename GUM_SCALAR >
typedef std::pair< const PRMClassElementContainer< GUM_SCALAR >*, const PRMClassElement< GUM_SCALAR >* > gum::prm::ClassDependencyGraph< GUM_SCALAR >::EltPair

Association between a class element and it's holding class.

Definition at line 51 of file classDependencyGraph.h.

◆ NodeMap

template<typename GUM_SCALAR >
typedef HashTable< const PRMClassElementContainer< GUM_SCALAR >*, HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >* > gum::prm::ClassDependencyGraph< GUM_SCALAR >::NodeMap
private

Code shortcut.

Definition at line 136 of file classDependencyGraph.h.

Constructor & Destructor Documentation

◆ ClassDependencyGraph() [1/2]

template<typename GUM_SCALAR >
INLINE gum::prm::ClassDependencyGraph< GUM_SCALAR >::ClassDependencyGraph ( const PRM< GUM_SCALAR > &  prm)

Default constructor.

Parameters
prmThe PRM<GUM_SCALAR> for which this ClassDependencyGraph<GUM_SCALAR> is constructed.

Definition at line 103 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

103  {
104  GUM_CONSTRUCTOR(ClassDependencyGraph);
105  _buildGraph_(prm);
106  }
void _buildGraph_(const PRM< GUM_SCALAR > &prm)
Build the class dependency graph.
ClassDependencyGraph(const PRM< GUM_SCALAR > &prm)
Default constructor.
+ Here is the call graph for this function:

◆ ClassDependencyGraph() [2/2]

template<typename GUM_SCALAR >
INLINE gum::prm::ClassDependencyGraph< GUM_SCALAR >::ClassDependencyGraph ( const ClassDependencyGraph< GUM_SCALAR > &  source)

Copy constructor.

Definition at line 109 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

110  :
111  _graph_(source._graph_),
112  _modalitites_(source._modalitites_), _elt_map_(source._elt_map_) {
113  GUM_CONS_CPY(ClassDependencyGraph);
114 
115  for (const auto elt: source._node_map_) {
117  elt.first,
118  new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >(*elt.second));
119  }
120  }
NodeProperty< Size > _modalitites_
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
ClassDependencyGraph(const PRM< GUM_SCALAR > &prm)
Default constructor.
NodeProperty< EltPair *> _elt_map_
Mapping between the nodes in graph with the PRMClassElement<GUM_SCALAR> in the PRM<GUM_SCALAR>.
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ ~ClassDependencyGraph()

template<typename GUM_SCALAR >
gum::prm::ClassDependencyGraph< GUM_SCALAR >::~ClassDependencyGraph ( )

Destructor.

Definition at line 35 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

35  {
36  GUM_DESTRUCTOR(ClassDependencyGraph);
37 
38  for (const auto& elt: _node_map_)
39  delete elt.second;
40 
41  for (const auto& elt: _elt_map_)
42  delete elt.second;
43  }
ClassDependencyGraph(const PRM< GUM_SCALAR > &prm)
Default constructor.
NodeProperty< EltPair *> _elt_map_
Mapping between the nodes in graph with the PRMClassElement<GUM_SCALAR> in the PRM<GUM_SCALAR>.
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
+ Here is the call graph for this function:

Member Function Documentation

◆ _addArcs_()

template<typename GUM_SCALAR >
void gum::prm::ClassDependencyGraph< GUM_SCALAR >::_addArcs_ ( const PRMClassElementContainer< GUM_SCALAR > &  c,
NodeId  node,
HashTable< const PRMClassElement< GUM_SCALAR > *, NodeId > &  map 
)
private

Add arcs in graph.

Definition at line 72 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

75  {
76  switch (c.get(node).elt_type()) {
78  const PRMSlotChain< GUM_SCALAR >& sc
79  = static_cast< const PRMSlotChain< GUM_SCALAR >& >(c.get(node));
80 
81  for (const auto chi: c.containerDag().children(node))
82  _graph_.addArc((*(_node_map_[&(sc.end())]))[&(sc.end().get(sc.lastElt().safeName()))],
83  map[&(c.get(chi))]);
84 
85  break;
86  }
87 
90  for (const auto chi: c.containerDag().children(node))
91  _graph_.addArc(map[&(c.get(node))], map[&(c.get(chi))]);
92 
93  break;
94  }
95 
96  default: { /* do nothing */
97  break;
98  }
99  }
100  }
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Definition: DAG_inl.h:42
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
+ Here is the call graph for this function:

◆ _addNode_()

template<typename GUM_SCALAR >
INLINE void gum::prm::ClassDependencyGraph< GUM_SCALAR >::_addNode_ ( const PRMClassElementContainer< GUM_SCALAR > *  c,
const PRMClassElement< GUM_SCALAR > &  elt 
)
private

Add nodes in graph while updating consequently all the mappings.

Definition at line 146 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

148  {
149  switch (elt.elt_type()) {
152  NodeId id = _graph_.addNode();
154  _node_map_[c]->insert(&elt, id);
155  _modalitites_.insert(id, elt.type().variable().domainSize());
156  break;
157  }
158 
159  default: { /* do nothing */
160  break;
161  }
162  }
163  }
NodeProperty< Size > _modalitites_
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
virtual NodeId addNode()
insert a new node and return its id
std::pair< const PRMClassElementContainer< GUM_SCALAR > *, const PRMClassElement< GUM_SCALAR > *> EltPair
Association between a class element and it&#39;s holding class.
NodeProperty< EltPair *> _elt_map_
Mapping between the nodes in graph with the PRMClassElement<GUM_SCALAR> in the PRM<GUM_SCALAR>.
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ _buildGraph_()

template<typename GUM_SCALAR >
void gum::prm::ClassDependencyGraph< GUM_SCALAR >::_buildGraph_ ( const PRM< GUM_SCALAR > &  prm)
private

Build the class dependency graph.

Definition at line 47 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

47  {
48  // First we add all nodes
49  for (const auto ci: prm.classes()) {
50  _node_map_.insert(ci, new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >());
51 
52  for (const auto node: ci->containerDag().nodes())
53  _addNode_(ci, ci->get(node));
54  }
55 
56  for (const auto ii: prm.interfaces()) {
57  _node_map_.insert(ii, new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >());
58 
59  for (const auto node: ii->containerDag().nodes()) {
60  _addNode_(ii, ii->get(node));
61  }
62  }
63 
64  // Then we add the arcs
65  for (const auto cc: prm.classes())
66  for (const auto node: cc->containerDag().nodes())
67  _addArcs_(*cc, node, *(_node_map_[cc]));
68  }
void _addArcs_(const PRMClassElementContainer< GUM_SCALAR > &c, NodeId node, HashTable< const PRMClassElement< GUM_SCALAR > *, NodeId > &map)
Add arcs in graph.
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
void _addNode_(const PRMClassElementContainer< GUM_SCALAR > *c, const PRMClassElement< GUM_SCALAR > &elt)
Add nodes in graph while updating consequently all the mappings.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ dag()

template<typename GUM_SCALAR >
INLINE const DAG & gum::prm::ClassDependencyGraph< GUM_SCALAR >::dag ( ) const

Returns a constant reference over the graph of the DAG representing the ClassDependencyGraph<GUM_SCALAR>.

Definition at line 123 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

123  {
124  return _graph_;
125  }
+ Here is the call graph for this function:

◆ get() [1/2]

template<typename GUM_SCALAR >
INLINE const ClassDependencyGraph< GUM_SCALAR >::EltPair & gum::prm::ClassDependencyGraph< GUM_SCALAR >::get ( NodeId  id) const

Returns a constant reference over the element assiociated with the node id in the ClassDependencyGraph<GUM_SCALAR>.

Exceptions
NotFoundRaised if no nodes matches id.

Definition at line 129 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

129  {
130  return *(_elt_map_[id]);
131  }
NodeProperty< EltPair *> _elt_map_
Mapping between the nodes in graph with the PRMClassElement<GUM_SCALAR> in the PRM<GUM_SCALAR>.
+ Here is the call graph for this function:

◆ get() [2/2]

template<typename GUM_SCALAR >
INLINE NodeId gum::prm::ClassDependencyGraph< GUM_SCALAR >::get ( const PRMClassElementContainer< GUM_SCALAR > &  c,
const PRMClassElement< GUM_SCALAR > &  elt 
) const

Returns the NodeId assign to the given PRMClassElement<GUM_SCALAR> of a given Class. Is is necessary to give both Class and PRMClassElement<GUM_SCALAR> because inherited PRMClassElement<GUM_SCALAR> are shared in the inheritance hierarchy.

Definition at line 135 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

136  {
137  return (*(_node_map_[&c]))[&elt];
138  }
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
+ Here is the call graph for this function:

◆ modalities()

template<typename GUM_SCALAR >
INLINE const NodeProperty< Size > & gum::prm::ClassDependencyGraph< GUM_SCALAR >::modalities ( ) const

Returns a mapping between the ClassDependencyGraph<GUM_SCALAR>'s nodes and their modalities.

Definition at line 141 of file classDependencyGraph_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

141  {
142  return _modalitites_;
143  }
NodeProperty< Size > _modalitites_
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
+ Here is the call graph for this function:

Member Data Documentation

◆ _elt_map_

template<typename GUM_SCALAR >
NodeProperty< EltPair* > gum::prm::ClassDependencyGraph< GUM_SCALAR >::_elt_map_
private

Mapping between the nodes in graph with the PRMClassElement<GUM_SCALAR> in the PRM<GUM_SCALAR>.

Definition at line 131 of file classDependencyGraph.h.

◆ _graph_

template<typename GUM_SCALAR >
DAG gum::prm::ClassDependencyGraph< GUM_SCALAR >::_graph_
private

The graph itself.

Definition at line 117 of file classDependencyGraph.h.

◆ _modalitites_

template<typename GUM_SCALAR >
NodeProperty< Size > gum::prm::ClassDependencyGraph< GUM_SCALAR >::_modalitites_
private

The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a Triangulation class over a ClassDependencyGraph<GUM_SCALAR>.

Definition at line 124 of file classDependencyGraph.h.

◆ _node_map_

template<typename GUM_SCALAR >
NodeMap gum::prm::ClassDependencyGraph< GUM_SCALAR >::_node_map_
private

Map each Class to a HashTable mapping the Class's ClassElements to their assigned NodeId in graph.

Definition at line 141 of file classDependencyGraph.h.


The documentation for this class was generated from the following files: