| 
									
										
										
										
											2014-12-09 19:13:57 +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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 11:09:31 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2015-02-25 22:09:33 +08:00
										 |  |  |  * @file    QP.h | 
					
						
							|  |  |  |  * @brief   Factor graphs of a Quadratic Programming problem | 
					
						
							|  |  |  |  * @date    Dec 8, 2014 | 
					
						
							|  |  |  |  * @author  Duy-Nguyen Ta | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <gtsam/linear/GaussianFactorGraph.h>
 | 
					
						
							| 
									
										
										
										
											2015-02-25 11:25:26 +08:00
										 |  |  | #include <gtsam_unstable/linear/EqualityFactorGraph.h>
 | 
					
						
							|  |  |  | #include <gtsam_unstable/linear/InequalityFactorGraph.h>
 | 
					
						
							| 
									
										
										
										
											2016-03-07 23:29:43 +08:00
										 |  |  | #include <gtsam/slam/dataset.h>
 | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2015-02-25 11:09:31 +08:00
										 |  |  |  * Struct contains factor graphs of a Quadratic Programming problem | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct QP { | 
					
						
							|  |  |  |   GaussianFactorGraph cost; //!< Quadratic cost factors
 | 
					
						
							| 
									
										
										
										
											2015-02-25 12:41:39 +08:00
										 |  |  |   EqualityFactorGraph equalities; //!< linear equality constraints: cE(x) = 0
 | 
					
						
							|  |  |  |   InequalityFactorGraph inequalities; //!< linear inequality constraints: cI(x) <= 0
 | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 20:12:40 +08:00
										 |  |  | private: | 
					
						
							|  |  |  |   mutable VariableIndex cachedCostVariableIndex_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  |   /** default constructor */ | 
					
						
							|  |  |  |   QP() : | 
					
						
							|  |  |  |       cost(), equalities(), inequalities() { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** constructor */ | 
					
						
							|  |  |  |   QP(const GaussianFactorGraph& _cost, | 
					
						
							| 
									
										
										
										
											2015-02-25 11:25:26 +08:00
										 |  |  |       const EqualityFactorGraph& _linearEqualities, | 
					
						
							|  |  |  |       const InequalityFactorGraph& _linearInequalities) : | 
					
						
							| 
									
										
										
										
											2016-06-14 10:58:36 +08:00
										 |  |  |       cost(_cost), equalities(_linearEqualities), inequalities( | 
					
						
							|  |  |  |           _linearInequalities) { | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** print */ | 
					
						
							|  |  |  |   void print(const std::string& s = "") { | 
					
						
							|  |  |  |     std::cout << s << std::endl; | 
					
						
							|  |  |  |     cost.print("Quadratic cost factors: "); | 
					
						
							|  |  |  |     equalities.print("Linear equality factors: "); | 
					
						
							|  |  |  |     inequalities.print("Linear inequality factors: "); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-16 20:12:40 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const VariableIndex& costVariableIndex() const { | 
					
						
							|  |  |  |     if (cachedCostVariableIndex_.size() == 0) | 
					
						
							|  |  |  |       cachedCostVariableIndex_ = VariableIndex(cost); | 
					
						
							|  |  |  |     return cachedCostVariableIndex_; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Vector costGradient(Key key, const VectorValues& delta) const { | 
					
						
							|  |  |  |     Vector g = Vector::Zero(delta.at(key).size()); | 
					
						
							|  |  |  |     if (costVariableIndex().find(key) != costVariableIndex().end()) { | 
					
						
							|  |  |  |       for (size_t factorIx : costVariableIndex()[key]) { | 
					
						
							|  |  |  |         GaussianFactor::shared_ptr factor = cost.at(factorIx); | 
					
						
							|  |  |  |         g += factor->gradient(key, delta); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return g; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-09 19:13:57 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 | 
					
						
							|  |  |  | 
 |