gtsam
Loading...
Searching...
No Matches
MultifrontalSolver.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
18
19#pragma once
20
22#include <gtsam/inference/Key.h>
28
29#include <iosfwd>
30#include <map>
31#include <memory>
32#include <stdexcept>
33#include <string>
34#include <unordered_set>
35#include <vector>
36
37namespace gtsam {
38
41
46class GTSAM_EXPORT MultifrontalSolverNotSupported : public std::runtime_error {
47 public:
48 explicit MultifrontalSolverNotSupported(const std::string& reason)
49 : std::runtime_error(BuildMessage(reason)) {}
50
51 private:
52 static std::string BuildMessage(const std::string& reason) {
53 std::string message = "MultifrontalSolver not supported: " + reason + ". ";
54 message +=
55 "Enable GTSAM_ALLOW_DEPRECATED_SINCE_V43 to default to the legacy "
56 "solver, or set linearSolverType = MULTIFRONTAL_CHOLESKY.";
57 return message;
58 }
59};
60
81class GTSAM_EXPORT MultifrontalSolver
82 : public ForestTraversal<MultifrontalSolver, MultifrontalClique> {
83 public:
86
89 std::map<Key, size_t> dims;
90 std::unordered_set<Key> fixedKeys;
93 std::vector<size_t> rowCounts;
94 };
95
97 using CliquePtr = std::shared_ptr<MultifrontalClique>;
100
101 protected:
102 std::vector<CliquePtr> roots_;
103 std::vector<CliquePtr> cliques_;
104 std::map<Key, size_t> dims_;
106 std::unordered_set<Key> fixedKeys_;
107 bool loaded_ = false;
108 bool eliminated_ = false;
109 bool partiallyEliminated_ = false;
111 size_t firstPhaseSize_ = 0;
113 double lastOldError_ = 0.0;
114 double lastNewError_ = 0.0;
115 bool hasDeltaError_ = false;
116
117 public:
130 MultifrontalSolver(const GaussianFactorGraph& graph, const Ordering& ordering,
131 const Parameters& params = Parameters{});
132
138 MultifrontalSolver(const GaussianFactorGraph& graph, const Ordering& ordering,
139 size_t firstPhaseSize,
140 const Parameters& params = Parameters{});
141
149 MultifrontalSolver(PrecomputedData data, const Ordering& ordering,
150 const Parameters& params = Parameters{});
151
153 MultifrontalSolver(PrecomputedData data, const Ordering& ordering,
154 size_t firstPhaseSize,
155 const Parameters& params = Parameters{});
156
169 static PrecomputedData Precompute(const GaussianFactorGraph& graph,
170 const Ordering& ordering);
171
182 void load(const GaussianFactorGraph& graph);
183
188 void eliminateInPlace();
189
194 void eliminateInPlace(const GaussianFactorGraph& graph);
195
200 void eliminatePartialInPlace();
201
203 void eliminatePartialInPlace(const GaussianFactorGraph& graph);
204
210 GaussianFactorGraph remainingFactorGraph() const;
211
218 GaussianBayesTree computeBayesTree() const;
219
225 const VectorValues& updateSolution();
226
230 const VectorValues& updateSolution(const VectorValues& retainedSolution);
231
236 double deltaError(double* oldError = nullptr,
237 double* newError = nullptr) const;
238
240 const std::vector<CliquePtr>& roots() const { return roots_; }
241
243 size_t cliqueCount() const { return cliques_.size(); }
244
246 void print(const std::string& s = "",
247 const KeyFormatter& keyFormatter = DefaultKeyFormatter) const;
248
250 friend std::ostream& operator<<(std::ostream& os,
251 const MultifrontalSolver& solver);
252};
253
254std::ostream& operator<<(std::ostream& os, const MultifrontalSolver& solver);
255
256} // namespace gtsam
Forest traversal helpers with optional TBB acceleration.
Variable ordering for the elimination algorithm.
Linear Factor Graph where all factors are Gaussians.
Parameters for the imperative multifrontal solver.
Factor Graph Values.
Build a symbolic junction tree that stores original factor indices.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
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
ForestTraversal(size_t numThreads=std::thread::hardware_concurrency())
Definition ForestTraversal.h:68
Definition Ordering.h:33
A Bayes tree representing a Gaussian density.
Definition GaussianBayesTree.h:53
A Linear Factor Graph is a factor graph where all factors are Gaussian, i.e.
Definition GaussianFactorGraph.h:77
Imperative multifrontal clique structure used by MultifrontalSolver.
Definition MultifrontalClique.h:71
Parameters for gtsam::MultifrontalSolver.
Definition MultifrontalParameters.h:37
Imperative-style multifrontal solver for Gaussian factor graphs.
Definition MultifrontalSolver.h:82
size_t cliqueCount() const
Get the total number of cliques in the solver.
Definition MultifrontalSolver.h:243
double lastOldError_
Cached old linearized error.
Definition MultifrontalSolver.h:113
MultifrontalParameters Parameters
Tuning parameters for traversal and reporting.
Definition MultifrontalSolver.h:85
VectorValues solution_
Cached solution vector.
Definition MultifrontalSolver.h:105
const std::vector< CliquePtr > & roots() const
Accessor for the roots of the elimination tree.
Definition MultifrontalSolver.h:240
Parameters params_
Tunable solver parameters.
Definition MultifrontalSolver.h:112
MultifrontalSolver(const GaussianFactorGraph &graph, const Ordering &ordering, const Parameters &params=Parameters{})
Construct the solver from a factor graph and an ordering.
Definition MultifrontalSolver.cpp:529
MultifrontalClique Node
Node type for tree traversal utilities.
Definition MultifrontalSolver.h:99
bool partiallyEliminated_
Whether partial elimination ran.
Definition MultifrontalSolver.h:109
Ordering ordering_
Complete variable ordering.
Definition MultifrontalSolver.h:110
std::shared_ptr< MultifrontalClique > CliquePtr
Shared pointer to a MultifrontalClique.
Definition MultifrontalSolver.h:97
std::vector< CliquePtr > cliques_
All cliques in the solver.
Definition MultifrontalSolver.h:103
std::unordered_set< Key > fixedKeys_
Keys fixed by constrained factors.
Definition MultifrontalSolver.h:106
bool hasDeltaError_
Whether updateSolution computed it.
Definition MultifrontalSolver.h:115
bool eliminated_
Whether eliminateInPlace() ran.
Definition MultifrontalSolver.h:108
double lastNewError_
Cached new linearized error.
Definition MultifrontalSolver.h:114
size_t firstPhaseSize_
Prefix eliminated in partial mode.
Definition MultifrontalSolver.h:111
bool loaded_
Whether load() has been called.
Definition MultifrontalSolver.h:107
std::map< Key, size_t > dims_
Map from variable key to dimension.
Definition MultifrontalSolver.h:104
std::vector< CliquePtr > roots_
Roots of the elimination tree.
Definition MultifrontalSolver.h:102
Precomputed symbolic and sizing data for multifrontal solver construction.
Definition MultifrontalSolver.h:88
std::vector< size_t > rowCounts
Row counts indexed by factor index.
Definition MultifrontalSolver.h:93
std::map< Key, size_t > dims
Map from variable key to dimension.
Definition MultifrontalSolver.h:89
IndexedJunctionTree indexedJunctionTree
Precomputed indexed junction tree.
Definition MultifrontalSolver.h:92
std::unordered_set< Key > fixedKeys
Keys fixed by constrained factors.
Definition MultifrontalSolver.h:90
VectorValues represents a collection of vector-valued variables associated each with a unique integer...
Definition VectorValues.h:73
A symbolic junction tree whose factors record the original factor indices from a corresponding (non-s...
Definition IndexedJunctionTree.h:58