diff --git a/cpp/Conditional.h b/cpp/Conditional.h index dba0a68d0..601c30d2c 100644 --- a/cpp/Conditional.h +++ b/cpp/Conditional.h @@ -9,57 +9,71 @@ #pragma once #include // for noncopyable +#include #include "Testable.h" namespace gtsam { - /** - * Base class for conditional densities - * - * We make it noncopyable so we enforce the fact that factors are - * kept in pointer containers. To be safe, you should make them - * immutable, i.e., practicing functional programming. - */ - class Conditional : boost::noncopyable, public Testable - { - protected: +/** + * Base class for conditional densities + * + * We make it noncopyable so we enforce the fact that factors are + * kept in pointer containers. To be safe, you should make them + * immutable, i.e., practicing functional programming. + */ +class Conditional: boost::noncopyable, public Testable { +protected: - /** key of random variable */ - std::string key_; + /** key of random variable */ + std::string key_; - public: +public: - /** constructor */ - Conditional(const std::string& key):key_(key) {} + /** constructor */ + Conditional(const std::string& key) : + key_(key) { + } - /* destructor */ - virtual ~Conditional() {}; + /* destructor */ + virtual ~Conditional() { + } + ; - /** check equality */ - bool equals(const Conditional& c, double tol = 1e-9) const { - return key_ == c.key_; - } + /** check equality */ + bool equals(const Conditional& c, double tol = 1e-9) const { + return key_ == c.key_; + } - /** return key */ - inline const std::string& key() const { return key_;} - - /** return parent keys */ - virtual std::list parents() const = 0; - - /** return the number of parents */ - virtual std::size_t nrParents() const = 0; - }; + /** return key */ + inline const std::string& key() const { + return key_; + } - // predicate to check whether a conditional has the sought key - template - class onKey { - const std::string& key_; - public: - onKey(const std::string& key):key_(key) {} - bool operator()(const typename Conditional::shared_ptr& conditional) { - return (conditional->key()==key_); - } - }; + /** return parent keys */ + virtual std::list parents() const = 0; + /** return the number of parents */ + virtual std::size_t nrParents() const = 0; +private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) { + ar & BOOST_SERIALIZATION_NVP(key_); + } +}; + +// predicate to check whether a conditional has the sought key +template +class onKey { + const std::string& key_; +public: + onKey(const std::string& key) : + key_(key) { + } + bool operator()(const typename Conditional::shared_ptr& conditional) { + return (conditional->key() == key_); + } +}; } diff --git a/cpp/ConditionalGaussian.h b/cpp/ConditionalGaussian.h index 2e3b941c8..2e424b36a 100644 --- a/cpp/ConditionalGaussian.h +++ b/cpp/ConditionalGaussian.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include "Conditional.h" @@ -44,12 +43,12 @@ protected: /** the names and the matrices connecting to parent nodes */ Parents parents_; - /** vector of standard deviations */ - Vector sigmas_; - /** the RHS vector */ Vector d_; + /** vector of standard deviations */ + Vector sigmas_; + public: /** default constructor needed for serialization */ @@ -141,10 +140,11 @@ private: friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) { + ar & boost::serialization::make_nvp("Conditional", boost::serialization::base_object(*this)); ar & BOOST_SERIALIZATION_NVP(R_); + ar & BOOST_SERIALIZATION_NVP(parents_); ar & BOOST_SERIALIZATION_NVP(d_); ar & BOOST_SERIALIZATION_NVP(sigmas_); - ar & BOOST_SERIALIZATION_NVP(parents_); } }; } diff --git a/cpp/SymbolicConditional.h b/cpp/SymbolicConditional.h index 8dd97f19f..adf6087d3 100644 --- a/cpp/SymbolicConditional.h +++ b/cpp/SymbolicConditional.h @@ -13,6 +13,7 @@ #include #include #include // TODO: make cpp file +#include #include "Conditional.h" namespace gtsam { @@ -88,6 +89,13 @@ namespace gtsam { return parents_.size(); } + private: + /** Serialization function */ + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) { + ar & boost::serialization::make_nvp("Conditional", boost::serialization::base_object(*this)); + ar & BOOST_SERIALIZATION_NVP(parents_); + } }; - } /// namespace gtsam