gtsam
Loading...
Searching...
No Matches
IndexedJunctionTree.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
17
18#pragma once
19
20#include <gtsam/base/types.h>
21#include <gtsam/inference/Key.h>
27
28#include <cstddef>
29#include <unordered_set>
30
31namespace gtsam {
32
33namespace internal {
35class IndexedSymbolicFactor : public SymbolicFactor {
36 public:
37 size_t index_;
38 IndexedSymbolicFactor(const KeyVector& keys, size_t index)
39 : SymbolicFactor(), index_(index) {
40 keys_ = keys;
41 }
42};
43} // namespace internal
44
58class GTSAM_EXPORT IndexedJunctionTree : public SymbolicJunctionTree {
59 public:
61
71 template <typename GRAPH>
72 IndexedJunctionTree(const GRAPH& graph, const Ordering& ordering,
73 const std::unordered_set<Key>& fixedKeys = {})
74 : SymbolicJunctionTree(makeIndexedEliminationTree(graph, ordering, fixedKeys)) {}
75
76 private:
77 template <typename GRAPH>
78 static SymbolicFactorGraph buildIndexedSymbolicFactorGraph(
79 const GRAPH& graph, const std::unordered_set<Key>& fixedKeys) {
80 SymbolicFactorGraph symbolicGraph;
81 symbolicGraph.reserve(graph.size());
82 for (size_t i = 0; i < graph.size(); ++i) {
83 if (!graph.at(i)) continue;
84 KeyVector keys;
85 keys.reserve(graph[i]->size());
86 for (Key key : graph[i]->keys()) {
87 if (!fixedKeys.count(key)) keys.push_back(key);
88 }
89 // Skip factors that are fully constrained away.
90 if (keys.empty()) continue;
91 symbolicGraph.emplace_shared<internal::IndexedSymbolicFactor>(keys, i);
92 }
93 return symbolicGraph;
94 }
95
96 template <typename GRAPH>
97 static SymbolicEliminationTree makeIndexedEliminationTree(
98 const GRAPH& graph, const Ordering& ordering,
99 const std::unordered_set<Key>& fixedKeys) {
100 SymbolicFactorGraph symbolicGraph =
101 buildIndexedSymbolicFactorGraph(graph, fixedKeys);
102 return SymbolicEliminationTree(std::move(symbolicGraph), ordering);
103 }
104};
105} // namespace gtsam
106
Typedefs for easier changing of types.
Variable ordering for the elimination algorithm.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
const KeyVector & keys() const
Access the factor's involved variable keys.
Definition Factor.h:143
KeyVector keys_
The keys involved in this factor.
Definition Factor.h:88
Definition Ordering.h:33
SymbolicJunctionTree(const SymbolicEliminationTree &eliminationTree)
Build the elimination tree of a factor graph using pre-computed column structure.
Definition SymbolicJunctionTree.cpp:30
IndexedJunctionTree(const GRAPH &graph, const Ordering &ordering, const std::unordered_set< Key > &fixedKeys={})
Construct an IndexedJunctionTree from any factor graph, ordering, and optional set of fixed keys to f...
Definition IndexedJunctionTree.h:72
SymbolicFactor()
Default constructor for I/O.
Definition SymbolicFactor.h:53
A EliminatableClusterTree, i.e., a set of variable clusters with factors, arranged in a tree,...
Definition SymbolicJunctionTree.h:51
SymbolicJunctionTree(const SymbolicEliminationTree &eliminationTree)
Build the elimination tree of a factor graph using pre-computed column structure.
Definition SymbolicJunctionTree.cpp:30