SingleValue.cpp
Go to the documentation of this file.
1 /*
2  * SingleValue.cpp
3  * @brief domain constraint
4  * @date Feb 13, 2012
5  * @author Frank Dellaert
6  */
7 
8 #include <gtsam/base/Testable.h>
12 
13 
14 namespace gtsam {
15 
16 using namespace std;
17 
18 /* ************************************************************************* */
19 void SingleValue::print(const string& s, const KeyFormatter& formatter) const {
20  cout << s << "SingleValue on "
21  << "j=" << formatter(keys_[0]) << " with value " << value_ << endl;
22 }
23 
24 /* ************************************************************************* */
26  return (double)(values.at(keys_[0]) == value_);
27 }
28 
29 /* ************************************************************************* */
31  const DiscreteKeys keys{DiscreteKey(keys_[0], cardinality_)};
32  vector<double> table;
33  for (size_t i1 = 0; i1 < cardinality_; i1++) table.push_back(i1 == value_);
34  DecisionTreeFactor converted(keys, table);
35  return converted;
36 }
37 
38 /* ************************************************************************* */
40  // TODO: can we do this more efficiently?
41  return toDecisionTreeFactor() * f;
42 }
43 
44 /* ************************************************************************* */
46  if (j != keys_[0])
47  throw invalid_argument("SingleValue check on wrong domain");
48  Domain& D = domains->at(j);
49  if (D.isSingleton()) {
50  if (D.firstValue() != value_) throw runtime_error("Unsatisfiable");
51  return false;
52  }
53  D = Domain(discreteKey(), value_);
54  return true;
55 }
56 
57 /* ************************************************************************* */
59  DiscreteValues::const_iterator it = values.find(keys_[0]);
60  if (it != values.end() && it->second != value_)
61  throw runtime_error("SingleValue::partiallyApply: unsatisfiable");
62  return std::make_shared<SingleValue>(keys_[0], cardinality_, value_);
63 }
64 
65 /* ************************************************************************* */
67  const Domains& domains) const {
68  const Domain& Dk = domains.at(keys_[0]);
69  if (Dk.isSingleton() && !Dk.contains(value_))
70  throw runtime_error("SingleValue::partiallyApply: unsatisfiable");
71  return std::make_shared<SingleValue>(discreteKey(), value_);
72 }
73 
74 /* ************************************************************************* */
75 } // namespace gtsam
gtsam::SingleValue::operator*
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
Multiply into a decisiontree.
Definition: SingleValue.cpp:39
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:44
gtsam::Domain::isSingleton
bool isSingleton() const
Definition: Domain.h:54
gtsam::Domain::contains
bool contains(size_t value) const
Definition: Domain.h:82
D
MatrixXcd D
Definition: EigenSolver_EigenSolver_MatrixType.cpp:14
s
RealScalar s
Definition: level1_cplx_impl.h:126
Testable.h
Concept check for values that can be used in unit tests.
gtsam::SingleValue::ensureArcConsistency
bool ensureArcConsistency(Key j, Domains *domains) const override
Definition: SingleValue.cpp:45
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::SingleValue::operator()
double operator()(const DiscreteValues &values) const override
Calculate value.
Definition: SingleValue.cpp:25
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
table
ArrayXXf table(10, 4)
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
SingleValue.h
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::Domain
Definition: Domain.h:20
gtsam::Domains
std::map< Key, Domain > Domains
Definition: Constraint.h:29
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
Domain.h
gtsam::SingleValue::partiallyApply
Constraint::shared_ptr partiallyApply(const DiscreteValues &values) const override
Partially apply known values.
Definition: SingleValue.cpp:58
gtsam
traits
Definition: SFMdata.h:40
i1
double i1(double x)
Definition: i1.c:150
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
std
Definition: BFloat16.h:88
gtsam::SingleValue::print
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition: SingleValue.cpp:19
gtsam::Constraint::shared_ptr
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
gtsam::SingleValue::toDecisionTreeFactor
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decisiontree.
Definition: SingleValue.cpp:30
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
DecisionTreeFactor.h


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:19