gtsam  4.0.0
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 
25 namespace gtsam {
26 
39  template<class FACTOR, class DERIVEDCONDITIONAL>
41  {
42  protected:
44  size_t nrFrontals_;
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 
70 
72  void print(const std::string& s = "Conditional", const KeyFormatter& formatter = DefaultKeyFormatter) const;
73 
75  bool equals(const This& c, double tol = 1e-9) const;
76 
78 
79  public:
82 
84  size_t nrFrontals() const { return nrFrontals_; }
85 
87  size_t nrParents() const { return asFactor().size() - nrFrontals_; }
88 
90  Key firstFrontalKey() const {
91  if(nrFrontals_ > 0)
92  return asFactor().front();
93  else
94  throw std::invalid_argument("Requested Conditional::firstFrontalKey from a conditional with zero frontal keys");
95  }
96 
98  Frontals frontals() const { return boost::make_iterator_range(beginFrontals(), endFrontals()); }
99 
101  Parents parents() const { return boost::make_iterator_range(beginParents(), endParents()); }
102 
104  typename FACTOR::const_iterator beginFrontals() const { return asFactor().begin(); }
105 
107  typename FACTOR::const_iterator endFrontals() const { return asFactor().begin() + nrFrontals_; }
108 
110  typename FACTOR::const_iterator beginParents() const { return endFrontals(); }
111 
113  typename FACTOR::const_iterator endParents() const { return asFactor().end(); }
114 
118 
120  size_t& nrFrontals() { return nrFrontals_; }
121 
123  typename FACTOR::iterator beginFrontals() { return asFactor().begin(); }
124 
126  typename FACTOR::iterator endFrontals() { return asFactor().begin() + nrFrontals_; }
127 
129  typename FACTOR::iterator beginParents() { return asFactor().begin() + nrFrontals_; }
130 
132  typename FACTOR::iterator endParents() { return asFactor().end(); }
133 
134  private:
135  // Cast to factor type (non-const) (casts down to derived conditional type, then up to factor type)
136  FACTOR& asFactor() { return static_cast<FACTOR&>(static_cast<DERIVEDCONDITIONAL&>(*this)); }
137 
138  // Cast to derived type (const) (casts down to derived conditional type, then up to factor type)
139  const FACTOR& asFactor() const { return static_cast<const FACTOR&>(static_cast<const DERIVEDCONDITIONAL&>(*this)); }
140 
142  friend class boost::serialization::access;
143  template<class ARCHIVE>
144  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
145  ar & BOOST_SERIALIZATION_NVP(nrFrontals_);
146  }
147 
149 
150  };
151 
152 } // gtsam
FACTOR::iterator beginParents()
Mutable iterator pointing to the first parent key.
Definition: Conditional.h:129
FACTOR::const_iterator endParents() const
Iterator pointing past the last parent key.
Definition: Conditional.h:113
FACTOR::iterator endParents()
Mutable iterator pointing past the last parent key.
Definition: Conditional.h:132
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
print with optional formatter
Definition: Conditional-inst.h:29
size_t & nrFrontals()
Mutable version of nrFrontals.
Definition: Conditional.h:120
boost::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:33
TODO: Update comments.
Definition: Conditional.h:40
Conditional(size_t nrFrontals)
Constructor.
Definition: Conditional.h:65
bool equals(const This &c, double tol=1e-9) const
check equality
Definition: Conditional-inst.h:42
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:84
boost::iterator_range< typename FACTOR::const_iterator > Frontals
View of the frontal keys (call frontals())
Definition: Conditional.h:52
size_t nrParents() const
return the number of parents
Definition: Conditional.h:87
Frontals frontals() const
return a view of the frontal keys
Definition: Conditional.h:98
FACTOR::const_iterator endFrontals() const
Iterator pointing past the last frontal key.
Definition: Conditional.h:107
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
FACTOR::iterator beginFrontals()
Mutable iterator pointing to first frontal key.
Definition: Conditional.h:123
Parents parents() const
return a view of the parent keys
Definition: Conditional.h:101
size_t nrFrontals_
The first nrFrontal variables are frontal and the rest are parents.
Definition: Conditional.h:44
FACTOR::iterator endFrontals()
Mutable iterator pointing past the last frontal key.
Definition: Conditional.h:126
FACTOR::const_iterator beginParents() const
Iterator pointing to the first parent key.
Definition: Conditional.h:110
Conditional()
Empty Constructor to make serialization possible.
Definition: Conditional.h:62
Key firstFrontalKey() const
Convenience function to get the first frontal key.
Definition: Conditional.h:90
FACTOR::const_iterator beginFrontals() const
Iterator pointing to first frontal key.
Definition: Conditional.h:104