gtsam
Loading...
Searching...
No Matches
DiscreteKey.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
19#pragma once
20
22#include <gtsam/inference/Key.h>
23
24#if GTSAM_ENABLE_BOOST_SERIALIZATION
25#include <boost/serialization/vector.hpp>
26#endif
27#include <map>
28#include <string>
29#include <vector>
30
31namespace gtsam {
32
38 using DiscreteKey = std::pair<Key,size_t>;
39
41 struct GTSAM_EXPORT DiscreteKeys: public std::vector<DiscreteKey> {
42
43 // Forward all constructors.
44 using std::vector<DiscreteKey>::vector;
45
47 explicit DiscreteKeys(const DiscreteKey& key) { push_back(key); }
48
50 explicit DiscreteKeys(std::map<Key, size_t> cardinalities) {
51 for (auto&& kv : cardinalities) emplace_back(kv);
52 }
53
55 DiscreteKeys(const std::vector<DiscreteKey>& keys) :
56 std::vector<DiscreteKey>(keys) {
57 }
58
60 DiscreteKeys(const std::vector<int>& cs);
61
63 KeyVector indices() const;
64
66 std::map<Key,size_t> cardinalities() const;
67
70 push_back(key);
71 return *this;
72 }
73
76 this->insert(this->end(), keys.begin(), keys.end());
77 return *this;
78 }
79
81 void print(const std::string& s = "",
82 const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
83
85 bool equals(const DiscreteKeys& other, double tol = 0) const;
86
87#if GTSAM_ENABLE_BOOST_SERIALIZATION
89 friend class boost::serialization::access;
90 template <class ARCHIVE>
91 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
92 ar& boost::serialization::make_nvp(
93 "DiscreteKeys",
94 boost::serialization::base_object<std::vector<DiscreteKey>>(*this));
95 }
96#endif
97
98 }; // DiscreteKeys
99
101 GTSAM_EXPORT DiscreteKeys operator&(const DiscreteKey& key1, const DiscreteKey& key2);
102
103 // traits
104 template <>
105 struct traits<DiscreteKeys> : public Testable<DiscreteKeys> {};
106
107 } // namespace gtsam
Included from all GTSAM files.
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:38
STL namespace.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
DiscreteKeys operator&(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition DiscreteKey.cpp:45
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
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 Group.h:37
Template to create a binary predicate.
Definition Testable.h:112
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:152
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:41
DiscreteKeys & operator&(const DiscreteKeys &keys)
Add multiple keys (non-const!).
Definition DiscreteKey.h:75
DiscreteKeys & operator&(const DiscreteKey &key)
Add a key (non-const!).
Definition DiscreteKey.h:69
std::map< Key, size_t > cardinalities() const
Return a map from index to cardinality.
Definition DiscreteKey.cpp:39
DiscreteKeys(const DiscreteKey &key)
Construct from a key.
Definition DiscreteKey.h:47
DiscreteKeys(const std::vector< DiscreteKey > &keys)
Construct from a vector of keys.
Definition DiscreteKey.h:55
DiscreteKeys(std::map< Key, size_t > cardinalities)
Construct from cardinalities.
Definition DiscreteKey.h:50