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 
21 #include <gtsam/global_includes.h>
22 #include <gtsam/inference/Key.h>
23 
24 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
25 #include <boost/serialization/vector.hpp>
26 #endif
27 #include <map>
28 #include <string>
29 #include <vector>
30 
31 namespace 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  DiscreteKeys() : std::vector<DiscreteKey>::vector() {}
48 
50  explicit DiscreteKeys(const DiscreteKey& key) { push_back(key); }
51 
53  explicit DiscreteKeys(std::map<Key, size_t> cardinalities) {
54  for (auto&& kv : cardinalities) emplace_back(kv);
55  }
56 
58  DiscreteKeys(const std::vector<DiscreteKey>& keys) :
59  std::vector<DiscreteKey>(keys) {
60  }
61 
63  DiscreteKeys(const std::vector<int>& cs);
64 
66  KeyVector indices() const;
67 
69  std::map<Key,size_t> cardinalities() const;
70 
73  push_back(key);
74  return *this;
75  }
76 
78  void print(const std::string& s = "",
79  const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
80 
82  bool equals(const DiscreteKeys& other, double tol = 0) const;
83 
84 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
85 
86  friend class boost::serialization::access;
87  template <class ARCHIVE>
88  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
89  ar& boost::serialization::make_nvp(
90  "DiscreteKeys",
91  boost::serialization::base_object<std::vector<DiscreteKey>>(*this));
92  }
93 #endif
94 
95  }; // DiscreteKeys
96 
98  GTSAM_EXPORT DiscreteKeys operator&(const DiscreteKey& key1, const DiscreteKey& key2);
99 
100  // traits
101  template <>
102  struct traits<DiscreteKeys> : public Testable<DiscreteKeys> {};
103 
104  } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
DiscreteKeys(std::map< Key, size_t > cardinalities)
Construct from cardinalities.
Definition: DiscreteKey.h:53
DiscreteKeys()
Constructor for serialization.
Definition: DiscreteKey.h:47
std::string serialize(const T &input)
serializes to a string
Definition: BFloat16.h:88
DiscreteKeys operator &(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition: DiscreteKey.cpp:45
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
Included from all GTSAM files.
const Symbol key1('v', 1)
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
DiscreteKeys(const std::vector< DiscreteKey > &keys)
Construct from a vector of keys.
Definition: DiscreteKey.h:58
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
DiscreteKeys(const DiscreteKey &key)
Construct from a key.
Definition: DiscreteKey.h:50
const G double tol
Definition: Group.h:86
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
const Symbol key2('v', 2)
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