aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
classDependencyGraph.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 _addArcs_(const PRMClassElementContainer< GUM_SCALAR >& c,
113  NodeId node,
114  HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >& map);
115 
116  /// The graph itself.
118 
119  /// The modalities map for each node in the
120  /// ClassDependencyGraph<GUM_SCALAR>.
121  /// This
122  /// is useful when using a Triangulation class over a
123  /// ClassDependencyGraph<GUM_SCALAR>.
125 
126  /// Mapping between the nodes in _graph_ with the
127  /// PRMClassElement<GUM_SCALAR>
128  /// in
129  /// the
130  /// PRM<GUM_SCALAR>.
132 
133  /// Code shortcut.
134  typedef HashTable< const PRMClassElementContainer< GUM_SCALAR >*,
135  HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >* >
137 
138  /// Map each Class to a HashTable mapping the Class's ClassElements to
139  /// their
140  /// assigned NodeId in _graph_.
142  };
143 
144 
145 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
146  extern template class ClassDependencyGraph< double >;
147 #endif
148 
149  } /* namespace prm */
150 } /* namespace gum */
151 
152 #include <agrum/PRM/classDependencyGraph_tpl.h>
153 
154 #endif /* GUM_ClassDependencyGraph_H */
void _addArcs_(const PRMClassElementContainer< GUM_SCALAR > &c, NodeId node, HashTable< const PRMClassElement< GUM_SCALAR > *, NodeId > &map)
Add arcs in graph.
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...
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
NodeProperty< Size > _modalitites_
The modalities map for each node in the ClassDependencyGraph<GUM_SCALAR>. This is useful when using a...
const EltPair & get(NodeId id) const
Returns a constant reference over the element assiociated with the node id in the ClassDependencyGrap...
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>.
ClassDependencyGraph(const ClassDependencyGraph< GUM_SCALAR > &source)
Copy constructor.
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
NodeMap _node_map_
Map each Class to a HashTable mapping the Class&#39;s ClassElements to their assigned NodeId in graph...
HashTable< const PRMClassElementContainer< GUM_SCALAR > *, HashTable< const PRMClassElement< GUM_SCALAR > *, NodeId > *> NodeMap
Code shortcut.
void _addNode_(const PRMClassElementContainer< GUM_SCALAR > *c, const PRMClassElement< GUM_SCALAR > &elt)
Add nodes in graph while updating consequently all the mappings.
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.