35template <
class FACTOR>
38 std::cout << (s.empty() ?
"" : s +
" ") << std::endl;
39 std::cout <<
"size: " << size() << std::endl;
40 for (
size_t i = 0; i < factors_.size(); i++) {
42 ss <<
"factor " << i <<
": ";
43 if (factors_[i]) factors_[i]->print(ss.str(), formatter);
48template <
class FACTOR>
51 if (factors_.size() != fg.
size())
return false;
54 for (
size_t i = 0; i < factors_.size(); i++) {
56 if (f1 ==
nullptr && f2 ==
nullptr)
continue;
57 if (f1 ==
nullptr || f2 ==
nullptr)
return false;
58 if (!f1->equals(*f2, tol))
return false;
64template <
class FACTOR>
73template <
class FACTOR>
77 if (factor) keys.insert(factor->begin(), factor->end());
83template <
class FACTOR>
86 keys.reserve(2 * size());
88 if (factor) keys.insert(keys.end(), factor->begin(), factor->end());
89 std::sort(keys.begin(), keys.end());
90 auto last = std::unique(keys.begin(), keys.end());
91 keys.erase(last, keys.end());
96template <
class FACTOR>
97template <
typename CONTAINER,
typename>
100 const size_t num_factors = factors.size();
104 for (
size_t j = 0; j < num_factors; ++j) {
109 resize(size() + num_factors - j);
118 newFactorIndices[j] = i;
122 for (
size_t i = 0; i < num_factors; ++i) newFactorIndices[i] = i + size();
125 return newFactorIndices;
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
FastVector< FactorIndex > FactorIndices
Define collection types:
Definition: Factor.h:33
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition: FactorGraph.h:93
virtual void print(const std::string &s="FactorGraph", const KeyFormatter &formatter=DefaultKeyFormatter) const
print out graph
Definition: FactorGraph-inst.h:36
KeySet keys() const
Potentially slow function to return all keys involved, sorted, as a set.
Definition: FactorGraph-inst.h:74
FactorIndices add_factors(const CONTAINER &factors, bool useEmptySlots=false)
Add new factors to a factor graph and returns a list of new factor indices, optionally finding and re...
Definition: FactorGraph-inst.h:98
KeyVector keyVector() const
Potentially slow function to return all keys involved, sorted, as a vector.
Definition: FactorGraph-inst.h:84
size_t nrFactors() const
return the number of non-null factors
Definition: FactorGraph-inst.h:65
size_t size() const
return the number of factors (including any null factors set by remove() ).
Definition: FactorGraph.h:305
bool equals(const This &fg, double tol=1e-9) const
Check equality.
Definition: FactorGraph-inst.h:49
boost::shared_ptr< FACTOR > sharedFactor
Shared pointer to a factor.
Definition: FactorGraph.h:97
FastVector< sharedFactor > factors_
concept check, makes sure FACTOR defines print and equals
Definition: FactorGraph.h:127