diff --git a/include/partition/multi_level_graph.hpp b/include/partition/multi_level_graph.hpp index 52b284ff1..7a5694797 100644 --- a/include/partition/multi_level_graph.hpp +++ b/include/partition/multi_level_graph.hpp @@ -85,6 +85,7 @@ class MultiLevelGraph : public util::StaticGraph } // Fast scan over all relevant border edges + // For level 0 this yield the same result as GetAdjacentEdgeRange auto GetBorderEdgeRange(const LevelID level, const NodeID node) const { auto begin = BeginBorderEdges(level, node); @@ -94,10 +95,11 @@ class MultiLevelGraph : public util::StaticGraph // Fast scan over all relevant internal edges, that is edges that will not // leave the cell of that node at the given level + // For level 0 this returns an empty edge range auto GetInternalEdgeRange(const LevelID level, const NodeID node) const { auto begin = SuperT::BeginEdges(node); - auto end = SuperT::BeginEdges(node) + node_to_edge_offset[node + level]; + auto end = BeginBorderEdges(level, node); return util::irange(begin, end); } @@ -110,7 +112,7 @@ class MultiLevelGraph : public util::StaticGraph return SuperT::BeginEdges(node) + node_to_edge_offset[index + level]; } - // We save the level as senitel at the end + // We save the level as sentinel at the end LevelID GetNumberOfLevels() const { return node_to_edge_offset.back(); } private: @@ -135,7 +137,7 @@ class MultiLevelGraph : public util::StaticGraph permutation.begin(), permutation.end(), [&edges, &highest_border_level](const auto &lhs, const auto &rhs) { - // sort by source node and then by level in acending order + // sort by source node and then by level in ascending order return std::tie(edges[lhs].source, highest_border_level[lhs], edges[lhs].target) < std::tie(edges[rhs].source, highest_border_level[rhs], edges[rhs].target); }); @@ -151,7 +153,7 @@ class MultiLevelGraph : public util::StaticGraph { auto num_levels = mlp.GetNumberOfLevels(); - // we save one senitel element at the end + // we save one sentinel element at the end node_to_edge_offset.reserve(num_levels * (max_border_node_id + 1) + 1); auto iter = edge_and_level_begin; for (auto node : util::irange(0, max_border_node_id + 1)) diff --git a/unit_tests/partition/multi_level_graph.cpp b/unit_tests/partition/multi_level_graph.cpp index 8336f5d2f..5e04803be 100644 --- a/unit_tests/partition/multi_level_graph.cpp +++ b/unit_tests/partition/multi_level_graph.cpp @@ -90,6 +90,25 @@ BOOST_AUTO_TEST_CASE(check_edges_sorting) CHECK_EQUAL_COLLECTIONS(graph.GetBorderEdgeRange(0, node), graph.GetAdjacentEdgeRange(node)); + // on level 0 there are no internal edges + for (auto node : util::irange(0, 13)) + CHECK_EQUAL_COLLECTIONS(graph.GetInternalEdgeRange(0, node), util::irange(0, 0)); + + // the union of border and internal edge needs to equal the adjacent edges + for (auto level : util::irange(0, 4)) + { + for (auto node : util::irange(0, 13)) + { + const auto adjacent = graph.GetAdjacentEdgeRange(node); + const auto border = graph.GetBorderEdgeRange(level, node); + const auto internal = graph.GetInternalEdgeRange(level, node); + std::vector merged; + std::copy(internal.begin(), internal.end(), std::back_inserter(merged)); + std::copy(border.begin(), border.end(), std::back_inserter(merged)); + CHECK_EQUAL_COLLECTIONS(adjacent, merged); + } + } + BOOST_CHECK_EQUAL(graph.GetBorderEdgeRange(1, 0).size(), 1); BOOST_CHECK_EQUAL(graph.GetBorderEdgeRange(1, 1).size(), 0); BOOST_CHECK_EQUAL(graph.GetBorderEdgeRange(1, 2).size(), 0);