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 
54  throw std::runtime_error("SingleValue::error not implemented");
55  }
56 
58  double evaluate(const Assignment<Key>& values) const override;
59 
61  DecisionTreeFactor toDecisionTreeFactor() const override;
62 
64  DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
65 
66  /*
67  * Ensure Arc-consistency: just sets domain[j] to {value_}.
68  * @param j domain to be checked
69  * @param (in/out) domains all domains, but only domains->at(j) will be checked.
70  * @return true if domains->at(j) was changed, false otherwise.
71  */
72  bool ensureArcConsistency(Key j, Domains* domains) const override;
73 
75  Constraint::shared_ptr partiallyApply(const DiscreteValues& values) const override;
76 
78  Constraint::shared_ptr partiallyApply(
79  const Domains& domains) const override;
80 };
81 
82 } // namespace gtsam
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:45
gtsam::SingleValue::shared_ptr
std::shared_ptr< SingleValue > shared_ptr
Definition: SingleValue.h:28
s
RealScalar s
Definition: level1_cplx_impl.h:126
Constraint.h
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::SingleValue
Definition: SingleValue.h:19
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::operator*
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
n
int n
Definition: BiCGSTAB_simple.cpp:1
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:156
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
gtsam::KeyFormatter
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
gtsam::SingleValue::equals
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: SingleValue.h:43
gtsam::Assignment< Key >
gtsam::Domains
std::map< Key, Domain > Domains
Definition: Constraint.h:29
gtsam::SingleValue::SingleValue
SingleValue(Key key, size_t n, size_t value)
Construct from key, cardinality, and given value.
Definition: SingleValue.h:31
DiscreteKey.h
specialized key for discrete variables
key
const gtsam::Symbol key('X', 0)
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam
traits
Definition: SFMdata.h:40
gtsam::SingleValue::discreteKey
DiscreteKey discreteKey() const
Definition: SingleValue.h:23
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::SingleValue::SingleValue
SingleValue(const DiscreteKey &dkey, size_t value)
Construct from DiscreteKey and given value.
Definition: SingleValue.h:35
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteFactor
Definition: DiscreteFactor.h:39
gtsam::Constraint::shared_ptr
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
gtsam::SingleValue::value_
size_t value_
< Number of values
Definition: SingleValue.h:21
gtsam::Constraint
Definition: Constraint.h:35
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::SingleValue::cardinality_
size_t cardinality_
Definition: SingleValue.h:20
test_callbacks.value
value
Definition: test_callbacks.py:160
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
gtsam::SingleValue::errorTree
AlgebraicDecisionTree< Key > errorTree() const override
Compute error for each assignment and return as a tree.
Definition: SingleValue.h:53


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:13:25