gtsam 4.2
gtsam
Loading...
Searching...
No Matches
CSP.h
1/*
2 * CSP.h
3 * @brief Constraint Satisfaction Problem class
4 * @date Feb 6, 2012
5 * @author Frank Dellaert
6 */
7
8#pragma once
9
11#include <gtsam_unstable/discrete/AllDiff.h>
12#include <gtsam_unstable/discrete/SingleValue.h>
13
14namespace gtsam {
15
21class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph {
22 public:
24
26 void addSingleValue(const DiscreteKey& dkey, size_t value) {
27 emplace_shared<SingleValue>(dkey, value);
28 }
29
31 void addAllDiff(const DiscreteKey& key1, const DiscreteKey& key2) {
33 }
34
36 void addAllDiff(const DiscreteKeys& dkeys) { emplace_shared<AllDiff>(dkeys); }
37
38 // /** return product of all factors as a single factor */
39 // DecisionTreeFactor product() const {
40 // DecisionTreeFactor result;
41 // for(const sharedFactor& factor: *this)
42 // if (factor) result = (*factor) * result;
43 // return result;
44 // }
45
46 // /*
47 // * Perform loopy belief propagation
48 // * True belief propagation would check for each value in domain
49 // * whether any satisfying separator assignment can be found.
50 // * This corresponds to hyper-arc consistency in CSP speak.
51 // * This can be done by creating a mini-factor graph and search.
52 // * For a nine-by-nine Sudoku, the search tree will be 8+6+6=20 levels
53 // deep.
54 // * It will be very expensive to exclude values that way.
55 // */
56 // void applyBeliefPropagation(size_t maxIterations = 10) const;
57
58 /*
59 * Apply arc-consistency ~ Approximate loopy belief propagation
60 * We need to give the domains to a constraint, and it returns
61 * a domain whose values don't conflict in the arc-consistency way.
62 * TODO: should get cardinality from DiscreteKeys
63 */
64 Domains runArcConsistency(size_t cardinality,
65 size_t maxIterations = 10) const;
66
68 bool runArcConsistency(const VariableIndex& index, Domains* domains) const;
69
70 /*
71 * Create a new CSP, applying the given Domain constraints.
72 */
73 CSP partiallyApply(const Domains& domains) const;
74}; // CSP
75
76} // namespace gtsam
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
DiscreteFactorGraph()
Default constructor.
Definition DiscreteFactorGraph.h:114
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
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Definition FactorGraph.h:192
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:43
Constraint Satisfaction Problem class A specialization of a DiscreteFactorGraph.
Definition CSP.h:21
void addSingleValue(const DiscreteKey &dkey, size_t value)
Add a unary constraint, allowing only a single value.
Definition CSP.h:26
void addAllDiff(const DiscreteKeys &dkeys)
Add a general AllDiff constraint.
Definition CSP.h:36
DiscreteValues Values
backwards compatibility
Definition CSP.h:23
void addAllDiff(const DiscreteKey &key1, const DiscreteKey &key2)
Add a binary AllDiff constraint.
Definition CSP.h:31