Fix constraints
							parent
							
								
									a24246ab63
								
							
						
					
					
						commit
						2b6545233a
					
				|  | @ -136,9 +136,6 @@ class GTSAM_EXPORT DiscreteFactor : public Factor { | |||
|   /**
 | ||||
|    * @brief Multiply in a DiscreteFactor and return the result as | ||||
|    * DiscreteFactor, both via shared pointers. | ||||
|    * | ||||
|    * @param df DiscreteFactor shared_ptr | ||||
|    * @return DiscreteFactor::shared_ptr | ||||
|    */ | ||||
|   virtual DiscreteFactor::shared_ptr multiply( | ||||
|       const DiscreteFactor::shared_ptr& df) const = 0; | ||||
|  | @ -170,7 +167,7 @@ class GTSAM_EXPORT DiscreteFactor : public Factor { | |||
|    *  | ||||
|    * @return DiscreteFactor::shared_ptr  | ||||
|    */ | ||||
|   DiscreteFactor::shared_ptr scale() const; | ||||
|   virtual DiscreteFactor::shared_ptr scale() const; | ||||
| 
 | ||||
|   /**
 | ||||
|    * Get the number of non-zero values contained in this factor. | ||||
|  |  | |||
|  | @ -72,6 +72,11 @@ class GTSAM_UNSTABLE_EXPORT AllDiff : public Constraint { | |||
|   /// Partially apply known values, domain version
 | ||||
|   Constraint::shared_ptr partiallyApply( | ||||
|       const Domains&) const override; | ||||
| 
 | ||||
|   // Scale just returns the same constraint.
 | ||||
|   DiscreteFactor::shared_ptr scale() const override { | ||||
|     return std::make_shared<AllDiff>(*this); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| }  // namespace gtsam
 | ||||
|  |  | |||
|  | @ -96,6 +96,11 @@ class BinaryAllDiff : public Constraint { | |||
|   AlgebraicDecisionTree<Key> errorTree() const override { | ||||
|     throw std::runtime_error("BinaryAllDiff::error not implemented"); | ||||
|   } | ||||
| 
 | ||||
|   // Scale just returns the same constraint.
 | ||||
|   DiscreteFactor::shared_ptr scale() const override { | ||||
|     return std::make_shared<BinaryAllDiff>(*this); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| }  // namespace gtsam
 | ||||
|  |  | |||
|  | @ -29,7 +29,9 @@ class Domain; | |||
| using Domains = std::map<Key, Domain>; | ||||
| 
 | ||||
| /**
 | ||||
|  * Base class for constraint factors | ||||
|  * Base class for constraint factors. | ||||
|  * This class is used to represent constraints on discrete variables. | ||||
|  * The values are always either 0 or 1, with at least one 1. | ||||
|  * Derived classes include SingleValue, BinaryAllDiff, and AllDiff. | ||||
|  */ | ||||
| class GTSAM_UNSTABLE_EXPORT Constraint : public DiscreteFactor { | ||||
|  | @ -80,6 +82,16 @@ class GTSAM_UNSTABLE_EXPORT Constraint : public DiscreteFactor { | |||
|   /// Partially apply known values, domain version
 | ||||
|   virtual shared_ptr partiallyApply(const Domains&) const = 0; | ||||
| 
 | ||||
|   /// Multiply in a DecisionTreeFactor.
 | ||||
|   DecisionTreeFactor operator*(const DecisionTreeFactor& df) const override { | ||||
|     throw std::logic_error("Constraint::operator* not implemented"); | ||||
|   } | ||||
| 
 | ||||
|   /// Multiply with scalar just returns the constraint.
 | ||||
|   DiscreteFactor::shared_ptr operator*(double /* s*/) const override { | ||||
|     throw std::logic_error("Constraint::operator* not implemented"); | ||||
|   } | ||||
| 
 | ||||
|   /// Multiply factors, DiscreteFactor::shared_ptr edition
 | ||||
|   DiscreteFactor::shared_ptr multiply( | ||||
|       const DiscreteFactor::shared_ptr& df) const override { | ||||
|  | @ -104,6 +116,8 @@ class GTSAM_UNSTABLE_EXPORT Constraint : public DiscreteFactor { | |||
|     return toDecisionTreeFactor().sum(keys); | ||||
|   } | ||||
| 
 | ||||
|   double max() const override { return 1.0; } | ||||
| 
 | ||||
|   DiscreteFactor::shared_ptr max(size_t nrFrontals) const override { | ||||
|     return toDecisionTreeFactor().max(nrFrontals); | ||||
|   } | ||||
|  |  | |||
|  | @ -114,6 +114,11 @@ class GTSAM_UNSTABLE_EXPORT Domain : public Constraint { | |||
| 
 | ||||
|   /// Partially apply known values, domain version
 | ||||
|   Constraint::shared_ptr partiallyApply(const Domains& domains) const override; | ||||
| 
 | ||||
|   // Scale just returns the same constraint.
 | ||||
|   DiscreteFactor::shared_ptr scale() const override { | ||||
|     return std::make_shared<Domain>(*this); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| }  // namespace gtsam
 | ||||
|  |  | |||
|  | @ -77,6 +77,11 @@ class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint { | |||
|   /// Partially apply known values, domain version
 | ||||
|   Constraint::shared_ptr partiallyApply( | ||||
|       const Domains& domains) const override; | ||||
| 
 | ||||
|   // Scale just returns the same constraint.
 | ||||
|   DiscreteFactor::shared_ptr scale() const override { | ||||
|     return std::make_shared<SingleValue>(*this); | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| }  // namespace gtsam
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue