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 
58  throw std::runtime_error("AllDiff::error not implemented");
59  }
60 
61  /*
62  * Ensure Arc-consistency by checking every possible value of domain j.
63  * @param j domain to be checked
64  * @param (in/out) domains all domains, but only domains->at(j) will be checked.
65  * @return true if domains->at(j) was changed, false otherwise.
66  */
67  bool ensureArcConsistency(Key j, Domains* domains) const override;
68 
70  Constraint::shared_ptr partiallyApply(const DiscreteValues&) const override;
71 
73  Constraint::shared_ptr partiallyApply(
74  const Domains&) const override;
75 };
76 
77 } // namespace gtsam
gtsam::AllDiff::cardinalities_
std::map< Key, size_t > cardinalities_
Definition: AllDiff.h:20
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:44
s
RealScalar s
Definition: level1_cplx_impl.h:126
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
gtsam::AllDiff
Definition: AllDiff.h:19
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::AlgebraicDecisionTree< Key >
gtsam::operator*
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:52
gtsam::AllDiff::equals
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: AllDiff.h:36
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
operator()
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
Definition: IndexedViewMethods.h:73
gtsam::AllDiff::discreteKey
DiscreteKey discreteKey(size_t i) const
Definition: AllDiff.h:22
gtsam::KeyFormatter
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
gtsam::Domains
std::map< Key, Domain > Domains
Definition: Constraint.h:29
DiscreteKey.h
specialized key for discrete variables
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
BinaryAllDiff.h
gtsam
traits
Definition: SFMdata.h:40
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::DiscreteFactor
Definition: DiscreteFactor.h:39
gtsam::Constraint::shared_ptr
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
gtsam::Constraint
Definition: Constraint.h:35
gtsam::AllDiff::errorTree
AlgebraicDecisionTree< Key > errorTree() const override
Compute error for each assignment and return as a tree.
Definition: AllDiff.h:57
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::equal
bool equal(const T &obj1, const T &obj2, double tol)
Definition: Testable.h:85
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:31:52