GTSAM  4.0.2
C++ library for smoothing and mapping (SAM)
AllDiff.h
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 
11 #include <gtsam_unstable/discrete/BinaryAllDiff.h>
12 
13 namespace gtsam {
14 
19 class GTSAM_UNSTABLE_EXPORT AllDiff : public Constraint {
20  std::map<Key, size_t> cardinalities_;
21 
22  DiscreteKey discreteKey(size_t i) const {
23  Key j = keys_[i];
24  return DiscreteKey(j, cardinalities_.at(j));
25  }
26 
27  public:
29  AllDiff(const DiscreteKeys& dkeys);
30 
31  // print
32  void print(const std::string& s = "", const KeyFormatter& formatter =
33  DefaultKeyFormatter) const override;
34 
36  bool equals(const DiscreteFactor& other, double tol) const override {
37  if (!dynamic_cast<const AllDiff*>(&other))
38  return false;
39  else {
40  const AllDiff& f(static_cast<const AllDiff&>(other));
41  return cardinalities_.size() == f.cardinalities_.size() &&
42  std::equal(cardinalities_.begin(), cardinalities_.end(),
43  f.cardinalities_.begin());
44  }
45  }
46 
48  double operator()(const DiscreteValues& values) const override;
49 
51  DecisionTreeFactor toDecisionTreeFactor() const override;
52 
54  DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
55 
56  /*
57  * Ensure Arc-consistency by checking every possible value of domain j.
58  * @param j domain to be checked
59  * @param (in/out) domains all domains, but only domains->at(j) will be checked.
60  * @return true if domains->at(j) was changed, false otherwise.
61  */
62  bool ensureArcConsistency(Key j, Domains* domains) const override;
63 
65  Constraint::shared_ptr partiallyApply(const DiscreteValues&) const override;
66 
68  Constraint::shared_ptr partiallyApply(
69  const Domains&) const override;
70 };
71 
72 } // namespace gtsam
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: AllDiff.h:36
Definition: DecisionTreeFactor.h:44
Definition: Constraint.h:35
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
GTSAM_EXPORT void print(const Matrix &A, const std::string &s, std::ostream &stream)
Definition: DiscreteValues.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
Definition: chartTesting.h:28
specialized key for discrete variables
Definition: DiscreteFactor.h:38
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
Definition: AllDiff.h:19
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:85
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41