26 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION
38 inverted.insert(make_pair((*
this)[
pos],
pos));
45 vector<int> dummy_groups(variableIndex.
size(), 0);
46 return Ordering::ColamdConstrained(variableIndex, dummy_groups);
51 std::vector<int>& cmember) {
52 gttic(Ordering_COLAMDConstrained);
55 const size_t nVars = variableIndex.
size();
66 const size_t nEntries = variableIndex.
nEntries(), nFactors =
71 vector<int>
A = vector<int>(Alen);
72 vector<int>
p = vector<int>(nVars + 1);
79 for (
auto key_factors: variableIndex) {
82 for(
size_t factorIndex:
column) {
83 A[count++] = (
int) factorIndex;
87 keys[index] = key_factors.first;
91 assert((
size_t)count == variableIndex.nEntries());
107 int rv =
ccolamd((
int) nFactors, (
int) nVars, (
int) Alen, &
A[0], &
p[0],
108 knobs,
stats, &cmember[0]);
110 throw runtime_error(
"ccolamd failed with return value " + to_string(rv));
117 gttic(Fill_Ordering);
120 for (
size_t j = 0;
j < nVars; ++
j)
122 gttoc(Fill_Ordering);
129 const KeyVector& constrainLast,
bool forceOrder) {
130 gttic(Ordering_COLAMDConstrainedLast);
132 size_t n = variableIndex.
size();
133 std::vector<int> cmember(
n, 0);
139 for (
auto key_factors: variableIndex)
140 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first,
j++));
144 int group = (constrainLast.size() !=
n ? 1 : 0);
145 for (
Key key: constrainLast) {
146 cmember[keyIndices.at(
key)] = group;
151 return Ordering::ColamdConstrained(variableIndex, cmember);
156 const KeyVector& constrainFirst,
bool forceOrder) {
157 gttic(Ordering_COLAMDConstrainedFirst);
160 size_t n = variableIndex.
size();
161 std::vector<int> cmember(
n,
none);
166 for (
auto key_factors: variableIndex)
167 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first,
j++));
172 for (
Key key: constrainFirst) {
173 cmember[keyIndices.at(
key)] = group;
178 if (!forceOrder && !constrainFirst.empty())
184 return Ordering::ColamdConstrained(variableIndex, cmember);
190 gttic(Ordering_COLAMDConstrained);
191 size_t n = variableIndex.
size();
192 std::vector<int> cmember(
n, 0);
197 for (
auto key_factors: variableIndex)
198 keyIndices.insert(keyIndices.end(), make_pair(key_factors.first,
j++));
202 for(
const key_group&
p: groups) {
204 cmember[keyIndices.at(
p.first)] =
p.second;
207 return Ordering::ColamdConstrained(variableIndex, cmember);
212 #ifdef GTSAM_SUPPORT_NESTED_DISSECTION
213 gttic(Ordering_METIS);
227 vector<idx_t> adj = met.
adj();
242 std::cout <<
"METIS failed during Nested Dissection ordering!\n";
253 throw runtime_error(
"GTSAM was built without support for Metis-based "
254 "nested dissection");
265 static const size_t varsPerLine = 10;
266 bool endedOnNewline =
false;
267 for (
size_t i = 0;
i <
size(); ++
i) {
268 if (
i % varsPerLine == 0)
269 cout <<
"Position " <<
i <<
": ";
270 if (
i % varsPerLine != 0)
272 cout << keyFormatter(at(
i));
273 if (
i % varsPerLine == varsPerLine - 1) {
275 endedOnNewline =
true;
277 endedOnNewline =
false;
287 this->push_back(
key);
293 this->push_back(
key);
304 bool Ordering::contains(
const Key&
key)
const {
305 return std::find(this->begin(), this->
end(), key) != this->
end();
310 return (*
this) ==
other;