23#include <gtsam/dllexport.h>
30using Domains = std::map<Key, Domain>;
38 typedef std::shared_ptr<Constraint> shared_ptr;
51 template <
class KeyIterator>
86 return this->toDecisionTreeFactor() * s;
91 return this->toDecisionTreeFactor() * dtf;
97 return this->toDecisionTreeFactor() / df;
104 return toDecisionTreeFactor().sum(nrFrontals);
108 return toDecisionTreeFactor().sum(
keys);
112 double max()
const override {
return toDecisionTreeFactor().max(); }
115 return toDecisionTreeFactor().max(nrFrontals);
119 return toDecisionTreeFactor().max(
keys);
124 throw std::runtime_error(
"Constraint::error not implemented");
130 throw std::runtime_error(
"Constraint::restrict not implemented");
139 const Names& names = {})
const override {
140 return "`Constraint` on " + std::to_string(size()) +
" variables\n";
145 const Names& names = {})
const override {
146 return "<p>Constraint on " + std::to_string(size()) +
" variables</p>";
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
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:43
An algebraic decision tree fixes the range of a DecisionTree to double.
Definition AlgebraicDecisionTree.h:41
virtual DiscreteFactor::shared_ptr operator*(double s) const override
Multiply by a scalar.
Definition Constraint.h:85
~Constraint() override
Virtual destructor.
Definition Constraint.h:63
virtual shared_ptr partiallyApply(const Domains &) const =0
Partially apply known values, domain version.
Constraint(const KeyVector &js)
Construct n-way constraint factor.
Definition Constraint.h:48
Constraint()
Default constructor for I/O.
DiscreteFactor::shared_ptr max(size_t nrFrontals) const override
Create new factor by maximizing over all values with the same separator.
Definition Constraint.h:114
DiscreteFactor::shared_ptr sum(const Ordering &keys) const override
Create new factor by summing all values with the same separator values.
Definition Constraint.h:107
DiscreteFactor::shared_ptr operator/(const DiscreteFactor::shared_ptr &df) const override
divide by DiscreteFactor::shared_ptr f (safely)
Definition Constraint.h:95
Constraint(Key j1, Key j2)
Construct binary constraint factor.
Definition Constraint.h:45
DiscreteFactor::shared_ptr restrict(const DiscreteValues &assignment) const override
Compute error for each assignment and return as a tree.
Definition Constraint.h:128
virtual shared_ptr partiallyApply(const DiscreteValues &) const =0
Partially apply known values.
double max() const override
Find the max value.
Definition Constraint.h:112
Constraint(KeyIterator beginKey, KeyIterator endKey)
Construct from a key iterator range.
Definition Constraint.h:52
AlgebraicDecisionTree< Key > errorTree() const override
Compute error for each assignment and return as a tree.
Definition Constraint.h:123
DecisionTreeFactor operator*(const DecisionTreeFactor &dtf) const override
Multiply by a DecisionTreeFactor and return a DecisionTreeFactor.
Definition Constraint.h:90
DiscreteFactor::shared_ptr max(const Ordering &keys) const override
Create new factor by maximizing over all values with the same separator.
Definition Constraint.h:118
std::string markdown(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as markdown table.
Definition Constraint.h:138
DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override
Create new factor by summing all values with the same separator values.
Definition Constraint.h:103
Constraint(Key j)
Construct unary constraint factor.
Definition Constraint.h:42
std::string html(const KeyFormatter &keyFormatter=DefaultKeyFormatter, const Names &names={}) const override
Render as html table.
Definition Constraint.h:144
uint64_t nrValues() const override
Get the number of non-zero values contained in this factor.
Definition Constraint.h:101
virtual bool ensureArcConsistency(Key j, Domains *domains) const =0
Ensure Arc-consistency by checking every possible value of domain j.
A discrete probabilistic factor.
Definition DecisionTreeFactor.h:42
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition DiscreteFactor.h:46
DiscreteValues::Names Names
Translation table from values to strings.
Definition DiscreteFactor.h:194
DiscreteFactor()
Default constructor creates empty factor.
Definition DiscreteFactor.h:65
A map from keys to values.
Definition DiscreteValues.h:34
The Domain class represents a constraint that restricts the possible values a particular variable,...
Definition Domain.h:21
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143