diff --git a/gtsam/discrete/DecisionTreeFactor.cpp b/gtsam/discrete/DecisionTreeFactor.cpp index 754627f9a..6a4aacd37 100644 --- a/gtsam/discrete/DecisionTreeFactor.cpp +++ b/gtsam/discrete/DecisionTreeFactor.cpp @@ -45,8 +45,9 @@ namespace gtsam { /* ************************************************************************* */ bool DecisionTreeFactor::equals(const DiscreteFactor& other, double tol) const { - if(!dynamic_cast(&other)) + if(!dynamic_cast(&other)) { return false; + } else { const DecisionTreeFactor& f(static_cast(other)); return Potentials::equals(f, tol); diff --git a/gtsam/discrete/DiscreteConditional.cpp b/gtsam/discrete/DiscreteConditional.cpp index 727214d61..df21e47b0 100644 --- a/gtsam/discrete/DiscreteConditional.cpp +++ b/gtsam/discrete/DiscreteConditional.cpp @@ -49,7 +49,7 @@ DiscreteConditional::DiscreteConditional(const DecisionTreeFactor& joint, const DecisionTreeFactor& marginal, const boost::optional& orderedKeys) : BaseFactor( ISDEBUG("DiscreteConditional::COUNT") ? joint : joint / marginal), BaseConditional( - joint.size()-marginal.size()) { + joint.size()-marginal.size()) { if (ISDEBUG("DiscreteConditional::DiscreteConditional")) cout << (firstFrontalKey()) << endl; //TODO Print all keys if (orderedKeys) { @@ -60,8 +60,8 @@ DiscreteConditional::DiscreteConditional(const DecisionTreeFactor& joint, /* ******************************************************************************** */ DiscreteConditional::DiscreteConditional(const Signature& signature) : - BaseFactor(signature.discreteKeysParentsFirst(), signature.cpt()), BaseConditional( - 1) { + BaseFactor(signature.discreteKeysParentsFirst(), signature.cpt()), BaseConditional( + 1) { } /* ******************************************************************************** */ @@ -72,9 +72,15 @@ void DiscreteConditional::print(const std::string& s, } /* ******************************************************************************** */ -bool DiscreteConditional::equals(const DiscreteConditional& other, +bool DiscreteConditional::equals(const DiscreteFactor& other, double tol) const { - return Potentials::equals(other, tol); + if (!dynamic_cast(&other)) + return false; + else { + const DecisionTreeFactor& f( + static_cast(other)); + return DecisionTreeFactor::equals(f, tol); + } } /* ******************************************************************************** */ @@ -82,15 +88,15 @@ Potentials::ADT DiscreteConditional::choose(const Values& parentsValues) const { ADT pFS(*this); Index j; size_t value; BOOST_FOREACH(Index key, parents()) - try { - j = (key); - value = parentsValues.at(j); - pFS = pFS.choose(j, value); - } catch (exception&) { - cout << "Key: " << j << " Value: " << value << endl; - pFS.print("pFS: "); - throw runtime_error("DiscreteConditional::choose: parent value missing"); - }; + try { + j = (key); + value = parentsValues.at(j); + pFS = pFS.choose(j, value); + } catch (exception&) { + cout << "Key: " << j << " Value: " << value << endl; + pFS.print("pFS: "); + throw runtime_error("DiscreteConditional::choose: parent value missing"); + }; return pFS; } diff --git a/gtsam/discrete/DiscreteConditional.h b/gtsam/discrete/DiscreteConditional.h index ff529ceff..ccc11f0b8 100644 --- a/gtsam/discrete/DiscreteConditional.h +++ b/gtsam/discrete/DiscreteConditional.h @@ -82,7 +82,7 @@ public: const IndexFormatter& formatter = DefaultIndexFormatter) const; /// GTSAM-style equals - bool equals(const DiscreteConditional& other, double tol = 1e-9) const; + bool equals(const DiscreteFactor& other, double tol = 1e-9) const; /// @} /// @name Standard Interface