Loading...
Searching...
No Matches
EliminationTree.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <utility>
#include <boost/shared_ptr.hpp>
#include <gtsam/base/Testable.h>
#include <gtsam/base/FastVector.h>
class EliminationTreeTester; // for unit tests, see testEliminationTree
namespace gtsam {
class VariableIndex;
class Ordering;
template<class BAYESNET, class GRAPH>
class EliminationTree
{
protected:
typedef EliminationTree<BAYESNET, GRAPH> This;
typedef boost::shared_ptr<This> shared_ptr;
public:
typedef GRAPH FactorGraphType;
typedef typename GRAPH::FactorType FactorType;
typedef typename boost::shared_ptr<FactorType> sharedFactor;
typedef BAYESNET BayesNetType;
typedef typename BayesNetType::ConditionalType ConditionalType;
typedef typename boost::shared_ptr<ConditionalType> sharedConditional;
typedef typename GRAPH::Eliminate Eliminate;
struct Node {
typedef FastVector<sharedFactor> Factors;
typedef FastVector<boost::shared_ptr<Node> > Children;
Key key;
Factors factors;
Children children;
sharedFactor eliminate(const boost::shared_ptr<BayesNetType>& output,
const Eliminate& function, const FastVector<sharedFactor>& childrenFactors) const;
void print(const std::string& str, const KeyFormatter& keyFormatter) const;
};
typedef boost::shared_ptr<Node> sharedNode;
protected:
GTSAM_CONCEPT_TESTABLE_TYPE(FactorType)
FastVector<sharedNode> roots_;
FastVector<sharedFactor> remainingFactors_;
EliminationTree(const FactorGraphType& factorGraph,
const VariableIndex& structure, const Ordering& order);
EliminationTree(const FactorGraphType& factorGraph, const Ordering& order);
EliminationTree(const This& other) { *this = other; }
This& operator=(const This& other);
public:
std::pair<boost::shared_ptr<BayesNetType>, boost::shared_ptr<FactorGraphType> >
eliminate(Eliminate function) const;
void print(const std::string& name = "EliminationTree: ",
const KeyFormatter& formatter = DefaultKeyFormatter) const;
protected:
bool equals(const This& other, double tol = 1e-9) const;
public:
const FastVector<sharedNode>& roots() const { return roots_; }
const FastVector<sharedFactor>& remainingFactors() const { return remainingFactors_; }
void swap(This& other);
protected:
EliminationTree() {}
private:
friend class ::EliminationTreeTester;
};
}
Testable.h
Concept check for values that can be used in unit tests.
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
gtsam::FastVector
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::KeyFormatter
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
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::EliminationTree::equals
bool equals(const This &other, double tol=1e-9) const
Test whether the tree is equal to another.
Definition EliminationTree-inst.h:214
gtsam::EliminationTree::print
void print(const std::string &name="EliminationTree: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
Print the tree to cout.
Definition EliminationTree-inst.h:207
gtsam::EliminationTree::eliminate
std::pair< boost::shared_ptr< BayesNetType >, boost::shared_ptr< FactorGraphType > > eliminate(Eliminate function) const
Eliminate the factors to a Bayes net and remaining factor graph.
Definition EliminationTree-inst.h:187
gtsam::EliminationTree::operator=
This & operator=(const This &other)
Assignment operator - makes a deep copy of the tree structure, but only pointers to factors are copie...
Definition EliminationTree-inst.h:172
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::This
EliminationTree< DiscreteBayesNet, DiscreteFactorGraph > This
Definition EliminationTree.h:54
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::roots_
FastVector< sharedNode > roots_
Definition EliminationTree.h:86
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::sharedFactor
boost::shared_ptr< FactorType > sharedFactor
Definition EliminationTree.h:60
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::BayesNetType
DiscreteBayesNet BayesNetType
Definition EliminationTree.h:61
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::sharedConditional
boost::shared_ptr< ConditionalType > sharedConditional
Definition EliminationTree.h:63
gtsam::EliminationTree::roots
const FastVector< sharedNode > & roots() const
Return the set of roots (one for a tree, multiple for a forest).
Definition EliminationTree.h:151
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::FactorGraphType
DiscreteFactorGraph FactorGraphType
Definition EliminationTree.h:58
gtsam::EliminationTree::swap
void swap(This &other)
Swap the data of this tree with another one, this operation is very fast.
Definition EliminationTree-inst.h:283
gtsam::EliminationTree::EliminationTree
EliminationTree()
Protected default constructor.
Definition EliminationTree.h:161
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::ConditionalType
BayesNetType::ConditionalType ConditionalType
Definition EliminationTree.h:62
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::shared_ptr
boost::shared_ptr< This > shared_ptr
Definition EliminationTree.h:55
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::FactorType
DiscreteFactorGraph::FactorType FactorType
Definition EliminationTree.h:59
gtsam::EliminationTree< DiscreteBayesNet, DiscreteFactorGraph >::sharedNode
boost::shared_ptr< Node > sharedNode
Definition EliminationTree.h:80
gtsam::EliminationTree::EliminationTree
EliminationTree(const FactorGraphType &factorGraph, const VariableIndex &structure, const Ordering &order)
Build the elimination tree of a factor graph using pre-computed column structure.
Definition EliminationTree-inst.h:77
gtsam::EliminationTree::remainingFactors
const FastVector< sharedFactor > & remainingFactors() const
Return the remaining factors that are not pulled into elimination.
Definition EliminationTree.h:154
gtsam::EliminationTree::Node
Definition EliminationTree.h:66
gtsam::EliminationTree::Node::key
Key key
key associated with root
Definition EliminationTree.h:70
gtsam::EliminationTree::Node::children
Children children
sub-trees
Definition EliminationTree.h:72
gtsam::EliminationTree::Node::factors
Factors factors
factors associated with root
Definition EliminationTree.h:71
gtsam::Ordering
Definition Ordering.h:34
gtsam::VariableIndex
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:43