| 
									
										
										
										
											2010-10-14 12:54:38 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SubgraphSolver.h | 
					
						
							|  |  |  |  * Created on: Dec 31, 2009 | 
					
						
							|  |  |  |  * @author: Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/linear/GaussianFactorGraph.h>
 | 
					
						
							|  |  |  | #include <gtsam/linear/GaussianBayesNet.h>
 | 
					
						
							|  |  |  | #include <gtsam/linear/SubgraphPreconditioner.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-19 03:29:16 +08:00
										 |  |  | #include <gtsam/nonlinear/Ordering.h>
 | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * A nonlinear system solver using subgraph preconditioning conjugate gradient | 
					
						
							|  |  |  |    * Concept NonLinearSolver<G,T,L> implements | 
					
						
							|  |  |  |    *   linearize: G * T -> L | 
					
						
							| 
									
										
										
										
											2010-10-09 11:09:58 +08:00
										 |  |  |    *   solve : L -> VectorValues | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 	template<class GRAPH, class VALUES> | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 	class SubgraphSolver { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	private: | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		typedef typename VALUES::Key Key; | 
					
						
							|  |  |  | 		typedef typename GRAPH::Constraint Constraint; | 
					
						
							|  |  |  | 		typedef typename GRAPH::Pose Pose; | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// TODO not hardcode
 | 
					
						
							|  |  |  | 		static const size_t maxIterations_=100; | 
					
						
							|  |  |  | 		static const double epsilon_=1e-4, epsilon_abs_=1e-5; | 
					
						
							| 
									
										
										
										
											2010-10-19 04:36:01 +08:00
										 |  |  | 		static const bool verbose_=true; | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* the ordering derived from the spanning tree */ | 
					
						
							|  |  |  | 		boost::shared_ptr<Ordering> ordering_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* the solution computed from the first subgraph */ | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		boost::shared_ptr<VALUES> theta_bar_; | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		GRAPH T_, C_; | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 		SubgraphSolver() {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		SubgraphSolver(const GRAPH& G, const VALUES& theta0); | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		void initialize(const GRAPH& G, const VALUES& theta0); | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		boost::shared_ptr<Ordering> ordering() const { return ordering_; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		boost::shared_ptr<VALUES> theta_bar() const { return theta_bar_; } | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * linearize the non-linear graph around the current config and build the subgraph preconditioner systme | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 		boost::shared_ptr<SubgraphPreconditioner> linearize(const GRAPH& G, const VALUES& theta_bar) const; | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-11 02:28:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-19 03:29:16 +08:00
										 |  |  | 		/**
 | 
					
						
							|  |  |  | 		 * solve for the optimal displacement in the tangent space, and then solve | 
					
						
							|  |  |  | 		 * the resulted linear system | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		VectorValues optimize(SubgraphPreconditioner& system) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		boost::shared_ptr<SubgraphSolver> prepareLinear(const SubgraphPreconditioner& fg) const { | 
					
						
							|  |  |  | 			return boost::shared_ptr<SubgraphSolver>(new SubgraphSolver(*this)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	  	/** expmap the Values given the stored Ordering */ | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 	  	VALUES expmap(const VALUES& config, const VectorValues& delta) const { | 
					
						
							| 
									
										
										
										
											2010-10-19 03:29:16 +08:00
										 |  |  | 	  	  return config.expmap(delta, *ordering_); | 
					
						
							|  |  |  | 	  	} | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-21 00:37:47 +08:00
										 |  |  | 	template<class GRAPH, class VALUES> const size_t SubgraphSolver<GRAPH,VALUES>::maxIterations_; | 
					
						
							|  |  |  | 	template<class GRAPH, class VALUES> const bool SubgraphSolver<GRAPH,VALUES>::verbose_; | 
					
						
							|  |  |  | 	template<class GRAPH, class VALUES> const double SubgraphSolver<GRAPH,VALUES>::epsilon_; | 
					
						
							|  |  |  | 	template<class GRAPH, class VALUES> const double SubgraphSolver<GRAPH,VALUES>::epsilon_abs_; | 
					
						
							| 
									
										
										
										
											2010-03-13 03:19:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // nsamespace gtsam
 |