gtsam
Loading...
Searching...
No Matches
MetisIndex.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
16
17#pragma once
18
19
20#include <gtsam/inference/Key.h>
22#include <gtsam/base/types.h>
23
24#include <vector>
25#include <map>
26#include <unordered_map>
27#include <iostream>
28
29namespace gtsam {
37class GTSAM_EXPORT MetisIndex {
38public:
39 typedef std::shared_ptr<MetisIndex> shared_ptr;
40
41private:
42 // Stores Key <-> integer value relationship
43 struct BiMap {
44 std::map<Key, int32_t> left;
45 std::unordered_map<int32_t, Key> right;
46 void insert(const Key& left_value, const int32_t& right_value) {
47 left[left_value] = right_value;
48 right[right_value] = left_value;
49 }
50 };
51
52 std::vector<int32_t> xadj_; // Index of node's adjacency list in adj
53 std::vector<int32_t> adj_; // Stores adjacency lists of all nodes, appended into a single vector
54 BiMap intKeyBMap_; // Stores Key <-> integer value relationship
55 size_t nKeys_;
56
57public:
60
62 MetisIndex() : nKeys_(0) {}
63
64 template<class FactorGraphType>
65 MetisIndex(const FactorGraphType& factorGraph) :
66 nKeys_(0) {
67 augment(factorGraph);
68 }
69
70 ~MetisIndex() {}
71
75
80 template<class FactorGraphType>
81 void augment(const FactorGraphType& factors);
82
83 const std::vector<int32_t>& xadj() const { return xadj_; }
84 const std::vector<int32_t>& adj() const { return adj_; }
85 size_t nValues() const { return nKeys_; }
86
87 Key intToKey(int32_t value) const { return intKeyBMap_.right.find(value)->second; }
88
92
94 void print(const std::string& str = "MetisIndex:") const {
95 std::cout << str << "\nxadj_: ";
96 for (const auto& x : xadj_) std::cout << x << " ";
97 std::cout << "\nadj_: ";
98 for (const auto& x : adj_) std::cout << x << " ";
99 std::cout << "\nKey <-> Index: ";
100 for (const auto& [i, k] : intKeyBMap_.left) std::cout << i << " <-> " << k << ", ";
101 std::cout << std::endl;
102 }
103
105};
106
107} // \ namespace gtsam
108
Typedefs for easier changing of types.
Factor Graph Base Class.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
The MetisIndex class converts a factor graph into the Compressed Sparse Row format for use in METIS a...
Definition MetisIndex.h:37
void print(const std::string &str="MetisIndex:") const
print to std::cout
Definition MetisIndex.h:94
MetisIndex()
Default constructor, creates empty MetisIndex.
Definition MetisIndex.h:62