gtsam 4.1.1
gtsam
Conditional.h
Go to the documentation of this file.
1/* ----------------------------------------------------------------------------
2
3 * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4 * Atlanta, Georgia 30332-0415
5 * All Rights Reserved
6 * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7
8 * See LICENSE for the license information
9
10 * -------------------------------------------------------------------------- */
11
18// \callgraph
19#pragma once
20
21#include <boost/range.hpp>
22
23#include <gtsam/inference/Key.h>
24
25namespace gtsam {
26
39 template<class FACTOR, class DERIVEDCONDITIONAL>
41 {
42 protected:
45
46 private:
49
50 public:
52 typedef boost::iterator_range<typename FACTOR::const_iterator> Frontals;
53
55 typedef boost::iterator_range<typename FACTOR::const_iterator> Parents;
56
57 protected:
60
63
66
68
69 public:
72
74 void print(const std::string& s = "Conditional", const KeyFormatter& formatter = DefaultKeyFormatter) const;
75
77 bool equals(const This& c, double tol = 1e-9) const;
78
80
83
85 size_t nrFrontals() const { return nrFrontals_; }
86
88 size_t nrParents() const { return asFactor().size() - nrFrontals_; }
89
92 if(nrFrontals_ > 0)
93 return asFactor().front();
94 else
95 throw std::invalid_argument("Requested Conditional::firstFrontalKey from a conditional with zero frontal keys");
96 }
97
99 Frontals frontals() const { return boost::make_iterator_range(beginFrontals(), endFrontals()); }
100
102 Parents parents() const { return boost::make_iterator_range(beginParents(), endParents()); }
103
105 typename FACTOR::const_iterator beginFrontals() const { return asFactor().begin(); }
106
108 typename FACTOR::const_iterator endFrontals() const { return asFactor().begin() + nrFrontals_; }
109
111 typename FACTOR::const_iterator beginParents() const { return endFrontals(); }
112
114 typename FACTOR::const_iterator endParents() const { return asFactor().end(); }
115
119
121 size_t& nrFrontals() { return nrFrontals_; }
122
124 typename FACTOR::iterator beginFrontals() { return asFactor().begin(); }
125
127 typename FACTOR::iterator endFrontals() { return asFactor().begin() + nrFrontals_; }
128
130 typename FACTOR::iterator beginParents() { return asFactor().begin() + nrFrontals_; }
131
133 typename FACTOR::iterator endParents() { return asFactor().end(); }
134
135 private:
136 // Cast to factor type (non-const) (casts down to derived conditional type, then up to factor type)
137 FACTOR& asFactor() { return static_cast<FACTOR&>(static_cast<DERIVEDCONDITIONAL&>(*this)); }
138
139 // Cast to derived type (const) (casts down to derived conditional type, then up to factor type)
140 const FACTOR& asFactor() const { return static_cast<const FACTOR&>(static_cast<const DERIVEDCONDITIONAL&>(*this)); }
141
144 template<class ARCHIVE>
145 void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
146 ar & BOOST_SERIALIZATION_NVP(nrFrontals_);
147 }
148
150
151 };
152
153} // gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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
TODO: Update comments.
Definition: Conditional.h:41
size_t nrFrontals_
The first nrFrontal variables are frontal and the rest are parents.
Definition: Conditional.h:44
Key firstFrontalKey() const
Convenience function to get the first frontal key.
Definition: Conditional.h:91
FACTOR::const_iterator endFrontals() const
Iterator pointing past the last frontal key.
Definition: Conditional.h:108
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
print with optional formatter
Definition: Conditional-inst.h:29
FACTOR::iterator endParents()
Mutable iterator pointing past the last parent key.
Definition: Conditional.h:133
FACTOR::iterator endFrontals()
Mutable iterator pointing past the last frontal key.
Definition: Conditional.h:127
Parents parents() const
return a view of the parent keys
Definition: Conditional.h:102
boost::iterator_range< typename FACTOR::const_iterator > Parents
View of the separator keys (call parents())
Definition: Conditional.h:55
size_t nrFrontals() const
return the number of frontals
Definition: Conditional.h:85
Conditional()
Empty Constructor to make serialization possible.
Definition: Conditional.h:62
Conditional(size_t nrFrontals)
Constructor.
Definition: Conditional.h:65
FACTOR::iterator beginParents()
Mutable iterator pointing to the first parent key.
Definition: Conditional.h:130
size_t & nrFrontals()
Mutable version of nrFrontals.
Definition: Conditional.h:121
FACTOR::iterator beginFrontals()
Mutable iterator pointing to first frontal key.
Definition: Conditional.h:124
boost::iterator_range< typename FACTOR::const_iterator > Frontals
View of the frontal keys (call frontals())
Definition: Conditional.h:52
Frontals frontals() const
return a view of the frontal keys
Definition: Conditional.h:99
friend class boost::serialization::access
Serialization function.
Definition: Conditional.h:143
FACTOR::const_iterator beginFrontals() const
Iterator pointing to first frontal key.
Definition: Conditional.h:105
size_t nrParents() const
return the number of parents
Definition: Conditional.h:88
FACTOR::const_iterator endParents() const
Iterator pointing past the last parent key.
Definition: Conditional.h:114
FACTOR::const_iterator beginParents() const
Iterator pointing to the first parent key.
Definition: Conditional.h:111
bool equals(const This &c, double tol=1e-9) const
check equality
Definition: Conditional-inst.h:42