| 
									
										
										
										
											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 { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * SingleValue constraint | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2013-03-14 02:56:21 +08:00
										 |  |  |   class GTSAM_UNSTABLE_EXPORT SingleValue: public Constraint { | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Number of values
 | 
					
						
							|  |  |  |     size_t cardinality_; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// allowed value
 | 
					
						
							|  |  |  |     size_t value_; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     DiscreteKey discreteKey() const { | 
					
						
							|  |  |  |       return DiscreteKey(keys_[0],cardinality_); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   public: | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     typedef boost::shared_ptr<SingleValue> shared_ptr; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Constructor
 | 
					
						
							| 
									
										
										
										
											2013-11-09 00:35:28 +08:00
										 |  |  |     SingleValue(Key key, size_t n, size_t value) : | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |       Constraint(key), cardinality_(n), value_(value) { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Constructor
 | 
					
						
							|  |  |  |     SingleValue(const DiscreteKey& dkey, size_t value) : | 
					
						
							|  |  |  |       Constraint(dkey.first), cardinality_(dkey.second), value_(value) { | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     // print
 | 
					
						
							|  |  |  |     virtual void print(const std::string& s = "", | 
					
						
							| 
									
										
										
										
											2013-11-09 00:35:28 +08:00
										 |  |  |         const KeyFormatter& formatter = DefaultKeyFormatter) const; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-12 01:42:30 +08:00
										 |  |  |     /// equals
 | 
					
						
							|  |  |  |     bool equals(const DiscreteFactor& other, double tol) const { | 
					
						
							|  |  |  |       if(!dynamic_cast<const SingleValue*>(&other)) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         const SingleValue& f(static_cast<const SingleValue&>(other)); | 
					
						
							|  |  |  |         return (cardinality_==f.cardinality_) && (value_==f.value_); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Calculate value
 | 
					
						
							|  |  |  |     virtual double operator()(const Values& values) const; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Convert into a decisiontree
 | 
					
						
							|  |  |  |     virtual DecisionTreeFactor toDecisionTreeFactor() const; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Multiply into a decisiontree
 | 
					
						
							|  |  |  |     virtual DecisionTreeFactor operator*(const DecisionTreeFactor& f) const; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /*
 | 
					
						
							|  |  |  |      * Ensure Arc-consistency | 
					
						
							|  |  |  |      * @param j domain to be checked | 
					
						
							|  |  |  |      * @param domains all other domains | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     bool ensureArcConsistency(size_t j, std::vector<Domain>& domains) const; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Partially apply known values
 | 
					
						
							|  |  |  |     virtual Constraint::shared_ptr partiallyApply( | 
					
						
							|  |  |  |         const Values& values) const; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     /// Partially apply known values, domain version
 | 
					
						
							|  |  |  |     virtual Constraint::shared_ptr partiallyApply( | 
					
						
							|  |  |  |         const std::vector<Domain>& domains) const; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace gtsam
 |