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 
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
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
DiscreteKey discreteKey(size_t i) const
Definition: AllDiff.h:22
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: AllDiff.h:36
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
leaf::MyValues values
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
const KeyFormatter & formatter
std::map< Key, Domain > Domains
Definition: Constraint.h:29
std::map< Key, size_t > cardinalities_
Definition: AllDiff.h:20
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
specialized key for discrete variables
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
const G double tol
Definition: Group.h:86
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:85
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
std::ptrdiff_t j
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:33:53