| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |  * @file    VectorConfig.h | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |  * @brief   Factor Graph Configuration | 
					
						
							|  |  |  |  * @author  Carlos Nieto | 
					
						
							|  |  |  |  * @author  Christian Potthast | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // \callgraph
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <boost/serialization/map.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-09 12:43:04 +08:00
										 |  |  | #include "Testable.h"
 | 
					
						
							|  |  |  | #include "Vector.h"
 | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  |   /** Factor Graph Configuration */ | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |   class VectorConfig : public Testable<VectorConfig> { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   protected: | 
					
						
							|  |  |  |     /** Map from string indices to values */ | 
					
						
							|  |  |  |     std::map<std::string, Vector> values; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     typedef std::map<std::string, Vector>::iterator iterator; | 
					
						
							|  |  |  |     typedef std::map<std::string, Vector>::const_iterator const_iterator; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-22 22:42:19 +08:00
										 |  |  |     VectorConfig() {} | 
					
						
							|  |  |  |     VectorConfig(const VectorConfig& cfg_in): values(cfg_in.values) {} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |     virtual ~VectorConfig() {} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** return all the nodes in the graph **/ | 
					
						
							| 
									
										
										
										
											2009-08-28 23:38:27 +08:00
										 |  |  |     std::vector<std::string> get_names() const { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |       std::vector<std::string> names; | 
					
						
							| 
									
										
										
										
											2009-08-28 23:38:27 +08:00
										 |  |  |       for(const_iterator it=values.begin(); it!=values.end(); it++) | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |         names.push_back(it->first); | 
					
						
							|  |  |  |       return names; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** Insert a value into the configuration with a given index */ | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |     VectorConfig& insert(const std::string& name, const Vector& val) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |       values.insert(std::make_pair(name,val)); | 
					
						
							|  |  |  |       return *this; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2009-09-09 12:43:04 +08:00
										 |  |  |      * Add a delta config, needed for use in NonlinearOptimizer | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |      * For VectorConfig, this is just addition. | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |     VectorConfig exmap(const VectorConfig & delta) const; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2009-08-29 04:06:29 +08:00
										 |  |  |     const_iterator begin() const {return values.begin();} | 
					
						
							|  |  |  |     const_iterator end()   const {return values.end();} | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** get a vector in the configuration by name */ | 
					
						
							|  |  |  |     Vector get(const std::string& name) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** operator[] syntax for get */ | 
					
						
							|  |  |  |     inline Vector operator[](const std::string& name) const { return get(name); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool contains(const std::string& name) const { | 
					
						
							|  |  |  |       const_iterator it = values.find(name); | 
					
						
							|  |  |  |       if (it==values.end()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** size of the configurations */ | 
					
						
							|  |  |  |     size_t size() const { | 
					
						
							|  |  |  |       return values.size(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** print */ | 
					
						
							|  |  |  |     void print(const std::string& name = "") const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** equals, for unit testing */ | 
					
						
							| 
									
										
										
										
											2009-10-15 04:39:59 +08:00
										 |  |  |     bool equals(const VectorConfig& expected, double tol=1e-9) const; | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void clear() {values.clear();} | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     /** Serialization function */ | 
					
						
							|  |  |  |     friend class boost::serialization::access; | 
					
						
							|  |  |  |     template<class Archive> | 
					
						
							|  |  |  |       void serialize(Archive & ar, const unsigned int version) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       ar & BOOST_SERIALIZATION_NVP(values); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |