AllDiff.h
Go to the documentation of this file.
1 /*
2  * AllDiff.h
3  * @brief General "all-different" constraint
4  * @date Feb 6, 2012
5  * @author Frank Dellaert
6  */
7 
8 #pragma once
9 
12 
13 namespace gtsam {
14 
22  class GTSAM_UNSTABLE_EXPORT AllDiff: public Constraint {
23 
24  std::map<Key,size_t> cardinalities_;
25 
26  DiscreteKey discreteKey(size_t i) const {
27  Key j = keys_[i];
28  return DiscreteKey(j,cardinalities_.at(j));
29  }
30 
31  public:
32 
34  AllDiff(const DiscreteKeys& dkeys);
35 
36  // print
37  void print(const std::string& s = "",
38  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
39 
41  bool equals(const DiscreteFactor& other, double tol) const override {
42  if(!dynamic_cast<const AllDiff*>(&other))
43  return false;
44  else {
45  const AllDiff& f(static_cast<const AllDiff&>(other));
46  return cardinalities_.size() == f.cardinalities_.size()
47  && std::equal(cardinalities_.begin(), cardinalities_.end(),
48  f.cardinalities_.begin());
49  }
50  }
51 
53  double operator()(const Values& values) const override;
54 
56  DecisionTreeFactor toDecisionTreeFactor() const override;
57 
59  DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
60 
61  /*
62  * Ensure Arc-consistency
63  * Arc-consistency involves creating binaryAllDiff constraints
64  * In which case the combinatorial hyper-arc explosion disappears.
65  * @param j domain to be checked
66  * @param domains all other domains
67  */
68  bool ensureArcConsistency(size_t j, std::vector<Domain>& domains) const override;
69 
71  Constraint::shared_ptr partiallyApply(const Values&) const override;
72 
74  Constraint::shared_ptr partiallyApply(const std::vector<Domain>&) const override;
75  };
76 
77 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: AllDiff.h:41
leaf::MyValues values
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:45
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
DiscreteKey discreteKey(size_t i) const
Definition: AllDiff.h:26
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
traits
Definition: chartTesting.h:28
specialized key for discrete variables
std::map< Key, size_t > cardinalities_
Definition: AllDiff.h:24
const G double tol
Definition: Group.h:83
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:83
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
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:36