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/discrete/AllDiff.h>
12#include <gtsam/discrete/SingleValue.h>
13#include <gtsam_unstable/dllexport.h>
14
15namespace gtsam {
16
22class GTSAM_UNSTABLE_EXPORT CSP : public DiscreteFactorGraph {
23 public:
25
27 void addSingleValue(const DiscreteKey& dkey, size_t value) {
28 emplace_shared<SingleValue>(dkey, value);
29 }
30
32 void addAllDiff(const DiscreteKey& key1, const DiscreteKey& key2) {
34 }
35
37 void addAllDiff(const DiscreteKeys& dkeys) { emplace_shared<AllDiff>(dkeys); }
38
39 // /** return product of all factors as a single factor */
40 // DecisionTreeFactor product() const {
41 // DecisionTreeFactor result;
42 // for(const sharedFactor& factor: *this)
43 // if (factor) result = (*factor) * result;
44 // return result;
45 // }
46
47 // /*
48 // * Perform loopy belief propagation
49 // * True belief propagation would check for each value in domain
50 // * whether any satisfying separator assignment can be found.
51 // * This corresponds to hyper-arc consistency in CSP speak.
52 // * This can be done by creating a mini-factor graph and search.
53 // * For a nine-by-nine Sudoku, the search tree will be 8+6+6=20 levels
54 // deep.
55 // * It will be very expensive to exclude values that way.
56 // */
57 // void applyBeliefPropagation(size_t maxIterations = 10) const;
58
59 /*
60 * Apply arc-consistency ~ Approximate loopy belief propagation
61 * We need to give the domains to a constraint, and it returns
62 * a domain whose values don't conflict in the arc-consistency way.
63 * TODO: should get cardinality from DiscreteKeys
64 */
65 Domains runArcConsistency(size_t cardinality,
66 size_t maxIterations = 10) const;
67
69 bool runArcConsistency(const VariableIndex& index, Domains* domains) const;
70
71 /*
72 * Create a new CSP, applying the given Domain constraints.
73 */
74 CSP partiallyApply(const Domains& domains) const;
75}; // CSP
76
77} // namespace gtsam
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:38
Global functions in a separate testing namespace.
Definition chartTesting.h:28
DiscreteFactorGraph()
Default constructor.
Definition DiscreteFactorGraph.h:113
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition DiscreteKey.h:41
A map from keys to values.
Definition DiscreteValues.h:34
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Definition FactorGraph.h:153
The VariableIndex class computes and stores the block column structure of a factor graph.
Definition VariableIndex.h:41
Constraint Satisfaction Problem class A specialization of a DiscreteFactorGraph.
Definition CSP.h:22
void addSingleValue(const DiscreteKey &dkey, size_t value)
Add a unary constraint, allowing only a single value.
Definition CSP.h:27
void addAllDiff(const DiscreteKeys &dkeys)
Add a general AllDiff constraint.
Definition CSP.h:37
DiscreteValues Values
backwards compatibility
Definition CSP.h:24
void addAllDiff(const DiscreteKey &key1, const DiscreteKey &key2)
Add a binary AllDiff constraint.
Definition CSP.h:32