| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * @file NonlinearConstraint-inl.h | 
					
						
							|  |  |  |  * @brief Implementation for NonlinearConstraints | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  |  * @author Alex Cunningham | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | #include <boost/bind.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | #include "NonlinearConstraint.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Implementations of base class
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | template <class Config> | 
					
						
							|  |  |  | NonlinearConstraint<Config>::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) | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | :	NonlinearFactor<Config>(1.0), | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	lagrange_key_(lagrange_key), p_(dim_lagrange), | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 	isEquality_(isEquality), g_(boost::bind(g, _1)) {} | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | template <class Config> | 
					
						
							|  |  |  | NonlinearConstraint<Config>::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) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | :	NonlinearFactor<Config>(noiseModel::Constrained::All(dim_lagrange)), | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 	lagrange_key_(lagrange_key), p_(dim_lagrange), | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 	g_(g), isEquality_(isEquality) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | template <class Config> | 
					
						
							|  |  |  | bool NonlinearConstraint<Config>::active(const Config& config) const { | 
					
						
							| 
									
										
										
										
											2010-01-18 13:38:53 +08:00
										 |  |  | 	return !(!isEquality_ && greaterThanOrEqual(unwhitenedError(config), zero(p_))); | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Implementations of unary nonlinear constraints
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key, class X> | 
					
						
							|  |  |  | NonlinearConstraint1<Config, Key, X>::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 10:39:02 +08:00
										 |  |  | 			Matrix (*gradG)(const Config& config), | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | 			size_t dim_constraint, | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 			const std::string& lagrange_key, | 
					
						
							|  |  |  | 			bool isEquality) : | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 				NonlinearConstraint<Config>(lagrange_key, dim_constraint, g, isEquality), | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 				G_(boost::bind(gradG, _1)), key_(key) | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | 		// set a good lagrange key here
 | 
					
						
							|  |  |  | 		// TODO:should do something smart to find a unique one
 | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | //		if (lagrange_key == "")
 | 
					
						
							|  |  |  | //			this->lagrange_key_ = "L0"
 | 
					
						
							|  |  |  | //		this->keys_.push_front(key);
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key, class X> | 
					
						
							|  |  |  | NonlinearConstraint1<Config, Key, X>::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 10:39:02 +08:00
										 |  |  | 			boost::function<Matrix(const Config& config)> gradG, | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 			size_t dim_constraint, | 
					
						
							|  |  |  | 			const std::string& lagrange_key, | 
					
						
							|  |  |  | 			bool isEquality) : | 
					
						
							|  |  |  | 				NonlinearConstraint<Config>(lagrange_key, dim_constraint, g, isEquality), | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 				G_(gradG), key_(key) | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	// set a good lagrange key here
 | 
					
						
							|  |  |  | 	// TODO:should do something smart to find a unique one
 | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | //	if (lagrange_key == "")
 | 
					
						
							|  |  |  | //		this->lagrange_key_ = "L_" + key;
 | 
					
						
							|  |  |  | //	this->keys_.push_front(key);
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key, class X> | 
					
						
							|  |  |  | void NonlinearConstraint1<Config, Key, X>::print(const std::string& s) const { | 
					
						
							|  |  |  | 	std::cout << "NonlinearConstraint1 [" << s << "]:\n"; | 
					
						
							|  |  |  | //			<< "  key:        " << key_ << "\n"
 | 
					
						
							|  |  |  | //			<< "  p:          " << this->p_ << "\n"
 | 
					
						
							|  |  |  | //			<< "  lambda key: " << this->lagrange_key_ << "\n";
 | 
					
						
							|  |  |  | //	if (this->isEquality_)
 | 
					
						
							|  |  |  | //		std::cout << "  Equality Factor" << std::endl;
 | 
					
						
							|  |  |  | //	else
 | 
					
						
							|  |  |  | //		std::cout << "  Inequality Factor" << std::endl;
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key, class X> | 
					
						
							|  |  |  | bool NonlinearConstraint1<Config, Key, X>::equals(const Factor<Config>& f, double tol) const { | 
					
						
							|  |  |  | 	const NonlinearConstraint1<Config, Key, X>* p = dynamic_cast<const NonlinearConstraint1<Config, Key, X>*> (&f); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	if (p == NULL) return false; | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 	if (!(key_ == p->key_)) return false; | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	if (this->lagrange_key_ != p->lagrange_key_) return false; | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	if (this->isEquality_ != p->isEquality_) return false; | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	return this->p_ == p->p_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +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
										 |  |  | std::pair<GaussianFactor::shared_ptr, GaussianFactor::shared_ptr> | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | NonlinearConstraint1<Config, Key, X>::linearize(const Config& config, const VectorConfig& lagrange) const { | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	// extract lagrange multiplier
 | 
					
						
							|  |  |  | 	Vector lambda = lagrange[this->lagrange_key_]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// find the error
 | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 	Vector g = g_(config); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// construct the gradient
 | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	Matrix grad = G_(config); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// construct probabilistic factor
 | 
					
						
							| 
									
										
										
										
											2009-12-09 05:10:38 +08:00
										 |  |  | 	Matrix A1 = vector_scale(lambda, grad); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 	GaussianFactor::shared_ptr factor(new | 
					
						
							|  |  |  | 			GaussianFactor(key_, A1, this->lagrange_key_, eye(this->p_), zero(this->p_), 1.0)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// construct the constraint
 | 
					
						
							| 
									
										
										
										
											2009-11-29 05:00:09 +08:00
										 |  |  | 	GaussianFactor::shared_ptr constraint(new GaussianFactor(key_, grad, -1*g, 0.0)); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return std::make_pair(factor, constraint); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // Implementations of binary nonlinear constraints
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key1, class X1, class Key2, class X2> | 
					
						
							|  |  |  | NonlinearConstraint2<Config, Key1, X1, Key2, X2>::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-24 06:10:52 +08:00
										 |  |  | 		size_t dim_constraint, | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 		const std::string& lagrange_key, | 
					
						
							|  |  |  | 		bool isEquality) : | 
					
						
							| 
									
										
										
										
											2009-11-29 03:18:02 +08:00
										 |  |  | 			NonlinearConstraint<Config>(lagrange_key, dim_constraint, g, isEquality), | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 			G1_(boost::bind(G1, _1)), G2_(boost::bind(G2, _1)), | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 			key1_(key1), key2_(key2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// set a good lagrange key here
 | 
					
						
							|  |  |  | 	// TODO:should do something smart to find a unique one
 | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | //	if (lagrange_key == "")
 | 
					
						
							|  |  |  | //		this->lagrange_key_ = "L_" + key1 + key2;
 | 
					
						
							|  |  |  | //	this->keys_.push_front(key1);
 | 
					
						
							|  |  |  | //	this->keys_.push_back(key2);
 | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template <class Config, class Key1, class X1, class Key2, class X2> | 
					
						
							|  |  |  | NonlinearConstraint2<Config, Key1, X1, Key2, X2>::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)  : | 
					
						
							|  |  |  | 				NonlinearConstraint<Config>(lagrange_key, dim_constraint, g, isEquality), | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 				G1_(G1), G2_(G2), | 
					
						
							| 
									
										
										
										
											2009-12-02 03:45:47 +08:00
										 |  |  | 				key1_(key1), key2_(key2) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | 	// set a good lagrange key here
 | 
					
						
							|  |  |  | 	// TODO:should do something smart to find a unique one
 | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | //	if (lagrange_key == "")
 | 
					
						
							|  |  |  | //		this->lagrange_key_ = "L_" + key1 + key2;
 | 
					
						
							|  |  |  | //	this->keys_.push_front(key1);
 | 
					
						
							|  |  |  | //	this->keys_.push_back(key2);
 | 
					
						
							| 
									
										
										
										
											2009-11-24 06:10:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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> | 
					
						
							|  |  |  | void NonlinearConstraint2<Config, Key1, X1, Key2, X2>::print(const std::string& s) const { | 
					
						
							|  |  |  | 	std::cout << "NonlinearConstraint2 [" << s << "]:\n"; | 
					
						
							|  |  |  | //			<< "  key1:       " << key1_ << "\n"
 | 
					
						
							|  |  |  | //			<< "  key2:       " << key2_ << "\n"
 | 
					
						
							|  |  |  | //			<< "  p:          " << this->p_ << "\n"
 | 
					
						
							|  |  |  | //			<< "  lambda key: " << this->lagrange_key_ << std::endl;
 | 
					
						
							| 
									
										
										
										
											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> | 
					
						
							|  |  |  | bool NonlinearConstraint2<Config, Key1, X1, Key2, X2>::equals(const Factor<Config>& f, double tol) const { | 
					
						
							|  |  |  | 	const NonlinearConstraint2<Config, Key1, X1, Key2, X2>* p = dynamic_cast<const NonlinearConstraint2<Config, Key1, X1, Key2, X2>*> (&f); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	if (p == NULL) return false; | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 	if (!(key1_ == p->key1_)) return false; | 
					
						
							|  |  |  | 	if (!(key2_ == p->key2_)) return false; | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	if (this->lagrange_key_ != p->lagrange_key_) return false; | 
					
						
							| 
									
										
										
										
											2009-11-29 02:35:36 +08:00
										 |  |  | 	if (this->isEquality_ != p->isEquality_) return false; | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	return this->p_ == p->p_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | template<class Config, class Key1, class X1, class Key2, class X2> | 
					
						
							| 
									
										
										
										
											2009-12-15 13:34:49 +08:00
										 |  |  | std::pair<GaussianFactor::shared_ptr, GaussianFactor::shared_ptr> NonlinearConstraint2< | 
					
						
							| 
									
										
										
										
											2010-01-19 13:33:44 +08:00
										 |  |  | 		Config, Key1, X1, Key2, X2>::linearize(const Config& config, const VectorConfig& lagrange) const { | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 	// extract lagrange multiplier
 | 
					
						
							|  |  |  | 	Vector lambda = lagrange[this->lagrange_key_]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// find the error
 | 
					
						
							| 
									
										
										
										
											2009-12-18 10:39:02 +08:00
										 |  |  | 	Vector g = g_(config); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// construct the gradients
 | 
					
						
							| 
									
										
										
										
											2009-12-18 11:05:47 +08:00
										 |  |  | 	Matrix grad1 = G1_(config); | 
					
						
							|  |  |  | 	Matrix grad2 = G2_(config); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// construct probabilistic factor
 | 
					
						
							| 
									
										
										
										
											2009-12-09 05:10:38 +08:00
										 |  |  | 	Matrix A1 = vector_scale(lambda, grad1); | 
					
						
							|  |  |  | 	Matrix A2 = vector_scale(lambda, grad2); | 
					
						
							| 
									
										
										
										
											2009-12-15 13:34:49 +08:00
										 |  |  | 	GaussianFactor::shared_ptr factor(new GaussianFactor(key1_, A1, key2_, A2, | 
					
						
							|  |  |  | 			this->lagrange_key_, eye(this->p_), zero(this->p_), 1.0)); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:50:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// construct the constraint
 | 
					
						
							| 
									
										
										
										
											2009-12-15 13:34:49 +08:00
										 |  |  | 	GaussianFactor::shared_ptr constraint(new GaussianFactor(key1_, grad1, | 
					
						
							|  |  |  | 			key2_, grad2, -1.0 * g, 0.0)); | 
					
						
							| 
									
										
										
										
											2009-11-20 11:04:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return std::make_pair(factor, constraint); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |