SingleValue.h
Go to the documentation of this file.
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 
19 class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint {
20  size_t cardinality_;
21  size_t value_;
22 
24  return DiscreteKey(keys_[0], cardinality_);
25  }
26 
27  public:
28  typedef std::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
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
const gtsam::Symbol key('X', 0)
size_t value_
< Number of values
Definition: SingleValue.h:21
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
SingleValue(Key key, size_t n, size_t value)
Construct from key, cardinality, and given value.
Definition: SingleValue.h:31
int n
leaf::MyValues values
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
std::map< Key, Domain > Domains
Definition: Constraint.h:29
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RealScalar s
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
traits
Definition: chartTesting.h:28
specialized key for discrete variables
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
DiscreteKey discreteKey() const
Definition: SingleValue.h:23
const G double tol
Definition: Group.h:86
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
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
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::ptrdiff_t j
std::shared_ptr< SingleValue > shared_ptr
Definition: SingleValue.h:28


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:35:49