| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  |  * 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file METISOrdering.cpp | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  |  * @brief Simple robot motion example, with prior and two odometry measurements, | 
					
						
							|  |  |  |  * using a METIS ordering | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  * @author Andrew Melim | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2014-11-18 01:06:59 +08:00
										 |  |  |  * Example of a simple 2D localization example optimized using METIS ordering | 
					
						
							|  |  |  |  * - For more details on the full optimization pipeline, see OdometryExample.cpp | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/geometry/Pose2.h>
 | 
					
						
							|  |  |  | #include <gtsam/nonlinear/LevenbergMarquardtOptimizer.h>
 | 
					
						
							|  |  |  | #include <gtsam/nonlinear/Marginals.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  | #include <gtsam/nonlinear/NonlinearFactorGraph.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  | #include <gtsam/nonlinear/Values.h>
 | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  | #include <gtsam/slam/BetweenFactor.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace gtsam; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int main(int argc, char** argv) { | 
					
						
							|  |  |  |   NonlinearFactorGraph graph; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  |   Pose2 priorMean(0.0, 0.0, 0.0);  // prior at origin
 | 
					
						
							|  |  |  |   auto priorNoise = noiseModel::Diagonal::Sigmas(Vector3(0.3, 0.3, 0.1)); | 
					
						
							| 
									
										
										
										
											2020-04-13 01:10:09 +08:00
										 |  |  |   graph.addPrior(1, priorMean, priorNoise); | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Pose2 odometry(2.0, 0.0, 0.0); | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  |   auto odometryNoise = noiseModel::Diagonal::Sigmas(Vector3(0.2, 0.2, 0.1)); | 
					
						
							| 
									
										
										
										
											2016-10-01 23:41:37 +08:00
										 |  |  |   graph.emplace_shared<BetweenFactor<Pose2> >(1, 2, odometry, odometryNoise); | 
					
						
							|  |  |  |   graph.emplace_shared<BetweenFactor<Pose2> >(2, 3, odometry, odometryNoise); | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  |   graph.print("\nFactor Graph:\n");  // print
 | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Values initial; | 
					
						
							|  |  |  |   initial.insert(1, Pose2(0.5, 0.0, 0.2)); | 
					
						
							|  |  |  |   initial.insert(2, Pose2(2.3, 0.1, -0.2)); | 
					
						
							|  |  |  |   initial.insert(3, Pose2(4.1, 0.1, 0.1)); | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  |   initial.print("\nInitial Estimate:\n");  // print
 | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // optimize using Levenberg-Marquardt optimization
 | 
					
						
							| 
									
										
										
										
											2014-10-22 03:56:40 +08:00
										 |  |  |   LevenbergMarquardtParams params; | 
					
						
							| 
									
										
										
										
											2020-05-10 07:08:31 +08:00
										 |  |  |   // In order to specify the ordering type, we need to se the "orderingType". By
 | 
					
						
							|  |  |  |   // default this parameter is set to OrderingType::COLAMD
 | 
					
						
							| 
									
										
										
										
											2014-11-18 05:16:52 +08:00
										 |  |  |   params.orderingType = Ordering::METIS; | 
					
						
							| 
									
										
										
										
											2014-10-22 03:56:40 +08:00
										 |  |  |   LevenbergMarquardtOptimizer optimizer(graph, initial, params); | 
					
						
							|  |  |  |   Values result = optimizer.optimize(); | 
					
						
							| 
									
										
										
										
											2014-10-22 01:15:48 +08:00
										 |  |  |   result.print("Final Result:\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return 0; | 
					
						
							| 
									
										
										
										
											2014-11-18 05:16:52 +08:00
										 |  |  | } |