diff --git a/gtsam/discrete/DiscreteConditional.cpp b/gtsam/discrete/DiscreteConditional.cpp index 371b15ac0..293b69748 100644 --- a/gtsam/discrete/DiscreteConditional.cpp +++ b/gtsam/discrete/DiscreteConditional.cpp @@ -147,10 +147,10 @@ void DiscreteConditional::solveInPlace(DiscreteValues* values) const { keys & dk; } // Get all Possible Configurations - vector allPosbValues = cartesianProduct(keys); + const auto allPosbValues = cartesianProduct(keys); // Find the MPE - for(DiscreteValues& frontalVals: allPosbValues) { + for(const auto& frontalVals: allPosbValues) { double pValueS = pFS(frontalVals); // P(F=value|S=parentsValues) // Update MPE solution if better if (pValueS > maxP) { diff --git a/gtsam/discrete/DiscreteValues.h b/gtsam/discrete/DiscreteValues.h index a1ee22e01..8d14319dc 100644 --- a/gtsam/discrete/DiscreteValues.h +++ b/gtsam/discrete/DiscreteValues.h @@ -32,7 +32,22 @@ namespace gtsam { * stores cardinality of a Discrete variable. It should be handled naturally in * the new class DiscreteValue, as the variable's type (domain) */ -using DiscreteValues = Assignment; +class DiscreteValues : public Assignment { + public: + using Assignment::Assignment; // all constructors + + // Construct from assignment. + DiscreteValues(const Assignment& a) : Assignment(a) {} + + void print(const std::string& s = "", + const KeyFormatter& keyFormatter = DefaultKeyFormatter) const { + std::cout << s << ": "; + for (const typename Assignment::value_type& keyValue : *this) + std::cout << "(" << keyFormatter(keyValue.first) << ", " + << keyValue.second << ")"; + std::cout << std::endl; + } +}; // traits template<> struct traits : public Testable {};