| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * EliminationTree.h | 
					
						
							|  |  |  |  * Created on: Feb 4, 2010 | 
					
						
							|  |  |  |  * @Author: Kai Ni | 
					
						
							|  |  |  |  * @Author: Frank Dellaert | 
					
						
							|  |  |  |  * @brief: The elimination tree | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <set>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/inference/IndexTable.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/ClusterTree.h>
 | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | template<class> class _EliminationTreeTester; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | 	/**
 | 
					
						
							| 
									
										
										
										
											2010-07-19 04:23:23 +08:00
										 |  |  | 	 * An elimination tree (see Gilbert01bit) associated with a factor graph and an ordering | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | 	 * is a cluster-tree where there is one node j for each variable, and the parent of each node | 
					
						
							| 
									
										
										
										
											2010-07-15 09:41:26 +08:00
										 |  |  | 	 * corresponds to the first variable up the ordering in the Cholesky factor that j is connected to. | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	template<class FG> | 
					
						
							|  |  |  | 	class EliminationTree: public ClusterTree<FG> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-15 07:48:51 +08:00
										 |  |  | 		// In an elimination tree, the clusters are called nodes
 | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | 		typedef typename ClusterTree<FG>::Cluster Node; | 
					
						
							|  |  |  | 		typedef typename Node::shared_ptr sharedNode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-15 07:48:51 +08:00
										 |  |  | 		// we typedef the following handy list of ordered factor graphs
 | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | 		typedef std::pair<Index, FG> NamedGraph; | 
					
						
							| 
									
										
										
										
											2010-07-15 07:48:51 +08:00
										 |  |  | 		typedef std::list<NamedGraph> OrderedGraphs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Number of variables */ | 
					
						
							|  |  |  | 		size_t nrVariables_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Map from ordering index to Nodes */ | 
					
						
							|  |  |  | 		typedef std::vector<sharedNode> Nodes; | 
					
						
							|  |  |  | 		Nodes nodes_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * add a factor graph fragment with given frontal key into the tree. Assumes | 
					
						
							|  |  |  | 		 * parent node was already added (will throw exception if not). | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  | //		void add(const FG& fg, Index key);
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Add a pre-created node by computing its parent and children. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		void add(const sharedNode& node); | 
					
						
							| 
									
										
										
										
											2010-07-15 07:48:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		/** Default constructor creates an empty elimination tree. */ | 
					
						
							|  |  |  | 		EliminationTree() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-15 07:48:51 +08:00
										 |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Constructor variant 1: from an ordered list of factor graphs | 
					
						
							|  |  |  | 		 * The list is supposed to be in elimination order, and for each | 
					
						
							|  |  |  | 		 * eliminated variable a list of factors to be eliminated. | 
					
						
							|  |  |  | 		 * This function assumes the input is correct (!) and will not check | 
					
						
							|  |  |  | 		 * whether the factors refer only to the correct set of variables. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | //		EliminationTree(const OrderedGraphs& orderedGraphs);
 | 
					
						
							| 
									
										
										
										
											2010-07-15 07:48:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * Constructor variant 2: given a factor graph and the elimination ordering | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 		EliminationTree(FG& fg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		friend class _EliminationTreeTester<FG>; | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	}; // EliminationTree
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	/** Class used to access private members for unit testing */ | 
					
						
							|  |  |  | 	template<class FG> | 
					
						
							|  |  |  | 	struct _EliminationTreeTester { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  EliminationTree<FG>& et_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 	  _EliminationTreeTester(EliminationTree<FG>& et) : et_(et) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  typename EliminationTree<FG>::sharedNode& root() { return et_.ClusterTree<FG>::root_; } | 
					
						
							|  |  |  | 	  typename EliminationTree<FG>::Nodes& nodes() { return et_.nodes_; } | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-14 23:22:37 +08:00
										 |  |  | } // namespace gtsam
 |