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);
119 for (
size_t j = 0;
j < nVars; ++
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();
241 std::cout <<
"METIS failed during Nested Dissection ordering!\n";
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->push_back(
key);
292 this->push_back(
key);
303 bool Ordering::contains(
const Key&
key)
const {
304 return std::find(this->begin(), this->
end(), key) != this->
end();
309 return (*
this) ==
other;