gtsam 4.2.0
gtsam
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
19#pragma once
20
22#include <gtsam/inference/Key.h>
23
24#include <boost/serialization/vector.hpp>
25#include <map>
26#include <string>
27#include <vector>
28
29namespace gtsam {
30
36 using DiscreteKey = std::pair<Key,size_t>;
37
39 struct GTSAM_EXPORT DiscreteKeys: public std::vector<DiscreteKey> {
40
41 // Forward all constructors.
42 using std::vector<DiscreteKey>::vector;
43
45 DiscreteKeys() : std::vector<DiscreteKey>::vector() {}
46
48 explicit DiscreteKeys(const DiscreteKey& key) { push_back(key); }
49
51 explicit DiscreteKeys(std::map<Key, size_t> cardinalities) {
52 for (auto&& kv : cardinalities) emplace_back(kv);
53 }
54
56 DiscreteKeys(const std::vector<DiscreteKey>& keys) :
57 std::vector<DiscreteKey>(keys) {
58 }
59
61 DiscreteKeys(const std::vector<int>& cs);
62
64 KeyVector indices() const;
65
67 std::map<Key,size_t> cardinalities() const;
68
71 push_back(key);
72 return *this;
73 }
74
76 void print(const std::string& s = "",
77 const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
78
80 bool equals(const DiscreteKeys& other, double tol = 0) const;
81
83 friend class boost::serialization::access;
84 template <class ARCHIVE>
85 void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
86 ar& boost::serialization::make_nvp(
87 "DiscreteKeys",
88 boost::serialization::base_object<std::vector<DiscreteKey>>(*this));
89 }
90
91 }; // DiscreteKeys
92
94 GTSAM_EXPORT DiscreteKeys operator&(const DiscreteKey& key1, const DiscreteKey& key2);
95
96 // traits
97 template <>
98 struct traits<DiscreteKeys> : public Testable<DiscreteKeys> {};
99
100 } // namespace gtsam
Included from all GTSAM files.
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition: DiscreteKey.h:36
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
DiscreteKeys operator&(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition: DiscreteKey.cpp:46
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
std::string serialize(const T &input)
serializes to a string
Definition: serialization.h:113
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:156
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
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:39
DiscreteKeys & operator&(const DiscreteKey &key)
Add a key (non-const!)
Definition: DiscreteKey.h:70
DiscreteKeys()
Constructor for serialization.
Definition: DiscreteKey.h:45
DiscreteKeys(const DiscreteKey &key)
Construct from a key.
Definition: DiscreteKey.h:48
DiscreteKeys(const std::vector< DiscreteKey > &keys)
Construct from a vector of keys.
Definition: DiscreteKey.h:56
DiscreteKeys(std::map< Key, size_t > cardinalities)
Construct from cardinalities.
Definition: DiscreteKey.h:51