32 #ifdef GTSAM_USE_BOOST_FEATURES 33 #include <boost/assign/list_inserter.hpp> 36 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 37 #include <boost/serialization/nvp.hpp> 38 #include <boost/serialization/vector.hpp> 42 #include <type_traits> 51 template <
class CLIQUE>
100 template <
class FACTOR>
104 typedef std::shared_ptr<FACTOR>
112 typedef std::shared_ptr<This>
116 template <
typename DERIVEDFACTOR>
117 using IsDerived =
typename std::enable_if<
121 template <
typename T>
126 template <
typename T>
139 return factors_ == other.factors_;
149 template <
typename ITERATOR>
151 push_back(firstFactor, lastFactor);
155 template <
class CONTAINER>
174 template <
class DERIVEDFACTOR,
typename = IsDerived<DERIVEDFACTOR>>
175 FactorGraph(std::initializer_list<std::shared_ptr<DERIVEDFACTOR>> sharedFactors)
176 : factors_(sharedFactors) {}
189 template <
class DERIVEDFACTOR>
191 factors_.push_back(std::shared_ptr<FACTOR>(factor));
195 template <
class DERIVEDFACTOR,
class... Args>
197 factors_.push_back(std::allocate_shared<DERIVEDFACTOR>(
199 std::forward<Args>(
args)...));
206 template <
class DERIVEDFACTOR>
208 factors_.push_back(std::allocate_shared<DERIVEDFACTOR>(
213 template <
class DERIVEDFACTOR>
218 #ifdef GTSAM_USE_BOOST_FEATURES 219 template <
class DERIVEDFACTOR>
221 typename std::enable_if<
223 boost::assign::list_inserter<RefCallPushBack<This>>>::type
224 operator+=(std::shared_ptr<DERIVEDFACTOR> factor) {
238 template <
typename ITERATOR>
240 ITERATOR lastFactor) {
241 factors_.insert(
end(), firstFactor, lastFactor);
245 template <
typename ITERATOR>
247 ITERATOR lastFactor) {
248 for (ITERATOR
f = firstFactor;
f != lastFactor; ++
f) push_back(*
f);
259 template <
typename CONTAINER>
261 push_back(container.begin(), container.end());
265 template <
typename CONTAINER>
267 push_back(container.begin(), container.end());
274 template <
class FACTOR_OR_CONTAINER>
275 void add(
const FACTOR_OR_CONTAINER& factorOrContainer) {
276 push_back(factorOrContainer);
279 #ifdef GTSAM_USE_BOOST_FEATURES 284 template <
class FACTOR_OR_CONTAINER>
285 boost::assign::list_inserter<CRefCallPushBack<This>>
operator+=(
286 const FACTOR_OR_CONTAINER& factorOrContainer) {
301 template <
class CLIQUE>
302 typename std::enable_if<
312 template <
typename CONTAINER,
typename = HasDerivedElementType<CONTAINER>>
313 FactorIndices add_factors(
const CONTAINER&
factors,
314 bool useEmptySlots =
false);
321 virtual void print(
const std::string&
s =
"FactorGraph",
325 bool equals(
const This& fg,
double tol = 1
e-9)
const;
334 size_t size()
const {
return factors_.size(); }
338 bool empty()
const {
return factors_.empty(); }
361 const_iterator
begin()
const {
return factors_.begin(); }
364 const_iterator
end()
const {
return factors_.end(); }
380 iterator
begin() {
return factors_.begin(); }
383 iterator
end() {
return factors_.end(); }
393 void remove(
size_t i) { factors_.at(
i).reset(); }
399 iterator
erase(iterator item) {
return factors_.erase(item); }
403 return factors_.erase(first, last);
411 void dot(std::ostream&
os,
420 void saveGraph(
const std::string&
filename,
429 size_t nrFactors()
const;
442 inline bool exists(
size_t idx)
const {
return idx <
size() && at(idx); }
445 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION 447 friend class boost::serialization::access;
448 template <
class ARCHIVE>
449 void serialize(ARCHIVE& ar,
const unsigned int ) {
450 ar& BOOST_SERIALIZATION_NVP(factors_);
void print(const Matrix &A, const string &s, ostream &stream)
sharedFactor back() const
void add(const FACTOR_OR_CONTAINER &factorOrContainer)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 & operator+=(bfloat16 &a, const bfloat16 &b)
void replace(size_t index, sharedFactor factor)
Concept check for values that can be used in unit tests.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
double dot(const V1 &a, const V2 &b)
std::string serialize(const T &input)
serializes to a string
void operator()(const A &a)
HasDerivedElementType< ITERATOR > push_back(ITERATOR firstFactor, ITERATOR lastFactor)
FactorGraph(ITERATOR firstFactor, ITERATOR lastFactor)
sharedFactor front() const
const sharedFactor operator[](size_t i) const
IsDerived< DERIVEDFACTOR > push_back(std::shared_ptr< DERIVEDFACTOR > factor)
Add a factor directly using a shared_ptr.
HasDerivedValueType< ITERATOR > push_back(ITERATOR firstFactor, ITERATOR lastFactor)
Push back many factors with an iterator (factors are copied)
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
HasDerivedValueType< CONTAINER > push_back(const CONTAINER &container)
Push back non-pointer objects in a container (factors are copied).
IsDerived< DERIVEDFACTOR > push_back(const DERIVEDFACTOR &factor)
const GaussianFactorGraph factors
typename std::enable_if< std::is_base_of< FactorType, DERIVEDFACTOR >::value >::type IsDerived
Check if a DERIVEDFACTOR is in fact derived from FactorType.
#define GTSAM_CONCEPT_TESTABLE_TYPE(T)
FastVector< sharedFactor >::iterator iterator
bool exists(size_t idx) const
FACTOR FactorType
factor type
static const KeyFormatter DefaultKeyFormatter
static const symbolic::SymbolExpr< internal::symbolic_last_tag > last
const KeyFormatter & formatter
IsDerived< DERIVEDFACTOR > add(std::shared_ptr< DERIVEDFACTOR > factor)
add is a synonym for push_back.
FastVector< FactorIndex > FactorIndices
Define collection types:
const_iterator begin() const
STL compatible allocator to use with types requiring a non standrad alignment.
sharedFactor & at(size_t i)
FactorGraph(const CONTAINER &factors)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
FactorGraph(std::initializer_list< std::shared_ptr< DERIVEDFACTOR >> sharedFactors)
void addFactorsToGraph(FactorGraph< FactorType > *graph) const
void operator()(const A &a)
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
sharedFactor & operator[](size_t i)
const_iterator end() const
Matrix< Scalar, Dynamic, Dynamic > C
DotWriter is a helper class for writing graphviz .dot files.
A thin wrapper around std::vector that uses a custom allocator.
typename std::enable_if< std::is_base_of< FactorType, typename T::value_type >::value >::type HasDerivedValueType
Check if T has a value_type derived from FactorType.
virtual void resize(size_t size)
FastVector< sharedFactor >::const_iterator const_iterator
ofstream os("timeSchurFactors.csv")
iterator erase(iterator first, iterator last)
HasDerivedElementType< CONTAINER > push_back(const CONTAINER &container)
std::enable_if< std::is_base_of< This, typename CLIQUE::FactorGraphType >::value >::type push_back(const BayesTree< CLIQUE > &bayesTree)
const sharedFactor at(size_t i) const
FactorGraph< FACTOR > This
Typedef for this class.
static EIGEN_DEPRECATED const end_t end
std::shared_ptr< This > shared_ptr
Shared pointer for this class.
void reserve(size_t size)
typename std::enable_if< std::is_base_of< FactorType, typename T::value_type::element_type >::value >::type HasDerivedElementType
Check if T has a pointer type derived from FactorType.
std::shared_ptr< FACTOR > sharedFactor
Shared pointer to a factor.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
iterator erase(iterator item)