| 
									
										
										
										
											2009-10-29 13:39:13 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SymbolicFactorGraph.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  Created on: Oct 29, 2009 | 
					
						
							|  |  |  |  *      Author: Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-13 15:09:56 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | #include <boost/format.hpp>
 | 
					
						
							| 
									
										
										
										
											2009-10-29 13:39:13 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/inference/SymbolicFactorGraph.h>
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | #include <gtsam/inference/BayesNet-inl.h>
 | 
					
						
							|  |  |  | #include <gtsam/inference/Factor-inl.h>
 | 
					
						
							| 
									
										
										
										
											2010-08-20 01:23:19 +08:00
										 |  |  | #include <gtsam/inference/inference-inl.h>
 | 
					
						
							| 
									
										
										
										
											2009-10-29 13:39:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-30 13:45:22 +08:00
										 |  |  | 	// Explicitly instantiate so we don't have to include everywhere
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  | 	template class FactorGraph<Factor>; | 
					
						
							|  |  |  | 	template class BayesNet<Conditional>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							|  |  |  | 	SymbolicFactorGraph::SymbolicFactorGraph(const BayesNet<Conditional>& bayesNet) : | 
					
						
							|  |  |  | 	    FactorGraph<Factor>(bayesNet) {} | 
					
						
							| 
									
										
										
										
											2009-10-30 13:45:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   void SymbolicFactorGraph::push_factor(Index key) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     boost::shared_ptr<Factor> factor(new Factor(key)); | 
					
						
							|  |  |  |     push_back(factor); | 
					
						
							| 
									
										
										
										
											2009-11-12 12:56:30 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   /** Push back binary factor */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   void SymbolicFactorGraph::push_factor(Index key1, Index key2) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     boost::shared_ptr<Factor> factor(new Factor(key1,key2)); | 
					
						
							|  |  |  |     push_back(factor); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2009-10-29 22:34:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   /** Push back ternary factor */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   void SymbolicFactorGraph::push_factor(Index key1, Index key2, Index key3) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     boost::shared_ptr<Factor> factor(new Factor(key1,key2,key3)); | 
					
						
							|  |  |  |     push_back(factor); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Push back 4-way factor */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   void SymbolicFactorGraph::push_factor(Index key1, Index key2, Index key3, Index key4) { | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     boost::shared_ptr<Factor> factor(new Factor(key1,key2,key3,key4)); | 
					
						
							|  |  |  |     push_back(factor); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |   std::set<Index, std::less<Index>, boost::fast_pool_allocator<Index> > | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |   SymbolicFactorGraph::keys() const { | 
					
						
							| 
									
										
										
										
											2010-10-12 05:14:35 +08:00
										 |  |  |     std::set<Index, std::less<Index>, boost::fast_pool_allocator<Index> > keys; | 
					
						
							| 
									
										
										
										
											2010-10-09 06:04:47 +08:00
										 |  |  |     BOOST_FOREACH(const sharedFactor& factor, *this) { | 
					
						
							|  |  |  |       if(factor) keys.insert(factor->begin(), factor->end()); } | 
					
						
							|  |  |  |     return keys; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //	/* ************************************************************************* */
 | 
					
						
							|  |  |  | //	SymbolicBayesNet
 | 
					
						
							|  |  |  | //	SymbolicFactorGraph::eliminateFrontals(const Ordering& ordering)
 | 
					
						
							|  |  |  | //	{
 | 
					
						
							|  |  |  | //		return Inference::Eliminate(ordering);
 | 
					
						
							|  |  |  | //	}
 | 
					
						
							| 
									
										
										
										
											2010-07-08 05:41:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-29 13:39:13 +08:00
										 |  |  | 	/* ************************************************************************* */ | 
					
						
							|  |  |  | } |