gtsam
Loading...
Searching...
No Matches
DiscreteSearch.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
22
25
26#include <queue>
27
28namespace gtsam {
29
44class GTSAM_EXPORT DiscreteSearch {
45 public:
62 struct Slot {
64 std::vector<DiscreteValues> assignments;
65 double heuristic;
66
67 friend std::ostream& operator<<(std::ostream& os, const Slot& slot) {
68 os << "Slot with " << slot.assignments.size()
69 << " assignments, heuristic=" << slot.heuristic;
70 os << ", factor:\n" << slot.factor->markdown() << std::endl;
71 return os;
72 }
73 };
74
79 struct Solution {
80 double error;
81 DiscreteValues assignment;
82 Solution(double err, const DiscreteValues& assign)
83 : error(err), assignment(assign) {}
84 friend std::ostream& operator<<(std::ostream& os, const Solution& sn) {
85 os << "[ error=" << sn.error << " assignment={" << sn.assignment << "}]";
86 return os;
87 }
88 };
89
90 public:
93
106 static DiscreteSearch FromFactorGraph(const DiscreteFactorGraph& factorGraph,
107 const Ordering& ordering,
108 bool buildJunctionTree = false);
109
112
114 DiscreteSearch(const DiscreteJunctionTree& junctionTree);
115
117 DiscreteSearch(const DiscreteBayesNet& bayesNet);
118
120 DiscreteSearch(const DiscreteBayesTree& bayesTree);
121
125
127 void print(const std::string& name = "DiscreteSearch: ",
128 const KeyFormatter& formatter = DefaultKeyFormatter) const;
129
133
135 double lowerBound() const { return lowerBound_; }
136
138 const std::vector<Slot>& slots() const { return slots_; }
139
150 std::vector<Solution> run(size_t K = 1) const;
151
153
154 private:
159 double computeHeuristic();
160
161 double lowerBound_;
162 std::vector<Slot> slots_;
163};
164
165using DiscreteSearchSolution = DiscreteSearch::Solution; // for wrapping
166} // namespace gtsam
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
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
A Bayes net made from discrete conditional distributions.
Definition DiscreteBayesNet.h:38
A Bayes tree representing a Discrete distribution.
Definition DiscreteBayesTree.h:74
Elimination tree for discrete factors.
Definition DiscreteEliminationTree.h:33
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition DiscreteFactor.h:46
A Discrete Factor Graph is a factor graph where all factors are Discrete, i.e.
Definition DiscreteFactorGraph.h:100
An EliminatableClusterTree, i.e., a set of variable clusters with factors, arranged in a tree,...
Definition DiscreteJunctionTree.h:54
double lowerBound() const
Return lower bound on the cost-to-go for the entire search.
Definition DiscreteSearch.h:135
const std::vector< Slot > & slots() const
Read access to the slots.
Definition DiscreteSearch.h:138
void print(const std::string &name="DiscreteSearch: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
Print the tree to cout.
Definition DiscreteSearch.cpp:215
static DiscreteSearch FromFactorGraph(const DiscreteFactorGraph &factorGraph, const Ordering &ordering, bool buildJunctionTree=false)
Construct from a DiscreteFactorGraph.
Definition DiscreteSearch.cpp:179
DiscreteSearch(const DiscreteEliminationTree &etree)
Construct from a DiscreteEliminationTree.
Definition DiscreteSearch.cpp:145
We structure the search as a set of slots, each with a factor and a set of variable assignments that ...
Definition DiscreteSearch.h:62
A map from keys to values.
Definition DiscreteValues.h:34
Definition Ordering.h:33