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 
18 #pragma once
19 
20 #include <map>
21 #include <vector>
22 
23 namespace gtsam {
24 
25 /* ************************************************************************* */
26 template<class FACTORGRAPH>
27 void MetisIndex::augment(const FACTORGRAPH& factors) {
28  std::map<int32_t, std::set<int32_t> > iAdjMap; // Stores a set of keys that are adjacent to key x, with adjMap.first
29  std::map<int32_t, std::set<int32_t> >::iterator iAdjMapIt;
30  std::set<Key> keySet;
31 
32  /* ********** Convert to CSR format ********** */
33  // Assuming that vertex numbering starts from 0 (C style),
34  // then the adjacency list of vertex i is stored in array adjncy
35  // starting at index xadj[i] and ending at(but not including)
36  // index xadj[i + 1](i.e., adjncy[xadj[i]] through
37  // and including adjncy[xadj[i + 1] - 1]).
38  int32_t keyCounter = 0;
39 
40  // First: Record a copy of each key inside the factorgraph and create a
41  // key to integer mapping. This is referenced during the adjaceny step
42  for (size_t i = 0; i < factors.size(); i++) {
43  if (factors[i]) {
44  for(const Key& key: *factors[i]) {
45  keySet.insert(keySet.end(), key); // Keep a track of all unique keys
46  if (intKeyBMap_.left.find(key) == intKeyBMap_.left.end()) {
47  intKeyBMap_.insert(key, keyCounter);
48  keyCounter++;
49  }
50  }
51  }
52  }
53 
54  // Create an adjacency mapping that stores the set of all adjacent keys for every key
55  for (size_t i = 0; i < factors.size(); i++) {
56  if (factors[i]) {
57  for(const Key& k1: *factors[i])
58  for(const Key& k2: *factors[i])
59  if (k1 != k2) {
60  // Store both in Key and int32_t format
61  int i = intKeyBMap_.left.at(k1);
62  int j = intKeyBMap_.left.at(k2);
63  iAdjMap[i].insert(iAdjMap[i].end(), j);
64  }
65  }
66  }
67 
68  // Number of keys referenced in this factor graph
69  nKeys_ = keySet.size();
70 
71  xadj_.push_back(0); // Always set the first index to zero
72  for (iAdjMapIt = iAdjMap.begin(); iAdjMapIt != iAdjMap.end(); ++iAdjMapIt) {
73  std::vector<int32_t> temp;
74  // Copy from the FastSet into a temporary vector
75  std::copy(iAdjMapIt->second.begin(), iAdjMapIt->second.end(),
76  std::back_inserter(temp));
77  // Insert each index's set in order by appending them to the end of adj_
78  adj_.insert(adj_.end(), temp.begin(), temp.end());
79  //adj_.push_back(temp);
80  xadj_.push_back((int32_t) adj_.size());
81  }
82 }
83 
84 } // \ gtsam
gtsam::MetisIndex::augment
void augment(const FACTORGRAPH &factors)
Definition: MetisIndex-inl.h:27
gtsam::MetisIndex::nKeys_
size_t nKeys_
Definition: MetisIndex.h:55
gtsam::MetisIndex::intKeyBMap_
BiMap intKeyBMap_
Definition: MetisIndex.h:54
simple_graph::factors
const GaussianFactorGraph factors
Definition: testJacobianFactor.cpp:213
iterator
Definition: pytypes.h:1460
gtsam::MetisIndex::BiMap::insert
void insert(const Key &left_value, const int32_t &right_value)
Definition: MetisIndex.h:46
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
k1
double k1(double x)
Definition: k1.c:133
gtsam::MetisIndex::BiMap::left
std::map< Key, int32_t > left
Definition: MetisIndex.h:44
gtsam::MetisIndex::xadj_
std::vector< int32_t > xadj_
Definition: MetisIndex.h:52
gtsam::MetisIndex::adj_
std::vector< int32_t > adj_
Definition: MetisIndex.h:53
key
const gtsam::Symbol key('X', 0)
gtsam
traits
Definition: SFMdata.h:40
int32_t
signed int int32_t
Definition: ms_stdint.h:82
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:10