gtsam  4.0.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  virtual void print(const std::string& s = "",
46  const KeyFormatter& formatter = DefaultKeyFormatter) const;
47 
49  bool equals(const DiscreteFactor& other, double tol) const {
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  virtual double operator()(const Values& values) const;
60 
62  virtual DecisionTreeFactor toDecisionTreeFactor() const;
63 
65  virtual DecisionTreeFactor operator*(const DecisionTreeFactor& f) const;
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;
73 
75  virtual Constraint::shared_ptr partiallyApply(
76  const Values& values) const;
77 
79  virtual Constraint::shared_ptr partiallyApply(
80  const std::vector<Domain>& domains) const;
81  };
82 
83 } // namespace gtsam
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:70
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: Constraint.h:32
specialized key for discrete variables
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:141
SingleValue constraint.
Definition: SingleValue.h:18
bool equals(const DiscreteFactor &other, double tol) const
equals
Definition: SingleValue.h:49
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:57
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: DiscreteFactor.h:34
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:33
SingleValue(Key key, size_t n, size_t value)
Constructor.
Definition: SingleValue.h:35
A discrete probabilistic factor.
Definition: DecisionTreeFactor.h:38
std::pair< Key, size_t > DiscreteKey
Key type for discrete conditionals Includes name and cardinality.
Definition: DiscreteKey.h:34
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
boost::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:40
SingleValue(const DiscreteKey &dkey, size_t value)
Constructor.
Definition: SingleValue.h:40
Point2 operator *(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:170