gtsam
Loading...
Searching...
No Matches
MetisIndex-inl.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/timing.h>
21
22#include <map>
23#include <vector>
24
25namespace gtsam {
26
27/* ************************************************************************* */
28template<class FactorGraphType>
29void MetisIndex::augment(const FactorGraphType& factors) {
30 std::map<int32_t, std::set<int32_t> > iAdjMap; // Stores a set of keys that are adjacent to key x, with adjMap.first
31 std::map<int32_t, std::set<int32_t> >::iterator iAdjMapIt;
32 KeySet keySet;
33
34 /* ********** Convert to CSR format ********** */
35 // Assuming that vertex numbering starts from 0 (C style),
36 // then the adjacency list of vertex i is stored in array adjncy
37 // starting at index xadj[i] and ending at(but not including)
38 // index xadj[i + 1](i.e., adjncy[xadj[i]] through
39 // and including adjncy[xadj[i + 1] - 1]).
40 int32_t keyCounter = 0;
41
42 // First: Record a copy of each key inside the factor graph and create a
43 // key to integer mapping. This is referenced during the adjacency step
44 for (size_t i = 0; i < factors.size(); i++) {
45 if (factors[i]) {
46 for(const Key& key: *factors[i]) {
47 keySet.insert(keySet.end(), key); // Keep a track of all unique keys
48 if (intKeyBMap_.left.find(key) == intKeyBMap_.left.end()) {
49 intKeyBMap_.insert(key, keyCounter);
50 keyCounter++;
51 }
52 }
53 }
54 }
55
56 // Create an adjacency mapping that stores the set of all adjacent keys for every key
57 for (size_t i = 0; i < factors.size(); i++) {
58 if (factors[i]) {
59 for(const Key& k1: *factors[i])
60 for(const Key& k2: *factors[i])
61 if (k1 != k2) {
62 // Store both in Key and int32_t format
63 int i = intKeyBMap_.left.at(k1);
64 int j = intKeyBMap_.left.at(k2);
65 iAdjMap[i].insert(iAdjMap[i].end(), j);
66 }
67 }
68 }
69
70 // Number of keys referenced in this factor graph
71 nKeys_ = keySet.size();
72
73 xadj_.push_back(0); // Always set the first index to zero
74 for (iAdjMapIt = iAdjMap.begin(); iAdjMapIt != iAdjMap.end(); ++iAdjMapIt) {
75 std::vector<int32_t> temp;
76 // Copy from the FastSet into a temporary vector
77 std::copy(iAdjMapIt->second.begin(), iAdjMapIt->second.end(),
78 std::back_inserter(temp));
79 // Insert each index's set in order by appending them to the end of adj_
80 adj_.insert(adj_.end(), temp.begin(), temp.end());
81 //adj_.push_back(temp);
82 xadj_.push_back((int32_t) adj_.size());
83 }
84}
85
86} // \ gtsam
Timing utilities.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
void augment(const FactorGraphType &factors)
Augment the variable index with new factors.
Definition MetisIndex-inl.h:29