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 
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
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
Assignment()=default
A insert(1, 2)=0
def update(text)
Definition: relicense.py:46
An assignment from labels to a discrete value index (size_t)
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
leaf::MyValues values
DiscreteValues(const Base &a)
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
static std::vector< DiscreteValues > CartesianProduct(const DiscreteKeys &keys)
Return a vector of DiscreteValues, one for each possible combination of values.
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
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
traits
Definition: chartTesting.h:28
specialized key for discrete variables
const G double tol
Definition: Group.h:86
const KeyVector keys
std::pair< iterator, bool > insert(const value_type &value)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
DiscreteValues(std::initializer_list< std::pair< const Key, size_t >> init)
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.
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:10