gtsam 4.2
gtsam
Loading...
Searching...
No Matches
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
19class 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
specialized key for discrete variables
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:36
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition Point2.h:47
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
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:45
Base class for discrete probabilistic factors The most general one is the derived DecisionTreeFactor.
Definition DiscreteFactor.h:38
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:39
A map from keys to values.
Definition DiscreteValues.h:34
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:85
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition AllDiff.h:36
void print(const std::string &s="", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
Definition AllDiff.cpp:22
AllDiff(const DiscreteKeys &dkeys)
Construct from keys.
Definition AllDiff.cpp:17
Constraint(Key j)
Construct unary constraint factor.
Definition Constraint.h:42