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 
62  Conditional() : nrFrontals_(0) {}
63 
65  Conditional(size_t nrFrontals) : nrFrontals_(nrFrontals) {}
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 
91  Key firstFrontalKey() const {
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 
143  friend class boost::serialization::access;
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
Conditional(size_t nrFrontals)
Definition: Conditional.h:65
FACTOR::const_iterator endParents() const
Definition: Conditional.h:114
size_t & nrFrontals()
Definition: Conditional.h:121
Frontals frontals() const
Definition: Conditional.h:99
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
size_t nrFrontals() const
Definition: Conditional.h:85
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
Key firstFrontalKey() const
Definition: Conditional.h:91
Parents parents() const
Definition: Conditional.h:102
void serialize(ARCHIVE &ar, const unsigned int)
Definition: Conditional.h:145
const KeyFormatter & formatter
void print(const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const
FACTOR::const_iterator beginParents() const
Definition: Conditional.h:111
FACTOR::iterator endFrontals()
Definition: Conditional.h:127
FACTOR::iterator endParents()
Definition: Conditional.h:133
FACTOR::const_iterator endFrontals() const
Definition: Conditional.h:108
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
size_t nrParents() const
Definition: Conditional.h:88
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
FACTOR::iterator beginFrontals()
Definition: Conditional.h:124
traits
Definition: chartTesting.h:28
FACTOR::const_iterator beginFrontals() const
Definition: Conditional.h:105
FACTOR::iterator beginParents()
Definition: Conditional.h:130
FACTOR & asFactor()
Definition: Conditional.h:137
const G double tol
Definition: Group.h:83
boost::iterator_range< typename FACTOR::const_iterator > Parents
Definition: Conditional.h:55
const FACTOR & asFactor() const
Definition: Conditional.h:140
Conditional< FACTOR, DERIVEDCONDITIONAL > This
Typedef to this class.
Definition: Conditional.h:48
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
boost::iterator_range< typename FACTOR::const_iterator > Frontals
Definition: Conditional.h:52
bool equals(const This &c, double tol=1e-9) const


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:50