CSP.h
Go to the documentation of this file.
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 
13 
14 namespace gtsam {
15 
21 class 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) {
32  emplace_shared<BinaryAllDiff>(key1, 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
key1
const Symbol key1('v', 1)
gtsam::DiscreteFactorGraph
Definition: DiscreteFactorGraph.h:99
DiscreteFactorGraph.h
gtsam::CSP::addAllDiff
void addAllDiff(const DiscreteKeys &dkeys)
Add a general AllDiff constraint.
Definition: CSP.h:36
gtsam::DiscreteKeys
DiscreteKeys is a set of keys that can be assembled using the & operator.
Definition: DiscreteKey.h:41
AllDiff.h
key2
const Symbol key2('v', 2)
SingleValue.h
gtsam::CSP::addAllDiff
void addAllDiff(const DiscreteKey &key1, const DiscreteKey &key2)
Add a binary AllDiff constraint.
Definition: CSP.h:31
gtsam::CSP::addSingleValue
void addSingleValue(const DiscreteKey &dkey, size_t value)
Add a unary constraint, allowing only a single value.
Definition: CSP.h:26
gtsam::Domains
std::map< Key, Domain > Domains
Definition: Constraint.h:29
gtsam::VariableIndex
Definition: VariableIndex.h:41
gtsam
traits
Definition: SFMdata.h:40
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::CSP
Definition: CSP.h:21
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Definition: DiscreteKey.h:38
test_callbacks.value
value
Definition: test_callbacks.py:160


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:22