From 76f793533aeabd0fb52789266d502ad7557d1662 Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 20 Oct 2017 11:50:21 +0000 Subject: [PATCH] Use copressed node-based graph for segregated edges check. --- .../extractor/node_based_graph_factory.hpp | 11 ++++----- src/extractor/extractor.cpp | 23 ++++++++++++++----- src/extractor/node_based_graph_factory.cpp | 9 +++----- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/extractor/node_based_graph_factory.hpp b/include/extractor/node_based_graph_factory.hpp index 91d2bc74c..9b6c2afae 100644 --- a/include/extractor/node_based_graph_factory.hpp +++ b/include/extractor/node_based_graph_factory.hpp @@ -36,11 +36,10 @@ class NodeBasedGraphFactory // node-based graph to represent the OSM network. This includes geometry compression, annotation // data optimisation and many other aspects. After this step, the edge-based graph factory can // turn the graph into the routing graph to be used with the navigation algorithms. - NodeBasedGraphFactory(const boost::filesystem::path &input_file); - - void CompressAll(ScriptingEnvironment &scripting_environment, - std::vector &turn_restrictions, - std::vector &conditional_turn_restrictions); + NodeBasedGraphFactory(const boost::filesystem::path &input_file, + ScriptingEnvironment &scripting_environment, + std::vector &turn_restrictions, + std::vector &conditional_turn_restrictions); auto &GetGraph() { return compressed_output_graph; } auto const &GetBarriers() const { return barriers; } @@ -76,7 +75,7 @@ class NodeBasedGraphFactory // unreferenced entries void CompressAnnotationData(); - // After produce, this will contain a compresse version of the node-based graph + // After produce, this will contain a compressed version of the node-based graph util::NodeBasedDynamicGraph compressed_output_graph; // To store the meta-data for the graph that is purely annotative / not used for the navigation // itself. Since the edges of a node-based graph form the nodes of the edge based graphs, we diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 870007273..546a8b151 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -212,7 +212,10 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) std::vector edge_based_node_weights; // Create a node-based graph from the OSRM file - NodeBasedGraphFactory node_based_graph_factory(config.GetPath(".osrm")); + NodeBasedGraphFactory node_based_graph_factory(config.GetPath(".osrm"), + scripting_environment, + turn_restrictions, + conditional_turn_restrictions); util::Log() << "Find segregated edges in node-based graph ..." << std::flush; TIMER_START(segregated); @@ -223,9 +226,6 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) util::Log() << "ok, after " << TIMER_SEC(segregated) << "s"; util::Log() << "Segregated edges count = " << segregated_count; - node_based_graph_factory.CompressAll( - scripting_environment, turn_restrictions, conditional_turn_restrictions); - util::Log() << "Writing nodes for nodes-based and edges-based graphs ..."; auto const &coordinates = node_based_graph_factory.GetCoordinates(); files::writeNodes( @@ -946,6 +946,7 @@ size_t Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory) auto &graph = factory.GetGraph(); auto const &annotation = factory.GetAnnotationData(); auto const &coordinates = factory.GetCoordinates(); + auto const &edges = factory.GetCompressedEdges(); auto const get_edge_name = [&](auto const &data) { /// @todo Make string normalization/lowercase/trim for comparison ... @@ -955,6 +956,17 @@ size_t Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory) return names.GetNameForID(id); }; + auto const get_edge_length = [&](EdgeID id) { + auto const geom = edges.GetBucketReference(id); + double length = 0.0; + for (size_t i = 1; i < geom.size(); ++i) + { + length += osrm::util::coordinate_calculation::haversineDistance( + coordinates[geom[i - 1].node_id], coordinates[geom[i].node_id]); + } + return length; + }; + auto const get_edge_classes = [&](auto const &data) { return annotation[data.annotation_data].classes; }; @@ -1027,8 +1039,7 @@ size_t Extractor::FindSegregatedNodes(NodeBasedGraphFactory &factory) NodeID const targetID = graph.GetTarget(edgeID); - if (osrm::util::coordinate_calculation::haversineDistance(coordinates[sourceID], - coordinates[targetID]) > 30.0) + if (get_edge_length(edgeID) > 30.0) continue; auto const targetEdges = graph.GetAdjacentEdgeRange(targetID); diff --git a/src/extractor/node_based_graph_factory.cpp b/src/extractor/node_based_graph_factory.cpp index 595aabd58..8fc7b9d24 100644 --- a/src/extractor/node_based_graph_factory.cpp +++ b/src/extractor/node_based_graph_factory.cpp @@ -15,16 +15,13 @@ namespace osrm namespace extractor { -NodeBasedGraphFactory::NodeBasedGraphFactory(const boost::filesystem::path &input_file) -{ - LoadDataFromFile(input_file); -} - -void NodeBasedGraphFactory::CompressAll( +NodeBasedGraphFactory::NodeBasedGraphFactory( + const boost::filesystem::path &input_file, ScriptingEnvironment &scripting_environment, std::vector &turn_restrictions, std::vector &conditional_turn_restrictions) { + LoadDataFromFile(input_file); Compress(scripting_environment, turn_restrictions, conditional_turn_restrictions); CompressGeometry(); CompressAnnotationData();