34class GTSAM_EXPORT DiscreteValues :
public Assignment<Key> {
36 using Base = Assignment<Key>;
40 using Assignment::Assignment;
43 DiscreteValues() =
default;
46 explicit DiscreteValues(
const Base& a) : Base(a) {}
49 DiscreteValues(std::initializer_list<std::pair<const Key, size_t>> init)
50 : Assignment<Key>{init} {}
57 void print(
const std::string& s =
"",
61 bool equals(
const DiscreteValues& x,
double tol = 1e-9)
const;
68 friend std::ostream&
operator<<(std::ostream& os,
const DiscreteValues& x);
71 std::pair<iterator, bool> insert(
const value_type& value) {
72 return Base::insert(value);
82 DiscreteValues& insert(
const std::pair<Key, size_t>& assignment);
91 DiscreteValues& insert(
const DiscreteValues& values);
102 DiscreteValues&
update(
const DiscreteValues& values);
119 bool contains(
Key key)
const {
return this->find(key) != this->end(); }
128 DiscreteValues result;
129 for (
const auto& [key, _] : keys) {
130 if (
auto it = this->find(key); it != this->end())
131 result[key] = it->second;
144 for (
const auto& [key, cardinality] : keys) {
145 if (!this->
contains(key)) result.emplace_back(key, cardinality);
167 using Names = std::map<Key, std::vector<std::string>>;
180 const Names& names = {})
const;
190 const Names& names = {})
const;
201std::string GTSAM_EXPORT
207std::string GTSAM_EXPORT
specialized key for discrete variables
An assignment from labels to a discrete value index (size_t).
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:160
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
string markdown(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of markdown.
Definition DiscreteValues.cpp:155
std::vector< DiscreteValues > cartesianProduct(const DiscreteKeys &keys)
Free version of CartesianProduct.
Definition DiscreteValues.h:196
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
static std::vector< AssignmentType > CartesianProduct(const std::vector< std::pair< Key, size_t > > &keys)
Definition Assignment.h:89
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:41
A map from keys to values.
Definition DiscreteValues.h:34
DiscreteValues & insert_or_assign(const DiscreteValues &values)
Insert each element of values if it does not already exist, else assign it.
Definition DiscreteValues.cpp:96
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a markdown table.
Definition DiscreteValues.cpp:114
std::map< Key, std::vector< std::string > > Names
Translation table from values to strings.
Definition DiscreteValues.h:167
DiscreteKeys missingKeys(const DiscreteKeys &keys) const
Return the keys that are not present in the DiscreteValues object.
Definition DiscreteValues.h:142
DiscreteValues filter(const DiscreteKeys &keys) const
Filter values by keys.
Definition DiscreteValues.h:127
friend std::ostream & operator<<(std::ostream &os, const DiscreteValues &x)
ostream operator:
Definition DiscreteValues.cpp:37
static std::string Translate(const Names &names, Key key, size_t index)
Translate an integer index value for given key to a string.
Definition DiscreteValues.cpp:104
DiscreteValues & update(const DiscreteValues &values)
Update values with corresponding keys from another DiscreteValues object.
Definition DiscreteValues.cpp:82
static std::vector< DiscreteValues > CartesianProduct(const DiscreteKeys &keys)
Return a vector of DiscreteValues, one for each possible combination of values.
Definition DiscreteValues.h:157
void print(const std::string &s="", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print required by Testable.
Definition DiscreteValues.cpp:43
bool contains(Key key) const
Check if the DiscreteValues contains the given key.
Definition DiscreteValues.h:119
bool equals(const DiscreteValues &x, double tol=1e-9) const
equals required by Testable for unit testing.
Definition DiscreteValues.cpp:51
The Factor::error simply extracts the.