gtsam 4.1.1
gtsam
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
13namespace gtsam {
14
22class GTSAM_UNSTABLE_EXPORT AllDiff : public Constraint {
23 std::map<Key, size_t> cardinalities_;
24
25 DiscreteKey discreteKey(size_t i) const {
26 Key j = keys_[i];
27 return DiscreteKey(j, cardinalities_.at(j));
28 }
29
30 public:
32 AllDiff(const DiscreteKeys& dkeys);
33
34 // print
35 void print(const std::string& s = "", const KeyFormatter& formatter =
36 DefaultKeyFormatter) const override;
37
39 bool equals(const DiscreteFactor& other, double tol) const override {
40 if (!dynamic_cast<const AllDiff*>(&other))
41 return false;
42 else {
43 const AllDiff& f(static_cast<const AllDiff&>(other));
44 return cardinalities_.size() == f.cardinalities_.size() &&
45 std::equal(cardinalities_.begin(), cardinalities_.end(),
46 f.cardinalities_.begin());
47 }
48 }
49
51 double operator()(const Values& values) const override;
52
54 DecisionTreeFactor toDecisionTreeFactor() const override;
55
57 DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
58
59 /*
60 * Ensure Arc-consistency
61 * Arc-consistency involves creating binaryAllDiff constraints
62 * In which case the combinatorial hyper-arc explosion disappears.
63 * @param j domain to be checked
64 * @param domains all other domains
65 */
66 bool ensureArcConsistency(size_t j,
67 std::vector<Domain>& domains) const override;
68
70 Constraint::shared_ptr partiallyApply(const Values&) const override;
71
73 Constraint::shared_ptr partiallyApply(
74 const std::vector<Domain>&) const override;
75};
76
77} // namespace gtsam
specialized key for discrete variables
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition: Matrix.cpp:155
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:47
std::pair< Key, size_t > DiscreteKey
Key type for discrete conditionals Includes name and cardinality.
Definition: DiscreteKey.h:34
bool equal(const T &obj1, const T &obj2, double tol)
Call equal on the object.
Definition: Testable.h:84
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:69
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
A discrete probabilistic factor.
Definition: DecisionTreeFactor.h:38
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: DiscreteFactor.h:34
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:37
A non-templated config holding any types of Manifold-group elements.
Definition: Values.h:63
General AllDiff constraint Returns 1 if values for all keys are different, 0 otherwise DiscreteFactor...
Definition: AllDiff.h:22
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: AllDiff.h:39
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition: Constraint.h:33