diff --git a/gtsam/discrete/DiscreteFactor.h b/gtsam/discrete/DiscreteFactor.h index 6fa074379..62f1e064b 100644 --- a/gtsam/discrete/DiscreteFactor.h +++ b/gtsam/discrete/DiscreteFactor.h @@ -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. diff --git a/gtsam_unstable/discrete/AllDiff.h b/gtsam_unstable/discrete/AllDiff.h index 1180abad4..67a6ffd18 100644 --- a/gtsam_unstable/discrete/AllDiff.h +++ b/gtsam_unstable/discrete/AllDiff.h @@ -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(*this); + } }; } // namespace gtsam diff --git a/gtsam_unstable/discrete/BinaryAllDiff.h b/gtsam_unstable/discrete/BinaryAllDiff.h index e96bfdfde..21d5f1642 100644 --- a/gtsam_unstable/discrete/BinaryAllDiff.h +++ b/gtsam_unstable/discrete/BinaryAllDiff.h @@ -96,6 +96,11 @@ class BinaryAllDiff : public Constraint { AlgebraicDecisionTree 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(*this); + } }; } // namespace gtsam diff --git a/gtsam_unstable/discrete/Constraint.h b/gtsam_unstable/discrete/Constraint.h index 328fabbea..91bcdbc20 100644 --- a/gtsam_unstable/discrete/Constraint.h +++ b/gtsam_unstable/discrete/Constraint.h @@ -29,7 +29,9 @@ class Domain; using Domains = std::map; /** - * 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); } diff --git a/gtsam_unstable/discrete/Domain.h b/gtsam_unstable/discrete/Domain.h index 6ce846201..b45b1f23e 100644 --- a/gtsam_unstable/discrete/Domain.h +++ b/gtsam_unstable/discrete/Domain.h @@ -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(*this); + } }; } // namespace gtsam diff --git a/gtsam_unstable/discrete/SingleValue.h b/gtsam_unstable/discrete/SingleValue.h index 3df1209b8..152a8f51b 100644 --- a/gtsam_unstable/discrete/SingleValue.h +++ b/gtsam_unstable/discrete/SingleValue.h @@ -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(*this); + } }; } // namespace gtsam