diff --git a/gtsam/base/kruskal-inl.h b/gtsam/base/kruskal-inl.h index 7f1a30151..50cf10260 100644 --- a/gtsam/base/kruskal-inl.h +++ b/gtsam/base/kruskal-inl.h @@ -53,6 +53,12 @@ inline std::vector sortedIndices(const std::vector &src) { template std::vector kruskal(const Graph &fg, const std::vector &weights) { + if (fg.size() != weights.size()) { + throw std::runtime_error( + "kruskal() failure: fg.size() != weights.size(), all factors need to " + "assigned a weight"); + } + // Create an index from variables to factor indices. const VariableIndex variableIndex(fg); diff --git a/gtsam/base/kruskal.h b/gtsam/base/kruskal.h index 8f5d75966..4b7493685 100644 --- a/gtsam/base/kruskal.h +++ b/gtsam/base/kruskal.h @@ -10,9 +10,11 @@ * -------------------------------------------------------------------------- */ /** - * @file SubgraphBuilder-inl.h + * @file kruskal.h * @date Dec 31, 2009 - * @author Frank Dellaert, Yong-Dian Jian + * @author Frank Dellaert + * @author Yong-Dian Jian + * @author Ankur Roy Chowdhury */ #pragma once @@ -22,9 +24,17 @@ #include namespace gtsam::utils { +/** + * Compute the minimum spanning tree (MST) using Kruskal's algorithm + * @param fg Factor graph + * @param weights Weights of the edges/factors in the factor graph + * @return Edge/factor indices spanning the MST + * @note Only binary factors are considered while constructing the spanning tree + * @note The indices of 'weights' should match the indices of the edges in the factor graph + */ template std::vector kruskal(const FactorGraph &fg, const std::vector &weights); -} +} // namespace gtsam::utils #include \ No newline at end of file