diff --git a/algorithms/tiny_components.hpp b/algorithms/tiny_components.hpp index 322137562..41e2836bf 100644 --- a/algorithms/tiny_components.hpp +++ b/algorithms/tiny_components.hpp @@ -76,7 +76,7 @@ class TarjanSCC bool on_stack; }; - std::vector components_index; + std::vector components_index; std::vector component_size_vector; std::shared_ptr m_node_based_graph; std::unordered_set barrier_node_set; @@ -84,18 +84,19 @@ class TarjanSCC unsigned size_one_counter; public: + template TarjanSCC(std::shared_ptr graph, const RestrictionMap &restrictions, - const std::vector &barrier_node_list) + const ContainerT &barrier_node_list) : components_index(graph->GetNumberOfNodes(), SPECIAL_NODEID), - m_node_based_graph(graph), m_restriction_map(restrictions), + m_node_based_graph(graph), m_restriction_map(restrictions), size_one_counter(0) { barrier_node_set.insert(std::begin(barrier_node_list), std::end(barrier_node_list)); BOOST_ASSERT(m_node_based_graph->GetNumberOfNodes() > 0); } - void Run() + void run() { TIMER_START(SCC_RUN); // The following is a hack to distinguish between stuff that happens @@ -160,7 +161,7 @@ class TarjanSCC // At an only_-restriction but not at the right turn // continue; } - + if (m_restriction_map.CheckIfTurnIsRestricted(u, v, vprime)) { // continue; @@ -231,6 +232,12 @@ class TarjanSCC } + std::size_t get_number_of_components() const + { + return component_size_vector.size(); + } + + unsigned get_component_size(const NodeID node) const { return component_size_vector[components_index[node]]; diff --git a/contractor/edge_based_graph_factory.cpp b/contractor/edge_based_graph_factory.cpp index c8f055307..d24d63a2b 100644 --- a/contractor/edge_based_graph_factory.cpp +++ b/contractor/edge_based_graph_factory.cpp @@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "edge_based_graph_factory.hpp" -#include "../algorithms/bfs_components.hpp" +#include "../algorithms/tiny_components.hpp" #include "../data_structures/percent.hpp" #include "../Util/compute_angle.hpp" #include "../Util/integer_range.hpp" @@ -473,12 +473,12 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() SimpleLogger().Write() << "Identifying components of the road network"; // Run a BFS on the undirected graph and identify small components - BFSComponentExplorer component_explorer( - *m_node_based_graph, *m_restriction_map, m_barrier_nodes); + TarjanSCC component_explorer( + m_node_based_graph, *m_restriction_map, m_barrier_nodes); component_explorer.run(); - SimpleLogger().Write() << "identified: " << component_explorer.GetNumberOfComponents() + SimpleLogger().Write() << "identified: " << component_explorer.get_number_of_components() << " many components"; SimpleLogger().Write() << "generating edge-expanded nodes"; @@ -507,8 +507,8 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() // Note: edges that end on barrier nodes or on a turn restriction // may actually be in two distinct components. We choose the smallest - const unsigned size_of_component = std::min(component_explorer.GetComponentSize(u), - component_explorer.GetComponentSize(v)); + const unsigned size_of_component = std::min(component_explorer.get_component_size(u), + component_explorer.get_component_size(v)); const bool component_is_tiny = (size_of_component < 1000); if (edge_data.edgeBasedNodeID == SPECIAL_NODEID) diff --git a/tools/components.cpp b/tools/components.cpp index 79b09e9f5..00acbaf4b 100644 --- a/tools/components.cpp +++ b/tools/components.cpp @@ -184,7 +184,7 @@ int main(int argc, char *argv[]) auto tarjan = osrm::make_unique>(graph, restriction_map, bollard_node_list); - tarjan->Run(); + tarjan->run(); // output TIMER_START(SCC_RUN_SETUP);