aGrUM  0.20.2
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 138 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 109 of file classDependencyGraph_tpl.h.

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

110  {
111  GUM_CONSTRUCTOR(ClassDependencyGraph);
112  buildGraph__(prm);
113  }
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 116 of file classDependencyGraph_tpl.h.

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

117  :
118  graph__(source.graph__),
119  modalitites__(source.modalitites__), elt_map__(source.elt_map__) {
120  GUM_CONS_CPY(ClassDependencyGraph);
121 
122  for (const auto elt: source.node_map__) {
124  elt.first,
125  new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >(
126  *elt.second));
127  }
128  }
NodeProperty< Size > modalitites__
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
NodeMap node_map__
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph__...
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>.
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  }
NodeMap node_map__
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph__...
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>.
+ 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 77 of file classDependencyGraph_tpl.h.

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

80  {
81  switch (c.get(node).elt_type()) {
83  const PRMSlotChain< GUM_SCALAR >& sc
84  = static_cast< const PRMSlotChain< GUM_SCALAR >& >(c.get(node));
85 
86  for (const auto chi: c.containerDag().children(node))
87  graph__.addArc((*(node_map__[&(sc.end())]))[&(
88  sc.end().get(sc.lastElt().safeName()))],
89  map[&(c.get(chi))]);
90 
91  break;
92  }
93 
96  for (const auto chi: c.containerDag().children(node))
97  graph__.addArc(map[&(c.get(node))], map[&(c.get(chi))]);
98 
99  break;
100  }
101 
102  default: { /* do nothing */
103  break;
104  }
105  }
106  }
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 155 of file classDependencyGraph_tpl.h.

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

157  {
158  switch (elt.elt_type()) {
161  NodeId id = graph__.addNode();
162  elt_map__.insert(
163  id,
165  node_map__[c]->insert(&elt, id);
166  modalitites__.insert(id, elt.type().variable().domainSize());
167  break;
168  }
169 
170  default: { /* do nothing */
171  break;
172  }
173  }
174  }
NodeProperty< Size > modalitites__
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
NodeMap node_map__
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph__...
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>.
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().

48  {
49  // First we add all nodes
50  for (const auto ci: prm.classes()) {
52  ci,
53  new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >());
54 
55  for (const auto node: ci->containerDag().nodes())
56  addNode__(ci, ci->get(node));
57  }
58 
59  for (const auto ii: prm.interfaces()) {
61  ii,
62  new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >());
63 
64  for (const auto node: ii->containerDag().nodes()) {
65  addNode__(ii, ii->get(node));
66  }
67  }
68 
69  // Then we add the arcs
70  for (const auto cc: prm.classes())
71  for (const auto node: cc->containerDag().nodes())
72  addArcs__(*cc, node, *(node_map__[cc]));
73  }
void addNode__(const PRMClassElementContainer< GUM_SCALAR > *c, const PRMClassElement< GUM_SCALAR > &elt)
Add nodes in graph__ while updating consequently all the mappings.
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__...
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 131 of file classDependencyGraph_tpl.h.

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

131  {
132  return graph__;
133  }
+ 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 137 of file classDependencyGraph_tpl.h.

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

137  {
138  return *(elt_map__[id]);
139  }
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 142 of file classDependencyGraph_tpl.h.

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

144  {
145  return (*(node_map__[&c]))[&elt];
146  }
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 150 of file classDependencyGraph_tpl.h.

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

150  {
151  return modalitites__;
152  }
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 132 of file classDependencyGraph.h.

◆ graph__

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

The graph itself.

Definition at line 118 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 125 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 143 of file classDependencyGraph.h.


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