| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * @file NonlinearConstraint.h | 
					
						
							|  |  |  |  * @brief Implements nonlinear constraints that can be linearized and | 
					
						
							|  |  |  |  * inserted into an existing nonlinear graph and solved via SQP | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | #include <boost/function.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | #include "NonlinearFactor.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Base class for nonlinear constraints | 
					
						
							|  |  |  |  * This allows for both equality and inequality constraints, | 
					
						
							|  |  |  |  * where equality constraints are active all the time (even slightly | 
					
						
							|  |  |  |  * nonzero constraint functions will still be active - inequality | 
					
						
							|  |  |  |  * constraints should be sure to force to actual zero) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The measurement z in the underlying NonlinearFactor is the | 
					
						
							|  |  |  |  * set of Lagrange multipliers. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | template <class Config> | 
					
						
							|  |  |  | class NonlinearConstraint : public NonlinearFactor<Config> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
											  
											
												Large gtsam refactoring
To support faster development *and* better performance Richard and I pushed through a large refactoring of NonlinearFactors.
The following are the biggest changes:
1) NonLinearFactor1 and NonLinearFactor2 are now templated on Config, Key type, and X type, where X is the argument to the measurement function.
2) The measurement itself is no longer kept in the nonlinear factor. Instead, a derived class (see testVSLAMFactor, testNonlinearEquality, testPose3Factor etc...) has to implement a function to compute the errors, "evaluateErrors". Instead of (h(x)-z), it needs to return (z-h(x)), so Ax-b is an approximation of the error. IMPORTANT: evaluateErrors needs - if asked - *combine* the calculation of the function value h(x) and the derivatives dh(x)/dx. This was a major performance issue. To do this, boost::optional<Matrix&> arguments are provided, and tin EvaluateErrors you just  says something like
	if (H) *H = Matrix_(3,6,....);
3) We are no longer using int or strings for nonlinear factors. Instead, the preferred key type is now Symbol, defined in Key.h. This is both fast and cool: you can construct it from an int, and cast it to a strong. It also does type checking: a Symbol<Pose3,'x'> will not match a Symbol<Pose2,'x'>
4) minor: take a look at LieConfig.h: it help you avoid writing a lot of code bu automatically creating configs for a certain type. See e.g. Pose3Config.h. A "double" LieConfig is on the way - Thanks Richard and Manohar !
											
										 
											2010-01-14 06:25:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	/** key for the lagrange multipliers */ | 
					
						
							|  |  |  | 	std::string lagrange_key_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** number of lagrange multipliers */ | 
					
						
							|  |  |  | 	size_t p_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	/** type of constraint */ | 
					
						
							|  |  |  | 	bool isEquality_; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 	/** calculates the constraint function of the current config
 | 
					
						
							|  |  |  | 	 * If the value is zero, the constraint is not active | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	 * Use boost.bind to create the function object | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 	 * @param config is a configuration of all the variables | 
					
						
							|  |  |  | 	 * @return the cost for each of p constraints, arranged in a vector | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 	boost::function<Vector(const Config& config)> g_; | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	/** Constructor - sets the cost function and the lagrange multipliers
 | 
					
						
							|  |  |  | 	 * @param lagrange_key is the label for the associated lagrange multipliers | 
					
						
							|  |  |  | 	 * @param dim_lagrange is the number of associated constraints | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	 * @param isEquality is true if the constraint is an equality constraint | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 	 * @param g is the cost function for the constraint | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 	NonlinearConstraint(const std::string& lagrange_key, | 
					
						
							|  |  |  | 						size_t dim_lagrange, | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 						Vector (*g)(const Config& config), | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 						bool isEquality=true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** Constructor - sets a more general cost function using boost::bind directly
 | 
					
						
							|  |  |  | 	 * @param lagrange_key is the label for the associated lagrange multipliers | 
					
						
							|  |  |  | 	 * @param dim_lagrange is the number of associated constraints | 
					
						
							|  |  |  | 	 * @param g is the cost function for the constraint | 
					
						
							|  |  |  | 	 * @param isEquality is true if the constraint is an equality constraint | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	NonlinearConstraint(const std::string& lagrange_key, | 
					
						
							|  |  |  | 						size_t dim_lagrange, | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 						boost::function<Vector(const Config& config)> g, | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 						bool isEquality=true); | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** returns the key used for the Lagrange multipliers */ | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | 	std::string lagrangeKey() const { return lagrange_key_; } | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** returns the number of lagrange multipliers */ | 
					
						
							|  |  |  | 	size_t nrConstraints() const { return p_; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	/** returns the type of constraint */ | 
					
						
							|  |  |  | 	bool isEquality() const { return isEquality_; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	/** Print */ | 
					
						
							|  |  |  | 	virtual void print(const std::string& s = "") const =0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** Check if two factors are equal */ | 
					
						
							|  |  |  | 	virtual bool equals(const Factor<Config>& f, double tol=1e-9) const=0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** error function - returns the result of the constraint function */ | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	inline Vector unwhitenedError(const Config& c) const { return g_(c); } | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Determines whether the constraint is active given a particular configuration | 
					
						
							|  |  |  | 	 * @param config is the input to the g(x) function | 
					
						
							|  |  |  | 	 * @return true if constraint needs to be linearized | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	bool active(const Config& config) const; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Linearize using a real Config and a VectorConfig of Lagrange multipliers | 
					
						
							|  |  |  | 	 * Returns the two separate Gaussian factors to solve | 
					
						
							|  |  |  | 	 * @param config is the real Config of the real variables | 
					
						
							|  |  |  | 	 * @param lagrange is the VectorConfig of lagrange multipliers | 
					
						
							|  |  |  | 	 * @return a pair GaussianFactor (probabilistic) and GaussianFactor (constraint) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	virtual std::pair<GaussianFactor::shared_ptr, GaussianFactor::shared_ptr> | 
					
						
							|  |  |  | 	linearize(const Config& config, const VectorConfig& lagrange) const=0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * linearize with only Config, which is not currently implemented | 
					
						
							|  |  |  | 	 * This will be implemented later for other constrained optimization | 
					
						
							|  |  |  | 	 * algorithms | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	virtual boost::shared_ptr<GaussianFactor> linearize(const Config& c) const { | 
					
						
							|  |  |  | 		throw std::invalid_argument("No current constraint linearization for a single Config!"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  |  * A unary constraint with arbitrary cost and jacobian functions | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key, class X> | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | class NonlinearConstraint1 : public NonlinearConstraint<Config> { | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	 * Calculates the jacobian of the constraint function | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	 * returns a pxn matrix | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	 * Use boost.bind to create the function object | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	 * @param config to use for linearization | 
					
						
							|  |  |  | 	 * @return the jacobian of the constraint in terms of key | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	boost::function<Matrix(const Config& config)> G_; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** key for the constrained variable */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 	Key key_; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Basic constructor | 
					
						
							|  |  |  | 	 * @param key is the identifier for the variable constrained | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	 * @param G gives the jacobian of the constraint function | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	 * @param g is the constraint function | 
					
						
							|  |  |  | 	 * @param dim_constraint is the size of the constraint (p) | 
					
						
							|  |  |  | 	 * @param lagrange_key is the identifier for the lagrange multiplier | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	 * @param isEquality is true if the constraint is an equality constraint | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	NonlinearConstraint1( | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 			Vector (*g)(const Config& config), | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 			const Key& key, | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			Matrix (*G)(const Config& config), | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 			size_t dim_constraint, | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 			const std::string& lagrange_key="", | 
					
						
							|  |  |  | 			bool isEquality=true); | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Basic constructor with boost function pointers | 
					
						
							|  |  |  | 	 * @param key is the identifier for the variable constrained | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	 * @param G gives the jacobian of the constraint function | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	 * @param g is the constraint function as a boost function pointer | 
					
						
							|  |  |  | 	 * @param dim_constraint is the size of the constraint (p) | 
					
						
							|  |  |  | 	 * @param lagrange_key is the identifier for the lagrange multiplier | 
					
						
							|  |  |  | 	 * @param isEquality is true if the constraint is an equality constraint | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	NonlinearConstraint1( | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 			boost::function<Vector(const Config& config)> g, | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 			const Key& key, | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			boost::function<Matrix(const Config& config)> G, | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 			size_t dim_constraint, | 
					
						
							|  |  |  | 			const std::string& lagrange_key="", | 
					
						
							|  |  |  | 			bool isEquality=true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 	/** Print */ | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	void print(const std::string& s = "") const; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/** Check if two factors are equal */ | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	bool equals(const Factor<Config>& f, double tol=1e-9) const; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Linearize using a real Config and a VectorConfig of Lagrange multipliers | 
					
						
							|  |  |  | 	 * Returns the two separate Gaussian factors to solve | 
					
						
							|  |  |  | 	 * @param config is the real Config of the real variables | 
					
						
							|  |  |  | 	 * @param lagrange is the VectorConfig of lagrange multipliers | 
					
						
							|  |  |  | 	 * @return a pair GaussianFactor (probabilistic) and GaussianFactor (constraint) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	std::pair<GaussianFactor::shared_ptr, GaussianFactor::shared_ptr> | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	linearize(const Config& config, const VectorConfig& lagrange) const; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  |  * A binary constraint with arbitrary cost and jacobian functions | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key1, class X1, class Key2, class X2> | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | class NonlinearConstraint2 : public NonlinearConstraint<Config> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	 * Calculates the jacobians of the constraint function in terms of | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	 * the first and second variables | 
					
						
							|  |  |  | 	 * returns a pxn matrix | 
					
						
							|  |  |  | 	 * @param config to use for linearization | 
					
						
							|  |  |  | 	 * @return the jacobian of the constraint in terms of key | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	boost::function<Matrix(const Config& config)> G1_; | 
					
						
							|  |  |  | 	boost::function<Matrix(const Config& config)> G2_; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	/** keys for the constrained variables */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 	Key1 key1_; | 
					
						
							|  |  |  | 	Key2 key2_; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Basic constructor | 
					
						
							|  |  |  | 	 * @param key is the identifier for the variable constrained | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	 * @param G gives the jacobian of the constraint function | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	 * @param g is the constraint function | 
					
						
							|  |  |  | 	 * @param dim_constraint is the size of the constraint (p) | 
					
						
							|  |  |  | 	 * @param lagrange_key is the identifier for the lagrange multiplier | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	 * @param isEquality is true if the constraint is an equality constraint | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	NonlinearConstraint2( | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 			Vector (*g)(const Config& config), | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 			const Key1& key1, | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			Matrix (*G1)(const Config& config), | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 			const Key2& key2, | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			Matrix (*G2)(const Config& config), | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 			size_t dim_constraint, | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 			const std::string& lagrange_key="", | 
					
						
							|  |  |  | 			bool isEquality=true); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Basic constructor with direct function objects | 
					
						
							|  |  |  | 	 * Use boost.bind to construct the function objects | 
					
						
							|  |  |  | 	 * @param key is the identifier for the variable constrained | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	 * @param G gives the jacobian of the constraint function | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	 * @param g is the constraint function | 
					
						
							|  |  |  | 	 * @param dim_constraint is the size of the constraint (p) | 
					
						
							|  |  |  | 	 * @param lagrange_key is the identifier for the lagrange multiplier | 
					
						
							|  |  |  | 	 * @param isEquality is true if the constraint is an equality constraint | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	NonlinearConstraint2( | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 			boost::function<Vector(const Config& config)> g, | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 			const Key1& key1, | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			boost::function<Matrix(const Config& config)> G1, | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 			const Key2& key2, | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			boost::function<Matrix(const Config& config)> G2, | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 			size_t dim_constraint, | 
					
						
							|  |  |  | 			const std::string& lagrange_key="", | 
					
						
							|  |  |  | 			bool isEquality=true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	/** Print */ | 
					
						
							|  |  |  | 	void print(const std::string& s = "") const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** Check if two factors are equal */ | 
					
						
							|  |  |  | 	bool equals(const Factor<Config>& f, double tol=1e-9) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * Linearize using a real Config and a VectorConfig of Lagrange multipliers | 
					
						
							|  |  |  | 	 * Returns the two separate Gaussian factors to solve | 
					
						
							|  |  |  | 	 * @param config is the real Config of the real variables | 
					
						
							|  |  |  | 	 * @param lagrange is the VectorConfig of lagrange multipliers | 
					
						
							|  |  |  | 	 * @return a pair GaussianFactor (probabilistic) and GaussianFactor (constraint) | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	std::pair<GaussianFactor::shared_ptr, GaussianFactor::shared_ptr> | 
					
						
							|  |  |  | 	linearize(const Config& config, const VectorConfig& lagrange) const; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-11-20 00:50:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |