gtsam 4.2.0
gtsam
Loading...
Searching...
No Matches
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
28namespace gtsam {
29
34class 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
124inline std::vector<DiscreteValues> cartesianProduct(const DiscreteKeys& keys) {
126}
127
129std::string markdown(const DiscreteValues& values,
130 const KeyFormatter& keyFormatter = DefaultKeyFormatter,
131 const DiscreteValues::Names& names = {});
132
134std::string html(const DiscreteValues& values,
135 const KeyFormatter& keyFormatter = DefaultKeyFormatter,
136 const DiscreteValues::Names& names = {});
137
138// traits
139template <>
140struct traits<DiscreteValues> : public Testable<DiscreteValues> {};
141
142} // namespace gtsam
An assignment from labels to a discrete value index (size_t)
specialized key for discrete variables
Global functions in a separate testing namespace.
Definition chartTesting.h:28
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition DiscreteValues.cpp:134
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition DiscreteValues.cpp:129
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
std::vector< DiscreteValues > cartesianProduct(const DiscreteKeys &keys)
Free version of CartesianProduct.
Definition DiscreteValues.h:124
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
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
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
Template to create a binary predicate.
Definition Testable.h:111
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
An assignment from labels to value index (size_t).
Definition Assignment.h:37
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
A map from keys to values.
Definition DiscreteValues.h:34
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition DiscreteValues.h:95
static std::vector< DiscreteValues > CartesianProduct(const DiscreteKeys &keys)
Return a vector of DiscreteValues, one for each possible combination of values.
Definition DiscreteValues.h:85
The Factor::error simply extracts the.