Loading...
Searching...
No Matches
HybridValues.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/discrete/Assignment.h>
#include <gtsam/discrete/DiscreteKey.h>
#include <gtsam/discrete/DiscreteValues.h>
#include <gtsam/inference/Key.h>
#include <gtsam/linear/VectorValues.h>
#include <gtsam/nonlinear/Values.h>
#include <map>
#include <string>
#include <vector>
namespace gtsam {
class GTSAM_EXPORT HybridValues {
private:
VectorValues continuous_;
DiscreteValues discrete_;
Values nonlinear_;
public:
HybridValues() = default;
HybridValues(const VectorValues& cv, const DiscreteValues& dv)
: continuous_(cv), discrete_(dv){};
HybridValues(const VectorValues& cv, const DiscreteValues& dv,
const Values& v)
: continuous_(cv), discrete_(dv), nonlinear_(v){};
void print(const std::string& s = "HybridValues",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
std::cout << s << ": \n";
continuous_.print(" Continuous",
keyFormatter); // print continuous components
discrete_.print(" Discrete", keyFormatter); // print discrete components
};
bool equals(const HybridValues& other, double tol = 1e-9) const {
return continuous_.equals(other.continuous_, tol) &&
discrete_.equals(other.discrete_, tol);
}
const VectorValues& continuous() const { return continuous_; }
const DiscreteValues& discrete() const { return discrete_; }
const Values& nonlinear() const { return nonlinear_; }
bool existsVector(Key j) { return continuous_.exists(j); };
bool existsDiscrete(Key j) { return (discrete_.find(j) != discrete_.end()); };
bool existsNonlinear(Key j) {
return nonlinear_.exists(j);
};
bool exists(Key j) {
return existsVector(j) || existsDiscrete(j) || existsNonlinear(j);
};
void insert(Key j, const Vector& value) { continuous_.insert(j, value); }
void insert(Key j, size_t value) { discrete_[j] = value; };
void insert_or_assign(Key j, const Vector& value) {
continuous_.insert_or_assign(j, value);
}
void insert_or_assign(Key j, size_t value) {
discrete_[j] = value;
}
HybridValues& insert(const VectorValues& values) {
continuous_.insert(values);
return *this;
}
HybridValues& insert(const DiscreteValues& values) {
discrete_.insert(values);
return *this;
}
HybridValues& insert(const Values& values) {
nonlinear_.insert(values);
return *this;
}
HybridValues& insert(const HybridValues& values) {
continuous_.insert(values.continuous());
discrete_.insert(values.discrete());
nonlinear_.insert(values.nonlinear());
return *this;
}
Vector& at(Key j) { return continuous_.at(j); };
size_t& atDiscrete(Key j) { return discrete_.at(j); };
HybridValues& update(const VectorValues& values) {
continuous_.update(values);
return *this;
}
HybridValues& update(const DiscreteValues& values) {
discrete_.update(values);
return *this;
}
HybridValues& update(const HybridValues& values) {
continuous_.update(values.continuous());
discrete_.update(values.discrete());
return *this;
}
VectorValues continuousSubset(const KeyVector& keys) const {
VectorValues measurements;
for (const auto& key : keys) {
measurements.insert(key, continuous_.at(key));
}
return measurements;
}
std::string html(
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const {
std::stringstream ss;
ss << this->continuous_.html(keyFormatter);
ss << this->discrete_.html(keyFormatter);
return ss.str();
};
};
// traits
template <>
struct traits<HybridValues> : public Testable<HybridValues> {};
} // namespace gtsam
Assignment.h
An assignment from labels to a discrete value index (size_t).
DiscreteValues.h
DiscreteKey.h
specialized key for discrete variables
Key.h
VectorValues.h
Factor Graph Values.
Values.h
A non-templated config holding any types of Manifold-group elements.
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:86
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::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
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::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::DiscreteValues
A map from keys to values.
Definition DiscreteValues.h:34
gtsam::DiscreteValues::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const
Output as a html table.
Definition DiscreteValues.cpp:104
gtsam::HybridValues
HybridValues represents a collection of DiscreteValues and VectorValues.
Definition HybridValues.h:38
gtsam::HybridValues::print
void print(const std::string &s="HybridValues", const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
print required by Testable for unit testing
Definition HybridValues.h:70
gtsam::HybridValues::insert
void insert(Key j, const Vector &value)
Insert a vector value with key j.
Definition HybridValues.h:117
gtsam::HybridValues::insert
HybridValues & insert(const DiscreteValues &values)
Insert all discrete values from values.
Definition HybridValues.h:144
gtsam::HybridValues::HybridValues
HybridValues(const VectorValues &cv, const DiscreteValues &dv, const Values &v)
Construct from all values types.
Definition HybridValues.h:61
gtsam::HybridValues::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Output as a html table.
Definition HybridValues.h:224
gtsam::HybridValues::continuousSubset
VectorValues continuousSubset(const KeyVector &keys) const
Extract continuous values with given keys.
Definition HybridValues.h:206
gtsam::HybridValues::insert_or_assign
void insert_or_assign(Key j, const Vector &value)
insert_or_assign() , similar to Values.h
Definition HybridValues.h:126
gtsam::HybridValues::insert
HybridValues & insert(const Values &values)
Insert all values from values.
Definition HybridValues.h:151
gtsam::HybridValues::equals
bool equals(const HybridValues &other, double tol=1e-9) const
equals required by Testable for unit testing
Definition HybridValues.h:79
gtsam::HybridValues::update
HybridValues & update(const VectorValues &values)
For all key/value pairs in values, replace continuous values with corresponding keys in this object w...
Definition HybridValues.h:181
gtsam::HybridValues::discrete
const DiscreteValues & discrete() const
Return the discrete values.
Definition HybridValues.h:92
gtsam::HybridValues::existsDiscrete
bool existsDiscrete(Key j)
Check whether a variable with key j exists in DiscreteValues.
Definition HybridValues.h:101
gtsam::HybridValues::continuous
const VectorValues & continuous() const
Return the multi-dimensional vector values.
Definition HybridValues.h:89
gtsam::HybridValues::at
Vector & at(Key j)
Read/write access to the vector value with key j, throws std::out_of_range if j does not exist.
Definition HybridValues.h:169
gtsam::HybridValues::exists
bool exists(Key j)
Check whether a variable with key j exists.
Definition HybridValues.h:109
gtsam::HybridValues::update
HybridValues & update(const DiscreteValues &values)
For all key/value pairs in values, replace discrete values with corresponding keys in this object wit...
Definition HybridValues.h:190
gtsam::HybridValues::insert
HybridValues & insert(const HybridValues &values)
Insert all values from values.
Definition HybridValues.h:158
gtsam::HybridValues::insert
HybridValues & insert(const VectorValues &values)
Insert all continuous values from values.
Definition HybridValues.h:137
gtsam::HybridValues::insert
void insert(Key j, size_t value)
Insert a discrete value with key j.
Definition HybridValues.h:123
gtsam::HybridValues::nonlinear
const Values & nonlinear() const
Return the nonlinear values.
Definition HybridValues.h:95
gtsam::HybridValues::existsNonlinear
bool existsNonlinear(Key j)
Check whether a variable with key j exists in values.
Definition HybridValues.h:104
gtsam::HybridValues::update
HybridValues & update(const HybridValues &values)
For all key/value pairs in values, replace all values with corresponding keys in this object with tho...
Definition HybridValues.h:199
gtsam::HybridValues::HybridValues
HybridValues()=default
Default constructor creates an empty HybridValues.
gtsam::HybridValues::existsVector
bool existsVector(Key j)
Check whether a variable with key j exists in VectorValues.
Definition HybridValues.h:98
gtsam::HybridValues::HybridValues
HybridValues(const VectorValues &cv, const DiscreteValues &dv)
Construct from DiscreteValues and VectorValues.
Definition HybridValues.h:57
gtsam::HybridValues::atDiscrete
size_t & atDiscrete(Key j)
Read/write access to the discrete value with key j, throws std::out_of_range if j does not exist.
Definition HybridValues.h:175
gtsam::HybridValues::insert_or_assign
void insert_or_assign(Key j, size_t value)
insert_or_assign() , similar to Values.h
Definition HybridValues.h:131
gtsam::VectorValues
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:74
gtsam::VectorValues::insert
iterator insert(const std::pair< Key, Vector > &key_value)
Insert a vector value with key j.
Definition VectorValues.cpp:91
gtsam::VectorValues::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter) const
Output as a html table.
Definition VectorValues.cpp:387
gtsam::Values
A non-templated config holding any types of Manifold-group elements.
Definition Values.h:65