Refactor elimination setup to not use C declaration style
parent
4ad482aa70
commit
a7573e8e6f
|
|
@ -344,18 +344,20 @@ EliminateHybrid(const HybridGaussianFactorGraph &factors,
|
||||||
// However this is also the case with iSAM2, so no pressure :)
|
// However this is also the case with iSAM2, so no pressure :)
|
||||||
|
|
||||||
// PREPROCESS: Identify the nature of the current elimination
|
// PREPROCESS: Identify the nature of the current elimination
|
||||||
std::unordered_map<Key, DiscreteKey> mapFromKeyToDiscreteKey;
|
|
||||||
std::set<DiscreteKey> discreteSeparatorSet;
|
|
||||||
std::set<DiscreteKey> discreteFrontals;
|
|
||||||
|
|
||||||
|
// First, identify the separator keys, i.e. all keys that are not frontal.
|
||||||
KeySet separatorKeys;
|
KeySet separatorKeys;
|
||||||
KeySet allContinuousKeys;
|
|
||||||
KeySet continuousFrontals;
|
|
||||||
KeySet continuousSeparator;
|
|
||||||
|
|
||||||
// This initializes separatorKeys and mapFromKeyToDiscreteKey
|
|
||||||
for (auto &&factor : factors) {
|
for (auto &&factor : factors) {
|
||||||
separatorKeys.insert(factor->begin(), factor->end());
|
separatorKeys.insert(factor->begin(), factor->end());
|
||||||
|
}
|
||||||
|
// remove frontals from separator
|
||||||
|
for (auto &k : frontalKeys) {
|
||||||
|
separatorKeys.erase(k);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a map from keys to DiscreteKeys
|
||||||
|
std::unordered_map<Key, DiscreteKey> mapFromKeyToDiscreteKey;
|
||||||
|
for (auto &&factor : factors) {
|
||||||
if (!factor->isContinuous()) {
|
if (!factor->isContinuous()) {
|
||||||
for (auto &k : factor->discreteKeys()) {
|
for (auto &k : factor->discreteKeys()) {
|
||||||
mapFromKeyToDiscreteKey[k.first] = k;
|
mapFromKeyToDiscreteKey[k.first] = k;
|
||||||
|
|
@ -363,50 +365,51 @@ EliminateHybrid(const HybridGaussianFactorGraph &factors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove frontals from separator
|
// Fill in discrete frontals and continuous frontals.
|
||||||
for (auto &k : frontalKeys) {
|
std::set<DiscreteKey> discreteFrontals;
|
||||||
separatorKeys.erase(k);
|
KeySet continuousFrontals;
|
||||||
}
|
|
||||||
|
|
||||||
// Fill in discrete frontals and continuous frontals for the end result
|
|
||||||
for (auto &k : frontalKeys) {
|
for (auto &k : frontalKeys) {
|
||||||
if (mapFromKeyToDiscreteKey.find(k) != mapFromKeyToDiscreteKey.end()) {
|
if (mapFromKeyToDiscreteKey.find(k) != mapFromKeyToDiscreteKey.end()) {
|
||||||
discreteFrontals.insert(mapFromKeyToDiscreteKey.at(k));
|
discreteFrontals.insert(mapFromKeyToDiscreteKey.at(k));
|
||||||
} else {
|
} else {
|
||||||
continuousFrontals.insert(k);
|
continuousFrontals.insert(k);
|
||||||
allContinuousKeys.insert(k);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in discrete frontals and continuous frontals for the end result
|
// Fill in discrete discrete separator keys and continuous separator keys.
|
||||||
|
std::set<DiscreteKey> discreteSeparatorSet;
|
||||||
|
KeySet continuousSeparator;
|
||||||
for (auto &k : separatorKeys) {
|
for (auto &k : separatorKeys) {
|
||||||
if (mapFromKeyToDiscreteKey.find(k) != mapFromKeyToDiscreteKey.end()) {
|
if (mapFromKeyToDiscreteKey.find(k) != mapFromKeyToDiscreteKey.end()) {
|
||||||
discreteSeparatorSet.insert(mapFromKeyToDiscreteKey.at(k));
|
discreteSeparatorSet.insert(mapFromKeyToDiscreteKey.at(k));
|
||||||
} else {
|
} else {
|
||||||
continuousSeparator.insert(k);
|
continuousSeparator.insert(k);
|
||||||
allContinuousKeys.insert(k);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if we have any continuous keys:
|
||||||
|
const bool discrete_only =
|
||||||
|
continuousFrontals.empty() && continuousSeparator.empty();
|
||||||
|
|
||||||
// NOTE: We should really defer the product here because of pruning
|
// NOTE: We should really defer the product here because of pruning
|
||||||
|
|
||||||
// Case 1: we are only dealing with continuous
|
if (discrete_only) {
|
||||||
if (mapFromKeyToDiscreteKey.empty() && !allContinuousKeys.empty()) {
|
// Case 1: we are only dealing with discrete
|
||||||
return continuousElimination(factors, frontalKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Case 2: we are only dealing with discrete
|
|
||||||
if (allContinuousKeys.empty()) {
|
|
||||||
return discreteElimination(factors, frontalKeys);
|
return discreteElimination(factors, frontalKeys);
|
||||||
}
|
} else {
|
||||||
|
// Case 2: we are only dealing with continuous
|
||||||
|
if (mapFromKeyToDiscreteKey.empty()) {
|
||||||
|
return continuousElimination(factors, frontalKeys);
|
||||||
|
} else {
|
||||||
|
// Case 3: We are now in the hybrid land!
|
||||||
#ifdef HYBRID_TIMING
|
#ifdef HYBRID_TIMING
|
||||||
tictoc_reset_();
|
tictoc_reset_();
|
||||||
#endif
|
#endif
|
||||||
// Case 3: We are now in the hybrid land!
|
|
||||||
return hybridElimination(factors, frontalKeys, continuousSeparator,
|
return hybridElimination(factors, frontalKeys, continuousSeparator,
|
||||||
discreteSeparatorSet);
|
discreteSeparatorSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************ */
|
/* ************************************************************************ */
|
||||||
void HybridGaussianFactorGraph::add(JacobianFactor &&factor) {
|
void HybridGaussianFactorGraph::add(JacobianFactor &&factor) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue