Domain.h
Go to the documentation of this file.
1 /*
2  * Domain.h
3  * @brief Domain restriction constraint
4  * @date Feb 13, 2012
5  * @author Frank Dellaert
6  */
7 
8 #pragma once
9 
12 
13 namespace gtsam {
14 
18  class GTSAM_UNSTABLE_EXPORT Domain: public Constraint {
19 
20  size_t cardinality_;
21  std::set<size_t> values_;
22 
23  public:
24 
25  typedef boost::shared_ptr<Domain> shared_ptr;
26 
27  // Constructor on Discrete Key initializes an "all-allowed" domain
28  Domain(const DiscreteKey& dkey) :
29  Constraint(dkey.first), cardinality_(dkey.second) {
30  for (size_t v = 0; v < cardinality_; v++)
31  values_.insert(v);
32  }
33 
34  // Constructor on Discrete Key with single allowed value
35  // Consider SingleValue constraint
36  Domain(const DiscreteKey& dkey, size_t v) :
37  Constraint(dkey.first), cardinality_(dkey.second) {
38  values_.insert(v);
39  }
40 
42  Domain(const Domain& other) :
43  Constraint(other.keys_[0]), values_(other.values_) {
44  }
45 
47  void insert(size_t value) {
48  values_.insert(value);
49  }
50 
52  void erase(size_t value) {
53  values_.erase(value);
54  }
55 
56  size_t nrValues() const {
57  return values_.size();
58  }
59 
60  bool isSingleton() const {
61  return nrValues() == 1;
62  }
63 
64  size_t firstValue() const {
65  return *values_.begin();
66  }
67 
68  // print
69  void print(const std::string& s = "",
70  const KeyFormatter& formatter = DefaultKeyFormatter) const override;
71 
73  bool equals(const DiscreteFactor& other, double tol) const override {
74  if(!dynamic_cast<const Domain*>(&other))
75  return false;
76  else {
77  const Domain& f(static_cast<const Domain&>(other));
78  return (cardinality_==f.cardinality_) && (values_==f.values_);
79  }
80  }
81 
82  bool contains(size_t value) const {
83  return values_.count(value)>0;
84  }
85 
87  double operator()(const Values& values) const override;
88 
90  DecisionTreeFactor toDecisionTreeFactor() const override;
91 
93  DecisionTreeFactor operator*(const DecisionTreeFactor& f) const override;
94 
95  /*
96  * Ensure Arc-consistency
97  * @param j domain to be checked
98  * @param domains all other domains
99  */
100  bool ensureArcConsistency(size_t j, std::vector<Domain>& domains) const override;
101 
107  bool checkAllDiff(const KeyVector keys, std::vector<Domain>& domains);
108 
110  Constraint::shared_ptr partiallyApply(const Values& values) const override;
111 
113  Constraint::shared_ptr partiallyApply(
114  const std::vector<Domain>& domains) const override;
115  };
116 
117 } // namespace gtsam
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
bool isSingleton() const
Definition: Domain.h:60
size_t cardinality_
Definition: Domain.h:20
ArrayXcf v
Definition: Cwise_arg.cpp:1
leaf::MyValues values
Point2 operator*(double s, const Point2 &p)
multiply with scalar
Definition: Point2.h:45
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
boost::shared_ptr< Domain > shared_ptr
allowed values
Definition: Domain.h:25
const KeyFormatter & formatter
bool equals(const DiscreteFactor &other, double tol) const override
equals
Definition: Domain.h:73
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
constexpr int first(int i)
Implementation details for constexpr functions.
std::set< size_t > values_
Cardinality.
Definition: Domain.h:21
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:34
size_t nrValues() const
Definition: Domain.h:56
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
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RealScalar s
Domain(const Domain &other)
Constructor.
Definition: Domain.h:42
Domain(const DiscreteKey &dkey)
Definition: Domain.h:28
traits
Definition: chartTesting.h:28
specialized key for discrete variables
size_t firstValue() const
Definition: Domain.h:64
const G double tol
Definition: Group.h:83
bool contains(size_t value) const
Definition: Domain.h:82
const KeyVector keys
Domain(const DiscreteKey &dkey, size_t v)
Definition: Domain.h:36
std::ptrdiff_t j
boost::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:36
void insert(size_t value)
insert a value, non const :-(
Definition: Domain.h:47
void erase(size_t value)
erase a value, non const :-(
Definition: Domain.h:52


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:59