| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SingleValue.h | 
					
						
							|  |  |  |  * @brief domain constraint | 
					
						
							|  |  |  |  * @date Feb 6, 2012 | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-15 17:51:26 +08:00
										 |  |  | #include <gtsam_unstable/discrete/Constraint.h>
 | 
					
						
							| 
									
										
										
										
											2012-04-16 07:12:17 +08:00
										 |  |  | #include <gtsam/discrete/DiscreteKey.h>
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/**
 | 
					
						
							|  |  |  | 	 * SingleValue constraint | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-05-15 17:51:26 +08:00
										 |  |  | 	class SingleValue: public Constraint { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/// Number of values
 | 
					
						
							|  |  |  | 		size_t cardinality_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// allowed value
 | 
					
						
							|  |  |  | 		size_t value_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		DiscreteKey discreteKey() const { | 
					
						
							|  |  |  | 			return DiscreteKey(keys_[0],cardinality_); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	public: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		typedef boost::shared_ptr<SingleValue> shared_ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Constructor
 | 
					
						
							|  |  |  | 		SingleValue(Index key, size_t n, size_t value) : | 
					
						
							| 
									
										
										
										
											2012-05-15 17:51:26 +08:00
										 |  |  | 			Constraint(key), cardinality_(n), value_(value) { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Constructor
 | 
					
						
							|  |  |  | 		SingleValue(const DiscreteKey& dkey, size_t value) : | 
					
						
							| 
									
										
										
										
											2012-05-15 17:51:26 +08:00
										 |  |  | 			Constraint(dkey.first), cardinality_(dkey.second), value_(value) { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// print
 | 
					
						
							|  |  |  | 		virtual void print(const std::string& s = "") const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Calculate value
 | 
					
						
							|  |  |  | 		virtual double operator()(const Values& values) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Convert into a decisiontree
 | 
					
						
							|  |  |  | 		virtual operator DecisionTreeFactor() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Multiply into a decisiontree
 | 
					
						
							|  |  |  | 		virtual DecisionTreeFactor operator*(const DecisionTreeFactor& f) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Ensure Arc-consistency | 
					
						
							|  |  |  | 		 * @param j domain to be checked | 
					
						
							|  |  |  | 		 * @param domains all other domains | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		bool ensureArcConsistency(size_t j, std::vector<Domain>& domains) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Partially apply known values
 | 
					
						
							| 
									
										
										
										
											2012-05-15 17:51:26 +08:00
										 |  |  | 		virtual Constraint::shared_ptr partiallyApply( | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 				const Values& values) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/// Partially apply known values, domain version
 | 
					
						
							| 
									
										
										
										
											2012-05-15 17:51:26 +08:00
										 |  |  | 		virtual Constraint::shared_ptr partiallyApply( | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 				const std::vector<Domain>& domains) const; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 |