gtsam 4.1.1
gtsam
SingleValue.h
1/*
2 * SingleValue.h
3 * @brief domain constraint
4 * @date Feb 6, 2012
5 * @author Frank Dellaert
6 */
7
8#pragma once
9
12
13namespace gtsam {
14
18class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint {
20 size_t cardinality_;
21
23 size_t value_;
24
25 DiscreteKey discreteKey() const {
26 return DiscreteKey(keys_[0], cardinality_);
27 }
28
29 public:
30 typedef boost::shared_ptr<SingleValue> shared_ptr;
31
33 SingleValue(Key key, size_t n, size_t value)
34 : Constraint(key), cardinality_(n), value_(value) {}
35
37 SingleValue(const DiscreteKey& dkey, size_t value)
38 : Constraint(dkey.first), cardinality_(dkey.second), value_(value) {}
39
40 // print
41 void print(const std::string& s = "", const KeyFormatter& formatter =
42 DefaultKeyFormatter) const override;
43
45 bool equals(const DiscreteFactor& other, double tol) const override {
46 if (!dynamic_cast<const SingleValue*>(&other))
47 return false;
48 else {
49 const SingleValue& f(static_cast<const SingleValue&>(other));
50 return (cardinality_ == f.cardinality_) && (value_ == f.value_);
51 }
52 }
53
55 double operator()(const Values& values) const override;
56
58 DecisionTreeFactor toDecisionTreeFactor() const override;
59
61 DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
62
63 /*
64 * Ensure Arc-consistency
65 * @param j domain to be checked
66 * @param domains all other domains
67 */
68 bool ensureArcConsistency(size_t j,
69 std::vector<Domain>& domains) const override;
70
72 Constraint::shared_ptr partiallyApply(const Values& values) const override;
73
75 Constraint::shared_ptr partiallyApply(
76 const std::vector<Domain>& domains) const override;
77};
78
79} // namespace gtsam
specialized key for discrete variables
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:47
std::pair< Key, size_t > DiscreteKey
Key type for discrete conditionals Includes name and cardinality.
Definition: DiscreteKey.h:34
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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 discrete probabilistic factor.
Definition: DecisionTreeFactor.h:38
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: DiscreteFactor.h:34
boost::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:40
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: Constraint.h:33
SingleValue constraint.
Definition: SingleValue.h:18
SingleValue(Key key, size_t n, size_t value)
Constructor.
Definition: SingleValue.h:33
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: SingleValue.h:45
SingleValue(const DiscreteKey &dkey, size_t value)
Constructor.
Definition: SingleValue.h:37