| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * SingleValue.h | 
					
						
							|  |  |  |  * @brief domain constraint | 
					
						
							|  |  |  |  * @date Feb 6, 2012 | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-16 07:12:17 +08:00
										 |  |  | #include <gtsam/discrete/DiscreteKey.h>
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  | #include <gtsam_unstable/discrete/Constraint.h>
 | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace gtsam { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * SingleValue constraint | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint { | 
					
						
							|  |  |  |   /// 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(Key key, size_t n, size_t value) | 
					
						
							|  |  |  |       : Constraint(key), cardinality_(n), value_(value) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Constructor
 | 
					
						
							|  |  |  |   SingleValue(const DiscreteKey& dkey, size_t value) | 
					
						
							|  |  |  |       : Constraint(dkey.first), cardinality_(dkey.second), value_(value) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // print
 | 
					
						
							|  |  |  |   void print(const std::string& s = "", const KeyFormatter& formatter = | 
					
						
							|  |  |  |                                             DefaultKeyFormatter) const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// equals
 | 
					
						
							|  |  |  |   bool equals(const DiscreteFactor& other, double tol) const override { | 
					
						
							|  |  |  |     if (!dynamic_cast<const SingleValue*>(&other)) | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       const SingleValue& f(static_cast<const SingleValue&>(other)); | 
					
						
							|  |  |  |       return (cardinality_ == f.cardinality_) && (value_ == f.value_); | 
					
						
							| 
									
										
										
										
											2013-10-12 01:42:30 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-10-12 01:42:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  |   /// Calculate value
 | 
					
						
							|  |  |  |   double operator()(const Values& values) const override; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  |   /// Convert into a decisiontree
 | 
					
						
							|  |  |  |   DecisionTreeFactor toDecisionTreeFactor() const override; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  |   /// Multiply into a decisiontree
 | 
					
						
							|  |  |  |   DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +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 override; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  |   /// Partially apply known values
 | 
					
						
							|  |  |  |   Constraint::shared_ptr partiallyApply(const Values& values) const override; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  |   /// Partially apply known values, domain version
 | 
					
						
							|  |  |  |   Constraint::shared_ptr partiallyApply( | 
					
						
							|  |  |  |       const std::vector<Domain>& domains) const override; | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2012-04-16 06:35:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-18 23:54:00 +08:00
										 |  |  | }  // namespace gtsam
 |