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 
25 
26 #include <queue>
27 
28 namespace gtsam {
29 
44 class 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;
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 
118 
121 
125 
127  void print(const std::string& name = "DiscreteSearch: ",
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 
166 } // namespace gtsam
gtsam::DiscreteSearch::Slot::assignments
std::vector< DiscreteValues > assignments
Definition: DiscreteSearch.h:64
DiscreteBayesNet.h
gtsam::DiscreteSearch::Slot::heuristic
double heuristic
Definition: DiscreteSearch.h:65
name
Annotation for function names.
Definition: attr.h:51
asia::bayesNet
static const DiscreteBayesNet bayesNet
Definition: testDiscreteSearch.cpp:30
gtsam::DiscreteFactorGraph
Definition: DiscreteFactorGraph.h:99
gtsam::DiscreteSearch
DiscreteSearch: Search for the K best solutions.
Definition: DiscreteSearch.h:44
asia::bayesTree
static const DiscreteBayesTree bayesTree
Definition: testDiscreteSearch.cpp:40
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
gtsam::DiscreteSearch::Solution::error
double error
Definition: DiscreteSearch.h:80
gtsam::DiscreteSearch::Solution::assignment
DiscreteValues assignment
Definition: DiscreteSearch.h:81
gtsam::DiscreteSearch::lowerBound
double lowerBound() const
Return lower bound on the cost-to-go for the entire search.
Definition: DiscreteSearch.h:135
gtsam::DiscreteSearch::Slot::operator<<
friend std::ostream & operator<<(std::ostream &os, const Slot &slot)
Definition: DiscreteSearch.h:67
os
ofstream os("timeSchurFactors.csv")
gtsam::DiscreteSearch::Solution
Definition: DiscreteSearch.h:79
asia::factorGraph
static const DiscreteFactorGraph factorGraph(bayesNet)
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::DiscreteSearch::lowerBound_
double lowerBound_
Lower bound on the cost-to-go for the entire search.
Definition: DiscreteSearch.h:161
gtsam::Solution
DiscreteSearch::Solution Solution
Definition: DiscreteSearch.cpp:26
gtsam::DiscreteJunctionTree
Definition: DiscreteJunctionTree.h:53
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:145
gtsam::DiscreteBayesNet
Definition: DiscreteBayesNet.h:38
gtsam::DiscreteEliminationTree
Elimination tree for discrete factors.
Definition: DiscreteEliminationTree.h:31
gtsam::KeyFormatter
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
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
DiscreteBayesTree.h
Discrete Bayes Tree, the result of eliminating a DiscreteJunctionTree.
ordering
static enum @1096 ordering
sn
static double sn[6]
Definition: fresnl.c:63
gtsam::DiscreteSearch::Solution::Solution
Solution(double err, const DiscreteValues &assign)
Definition: DiscreteSearch.h:82
gtsam::DiscreteSearch::Slot
Definition: DiscreteSearch.h:62
gtsam
traits
Definition: SFMdata.h:40
gtsam::DiscreteFactor::shared_ptr
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
Definition: DiscreteFactor.h:45
error
static double error
Definition: testRot3.cpp:37
K
#define K
Definition: igam.h:8
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
gtsam::DiscreteSearch::slots
const std::vector< Slot > & slots() const
Read access to the slots.
Definition: DiscreteSearch.h:138
gtsam::DiscreteBayesTree
A Bayes tree representing a Discrete distribution.
Definition: DiscreteBayesTree.h:73
gtsam::DiscreteSearch::Slot::factor
DiscreteFactor::shared_ptr factor
Definition: DiscreteSearch.h:63
gtsam::DiscreteSearch::slots_
std::vector< Slot > slots_
The slots to fill in the search.
Definition: DiscreteSearch.h:162
gtsam::Ordering
Definition: inference/Ordering.h:33
gtsam::DiscreteSearch::Solution::operator<<
friend std::ostream & operator<<(std::ostream &os, const Solution &sn)
Definition: DiscreteSearch.h:84


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:36