gtsam 4.2
gtsam
Loading...
Searching...
No Matches
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
19class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint {
20 size_t cardinality_;
21 size_t value_;
22
23 DiscreteKey discreteKey() const {
24 return DiscreteKey(keys_[0], cardinality_);
25 }
26
27 public:
28 typedef boost::shared_ptr<SingleValue> shared_ptr;
29
31 SingleValue(Key key, size_t n, size_t value)
32 : Constraint(key), cardinality_(n), value_(value) {}
33
35 SingleValue(const DiscreteKey& dkey, size_t value)
36 : Constraint(dkey.first), cardinality_(dkey.second), value_(value) {}
37
38 // print
39 void print(const std::string& s = "", const KeyFormatter& formatter =
40 DefaultKeyFormatter) const override;
41
43 bool equals(const DiscreteFactor& other, double tol) const override {
44 if (!dynamic_cast<const SingleValue*>(&other))
45 return false;
46 else {
47 const SingleValue& f(static_cast<const SingleValue&>(other));
48 return (cardinality_ == f.cardinality_) && (value_ == f.value_);
49 }
50 }
51
53 double operator()(const DiscreteValues& values) const override;
54
56 DecisionTreeFactor toDecisionTreeFactor() const override;
57
59 DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
60
61 /*
62 * Ensure Arc-consistency: just sets domain[j] to {value_}.
63 * @param j domain to be checked
64 * @param (in/out) domains all domains, but only domains->at(j) will be checked.
65 * @return true if domains->at(j) was changed, false otherwise.
66 */
67 bool ensureArcConsistency(Key j, Domains* domains) const override;
68
70 Constraint::shared_ptr partiallyApply(const DiscreteValues& values) const override;
71
73 Constraint::shared_ptr partiallyApply(
74 const Domains& domains) const override;
75};
76
77} // namespace gtsam
specialized key for discrete variables
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
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition Point2.h:47
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:45
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition DiscreteFactor.h:38
A map from keys to values.
Definition DiscreteValues.h:34
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:85
Constraint(Key j)
Construct unary constraint factor.
Definition Constraint.h:42
SingleValue(Key key, size_t n, size_t value)
Construct from key, cardinality, and given value.
Definition SingleValue.h:31
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition SingleValue.h:43
SingleValue(const DiscreteKey &dkey, size_t value)
Construct from DiscreteKey and given value.
Definition SingleValue.h:35