Loading...
Searching...
No Matches
DiscreteKey.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/global_includes.h>
#include <gtsam/inference/Key.h>
#include <boost/serialization/vector.hpp>
#include <map>
#include <string>
#include <vector>
namespace gtsam {
using DiscreteKey = std::pair<Key,size_t>;
struct GTSAM_EXPORT DiscreteKeys: public std::vector<DiscreteKey> {
// Forward all constructors.
using std::vector<DiscreteKey>::vector;
DiscreteKeys() : std::vector<DiscreteKey>::vector() {}
explicit DiscreteKeys(const DiscreteKey& key) { push_back(key); }
explicit DiscreteKeys(std::map<Key, size_t> cardinalities) {
for (auto&& kv : cardinalities) emplace_back(kv);
}
DiscreteKeys(const std::vector<DiscreteKey>& keys) :
std::vector<DiscreteKey>(keys) {
}
DiscreteKeys(const std::vector<int>& cs);
KeyVector indices() const;
std::map<Key,size_t> cardinalities() const;
DiscreteKeys& operator&(const DiscreteKey& key) {
push_back(key);
return *this;
}
void print(const std::string& s = "",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
bool equals(const DiscreteKeys& other, double tol = 0) const;
friend class boost::serialization::access;
template <class ARCHIVE>
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
ar& boost::serialization::make_nvp(
"DiscreteKeys",
boost::serialization::base_object<std::vector<DiscreteKey>>(*this));
}
}; // DiscreteKeys
GTSAM_EXPORT DiscreteKeys operator&(const DiscreteKey& key1, const DiscreteKey& key2);
// traits
template <>
struct traits<DiscreteKeys> : public Testable<DiscreteKeys> {};
} // namespace gtsam
Key.h
global_includes.h
Included from all GTSAM files.
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:36
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::operator&
DiscreteKeys operator&(const DiscreteKey &key1, const DiscreteKey &key2)
Create a list from two keys.
Definition DiscreteKey.cpp:46
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::KeyFormatter
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
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
gtsam::DiscreteKeys::operator&
DiscreteKeys & operator&(const DiscreteKey &key)
Add a key (non-const!).
Definition DiscreteKey.h:70
gtsam::DiscreteKeys::cardinalities
std::map< Key, size_t > cardinalities() const
Return a map from index to cardinality.
Definition DiscreteKey.cpp:40
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys()
Constructor for serialization.
Definition DiscreteKey.h:45
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys(const DiscreteKey &key)
Construct from a key.
Definition DiscreteKey.h:48
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys(const std::vector< DiscreteKey > &keys)
Construct from a vector of keys.
Definition DiscreteKey.h:56
gtsam::DiscreteKeys::DiscreteKeys
DiscreteKeys(std::map< Key, size_t > cardinalities)
Construct from cardinalities.
Definition DiscreteKey.h:51