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