GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
EliminationTree.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8 * See LICENSE for the license information
9 
10 * -------------------------------------------------------------------------- */
11 
18 #pragma once
19 
20 #include <utility>
21 #include <memory>
22 
23 #include <gtsam/base/Testable.h>
24 #include <gtsam/base/FastVector.h>
25 
26 class EliminationTreeTester; // for unit tests, see testEliminationTree
27 
28 namespace gtsam {
29 
30  class VariableIndex;
31  class Ordering;
32 
50  template<class BAYESNET, class GRAPH>
52  {
53  protected:
55  typedef std::shared_ptr<This> shared_ptr;
56 
57  public:
58  typedef GRAPH FactorGraphType;
59  typedef typename GRAPH::FactorType FactorType;
60  typedef typename std::shared_ptr<FactorType> sharedFactor;
61  typedef BAYESNET BayesNetType;
63  typedef typename std::shared_ptr<ConditionalType> sharedConditional;
64  typedef typename GRAPH::Eliminate Eliminate;
65 
66  struct Node {
67  typedef FastVector<sharedFactor> Factors;
68  typedef FastVector<std::shared_ptr<Node> > Children;
69 
70  Key key;
71  Factors factors;
72  Children children;
73 
74  sharedFactor eliminate(const std::shared_ptr<BayesNetType>& output,
75  const Eliminate& function, const FastVector<sharedFactor>& childrenFactors) const;
76 
77  void print(const std::string& str, const KeyFormatter& keyFormatter) const;
78  };
79 
80  typedef std::shared_ptr<Node> sharedNode;
81 
82  protected:
84  GTSAM_CONCEPT_TESTABLE_TYPE(FactorType)
85 
86  FastVector<sharedNode> roots_;
87  FastVector<sharedFactor> remainingFactors_;
88 
91 
100  EliminationTree(const FactorGraphType& factorGraph,
101  const VariableIndex& structure, const Ordering& order);
102 
108  EliminationTree(const FactorGraphType& factorGraph, const Ordering& order);
109 
112  EliminationTree(const This& other) { *this = other; }
113 
116  This& operator=(const This& other);
117 
119 
120  public:
121  ~EliminationTree();
124 
130  std::pair<std::shared_ptr<BayesNetType>, std::shared_ptr<FactorGraphType> >
131  eliminate(Eliminate function) const;
132 
136 
138  void print(const std::string& name = "EliminationTree: ",
139  const KeyFormatter& formatter = DefaultKeyFormatter) const;
140 
141  protected:
143  bool equals(const This& other, double tol = 1e-9) const;
144 
146 
147  public:
150 
152  const FastVector<sharedNode>& roots() const { return roots_; }
153 
155  const FastVector<sharedFactor>& remainingFactors() const { return remainingFactors_; }
156 
158  void swap(This& other);
159 
160  protected:
163 
164  private:
166  friend class ::EliminationTreeTester;
167  };
168 
169 }
FastVector< sharedNode > roots_
Definition: EliminationTree.h:86
Factors factors
factors associated with root
Definition: EliminationTree.h:71
bool equals(const This &other, double tol=1e-9) const
Definition: EliminationTree-inst.h:251
const FastVector< sharedNode > & roots() const
Definition: EliminationTree.h:152
Definition: EliminationTree.h:51
Concept check for values that can be used in unit tests.
GRAPH FactorGraphType
The factor graph type.
Definition: EliminationTree.h:58
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
void swap(This &other)
Definition: EliminationTree-inst.h:320
Definition: Ordering.h:37
Children children
sub-trees
Definition: EliminationTree.h:72
Definition: EliminationTree.h:66
EliminationTree()
Protected default constructor.
Definition: EliminationTree.h:162
Definition: GaussianConditional.h:38
BayesNetType::ConditionalType ConditionalType
The type of conditionals.
Definition: EliminationTree.h:62
EliminationTree< BAYESNET, GRAPH > This
This class.
Definition: EliminationTree.h:54
std::shared_ptr< ConditionalType > sharedConditional
Shared pointer to a conditional.
Definition: EliminationTree.h:63
Key key
key associated with root
Definition: EliminationTree.h:70
const FastVector< sharedFactor > & remainingFactors() const
Definition: EliminationTree.h:155
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
A thin wrapper around std::vector that uses a custom allocator.
Definition: chartTesting.h:28
~EliminationTree()
Definition: EliminationTree-inst.h:192
Definition: VariableIndex.h:41
BAYESNET BayesNetType
The BayesNet corresponding to FACTOR.
Definition: EliminationTree.h:61
This & operator=(const This &other)
Definition: EliminationTree-inst.h:172
std::shared_ptr< This > shared_ptr
Shared pointer to this class.
Definition: EliminationTree.h:55
GRAPH::FactorType FactorType
The type of factors.
Definition: EliminationTree.h:59
std::shared_ptr< FactorType > sharedFactor
Shared pointer to a factor.
Definition: EliminationTree.h:60
std::shared_ptr< Node > sharedNode
Shared pointer to Node.
Definition: EliminationTree.h:80
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102