Added serialization of base class
parent
ddc0173671
commit
1f15650da0
|
@ -9,6 +9,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <boost/utility.hpp> // for noncopyable
|
#include <boost/utility.hpp> // for noncopyable
|
||||||
|
#include <boost/serialization/string.hpp>
|
||||||
#include "Testable.h"
|
#include "Testable.h"
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -20,8 +21,7 @@ namespace gtsam {
|
||||||
* kept in pointer containers. To be safe, you should make them
|
* kept in pointer containers. To be safe, you should make them
|
||||||
* immutable, i.e., practicing functional programming.
|
* immutable, i.e., practicing functional programming.
|
||||||
*/
|
*/
|
||||||
class Conditional : boost::noncopyable, public Testable<Conditional>
|
class Conditional: boost::noncopyable, public Testable<Conditional> {
|
||||||
{
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/** key of random variable */
|
/** key of random variable */
|
||||||
|
@ -30,10 +30,14 @@ namespace gtsam {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** constructor */
|
/** constructor */
|
||||||
Conditional(const std::string& key):key_(key) {}
|
Conditional(const std::string& key) :
|
||||||
|
key_(key) {
|
||||||
|
}
|
||||||
|
|
||||||
/* destructor */
|
/* destructor */
|
||||||
virtual ~Conditional() {};
|
virtual ~Conditional() {
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
/** check equality */
|
/** check equality */
|
||||||
bool equals(const Conditional& c, double tol = 1e-9) const {
|
bool equals(const Conditional& c, double tol = 1e-9) const {
|
||||||
|
@ -41,13 +45,23 @@ namespace gtsam {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** return key */
|
/** return key */
|
||||||
inline const std::string& key() const { return key_;}
|
inline const std::string& key() const {
|
||||||
|
return key_;
|
||||||
|
}
|
||||||
|
|
||||||
/** return parent keys */
|
/** return parent keys */
|
||||||
virtual std::list<std::string> parents() const = 0;
|
virtual std::list<std::string> parents() const = 0;
|
||||||
|
|
||||||
/** return the number of parents */
|
/** return the number of parents */
|
||||||
virtual std::size_t nrParents() const = 0;
|
virtual std::size_t nrParents() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Serialization function */
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive & ar, const unsigned int version) {
|
||||||
|
ar & BOOST_SERIALIZATION_NVP(key_);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// predicate to check whether a conditional has the sought key
|
// predicate to check whether a conditional has the sought key
|
||||||
|
@ -55,11 +69,11 @@ namespace gtsam {
|
||||||
class onKey {
|
class onKey {
|
||||||
const std::string& key_;
|
const std::string& key_;
|
||||||
public:
|
public:
|
||||||
onKey(const std::string& key):key_(key) {}
|
onKey(const std::string& key) :
|
||||||
|
key_(key) {
|
||||||
|
}
|
||||||
bool operator()(const typename Conditional::shared_ptr& conditional) {
|
bool operator()(const typename Conditional::shared_ptr& conditional) {
|
||||||
return (conditional->key() == key_);
|
return (conditional->key() == key_);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/serialization/map.hpp>
|
#include <boost/serialization/map.hpp>
|
||||||
#include <boost/serialization/string.hpp>
|
|
||||||
#include <boost/serialization/shared_ptr.hpp>
|
#include <boost/serialization/shared_ptr.hpp>
|
||||||
|
|
||||||
#include "Conditional.h"
|
#include "Conditional.h"
|
||||||
|
@ -44,12 +43,12 @@ protected:
|
||||||
/** the names and the matrices connecting to parent nodes */
|
/** the names and the matrices connecting to parent nodes */
|
||||||
Parents parents_;
|
Parents parents_;
|
||||||
|
|
||||||
/** vector of standard deviations */
|
|
||||||
Vector sigmas_;
|
|
||||||
|
|
||||||
/** the RHS vector */
|
/** the RHS vector */
|
||||||
Vector d_;
|
Vector d_;
|
||||||
|
|
||||||
|
/** vector of standard deviations */
|
||||||
|
Vector sigmas_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** default constructor needed for serialization */
|
/** default constructor needed for serialization */
|
||||||
|
@ -141,10 +140,11 @@ private:
|
||||||
friend class boost::serialization::access;
|
friend class boost::serialization::access;
|
||||||
template<class Archive>
|
template<class Archive>
|
||||||
void serialize(Archive & ar, const unsigned int version) {
|
void serialize(Archive & ar, const unsigned int version) {
|
||||||
|
ar & boost::serialization::make_nvp("Conditional", boost::serialization::base_object<Conditional>(*this));
|
||||||
ar & BOOST_SERIALIZATION_NVP(R_);
|
ar & BOOST_SERIALIZATION_NVP(R_);
|
||||||
|
ar & BOOST_SERIALIZATION_NVP(parents_);
|
||||||
ar & BOOST_SERIALIZATION_NVP(d_);
|
ar & BOOST_SERIALIZATION_NVP(d_);
|
||||||
ar & BOOST_SERIALIZATION_NVP(sigmas_);
|
ar & BOOST_SERIALIZATION_NVP(sigmas_);
|
||||||
ar & BOOST_SERIALIZATION_NVP(parents_);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/foreach.hpp> // TODO: make cpp file
|
#include <boost/foreach.hpp> // TODO: make cpp file
|
||||||
|
#include <boost/serialization/list.hpp>
|
||||||
#include "Conditional.h"
|
#include "Conditional.h"
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
@ -88,6 +89,13 @@ namespace gtsam {
|
||||||
return parents_.size();
|
return parents_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Serialization function */
|
||||||
|
friend class boost::serialization::access;
|
||||||
|
template<class Archive>
|
||||||
|
void serialize(Archive & ar, const unsigned int version) {
|
||||||
|
ar & boost::serialization::make_nvp("Conditional", boost::serialization::base_object<Conditional>(*this));
|
||||||
|
ar & BOOST_SERIALIZATION_NVP(parents_);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} /// namespace gtsam
|
} /// namespace gtsam
|
||||||
|
|
Loading…
Reference in New Issue