BinaryAllDiff.h
Go to the documentation of this file.
1 /*
2  * BinaryAllDiff.h
3  * @brief Binary "all-different" constraint
4  * @date Feb 6, 2012
5  * @author Frank Dellaert
6  */
7 
8 #pragma once
9 
13 
14 namespace gtsam {
15 
23  class BinaryAllDiff: public Constraint {
24 
26 
27  public:
28 
31  Constraint(key1.first, key2.first),
32  cardinality0_(key1.second), cardinality1_(key2.second) {
33  }
34 
35  // print
36  void print(const std::string& s = "",
37  const KeyFormatter& formatter = DefaultKeyFormatter) const override {
38  std::cout << s << "BinaryAllDiff on " << formatter(keys_[0]) << " and "
39  << formatter(keys_[1]) << std::endl;
40  }
41 
43  bool equals(const DiscreteFactor& other, double tol) const override {
44  if(!dynamic_cast<const BinaryAllDiff*>(&other))
45  return false;
46  else {
47  const BinaryAllDiff& f(static_cast<const BinaryAllDiff&>(other));
48  return (cardinality0_==f.cardinality0_) && (cardinality1_==f.cardinality1_);
49  }
50  }
51 
53  double operator()(const Values& values) const override {
54  return (double) (values.at(keys_[0]) != values.at(keys_[1]));
55  }
56 
60  keys.push_back(DiscreteKey(keys_[0],cardinality0_));
61  keys.push_back(DiscreteKey(keys_[1],cardinality1_));
62  std::vector<double> table;
63  for (size_t i1 = 0; i1 < cardinality0_; i1++)
64  for (size_t i2 = 0; i2 < cardinality1_; i2++)
65  table.push_back(i1 != i2);
66  DecisionTreeFactor converted(keys, table);
67  return converted;
68  }
69 
72  // TODO: can we do this more efficiently?
73  return toDecisionTreeFactor() * f;
74  }
75 
76  /*
77  * Ensure Arc-consistency
78  * @param j domain to be checked
79  * @param domains all other domains
80  */
82  bool ensureArcConsistency(size_t j, std::vector<Domain>& domains) const override {
83 // throw std::runtime_error(
84 // "BinaryAllDiff::ensureArcConsistency not implemented");
85  return false;
86  }
87 
89  Constraint::shared_ptr partiallyApply(const Values&) const override {
90  throw std::runtime_error("BinaryAllDiff::partiallyApply not implemented");
91  }
92 
95  const std::vector<Domain>&) const override {
96  throw std::runtime_error("BinaryAllDiff::partiallyApply not implemented");
97  }
98  };
99 
100 } // namespace gtsam
Constraint::shared_ptr partiallyApply(const Values &) const override
Partially apply known values.
Definition: BinaryAllDiff.h:89
Constraint::shared_ptr partiallyApply(const std::vector< Domain > &) const override
Partially apply known values, domain version.
Definition: BinaryAllDiff.h:94
leaf::MyValues values
DecisionTreeFactor operator*(const DecisionTreeFactor &f) const override
Multiply into a decisiontree.
Definition: BinaryAllDiff.h:71
bool ensureArcConsistency(size_t j, std::vector< Domain > &domains) const override
Definition: BinaryAllDiff.h:82
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:72
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition: BinaryAllDiff.h:36
const Symbol key1('v', 1)
constexpr int first(int i)
Implementation details for constexpr functions.
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 >)
RealScalar s
DecisionTreeFactor toDecisionTreeFactor() const override
Convert into a decisiontree.
Definition: BinaryAllDiff.h:58
traits
Definition: chartTesting.h:28
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: BinaryAllDiff.h:43
ArrayXXf table(10, 4)
const KeyVector & keys() const
Access the factor&#39;s involved variable keys.
Definition: Factor.h:124
const Symbol key2('v', 2)
BinaryAllDiff(const DiscreteKey &key1, const DiscreteKey &key2)
cardinality
Definition: BinaryAllDiff.h:30
const G double tol
Definition: Group.h:83
double operator()(const Values &values) const override
Calculate value.
Definition: BinaryAllDiff.h:53
std::ptrdiff_t j
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:41:42