25 #include <boost/serialization/nvp.hpp>
26 #include <boost/assign/list_inserter.hpp>
27 #include <boost/bind.hpp>
28 #include <boost/make_shared.hpp>
29 #include <boost/utility/enable_if.hpp>
30 #include <boost/type_traits.hpp>
39 template<
class CLIQUE>
class BayesTree;
49 void operator()(
const A& a) { obj.push_back(a); }
60 void operator()(A& a) { obj.push_back(a); }
71 void operator()(
const A& a) { obj.addCopy(a); }
79 template<
class FACTOR>
91 typedef boost::shared_ptr<This> shared_ptr;
95 GTSAM_CONCEPT_TESTABLE_TYPE(FACTOR)
107 template<
typename ITERATOR>
111 template<
class CONTAINER>
153 template<
class DERIVEDFACTOR>
154 typename boost::enable_if<boost::is_base_of<FactorType, DERIVEDFACTOR> >::type
156 factors_.push_back(boost::shared_ptr<FACTOR>(factor)); }
163 template<
typename ITERATOR>
164 typename boost::enable_if<boost::is_base_of<FactorType, typename ITERATOR::value_type::element_type> >::type
169 template<
typename CONTAINER>
170 typename boost::enable_if<boost::is_base_of<FactorType, typename CONTAINER::value_type::element_type> >::type
172 push_back(container.begin(), container.end());
177 template<
class CLIQUE>
178 typename boost::enable_if<boost::is_base_of<This, typename CLIQUE::FactorGraphType> >::type
185 template<
class DERIVEDFACTOR>
186 typename boost::enable_if<boost::is_base_of<FactorType, DERIVEDFACTOR> >::type
188 factors_.push_back(boost::make_shared<DERIVEDFACTOR>(factor));
192 template<
typename ITERATOR>
193 typename boost::enable_if<boost::is_base_of<FactorType, typename ITERATOR::value_type> >::type
195 for (ITERATOR f = firstFactor; f != lastFactor; ++f)
200 template<
typename CONTAINER>
201 typename boost::enable_if<boost::is_base_of<FactorType, typename CONTAINER::value_type> >::type
203 push_back(container.begin(), container.end());
207 template<
class DERIVEDFACTOR>
208 typename boost::enable_if<boost::is_base_of<FactorType, DERIVEDFACTOR>,
209 boost::assign::list_inserter<RefCallPushBack<This> > >::type
215 boost::assign::list_inserter<CRefCallPushBack<This> >
221 template<
class FACTOR_OR_CONTAINER>
222 boost::assign::list_inserter<CRefCallPushBack<This> >
228 template<
class DERIVEDFACTOR>
229 typename boost::enable_if<boost::is_base_of<FactorType, DERIVEDFACTOR> >::type
230 add(boost::shared_ptr<DERIVEDFACTOR> factor) {
240 template<
class FACTOR_OR_CONTAINER>
241 void add(
const FACTOR_OR_CONTAINER& factorOrContainer) {
250 void print(
const std::string& s =
"FactorGraph",
251 const KeyFormatter& formatter = DefaultKeyFormatter)
const;
255 bool equals(
const This& fg,
double tol = 1e-9)
const;
339 inline bool exists(
size_t idx)
const {
return idx <
size() &&
at(idx); }
344 friend class boost::serialization::access;
345 template<
class ARCHIVE>
346 void serialize(ARCHIVE & ar,
const unsigned int version) {
347 ar & BOOST_SERIALIZATION_NVP(
factors_);
void add(const FACTOR_OR_CONTAINER &factorOrContainer)
Add a factor or container of factors, including STL collections, BayesTrees, etc. ...
Definition: FactorGraph.h:241
const sharedFactor at(size_t i) const
Get a specific factor by index (this checks array bounds and may throw an exception, as opposed to operator[] which does not).
Definition: FactorGraph.h:271
Definition: BayesTree.h:64
Helper.
Definition: FactorGraph.h:54
void erase(iterator item)
Erase factor and rearrange other factors to take up the empty space.
Definition: FactorGraph.h:323
void print(const std::string &s="FactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const
print out graph
Definition: FactorGraph-inst.h:36
size_t nrFactors() const
return the number of non-null factors
Definition: FactorGraph-inst.h:66
sharedFactor front() const
Get the first factor.
Definition: FactorGraph.h:295
FastVector< sharedFactor > factors_
concept check, makes sure FACTOR defines print and equals
Definition: FactorGraph.h:98
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition: BayesTree.h:32
const_iterator begin() const
Iterator to beginning of factors.
Definition: FactorGraph.h:289
iterator end()
non-const STL-style end()
Definition: FactorGraph.h:308
Helper.
Definition: FactorGraph.h:65
bool empty() const
Check if the graph is empty (null factors set by remove() will cause this to return false)...
Definition: FactorGraph.h:266
boost::enable_if< boost::is_base_of< FactorType, typename CONTAINER::value_type::element_type > >::type push_back(const CONTAINER &container)
push back many factors as shared_ptr's in a container (factors are not copied)
Definition: FactorGraph.h:171
boost::enable_if< boost::is_base_of< FactorType, typename ITERATOR::value_type::element_type > >::type push_back(ITERATOR firstFactor, ITERATOR lastFactor)
push back many factors with an iterator over shared_ptr (factors are not copied)
Definition: FactorGraph.h:165
const sharedFactor operator[](size_t i) const
Get a specific factor by index (this does not check array bounds, as opposed to at() which does)...
Definition: FactorGraph.h:281
void addFactorsToGraph(FactorGraph< FactorType > &graph) const
Add all cliques in this BayesTree to the specified factor graph.
Definition: BayesTree-inst.h:156
boost::enable_if< boost::is_base_of< FactorType, DERIVEDFACTOR > >::type push_back(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:155
void erase(iterator first, iterator last)
Erase factors and rearrange other factors to take up the empty space.
Definition: FactorGraph.h:326
boost::shared_ptr< FACTOR > sharedFactor
Shared pointer to a factor.
Definition: FactorGraph.h:84
bool exists(size_t idx) const
MATLAB interface utility: Checks whether a factor index idx exists in the graph and is a live pointer...
Definition: FactorGraph.h:339
size_t size() const
return the number of factors (including any null factors set by remove() ).
Definition: FactorGraph.h:263
void resize(size_t size)
Directly resize the number of factors in the graph.
Definition: FactorGraph.h:314
iterator begin()
non-const STL-style begin()
Definition: FactorGraph.h:305
void add(const sharedFactor &factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:235
boost::enable_if< boost::is_base_of< FactorType, typename CONTAINER::value_type > >::type push_back(const CONTAINER &container)
push back many factors as non-pointer objects in a container (factors are copied) ...
Definition: FactorGraph.h:202
Concept check for values that can be used in unit tests.
void replace(size_t index, sharedFactor factor)
replace a factor by index
Definition: FactorGraph.h:320
bool equals(const This &fg, double tol=1e-9) const
Check equality.
Definition: FactorGraph-inst.h:49
boost::enable_if< boost::is_base_of< FactorType, typename ITERATOR::value_type > >::type push_back(ITERATOR firstFactor, ITERATOR lastFactor)
push back many factors with an iterator over plain factors (factors are copied)
Definition: FactorGraph.h:194
boost::enable_if< boost::is_base_of< FactorType, DERIVEDFACTOR > >::type push_back(const DERIVEDFACTOR &factor)
Add a factor by value, will be copy-constructed (use push_back with a shared_ptr to avoid the copy)...
Definition: FactorGraph.h:187
sharedFactor & operator[](size_t i)
Get a specific factor by index (this does not check array bounds, as opposed to at() which does)...
Definition: FactorGraph.h:286
boost::enable_if< boost::is_base_of< FactorType, DERIVEDFACTOR >, boost::assign::list_inserter< RefCallPushBack< This > > >::type operator+=(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:210
FactorGraph(const CONTAINER &factors)
Construct from container of factors (shared_ptr or plain objects)
Definition: FactorGraph.h:112
boost::assign::list_inserter< CRefCallPushBack< This > > operator+=(const sharedFactor &factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:216
sharedFactor & at(size_t i)
Get a specific factor by index (this checks array bounds and may throw an exception, as opposed to operator[] which does not).
Definition: FactorGraph.h:276
boost::enable_if< boost::is_base_of< FactorType, DERIVEDFACTOR > >::type add(boost::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:230
const_iterator end() const
Iterator to end of factors.
Definition: FactorGraph.h:292
FastSet< Key > keys() const
Potentially very slow function to return all keys involved.
Definition: FactorGraph-inst.h:75
boost::enable_if< boost::is_base_of< This, typename CLIQUE::FactorGraphType > >::type push_back(const BayesTree< CLIQUE > &bayesTree)
push back a BayesTree as a collection of factors.
Definition: FactorGraph.h:179
sharedFactor back() const
Get the last factor.
Definition: FactorGraph.h:298
boost::assign::list_inserter< CRefCallPushBack< This > > operator+=(const FACTOR_OR_CONTAINER &factorOrContainer)
Add a factor or container of factors, including STL collections, BayesTrees, etc. ...
Definition: FactorGraph.h:223
void push_back(const sharedFactor &factor)
Add a factor directly using a shared_ptr.
Definition: FactorGraph.h:159
FACTOR FactorType
factor type
Definition: FactorGraph.h:83
Definition: FastVector.h:38
void reserve(size_t size)
Reserve space for the specified number of factors if you know in advance how many there will be (work...
Definition: FactorGraph.h:148
A thin wrapper around std::vector that uses boost's pool_allocator.
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: types.h:62
FactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
Constructor from iterator over factors (shared_ptr or plain objects)
Definition: FactorGraph.h:108
Helper.
Definition: FactorGraph.h:43