GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
DiscreteValues.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 #pragma once
19 
22 #include <gtsam/inference/Key.h>
23 
24 #include <map>
25 #include <string>
26 #include <vector>
27 
28 namespace gtsam {
29 
34 class GTSAM_EXPORT DiscreteValues : public Assignment<Key> {
35  public:
36  using Base = Assignment<Key>; // base class
37 
40  using Assignment::Assignment; // all constructors
41 
42  // Define the implicit default constructor.
43  DiscreteValues() = default;
44 
45  // Construct from assignment.
46  explicit DiscreteValues(const Base& a) : Base(a) {}
47 
48  // Construct from initializer list.
49  DiscreteValues(std::initializer_list<std::pair<const Key, size_t>> init)
50  : Assignment<Key>{init} {}
51 
55 
57  void print(const std::string& s = "",
58  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
59 
61  bool equals(const DiscreteValues& x, double tol = 1e-9) const;
62 
66 
67  // insert in base class;
68  std::pair<iterator, bool> insert( const value_type& value ){
69  return Base::insert(value);
70  }
71 
74  DiscreteValues& insert(const DiscreteValues& values);
75 
79  DiscreteValues& update(const DiscreteValues& values);
80 
85  static std::vector<DiscreteValues> CartesianProduct(
86  const DiscreteKeys& keys) {
87  return Base::CartesianProduct<DiscreteValues>(keys);
88  }
89 
93 
95  using Names = std::map<Key, std::vector<std::string>>;
96 
98  static std::string Translate(const Names& names, Key key, size_t index);
99 
107  std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
108  const Names& names = {}) const;
109 
117  std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
118  const Names& names = {}) const;
119 
121 };
122 
124 std::string markdown(const DiscreteValues& values,
125  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
126  const DiscreteValues::Names& names = {});
127 
129 std::string html(const DiscreteValues& values,
130  const KeyFormatter& keyFormatter = DefaultKeyFormatter,
131  const DiscreteValues::Names& names = {});
132 
133 // traits
134 template <>
135 struct traits<DiscreteValues> : public Testable<DiscreteValues> {};
136 
137 } // namespace gtsam
std::string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteValues::Names &names={})
Free version of markdown.
An assignment from labels to a discrete value index (size_t)
Definition: Testable.h:152
Definition: Group.h:43
static std::vector< DiscreteValues > CartesianProduct(const DiscreteKeys &keys)
Return a vector of DiscreteValues, one for each possible combination of values.
Definition: DiscreteValues.h:85
Definition: Testable.h:112
GTSAM_EXPORT void print(const Matrix &A, const std::string &s, std::ostream &stream)
Definition: DiscreteValues.h:34
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
Definition: Assignment.h:37
Definition: chartTesting.h:28
specialized key for discrete variables
std::string html(const DiscreteValues &values, const KeyFormatter &keyFormatter=DefaultKeyFormatter, const DiscreteValues::Names &names={})
Free version of html.
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition: DiscreteValues.h:95
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41