Constraint.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
18 #pragma once
19 
22 #include <gtsam_unstable/dllexport.h>
23 
24 #include <map>
25 
26 namespace gtsam {
27 
28 class Domain;
29 using Domains = std::map<Key, Domain>;
30 
35 class GTSAM_UNSTABLE_EXPORT Constraint : public DiscreteFactor {
36  public:
37  typedef std::shared_ptr<Constraint> shared_ptr;
38 
39  protected:
42 
45 
47  Constraint(const KeyVector& js) : DiscreteFactor(js) {}
48 
50  template <class KeyIterator>
51  Constraint(KeyIterator beginKey, KeyIterator endKey)
52  : DiscreteFactor(beginKey, endKey) {}
53 
54  public:
57 
59  Constraint();
60 
62  ~Constraint() override {}
63 
67 
68  /*
69  * Ensure Arc-consistency by checking every possible value of domain j.
70  * @param j domain to be checked
71  * @param (in/out) domains all domains, but only domains->at(j) will be
72  * checked.
73  * @return true if domains->at(j) was changed, false otherwise.
74  */
75  virtual bool ensureArcConsistency(Key j, Domains* domains) const = 0;
76 
78  virtual shared_ptr partiallyApply(const DiscreteValues&) const = 0;
79 
81  virtual shared_ptr partiallyApply(const Domains&) const = 0;
82 
85  const DiscreteFactor::shared_ptr& df) const override {
86  return std::make_shared<DecisionTreeFactor>(
87  this->operator*(df->toDecisionTreeFactor()));
88  }
89 
92  const DiscreteFactor::shared_ptr& df) const override {
93  return this->toDecisionTreeFactor() / df;
94  }
95 
97  uint64_t nrValues() const override { return 1; };
98 
99  DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override {
100  return toDecisionTreeFactor().sum(nrFrontals);
101  }
102 
103  DiscreteFactor::shared_ptr sum(const Ordering& keys) const override {
104  return toDecisionTreeFactor().sum(keys);
105  }
106 
107  DiscreteFactor::shared_ptr max(size_t nrFrontals) const override {
108  return toDecisionTreeFactor().max(nrFrontals);
109  }
110 
111  DiscreteFactor::shared_ptr max(const Ordering& keys) const override {
112  return toDecisionTreeFactor().max(keys);
113  }
114 
118 
120  std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
121  const Names& names = {}) const override {
122  return "`Constraint` on " + std::to_string(size()) + " variables\n";
123  }
124 
126  std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
127  const Names& names = {}) const override {
128  return "<p>Constraint on " + std::to_string(size()) + " variables</p>";
129  }
130 
132 };
133 // DiscreteFactor
134 
135 } // namespace gtsam
gtsam::Constraint::max
DiscreteFactor::shared_ptr max(const Ordering &keys) const override
Create new factor by maximizing over all values with the same separator.
Definition: Constraint.h:111
gtsam::Constraint::max
DiscreteFactor::shared_ptr max(size_t nrFrontals) const override
Create new factor by maximizing over all values with the same separator.
Definition: Constraint.h:107
gtsam::Constraint::multiply
DiscreteFactor::shared_ptr multiply(const DiscreteFactor::shared_ptr &df) const override
Multiply factors, DiscreteFactor::shared_ptr edition.
Definition: Constraint.h:84
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::Constraint::operator/
DiscreteFactor::shared_ptr operator/(const DiscreteFactor::shared_ptr &df) const override
divide by DiscreteFactor::shared_ptr f (safely)
Definition: Constraint.h:91
gtsam::Constraint::Constraint
Constraint(KeyIterator beginKey, KeyIterator endKey)
construct from container
Definition: Constraint.h:51
gtsam::Constraint::markdown
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as markdown table.
Definition: Constraint.h:120
gtsam::Constraint::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as html table.
Definition: Constraint.h:126
gtsam::Constraint::sum
DiscreteFactor::shared_ptr sum(const Ordering &keys) const override
Create new factor by summing all values with the same separator values.
Definition: Constraint.h:103
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::Constraint::Constraint
Constraint(const KeyVector &js)
Construct n-way constraint factor.
Definition: Constraint.h:47
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
gtsam::Constraint::nrValues
uint64_t nrValues() const override
Get the number of non-zero values contained in this factor.
Definition: Constraint.h:97
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
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
DiscreteFactor.h
gtsam::Domains
std::map< Key, Domain > Domains
Definition: Constraint.h:29
process_shonan_timing_results.names
dictionary names
Definition: process_shonan_timing_results.py:175
gtsam
traits
Definition: SFMdata.h:40
DiscreteValues.h
gtsam::DiscreteFactor::shared_ptr
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:45
gtsam::DiscreteFactor::Names
DiscreteValues::Names Names
Translation table from values to strings.
Definition: DiscreteFactor.h:172
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::Constraint::Constraint
Constraint(Key j1, Key j2)
Construct binary constraint factor.
Definition: Constraint.h:44
uint64_t
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
gtsam::DiscreteFactor
Definition: DiscreteFactor.h:40
gtsam::Constraint::sum
DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override
Create new factor by summing all values with the same separator values.
Definition: Constraint.h:99
gtsam::Constraint::shared_ptr
std::shared_ptr< Constraint > shared_ptr
Definition: Constraint.h:37
gtsam::Constraint
Definition: Constraint.h:35
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::Constraint::~Constraint
~Constraint() override
Virtual destructor.
Definition: Constraint.h:62
j1
double j1(double x)
Definition: j1.c:174
gtsam::Constraint::Constraint
Constraint(Key j)
Construct unary constraint factor.
Definition: Constraint.h:41


gtsam
Author(s):
autogenerated on Tue Jan 7 2025 04:02:00