| 
									
										
										
										
											2014-01-29 08:38:28 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * NestedDissection.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *   Created on: Nov 27, 2010 | 
					
						
							|  |  |  |  *       Author: nikai | 
					
						
							|  |  |  |  *  Description: apply nested dissection algorithm to the factor graph | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2014-01-29 08:38:28 +08:00
										 |  |  | #include <gtsam/nonlinear/Ordering.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { namespace partition { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 00:44:46 +08:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    *  Apply nested dissection algorithm to nonlinear factor graphs | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   template <class NLG, class SubNLG, class GenericGraph> | 
					
						
							|  |  |  |   class NestedDissection { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  |     typedef std::shared_ptr<SubNLG> sharedSubNLG; | 
					
						
							| 
									
										
										
										
											2014-10-31 00:44:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     NLG fg_;                          // the original nonlinear factor graph
 | 
					
						
							|  |  |  |     Ordering ordering_;               // the variable ordering in the nonlinear factor graph
 | 
					
						
							|  |  |  |     std::vector<Symbol> int2symbol_;  // the mapping from integer key to symbol
 | 
					
						
							|  |  |  |     sharedSubNLG root_;               // the root of generated cluster tree
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     sharedSubNLG root() const { return root_; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     /* constructor with post-determined partitoning*/ | 
					
						
							|  |  |  |     NestedDissection(const NLG& fg, const Ordering& ordering, const int numNodeStopPartition, const int minNodesPerMap, const bool verbose = false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* constructor with pre-determined cuts*/ | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  |     NestedDissection(const NLG& fg, const Ordering& ordering, const std::shared_ptr<Cuts>& cuts, const bool verbose = false); | 
					
						
							| 
									
										
										
										
											2014-10-31 00:44:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     /* convert generic subgraph to nonlinear subgraph  */ | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  |     sharedSubNLG makeSubNLG(const NLG& fg, const std::vector<size_t>& frontals,  const std::vector<size_t>& sep,  const std::shared_ptr<SubNLG>& parent) const; | 
					
						
							| 
									
										
										
										
											2014-10-31 00:44:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void processFactor(const typename GenericGraph::value_type& factor, const std::vector<int>& partitionTable,  // input
 | 
					
						
							|  |  |  |           std::vector<GenericGraph>& frontalFactors, NLG& sepFactors, std::vector<std::set<size_t> >& childSeps, // output factor graphs
 | 
					
						
							|  |  |  |           typename SubNLG::Weeklinks& weeklinks) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* recursively partition the generic graph */ | 
					
						
							|  |  |  |     void partitionFactorsAndVariables( | 
					
						
							|  |  |  |         const GenericGraph& fg, const GenericUnaryGraph& unaryFactors, | 
					
						
							|  |  |  |         const std::vector<size_t>& keys, const std::vector<int>& partitionTable, const int numSubmaps,  // input
 | 
					
						
							|  |  |  |         std::vector<GenericGraph>& frontalFactors, vector<GenericUnaryGraph>& frontalUnaryFactors, NLG& sepFactors,   // output factor graphs
 | 
					
						
							|  |  |  |         std::vector<std::vector<size_t> >& childFrontals, std::vector<std::vector<size_t> >& childSeps, std::vector<size_t>& localFrontals,  // output sub-orderings
 | 
					
						
							|  |  |  |         typename SubNLG::Weeklinks& weeklinks) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     NLG collectOriginalFactors(const GenericGraph& gfg, const GenericUnaryGraph& unaryFactors) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* recursively partition the generic graph */ | 
					
						
							|  |  |  |     sharedSubNLG recursivePartition(const GenericGraph& gfg, const GenericUnaryGraph& unaryFactors, const std::vector<size_t>& frontals, const std::vector<size_t>& sep, | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  |           const int numNodeStopPartition, const int minNodesPerMap, const std::shared_ptr<SubNLG>& parent, WorkSpace& workspace, const bool verbose) const; | 
					
						
							| 
									
										
										
										
											2014-10-31 00:44:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* recursively partition the generic graph */ | 
					
						
							|  |  |  |     sharedSubNLG recursivePartition(const GenericGraph& gfg, const GenericUnaryGraph& unaryFactors, const std::vector<size_t>& frontals, const std::vector<size_t>& sep, | 
					
						
							| 
									
										
										
										
											2023-01-18 06:05:12 +08:00
										 |  |  |         const std::shared_ptr<Cuts>& cuts, const std::shared_ptr<SubNLG>& parent, WorkSpace& workspace, const bool verbose) const; | 
					
						
							| 
									
										
										
										
											2014-10-31 00:44:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2014-01-29 08:38:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | }} //namespace
 |