aGrUM  0.14.2
DFSTree.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_DFS_TREE_H
28 #define GUM_DFS_TREE_H
29 
30 #include <list>
31 #include <ostream>
32 #include <utility>
33 #include <vector>
34 
35 #include <agrum/core/math/math.h>
36 #include <agrum/core/bijection.h>
37 #include <agrum/core/sequence.h>
38 #include <agrum/core/set.h>
39 
40 #include <agrum/graphs/diGraph.h>
41 
43 
47 
49 
50 namespace gum {
51  namespace prm {
52 
53  template < typename GUM_SCALAR >
54  class GSpan;
55 
56  namespace gspan {
57  template < typename GUM_SCALAR >
59 
67  template < typename GUM_SCALAR >
68  class DFSTree : private DiGraph {
69  public:
70  // =========================================================================
72  // ==========================================================================
74 
76  // DFSTree(InterfaceGraph<GUM_SCALAR>* graph);
79 
81  ~DFSTree();
82 
84  // =========================================================================
86  // ==========================================================================
88 
89  const InterfaceGraph< GUM_SCALAR >& graph() const;
90 
91  struct PatternData {
93  explicit PatternData(Pattern* p);
95  PatternData(const PatternData& from);
97  ~PatternData();
101  std::list< NodeId > children;
112  };
113 
115  std::list< NodeId >& roots();
116 
118  const std::list< NodeId >& roots() const;
119 
121  Pattern& parent(const Pattern& p);
122 
124  const Pattern& parent(const Pattern& p) const;
125 
127  std::list< NodeId >& children(const Pattern& p);
128 
130  const std::list< NodeId >& children(const Pattern& p) const;
131 
133  Pattern& pattern(NodeId id);
134 
136  const Pattern& pattern(NodeId id) const;
137 
144  void addRoot(LabelData& data);
145 
162  EdgeGrowth< GUM_SCALAR >& edge_growth,
163  Size min_freq);
164 
166  // =========================================================================
168  // ==========================================================================
170 
187  UndiGraph& iso_graph(const Pattern& p);
188 
214  NodeId node);
215 
224 
227  double frequency(const Pattern& p) const;
228 
230  PatternData& data(const Pattern& p);
232  const PatternData& data(const Pattern& p) const;
233 
236 
238  const SearchStrategy< GUM_SCALAR >& strategy() const;
239 
246  explicit NeighborDegreeSort(UndiGraph& graph);
248  NeighborDegreeSort(const NeighborDegreeSort& source);
252  bool operator()(NodeId i, NodeId j);
255  };
256 
258 
259  private:
262 
264  std::list< NodeId > __roots;
265 
269 
272 
275 
277  void __checkGrowth(Pattern& p,
278  Pattern* child,
279  EdgeGrowth< GUM_SCALAR >& edge_growth);
280 
282  void __addChild(Pattern& p,
283  Pattern* child,
284  EdgeGrowth< GUM_SCALAR >& edge_growth);
285 
287  bool __is_new_seq(
290 
294  void __initialiaze_root(Pattern* p,
296 
297  // Used by __find_sub_pattern.
300  };
301 
302 
303 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
304  extern template class DFSTree< double >;
305 #endif
306 
307 
308  } /* namespace gspan */
309  } /* namespace prm */
310 } /* namespace gum */
311 
313 
314 #endif /* GUM_DFS_TREE_H */
Useful macros for maths.
PatternData(Pattern *p)
Constructor.
Definition: DFSTree_tpl.h:567
const InterfaceGraph< GUM_SCALAR > * __graph
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:261
~DFSTree()
Destructor.
Definition: DFSTree_tpl.h:34
This class is used to define an edge growth of a pattern in this DFSTree.
Definition: edgeGrowth.h:60
Base classes for oriented graphs.
SearchStrategy< GUM_SCALAR > * __strategy
The strategy used to prune the search tree.
Definition: DFSTree.h:274
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
void __addChild(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Add a child to this DFSTree.
Definition: DFSTree_tpl.h:158
Sets of elements (i.e.
Inner class to handle data about labels in this interface graph.
Pattern * pattern
The pattern.
Definition: DFSTree.h:99
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
Definition: PRMInstance.h:60
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1019
Pattern & growPattern(Pattern &p, EdgeGrowth< GUM_SCALAR > &edge_growth, Size min_freq)
Add a one edge growth of p as one of its child.
Definition: DFSTree_tpl.h:225
Abstract class representing an element of PRM class.
std::list< NodeId > __roots
The list of root patterns in this DFSTree.
Definition: DFSTree.h:264
UndiGraph & g
The isomorphism graph.
Definition: DFSTree.h:254
Inner class to handle data about edges in __graph.
This is used to generate the max_indep_set of a Pattern.
Definition: DFSTree.h:244
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
void addRoot(LabelData &data)
Add a one edge Pattern in this DFSTree.
Definition: DFSTree_tpl.h:46
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
bool __is_new_seq(Sequence< PRMInstance< GUM_SCALAR > * > &seq, NodeProperty< Sequence< PRMInstance< GUM_SCALAR > * > * > &iso_map)
Check if an instance match is redundant.
Definition: DFSTree_tpl.h:139
The class for generic Hash Tables.
Definition: hashTable.h:676
std::list< NodeId > & roots()
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:385
const InterfaceGraph< GUM_SCALAR > & graph() const
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:497
A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph...
Definition: DFSTree.h:68
Size cost
The cost of this Pattern.
Definition: DFSTree.h:109
Base class for all oriented graphs.
Definition: diGraph.h:108
Headers of the DFSTree class.
Headers of the SearchStrategy class and child.
Set< NodeId > max_indep_set
The maximal independent set of p.
Definition: DFSTree.h:107
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
NodeProperty< Sequence< PRMInstance< GUM_SCALAR > *> *> iso_map
The instances matching p in the interface graph.
Definition: DFSTree.h:105
Inline implementation of the DFSTree class.
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Definition: DFSTree_tpl.h:527
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
This class discovers pattern in a PRM<GUM_SCALAR>&#39;s PRMSystem<GUM_SCALAR> to speed up structured infe...
Definition: DFSTree.h:54
void __initialiaze_root(Pattern *p, Sequence< EdgeData< GUM_SCALAR > * > &seq)
This initialize the DSFTree with a new root.
Definition: DFSTree_tpl.h:90
Base class for undirected graphs.
Definition: undiGraph.h:106
Headers of InterfaceGraph.
Size gain
The gain of this Pattern.
Definition: DFSTree.h:111
PatternData & data(const Pattern &p)
Definition: DFSTree_tpl.h:516
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:271
double frequency(const Pattern &p) const
Returns the frequency of p respecting it&#39;s maximal independent set.
Definition: DFSTree_tpl.h:510
bool __test_equality(HashTable< PRMClassElement< GUM_SCALAR > *, Size > &x, HashTable< PRMClassElement< GUM_SCALAR > *, Size > &y)
Definition: DFSTree_tpl.h:339
void __checkGrowth(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Raise different exceptions if child is invalid or illegal.
Definition: DFSTree_tpl.h:185
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Pattern & parent(const Pattern &p)
Returns the parent of p in this DFSTree.
Definition: DFSTree_tpl.h:395
UndiGraph iso_graph
The isomorphism graph of the pattern.
Definition: DFSTree.h:103
Headers of the Pattern class.
Bijection< NodeId, Pattern *> __node_map
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:268
std::list< NodeId > children
The list of the pattern&#39;s children, sorted lexicographically.
Definition: DFSTree.h:101
This contains all the information we want for a node in a DFSTree.
Definition: pattern.h:70
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: DFSTree_tpl.h:372
This is an abstract class used to tune search strategies in the gspan algorithm.
Definition: DFSTree.h:58
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Set of pairs of elements with fast search for both elements.