| 
									
										
										
										
											2014-12-23 08:49:32 +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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |  * @file 	 LinearInequalityFactor.h | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |  * @brief   | 
					
						
							| 
									
										
										
										
											2015-02-25 22:09:33 +08:00
										 |  |  |  * @author   Duy-Nguyen Ta | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |  * @date 	 Sep 30, 2013 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | #include <gtsam_unstable/nonlinear/LinearEqualityFactor.h>
 | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * A convenient base class for creating a linear inequality constraint, e.g., Ax <= 0, | 
					
						
							|  |  |  |  * at the nonlinear level with 1 variable. | 
					
						
							|  |  |  |  * To derive from this class, implement computeError(). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | template<class VALUE> | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | class LinearInequalityFactor1: public LinearEqualityFactor1<VALUE> { | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // typedefs for value types pulled from keys
 | 
					
						
							|  |  |  |   typedef VALUE X; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   typedef LinearEqualityFactor1<VALUE> Base; | 
					
						
							|  |  |  |   typedef LinearInequalityFactor1<VALUE> This; | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Default Constructor for I/O | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   LinearInequalityFactor1() { | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor | 
					
						
							|  |  |  |    * @param j key of the variable | 
					
						
							|  |  |  |    * @param constraintDim number of dimensions of the constraint error function | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   LinearInequalityFactor1(Key key, Key dualKey) : | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |       Base(key, dualKey, 1) { | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   virtual ~LinearInequalityFactor1() { | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    *  Override this method to finish implementing a binary factor. | 
					
						
							|  |  |  |    *  If any of the optional Matrix reference arguments are specified, it should compute | 
					
						
							|  |  |  |    *  both the function evaluation and its derivative(s) in X1 (and/or X2). | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |   virtual double | 
					
						
							|  |  |  |   computeError(const X&, boost::optional<Matrix&> H1 = boost::none) const = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** predefine evaluateError to return a 1-dimension vector */ | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |   virtual Vector | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |   evaluateError(const X& x, boost::optional<Matrix&> H1 = boost::none) const { | 
					
						
							|  |  |  |     return (Vector(1) << computeError(x, H1)).finished(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | // \class LinearEqualityFactor1
 | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * A convenient base class for creating a linear inequality constraint, e.g., Ax <= 0, | 
					
						
							|  |  |  |  * at the nonlinear level with 1 variable. | 
					
						
							|  |  |  |  * To derive from this class, implement computeError(). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  | template<class VALUE1, class VALUE2> | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | class LinearInequalityFactor2: public LinearEqualityFactor2<VALUE1, VALUE2> { | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // typedefs for value types pulled from keys
 | 
					
						
							|  |  |  |   typedef VALUE1 X1; | 
					
						
							|  |  |  |   typedef VALUE2 X2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   typedef LinearEqualityFactor2<VALUE1, VALUE2> Base; | 
					
						
							|  |  |  |   typedef LinearInequalityFactor2<VALUE1, VALUE2> This; | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Default Constructor for I/O | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   LinearInequalityFactor2() { | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor | 
					
						
							|  |  |  |    * @param j1 key of the first variable | 
					
						
							|  |  |  |    * @param j2 key of the second variable | 
					
						
							|  |  |  |    * @param constraintDim number of dimensions of the constraint error function | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   LinearInequalityFactor2(Key j1, Key j2, Key dualKey) : | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |     Base(j1, j2, 1) { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  |   virtual ~LinearInequalityFactor2() { | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    *  Override this method to finish implementing a binary factor. | 
					
						
							|  |  |  |    *  If any of the optional Matrix reference arguments are specified, it should compute | 
					
						
							|  |  |  |    *  both the function evaluation and its derivative(s) in X1 (and/or X2). | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   virtual double | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |   computeError(const X1&, const X2&, boost::optional<Matrix&> H1 = boost::none, | 
					
						
							|  |  |  |       boost::optional<Matrix&> H2 = boost::none) const = 0; | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  |   /** predefine evaluateError to return a 1-dimension vector */ | 
					
						
							|  |  |  |   virtual Vector | 
					
						
							|  |  |  |   evaluateError(const X1& x1, const X2& x2, boost::optional<Matrix&> H1 = boost::none, | 
					
						
							|  |  |  |       boost::optional<Matrix&> H2 = boost::none) const { | 
					
						
							|  |  |  |     return (Vector(1) << computeError(x1, x2, H1, H2)).finished(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2015-02-25 12:40:53 +08:00
										 |  |  | // \class LinearEqualityFactor2
 | 
					
						
							| 
									
										
										
										
											2014-12-23 07:20:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-23 03:41:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } /* namespace gtsam */ |