aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
classDependencyGraph_tpl.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 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  const PRM< GUM_SCALAR >& prm) {
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  }
74 
75  // Add arcs in graph__.
76  template < typename GUM_SCALAR >
79  NodeId node,
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  }
107 
108  template < typename GUM_SCALAR >
110  const PRM< GUM_SCALAR >& prm) {
112  buildGraph__(prm);
113  }
114 
115  template < typename GUM_SCALAR >
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  }
129 
130  template < typename GUM_SCALAR >
132  return graph__;
133  }
134 
135  template < typename GUM_SCALAR >
136  INLINE const typename ClassDependencyGraph< GUM_SCALAR >::EltPair&
138  return *(elt_map__[id]);
139  }
140 
141  template < typename GUM_SCALAR >
144  const PRMClassElement< GUM_SCALAR >& elt) const {
145  return (*(node_map__[&c]))[&elt];
146  }
147 
148  template < typename GUM_SCALAR >
149  INLINE const NodeProperty< Size >&
151  return modalitites__;
152  }
153 
154  template < typename GUM_SCALAR >
157  const PRMClassElement< GUM_SCALAR >& elt) {
158  switch (elt.elt_type()) {
161  NodeId id = graph__.addNode();
163  id,
165  node_map__[c]->insert(&elt, id);
167  break;
168  }
169 
170  default: { /* do nothing */
171  break;
172  }
173  }
174  }
175 
176  } /* namespace prm */
177 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)