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 
91  virtual DiscreteFactor::shared_ptr operator*(double s) const override {
92  return this->toDecisionTreeFactor() * s;
93  }
94 
96  DecisionTreeFactor operator*(const DecisionTreeFactor& dtf) const override {
97  return this->toDecisionTreeFactor() * dtf;
98  }
99 
102  const DiscreteFactor::shared_ptr& df) const override {
103  return this->toDecisionTreeFactor() / df;
104  }
105 
107  uint64_t nrValues() const override { return 1; };
108 
109  DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override {
110  return toDecisionTreeFactor().sum(nrFrontals);
111  }
112 
113  DiscreteFactor::shared_ptr sum(const Ordering& keys) const override {
114  return toDecisionTreeFactor().sum(keys);
115  }
116 
118  double max() const override { return toDecisionTreeFactor().max(); }
119 
120  DiscreteFactor::shared_ptr max(size_t nrFrontals) const override {
121  return toDecisionTreeFactor().max(nrFrontals);
122  }
123 
124  DiscreteFactor::shared_ptr max(const Ordering& keys) const override {
125  return toDecisionTreeFactor().max(keys);
126  }
127 
130  throw std::runtime_error("Constraint::error not implemented");
131  }
132 
135  const DiscreteValues& assignment) const override {
136  throw std::runtime_error("Constraint::restrict not implemented");
137  }
138 
142 
144  std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
145  const Names& names = {}) const override {
146  return "`Constraint` on " + std::to_string(size()) + " variables\n";
147  }
148 
150  std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
151  const Names& names = {}) const override {
152  return "<p>Constraint on " + std::to_string(size()) + " variables</p>";
153  }
154 
156 };
157 // DiscreteFactor
158 
159 } // 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:124
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:120
gtsam::DecisionTreeFactor
Definition: DecisionTreeFactor.h:45
gtsam::Constraint::operator*
DecisionTreeFactor operator*(const DecisionTreeFactor &dtf) const override
Multiply by a DecisionTreeFactor and return a DecisionTreeFactor.
Definition: Constraint.h:96
s
RealScalar s
Definition: level1_cplx_impl.h:126
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:101
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:144
gtsam::Constraint::restrict
DiscreteFactor::shared_ptr restrict(const DiscreteValues &assignment) const override
Compute error for each assignment and return as a tree.
Definition: Constraint.h:134
gtsam::Constraint::html
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as html table.
Definition: Constraint.h:150
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:113
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::AlgebraicDecisionTree< Key >
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::max
double max() const override
Find the max value.
Definition: Constraint.h:118
gtsam::Constraint::operator*
virtual DiscreteFactor::shared_ptr operator*(double s) const override
Multiply by a scalar.
Definition: Constraint.h:91
gtsam::Constraint::nrValues
uint64_t nrValues() const override
Get the number of non-zero values contained in this factor.
Definition: Constraint.h:107
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
gtsam::Constraint::errorTree
AlgebraicDecisionTree< Key > errorTree() const override
Compute error for each assignment and return as a tree.
Definition: Constraint.h:129
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:190
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:109
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 Wed Mar 19 2025 03:01:26