22 #include <boost/format.hpp> 27 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION 39 inverted.insert(make_pair((*
this)[
pos],
pos));
46 vector<int> dummy_groups(variableIndex.
size(), 0);
47 return Ordering::ColamdConstrained(variableIndex, dummy_groups);
52 std::vector<int>& cmember) {
53 gttic(Ordering_COLAMDConstrained);
56 const size_t nVars = variableIndex.
size();
67 const size_t nEntries = variableIndex.
nEntries(), nFactors =
72 vector<int>
A = vector<int>(Alen);
73 vector<int>
p = vector<int>(nVars + 1);
80 for (
auto key_factors: variableIndex) {
83 for(
size_t factorIndex: column) {
84 A[count++] = (
int) factorIndex;
88 keys[index] = key_factors.first;
92 assert((
size_t)count == variableIndex.nEntries());
108 int rv =
ccolamd((
int) nFactors, (
int) nVars, (
int) Alen, &A[0], &p[0],
109 knobs, stats, &cmember[0]);
112 (boost::format(
"ccolamd failed with return value %1%") % rv).
str());
118 gttic(Fill_Ordering);
120 result.resize(nVars);
121 for (
size_t j = 0;
j < nVars; ++
j)
122 result[
j] = keys[p[
j]];
123 gttoc(Fill_Ordering);
130 const KeyVector& constrainLast,
bool forceOrder) {
131 gttic(Ordering_COLAMDConstrainedLast);
133 size_t n = variableIndex.
size();
134 std::vector<int> cmember(n, 0);
140 for (
auto key_factors: variableIndex)
141 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
145 int group = (constrainLast.size() != n ? 1 : 0);
146 for (
Key key: constrainLast) {
147 cmember[keyIndices.at(
key)] = group;
152 return Ordering::ColamdConstrained(variableIndex, cmember);
157 const KeyVector& constrainFirst,
bool forceOrder) {
158 gttic(Ordering_COLAMDConstrainedFirst);
161 size_t n = variableIndex.
size();
162 std::vector<int> cmember(n, none);
167 for (
auto key_factors: variableIndex)
168 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
173 for (
Key key: constrainFirst) {
174 cmember[keyIndices.at(
key)] = group;
179 if (!forceOrder && !constrainFirst.empty())
185 return Ordering::ColamdConstrained(variableIndex, cmember);
191 gttic(Ordering_COLAMDConstrained);
192 size_t n = variableIndex.
size();
193 std::vector<int> cmember(n, 0);
198 for (
auto key_factors: variableIndex)
199 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
203 for(
const key_group&
p: groups) {
205 cmember[keyIndices.at(
p.first)] =
p.second;
208 return Ordering::ColamdConstrained(variableIndex, cmember);
213 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION 214 gttic(Ordering_METIS);
228 vector<idx_t> adj = met.
adj();
238 outputError =
METIS_NodeND(&size, &xadj[0], &adj[0],
nullptr,
nullptr, &perm[0],
243 std::cout <<
"METIS failed during Nested Dissection ordering!\n";
248 for (
size_t j = 0;
j < (
size_t) size; ++
j) {
254 throw runtime_error(
"GTSAM was built without support for Metis-based " 255 "nested dissection");
266 static const size_t varsPerLine = 10;
267 bool endedOnNewline =
false;
268 for (
size_t i = 0;
i <
size(); ++
i) {
269 if (
i % varsPerLine == 0)
270 cout <<
"Position " <<
i <<
": ";
271 if (i % varsPerLine != 0)
273 cout << keyFormatter(at(i));
274 if (i % varsPerLine == varsPerLine - 1) {
276 endedOnNewline =
true;
278 endedOnNewline =
false;
288 return (*
this) == other;
void print(const Matrix &A, const string &s, ostream &stream)
size_t ccolamd_recommended(int nnz, int n_row, int n_col)
const_iterator begin() const
Iterator to the first variable entry.
void ccolamd_set_defaults(double knobs[CCOLAMD_KNOBS])
FastVector< FactorIndex > FactorIndices
Define collection types:
#define CCOLAMD_DENSE_ROW
idx_t idx_t idx_t idx_t idx_t idx_t * iperm
Key intToKey(int32_t value) const
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
int METIS_NodeND(idx_t *nvtxs, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *options, idx_t *perm, idx_t *iperm)
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
const std::vector< int32_t > & xadj() const
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
idx_t idx_t idx_t idx_t idx_t * perm
#define CCOLAMD_DENSE_COL
int ccolamd(int n_row, int n_col, int Alen, int A[], int p[], double knobs[CCOLAMD_KNOBS], int stats[CCOLAMD_STATS], int cmember[])
size_t nFactors() const
The number of factors in the original factor graph.
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
const std::vector< int32_t > & adj() const
std::uint64_t Key
Integer nonlinear key type.