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
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
Multiply into a decisiontree.
Definition: SingleValue.cpp:39
Concept check for values that can be used in unit tests.
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
bool ensureArcConsistency(Key j, Domains *domains) const override
Definition: SingleValue.cpp:45
leaf::MyValues values
Definition: BFloat16.h:88
bool isSingleton() const
Definition: Domain.h:54
size_t firstValue() const
Definition: Domain.h:56
const KeyFormatter & formatter
std::map< Key, Domain > Domains
Definition: Constraint.h:29
Constraint::shared_ptr partiallyApply(const DiscreteValues &values) const override
Partially apply known values.
Definition: SingleValue.cpp:58
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
bool contains(size_t value) const
Definition: Domain.h:77
ArrayXXf table(10, 4)
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition: SingleValue.cpp:19
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decisiontree.
Definition: SingleValue.cpp:30
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
const KeyVector keys
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::ptrdiff_t j
double operator()(const DiscreteValues &values) const override
Calculate value.
Definition: SingleValue.cpp:25
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41


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