aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
classDependencyGraph.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of ClassDependencyGraph<GUM_SCALAR>.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_ClassDependencyGraph_H
30 #define GUM_ClassDependencyGraph_H
31 
32 #include <agrum/PRM/PRM.h>
33 
34 namespace gum {
35  namespace prm {
36 
37  /**
38  * @class ClassDependencyGraph
39  * @headerfile classDependencyGraph.h <agrum/PRM/classDependencyGraph.h>
40  * @brief This class represent the dependencies of all classes in a
41  *PRM<GUM_SCALAR>.
42  *
43  * A Class Dependency Graph does listen to changes in it's PRM<GUM_SCALAR>.
44  */
45  template < typename GUM_SCALAR >
47  public:
48  /// Association between a class element and it's holding class.
49  typedef std::pair< const PRMClassElementContainer< GUM_SCALAR >*,
50  const PRMClassElement< GUM_SCALAR >* >
52 
53  // ========================================================================
54  /// @name Constructors and Destructor.
55  // ========================================================================
56  /// @{
57 
58  /// Default constructor.
59  /// @param prm The PRM<GUM_SCALAR> for which this
60  /// ClassDependencyGraph<GUM_SCALAR> is constructed.
61  ClassDependencyGraph(const PRM< GUM_SCALAR >& prm);
62 
63  /// Copy constructor.
64  ClassDependencyGraph(const ClassDependencyGraph< GUM_SCALAR >& source);
65 
66  /// Destructor.
68 
69  /// @}
70  // ========================================================================
71  /// @name Getters & setters.
72  // ========================================================================
73  /// @{
74 
75  /// Returns a constant reference over the graph of the DAG representing
76  /// the ClassDependencyGraph<GUM_SCALAR>.
77  const DAG& dag() const;
78 
79  /// Returns a constant reference over the element assiociated with the
80  /// node
81  /// id in the ClassDependencyGraph<GUM_SCALAR>.
82  /// @throw NotFound Raised if no nodes matches id.
83  const EltPair& get(NodeId id) const;
84 
85  /// @brief Returns the NodeId assign to the given
86  /// PRMClassElement<GUM_SCALAR>
87  /// of a
88  /// given Class.
89  /// Is is necessary to give both Class and PRMClassElement<GUM_SCALAR>
90  /// because
91  /// inherited PRMClassElement<GUM_SCALAR> are shared in the inheritance
92  /// hierarchy.
94  const PRMClassElement< GUM_SCALAR >& elt) const;
95 
96  /// Returns a mapping between the ClassDependencyGraph<GUM_SCALAR>'s nodes
97  /// and
98  /// their
99  /// modalities.
100  const NodeProperty< Size >& modalities() const;
101 
102  /// @}
103  private:
104  /// Build the class dependency graph.
105  void buildGraph__(const PRM< GUM_SCALAR >& prm);
106 
107  /// Add nodes in graph__ while updating consequently all the mappings.
108  void addNode__(const PRMClassElementContainer< GUM_SCALAR >* c,
109  const PRMClassElement< GUM_SCALAR >& elt);
110 
111  /// Add arcs in graph__.
112  void
113  addArcs__(const PRMClassElementContainer< GUM_SCALAR >& c,
114  NodeId node,
115  HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >& map);
116 
117  /// The graph itself.
119 
120  /// The modalities map for each node in the
121  /// ClassDependencyGraph<GUM_SCALAR>.
122  /// This
123  /// is useful when using a Triangulation class over a
124  /// ClassDependencyGraph<GUM_SCALAR>.
126 
127  /// Mapping between the nodes in graph__ with the
128  /// PRMClassElement<GUM_SCALAR>
129  /// in
130  /// the
131  /// PRM<GUM_SCALAR>.
133 
134  /// Code shortcut.
135  typedef HashTable<
137  HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >* >
139 
140  /// Map each Class to a HashTable mapping the Class's ClassElements to
141  /// their
142  /// assigned NodeId in graph__.
144  };
145 
146 
147 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
148  extern template class ClassDependencyGraph< double >;
149 #endif
150 
151  } /* namespace prm */
152 } /* namespace gum */
153 
154 #include <agrum/PRM/classDependencyGraph_tpl.h>
155 
156 #endif /* GUM_ClassDependencyGraph_H */
void buildGraph__(const PRM< GUM_SCALAR > &prm)
Build the class dependency graph.
const DAG & dag() const
Returns a constant reference over the graph of the DAG representing the ClassDependencyGraph<GUM_SCAL...
NodeProperty< Size > modalitites__
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
void addNode__(const PRMClassElementContainer< GUM_SCALAR > *c, const PRMClassElement< GUM_SCALAR > &elt)
Add nodes in graph__ while updating consequently all the mappings.
const EltPair & get(NodeId id) const
Returns a constant reference over the element assiociated with the node id in the ClassDependencyGrap...
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__...
ClassDependencyGraph(const PRM< GUM_SCALAR > &prm)
Default constructor.
ClassDependencyGraph(const ClassDependencyGraph< GUM_SCALAR > &source)
Copy constructor.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
NodeProperty< EltPair *> elt_map__
Mapping between the nodes in graph__ with the PRMClassElement<GUM_SCALAR> in the PRM<GUM_SCALAR>.
HashTable< const PRMClassElementContainer< GUM_SCALAR > *, HashTable< const PRMClassElement< GUM_SCALAR > *, NodeId > *> NodeMap
Code shortcut.
const NodeProperty< Size > & modalities() const
Returns a mapping between the ClassDependencyGraph<GUM_SCALAR>&#39;s nodes and their modalities.
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.