aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
classDependencyGraph_tpl.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 Inline implementation of ClassDependencyGraph.
25  *
26  * @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #include <agrum/PRM/classDependencyGraph.h>
29 
30 namespace gum {
31  namespace prm {
32 
33  // Destructor.
34  template < typename GUM_SCALAR >
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  }
44 
45  // Build the class dependency graph.
46  template < typename GUM_SCALAR >
48  // First we add all nodes
49  for (const auto ci: prm.classes()) {
51 
52  for (const auto node: ci->containerDag().nodes())
53  _addNode_(ci, ci->get(node));
54  }
55 
56  for (const auto ii: prm.interfaces()) {
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  }
69 
70  // Add arcs in _graph_.
71  template < typename GUM_SCALAR >
74  NodeId node,
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  }
101 
102  template < typename GUM_SCALAR >
105  _buildGraph_(prm);
106  }
107 
108  template < typename GUM_SCALAR >
114 
115  for (const auto elt: source._node_map_) {
117  elt.first,
118  new HashTable< const PRMClassElement< GUM_SCALAR >*, NodeId >(*elt.second));
119  }
120  }
121 
122  template < typename GUM_SCALAR >
124  return _graph_;
125  }
126 
127  template < typename GUM_SCALAR >
128  INLINE const typename ClassDependencyGraph< GUM_SCALAR >::EltPair&
130  return *(_elt_map_[id]);
131  }
132 
133  template < typename GUM_SCALAR >
134  INLINE NodeId
136  const PRMClassElement< GUM_SCALAR >& elt) const {
137  return (*(_node_map_[&c]))[&elt];
138  }
139 
140  template < typename GUM_SCALAR >
142  return _modalitites_;
143  }
144 
145  template < typename GUM_SCALAR >
148  const PRMClassElement< GUM_SCALAR >& elt) {
149  switch (elt.elt_type()) {
152  NodeId id = _graph_.addNode();
154  _node_map_[c]->insert(&elt, id);
156  break;
157  }
158 
159  default: { /* do nothing */
160  break;
161  }
162  }
163  }
164 
165  } /* namespace prm */
166 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)