25 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION 37 inverted.insert(make_pair((*
this)[
pos],
pos));
44 vector<int> dummy_groups(variableIndex.
size(), 0);
45 return Ordering::ColamdConstrained(variableIndex, dummy_groups);
50 std::vector<int>& cmember) {
51 gttic(Ordering_COLAMDConstrained);
54 const size_t nVars = variableIndex.
size();
65 const size_t nEntries = variableIndex.
nEntries(), nFactors =
70 vector<int>
A = vector<int>(Alen);
71 vector<int>
p = vector<int>(nVars + 1);
78 for (
auto key_factors: variableIndex) {
81 for(
size_t factorIndex: column) {
82 A[count++] = (
int) factorIndex;
86 keys[index] = key_factors.first;
90 assert((
size_t)count == variableIndex.nEntries());
106 int rv =
ccolamd((
int) nFactors, (
int) nVars, (
int) Alen, &A[0], &p[0],
107 knobs, stats, &cmember[0]);
109 throw runtime_error(
"ccolamd failed with return value " + to_string(rv));
116 gttic(Fill_Ordering);
118 result.resize(nVars);
119 for (
size_t j = 0;
j < nVars; ++
j)
120 result[
j] = keys[p[
j]];
121 gttoc(Fill_Ordering);
128 const KeyVector& constrainLast,
bool forceOrder) {
129 gttic(Ordering_COLAMDConstrainedLast);
131 size_t n = variableIndex.
size();
132 std::vector<int> cmember(n, 0);
138 for (
auto key_factors: variableIndex)
139 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
143 int group = (constrainLast.size() != n ? 1 : 0);
144 for (
Key key: constrainLast) {
145 cmember[keyIndices.at(
key)] = group;
150 return Ordering::ColamdConstrained(variableIndex, cmember);
155 const KeyVector& constrainFirst,
bool forceOrder) {
156 gttic(Ordering_COLAMDConstrainedFirst);
159 size_t n = variableIndex.
size();
160 std::vector<int> cmember(n, none);
165 for (
auto key_factors: variableIndex)
166 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
171 for (
Key key: constrainFirst) {
172 cmember[keyIndices.at(
key)] = group;
177 if (!forceOrder && !constrainFirst.empty())
183 return Ordering::ColamdConstrained(variableIndex, cmember);
189 gttic(Ordering_COLAMDConstrained);
190 size_t n = variableIndex.
size();
191 std::vector<int> cmember(n, 0);
196 for (
auto key_factors: variableIndex)
197 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first, j++));
201 for(
const key_group&
p: groups) {
203 cmember[keyIndices.at(
p.first)] =
p.second;
206 return Ordering::ColamdConstrained(variableIndex, cmember);
211 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION 212 gttic(Ordering_METIS);
226 vector<idx_t> adj = met.
adj();
236 outputError =
METIS_NodeND(&size, &xadj[0], &adj[0],
nullptr,
nullptr, &perm[0],
241 std::cout <<
"METIS failed during Nested Dissection ordering!\n";
246 for (
size_t j = 0;
j < (
size_t) size; ++
j) {
252 throw runtime_error(
"GTSAM was built without support for Metis-based " 253 "nested dissection");
264 static const size_t varsPerLine = 10;
265 bool endedOnNewline =
false;
266 for (
size_t i = 0;
i <
size(); ++
i) {
267 if (
i % varsPerLine == 0)
268 cout <<
"Position " <<
i <<
": ";
269 if (i % varsPerLine != 0)
271 cout << keyFormatter(at(i));
272 if (i % varsPerLine == varsPerLine - 1) {
274 endedOnNewline =
true;
276 endedOnNewline =
false;
286 this->
insert(this->
end(), keys.begin(), keys.end());
291 bool Ordering::contains(
const Key&
key)
const {
292 return std::find(this->begin(), this->
end(), key) != this->
end();
297 return (*
this) ==
other;
const gtsam::Symbol key('X', 0)
size_t ccolamd_recommended(int nnz, int n_row, int n_col)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 & operator+=(bfloat16 &a, const bfloat16 &b)
Key intToKey(int32_t value) const
void ccolamd_set_defaults(double knobs [CCOLAMD_KNOBS])
size_t size() const
The number of variable entries. This is equal to the number of unique variable Keys.
#define CCOLAMD_DENSE_ROW
size_t nEntries() const
The number of nonzero blocks, i.e. the number of variable-factor entries.
const std::vector< int32_t > & adj() const
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
size_t nFactors() const
The number of factors in the original factor graph.
idx_t idx_t idx_t idx_t idx_t idx_t * iperm
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
int METIS_NodeND(idx_t *nvtxs, idx_t *xadj, idx_t *adjncy, idx_t *vwgt, idx_t *options, idx_t *perm, idx_t *iperm)
const std::vector< int32_t > & xadj() const
FastVector< FactorIndex > FactorIndices
Define collection types:
idx_t idx_t idx_t idx_t idx_t * perm
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
#define CCOLAMD_DENSE_COL
const_iterator begin() const
Iterator to the first variable entry.
static EIGEN_DEPRECATED const end_t end
int ccolamd(int n_row, int n_col, int Alen, int A [], int p [], double knobs [CCOLAMD_KNOBS], int stats [CCOLAMD_STATS], int cmember [])
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
const MATRIX::ConstColXpr column(const MATRIX &A, size_t j)
std::uint64_t Key
Integer nonlinear key type.