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 
11 #include <gtsam/base/Testable.h>
12 #include <boost/make_shared.hpp>
13 
14 namespace gtsam {
15 
16  using namespace std;
17 
18  /* ************************************************************************* */
19  void SingleValue::print(const string& s,
20  const KeyFormatter& formatter) const {
21  cout << s << "SingleValue on " << "j=" << formatter(keys_[0])
22  << " with value " << value_ << endl;
23  }
24 
25  /* ************************************************************************* */
26  double SingleValue::operator()(const Values& values) const {
27  return (double) (values.at(keys_[0]) == value_);
28  }
29 
30  /* ************************************************************************* */
33  keys += DiscreteKey(keys_[0],cardinality_);
34  vector<double> table;
35  for (size_t i1 = 0; i1 < cardinality_; i1++)
36  table.push_back(i1 == value_);
37  DecisionTreeFactor converted(keys, table);
38  return converted;
39  }
40 
41  /* ************************************************************************* */
43  // TODO: can we do this more efficiently?
44  return toDecisionTreeFactor() * f;
45  }
46 
47  /* ************************************************************************* */
49  vector<Domain>& domains) const {
50  if (j != keys_[0]) throw invalid_argument(
51  "SingleValue check on wrong domain");
52  Domain& D = domains[j];
53  if (D.isSingleton()) {
54  if (D.firstValue() != value_) throw runtime_error("Unsatisfiable");
55  return false;
56  }
57  D = Domain(discreteKey(),value_);
58  return true;
59  }
60 
61  /* ************************************************************************* */
63  Values::const_iterator it = values.find(keys_[0]);
64  if (it != values.end() && it->second != value_) throw runtime_error(
65  "SingleValue::partiallyApply: unsatisfiable");
66  return boost::make_shared < SingleValue > (keys_[0], cardinality_, value_);
67  }
68 
69  /* ************************************************************************* */
71  const vector<Domain>& domains) const {
72  const Domain& Dk = domains[keys_[0]];
73  if (Dk.isSingleton() && !Dk.contains(value_)) throw runtime_error(
74  "SingleValue::partiallyApply: unsatisfiable");
75  return boost::make_shared < SingleValue > (discreteKey(), value_);
76  }
77 
78 /* ************************************************************************* */
79 } // namespace gtsam
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
Multiply into a decisiontree.
Definition: SingleValue.cpp:42
bool isSingleton() const
Definition: Domain.h:60
Concept check for values that can be used in unit tests.
double operator()(const Values &values) const override
Calculate value.
Definition: SingleValue.cpp:26
leaf::MyValues values
Definition: Half.h:150
Constraint::shared_ptr partiallyApply(const Values &values) const override
Partially apply known values.
Definition: SingleValue.cpp:62
const KeyFormatter & formatter
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:34
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
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
boost::transform_iterator< boost::function1< ConstKeyValuePair, const ConstKeyValuePtrPair & >, KeyValueMap::const_iterator > const_iterator
Const forward iterator, with value type ConstKeyValuePair.
Definition: Values.h:124
RealScalar s
traits
Definition: chartTesting.h:28
size_t firstValue() const
Definition: Domain.h:64
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:31
bool contains(size_t value) const
Definition: Domain.h:82
const KeyVector keys
std::ptrdiff_t j
bool ensureArcConsistency(size_t j, std::vector< Domain > &domains) const override
Definition: SingleValue.cpp:48
boost::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:36
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:44:12