From f8a1cf69356127ba4343faf7bbd9e47570b075b0 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Tue, 14 Mar 2017 21:20:32 +0000 Subject: [PATCH] Remove .osrm.edge_segment_update not needed anymore --- .../extractor/edge_based_graph_factory.hpp | 2 - include/extractor/extractor_config.hpp | 2 - include/updater/updater_config.hpp | 2 - src/extractor/edge_based_graph_factory.cpp | 68 +++------------ src/extractor/extractor.cpp | 1 - src/updater/updater.cpp | 85 +++++++++---------- 6 files changed, 50 insertions(+), 110 deletions(-) diff --git a/include/extractor/edge_based_graph_factory.hpp b/include/extractor/edge_based_graph_factory.hpp index 174c2cb0385..33aabe33401 100644 --- a/include/extractor/edge_based_graph_factory.hpp +++ b/include/extractor/edge_based_graph_factory.hpp @@ -112,7 +112,6 @@ class EdgeBasedGraphFactory void Run(ScriptingEnvironment &scripting_environment, const std::string &original_edge_data_filename, const std::string &turn_lane_data_filename, - const std::string &edge_segment_lookup_filename, const std::string &turn_weight_penalties_filename, const std::string &turn_duration_penalties_filename, const std::string &turn_penalties_index_filename, @@ -182,7 +181,6 @@ class EdgeBasedGraphFactory void GenerateEdgeExpandedEdges(ScriptingEnvironment &scripting_environment, const std::string &original_edge_data_filename, const std::string &turn_lane_data_filename, - const std::string &edge_segment_lookup_filename, const std::string &turn_weight_penalties_filename, const std::string &turn_duration_penalties_filename, const std::string &turn_penalties_index_filename, diff --git a/include/extractor/extractor_config.hpp b/include/extractor/extractor_config.hpp index 123c0155df0..f47d4f55a5d 100644 --- a/include/extractor/extractor_config.hpp +++ b/include/extractor/extractor_config.hpp @@ -70,7 +70,6 @@ struct ExtractorConfig edge_graph_output_path = basepath + ".osrm.ebg"; rtree_nodes_output_path = basepath + ".osrm.ramIndex"; rtree_leafs_output_path = basepath + ".osrm.fileIndex"; - edge_segment_lookup_path = basepath + ".osrm.edge_segment_lookup"; turn_duration_penalties_path = basepath + ".osrm.turn_duration_penalties"; turn_weight_penalties_path = basepath + ".osrm.turn_weight_penalties"; turn_penalties_index_path = basepath + ".osrm.turn_penalties_index"; @@ -109,7 +108,6 @@ struct ExtractorConfig bool generate_edge_lookup; std::string turn_penalties_index_path; - std::string edge_segment_lookup_path; bool use_metadata; }; diff --git a/include/updater/updater_config.hpp b/include/updater/updater_config.hpp index 4f905abeb2e..7c6cb9e78c0 100644 --- a/include/updater/updater_config.hpp +++ b/include/updater/updater_config.hpp @@ -43,7 +43,6 @@ struct UpdaterConfig final void UseDefaultOutputNames() { edge_based_graph_path = osrm_input_path.string() + ".ebg"; - edge_segment_lookup_path = osrm_input_path.string() + ".edge_segment_lookup"; turn_weight_penalties_path = osrm_input_path.string() + ".turn_weight_penalties"; turn_duration_penalties_path = osrm_input_path.string() + ".turn_duration_penalties"; turn_penalties_index_path = osrm_input_path.string() + ".turn_penalties_index"; @@ -58,7 +57,6 @@ struct UpdaterConfig final std::string edge_based_graph_path; - std::string edge_segment_lookup_path; std::string turn_weight_penalties_path; std::string turn_duration_penalties_path; std::string turn_penalties_index_path; diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 3761a839302..781ff2e0389 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -196,7 +196,6 @@ void EdgeBasedGraphFactory::FlushVectorToStream( void EdgeBasedGraphFactory::Run(ScriptingEnvironment &scripting_environment, const std::string &original_edge_data_filename, const std::string &turn_lane_data_filename, - const std::string &edge_segment_lookup_filename, const std::string &turn_weight_penalties_filename, const std::string &turn_duration_penalties_filename, const std::string &turn_penalties_index_filename, @@ -216,7 +215,6 @@ void EdgeBasedGraphFactory::Run(ScriptingEnvironment &scripting_environment, GenerateEdgeExpandedEdges(scripting_environment, original_edge_data_filename, turn_lane_data_filename, - edge_segment_lookup_filename, turn_weight_penalties_filename, turn_duration_penalties_filename, turn_penalties_index_filename, @@ -330,7 +328,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( ScriptingEnvironment &scripting_environment, const std::string &original_edge_data_filename, const std::string &turn_lane_data_filename, - const std::string &edge_segment_lookup_filename, const std::string &turn_weight_penalties_filename, const std::string &turn_duration_penalties_filename, const std::string &turn_penalties_index_filename, @@ -347,9 +344,6 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( storage::io::FileWriter edge_data_file(original_edge_data_filename, storage::io::FileWriter::HasNoFingerprint); - storage::io::FileWriter edge_segment_file(edge_segment_lookup_filename, - storage::io::FileWriter::HasNoFingerprint); - storage::io::FileWriter turn_penalties_index_file(turn_penalties_index_filename, storage::io::FileWriter::HasNoFingerprint); @@ -584,59 +578,19 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( turn_duration_penalties.push_back(duration_penalty); } - // Here is where we write out the mapping between the edge-expanded edges, and - // the node-based edges that are originally used to calculate the `distance` - // for the edge-expanded edges. About 40 lines back, there is: - // - // unsigned distance = edge_data1.distance; - // - // This tells us that the weight for an edge-expanded-edge is based on the - // weight - // of the *source* node-based edge. Therefore, we will look up the individual - // segments of the source node-based edge, and write out a mapping between - // those and the edge-based-edge ID. - // External programs can then use this mapping to quickly perform - // updates to the edge-expanded-edge based directly on its ID. + // We write out the mapping between the edge-expanded edges and the + // original nodes. Since each edge represents a possible maneuver, external + // programs can use this to quickly perform updates to edge weights in order + // to penalize certain turns. + + // If this edge is 'trivial' -- where the compressed edge corresponds + // exactly to an original OSM segment -- we can pull the turn's preceding + // node ID directly with `node_along_road_entering`; otherwise, we need to + // look + // up the node + // immediately preceding the turn from the compressed edge container. if (generate_edge_lookup) { - const auto node_based_edges = - m_compressed_edge_container.GetBucketReference(incoming_edge); - NodeID previous = node_along_road_entering; - - const unsigned node_count = node_based_edges.size() + 1; - const QueryNode &first_node = m_node_info_list[previous]; - - lookup::SegmentHeaderBlock header = {node_count, first_node.node_id}; - - edge_segment_file.WriteOne(header); - - for (auto target_node : node_based_edges) - { - const QueryNode &from = m_node_info_list[previous]; - const QueryNode &to = m_node_info_list[target_node.node_id]; - const double segment_length = - util::coordinate_calculation::greatCircleDistance(from, to); - - lookup::SegmentBlock nodeblock{to.node_id, - segment_length, - target_node.weight, - target_node.duration}; - - edge_segment_file.WriteOne(nodeblock); - previous = target_node.node_id; - } - - // We also now write out the mapping between the edge-expanded edges and the - // original nodes. Since each edge represents a possible maneuver, external - // programs can use this to quickly perform updates to edge weights in order - // to penalize certain turns. - - // If this edge is 'trivial' -- where the compressed edge corresponds - // exactly to an original OSM segment -- we can pull the turn's preceding - // node ID directly with `node_along_road_entering`; otherwise, we need to - // look - // up the node - // immediately preceding the turn from the compressed edge container. const bool isTrivial = m_compressed_edge_container.IsTrivial(incoming_edge); const auto &from_node = diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 497c4ec6b59..296b13ba675 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -483,7 +483,6 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, edge_based_graph_factory.Run(scripting_environment, config.edge_output_path, config.turn_lane_data_file_name, - config.edge_segment_lookup_path, config.turn_weight_penalties_path, config.turn_duration_penalties_path, config.turn_penalties_index_path, diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index 343d7bae1fa..affe73769fa 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -422,14 +422,6 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e return boost::interprocess::mapped_region(); }(); - const auto edge_segment_region = [&] { - if (update_edge_weights || update_turn_penalties) - { - return mmapFile(config.edge_segment_lookup_path, boost::interprocess::read_only); - } - return boost::interprocess::mapped_region(); - }(); - // Set the struct packing to 1 byte word sizes. This prevents any padding. We only use // this struct once, so any alignment penalty is trivial. If this is *not* done, then // the struct will be padded out by an extra 4 bytes, and sizeof() will mean we read @@ -470,7 +462,6 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e edge_based_edge_list.reserve(graph_header.number_of_edges); util::Log() << "Reading " << graph_header.number_of_edges << " edges from the edge based graph"; - auto segment_speed_lookup = csv::readSegmentValues(config.segment_speed_lookup_paths); auto turn_penalty_lookup = csv::readTurnValues(config.turn_penalty_lookup_paths); storage::io::FileReader edges_input_file(config.osrm_input_path.string() + ".edges", @@ -482,6 +473,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e extractor::SegmentDataContainer segment_data; if (update_edge_weights) { + auto segment_speed_lookup = csv::readSegmentValues(config.segment_speed_lookup_paths); + TIMER_START(segment); std::tie(updated_segments, segment_data) = updaterSegmentData(config, profile_properties, segment_speed_lookup); @@ -490,6 +483,10 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e TIMER_STOP(segment); util::Log() << "Updating segment data took " << TIMER_MSEC(segment) << "ms."; } + else if (update_turn_penalties) + { + extractor::io::read(config.geometry_path, segment_data); + } std::vector turn_weight_penalties; std::vector turn_duration_penalties; @@ -529,8 +526,6 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e sizeof(EdgeBasedGraphHeader)); BOOST_ASSERT(is_aligned(edge_based_edge_ptr)); - auto edge_segment_byte_ptr = reinterpret_cast(edge_segment_region.get_address()); - bool fallback_to_duration = true; for (std::uint64_t edge_index = 0; edge_index < graph_header.number_of_edges; ++edge_index) { @@ -559,47 +554,44 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e } } - using extractor::lookup::SegmentHeaderBlock; - using extractor::lookup::SegmentBlock; - - auto header = reinterpret_cast(edge_segment_byte_ptr); - BOOST_ASSERT(is_aligned(header)); - edge_segment_byte_ptr += sizeof(SegmentHeaderBlock); - - auto first = reinterpret_cast(edge_segment_byte_ptr); - BOOST_ASSERT(is_aligned(first)); - edge_segment_byte_ptr += sizeof(SegmentBlock) * (header->num_osm_nodes - 1); - auto last = reinterpret_cast(edge_segment_byte_ptr); - if (needs_update) { // Find a segment with zero speed and simultaneously compute the new edge weight EdgeWeight new_weight = 0; EdgeWeight new_duration = 0; - auto osm_node_id = header->previous_osm_node_id; - bool skip_edge = - std::find_if(first, last, [&](const auto &segment) { - auto segment_weight = segment.segment_weight; - auto segment_duration = segment.segment_duration; - if (auto value = segment_speed_lookup({osm_node_id, segment.this_osm_node_id})) - { - // If we hit a 0-speed edge, then it's effectively not traversible. - // We don't want to include it in the edge_based_edge_list. - if (value->speed == 0) - return true; - - segment_duration = convertToDuration(value->speed, segment.segment_length); + bool skip_edge = false; - segment_weight = - convertToWeight(value->weight, weight_multiplier, segment_duration); + const auto geometry_id = edge_data[edge_index].via_geometry; + if (geometry_id.forward) + { + const auto weights = segment_data.GetForwardWeights(geometry_id.id); + for (const auto weight : weights) + { + if (weight == INVALID_EDGE_WEIGHT) + { + skip_edge = true; + break; } - - // Update the edge weight and the next OSM node ID - osm_node_id = segment.this_osm_node_id; - new_weight += segment_weight; - new_duration += segment_duration; - return false; - }) != last; + new_weight += weight; + } + const auto durations = segment_data.GetForwardDurations(geometry_id.id); + new_duration = std::accumulate(durations.begin(), durations.end(), 0); + } + else + { + const auto weights = segment_data.GetReverseWeights(geometry_id.id); + for (const auto weight : weights) + { + if (weight == INVALID_EDGE_WEIGHT) + { + skip_edge = true; + break; + } + new_weight += weight; + } + const auto durations = segment_data.GetReverseDurations(geometry_id.id); + new_duration = std::accumulate(durations.begin(), durations.end(), 0); + } // Update the node-weight cache. This is the weight of the edge-based-node only, // it doesn't include the turn. We may visit the same node multiple times, but @@ -625,7 +617,8 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e ? value->weight * weight_multiplier : turn_duration_penalty * weight_multiplier / 10.)); - const auto weight_min_value = static_cast(header->num_osm_nodes); + const auto num_nodes = segment_data.GetForwardGeometry(geometry_id.id).size(); + const auto weight_min_value = static_cast(num_nodes); if (turn_weight_penalty + new_weight < weight_min_value) { util::Log(logWARNING) << "turn penalty " << turn_weight_penalty << " for turn "