From 8dba0bb03a0a2f92711a3737c58153cd917eab4f Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Wed, 10 May 2017 21:02:19 +0200 Subject: [PATCH 1/9] Merge part of .nodes fields into .nodes_data --- .../extractor/edge_based_graph_factory.hpp | 2 + src/extractor/edge_based_graph_factory.cpp | 66 ++++++++++++------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/include/extractor/edge_based_graph_factory.hpp b/include/extractor/edge_based_graph_factory.hpp index 46c7a156bfd..00891c3aaf3 100644 --- a/include/extractor/edge_based_graph_factory.hpp +++ b/include/extractor/edge_based_graph_factory.hpp @@ -7,6 +7,7 @@ #include "extractor/edge_based_edge.hpp" #include "extractor/edge_based_node.hpp" #include "extractor/extraction_turn.hpp" +#include "extractor/node_data_container.hpp" #include "extractor/guidance/turn_analysis.hpp" #include "extractor/guidance/turn_instruction.hpp" #include "extractor/guidance/turn_lane_types.hpp" @@ -129,6 +130,7 @@ class EdgeBasedGraphFactory //! list of edge based nodes (compressed segments) std::vector m_edge_based_node_list; + EdgeBasedNodeDataExternalContainer m_ebg_node_data_container; util::DeallocatingVector m_edge_based_edge_list; EdgeID m_max_edge_id; diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 8a6a6cdbff4..08c0ad38129 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -134,7 +134,21 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N return SegmentID{edge_based_node_id, true}; }; - // traverse arrays + // Add edge-based node data for forward and reverse nodes indexed by edge_id + BOOST_ASSERT(forward_data.edge_id != SPECIAL_EDGEID); + m_ebg_node_data_container.SetData(forward_data.edge_id, + GeometryID{packed_geometry_id, true}, + forward_data.name_id, + forward_data.travel_mode); + if (reverse_data.edge_id != SPECIAL_EDGEID) + { + m_ebg_node_data_container.SetData(reverse_data.edge_id, + GeometryID{packed_geometry_id, false}, + reverse_data.name_id, + reverse_data.travel_mode); + } + + // Add segments of edge-based nodes for (const auto i : util::irange(std::size_t{0}, segment_count)) { BOOST_ASSERT( @@ -244,6 +258,9 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_fi { std::vector mapping; + // TODO: make m_ebg_node_data_container local + m_ebg_node_data_container = EdgeBasedNodeDataExternalContainer(m_max_edge_id + 1); + util::Log() << "Generating edge expanded nodes ... "; { util::UnbufferedLog log; @@ -252,35 +269,34 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_fi m_compressed_edge_container.InitializeBothwayVector(); // loop over all edges and generate new set of nodes - for (const auto node_u : util::irange(0u, m_node_based_graph->GetNumberOfNodes())) + for (const auto nbg_node_u : util::irange(0u, m_node_based_graph->GetNumberOfNodes())) { - BOOST_ASSERT(node_u != SPECIAL_NODEID); - BOOST_ASSERT(node_u < m_node_based_graph->GetNumberOfNodes()); - progress.PrintStatus(node_u); - for (EdgeID e1 : m_node_based_graph->GetAdjacentEdgeRange(node_u)) + BOOST_ASSERT(nbg_node_u != SPECIAL_NODEID); + progress.PrintStatus(nbg_node_u); + for (EdgeID nbg_edge_id : m_node_based_graph->GetAdjacentEdgeRange(nbg_node_u)) { - const EdgeData &edge_data = m_node_based_graph->GetEdgeData(e1); - BOOST_ASSERT(e1 != SPECIAL_EDGEID); - const NodeID node_v = m_node_based_graph->GetTarget(e1); + BOOST_ASSERT(nbg_edge_id != SPECIAL_EDGEID); + + const EdgeData &nbg_edge_data = m_node_based_graph->GetEdgeData(nbg_edge_id); + const NodeID nbg_node_v = m_node_based_graph->GetTarget(nbg_edge_id); + BOOST_ASSERT(nbg_node_v != SPECIAL_NODEID); + BOOST_ASSERT(nbg_node_u != nbg_node_v); - BOOST_ASSERT(SPECIAL_NODEID != node_v); // pick only every other edge, since we have every edge as an outgoing // and incoming egde - if (node_u > node_v) + if (nbg_node_u >= nbg_node_v) { continue; } - BOOST_ASSERT(node_u < node_v); - // if we found a non-forward edge reverse and try again - if (edge_data.edge_id == SPECIAL_NODEID) + if (nbg_edge_data.edge_id == SPECIAL_NODEID) { - mapping.push_back(InsertEdgeBasedNode(node_v, node_u)); + mapping.push_back(InsertEdgeBasedNode(nbg_node_v, nbg_node_u)); } else { - mapping.push_back(InsertEdgeBasedNode(node_u, node_v)); + mapping.push_back(InsertEdgeBasedNode(nbg_node_u, nbg_node_v)); } } } @@ -291,8 +307,6 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_fi { // TODO: refactor saving edge-based node data with InsertEdgeBasedNode - EdgeBasedNodeDataExternalContainer ebg_node_data_container(m_max_edge_id + 1); - for (const auto nbg_node_id : util::irange(0u, m_node_based_graph->GetNumberOfNodes())) { for (const auto nbg_edge_id : m_node_based_graph->GetAdjacentEdgeRange(nbg_node_id)) @@ -317,18 +331,22 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_fi nbg_edge_id) : SPECIAL_GEOMETRYID; - ebg_node_data_container.SetData(nbg_edge_data.edge_id, - GeometryID{geometry_id, is_encoded_forwards}, - nbg_edge_data.name_id, - nbg_edge_data.travel_mode); + BOOST_ASSERT(m_ebg_node_data_container.GetNameID(nbg_edge_data.edge_id) == nbg_edge_data.name_id); + BOOST_ASSERT(m_ebg_node_data_container.GetTravelMode(nbg_edge_data.edge_id) == nbg_edge_data.travel_mode); + + // m_ebg_node_data_container.SetData(nbg_edge_data.edge_id, + // GeometryID{geometry_id, is_encoded_forwards}, + // nbg_edge_data.name_id, + // nbg_edge_data.travel_mode); } } - - files::writeNodeData(node_data_filename, ebg_node_data_container); } util::Log() << "Generated " << m_edge_based_node_list.size() << " nodes in edge-expanded graph"; + files::writeNodeData(node_data_filename, m_ebg_node_data_container); + m_ebg_node_data_container = EdgeBasedNodeDataExternalContainer(); + return mapping; } From 32a92adb212e01edc3c36cdb5d217e4100e099e0 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Thu, 11 May 2017 09:13:59 +0200 Subject: [PATCH 2/9] Remove data duplicates in .node file --- include/engine/api/base_api.hpp | 15 ++-- include/engine/geospatial_query.hpp | 33 +++++--- include/engine/guidance/assemble_geometry.hpp | 12 ++- include/engine/guidance/assemble_leg.hpp | 9 +- include/engine/guidance/assemble_steps.hpp | 36 ++++---- include/engine/hint.hpp | 4 +- include/engine/phantom_node.hpp | 33 ++------ .../routing_algorithms/routing_base.hpp | 82 ++++++++----------- .../extractor/edge_based_graph_factory.hpp | 2 +- include/extractor/edge_based_node.hpp | 29 ++----- src/engine/plugins/tile.cpp | 35 +++++--- src/engine/routing_algorithms/tile_turns.cpp | 12 ++- src/extractor/edge_based_graph_factory.cpp | 28 +++---- unit_tests/server/parameters_parser.cpp | 50 +++++------ unit_tests/util/static_rtree.cpp | 1 - 15 files changed, 186 insertions(+), 195 deletions(-) diff --git a/include/engine/api/base_api.hpp b/include/engine/api/base_api.hpp index 672ddf594e0..0e0dad33b1f 100644 --- a/include/engine/api/base_api.hpp +++ b/include/engine/api/base_api.hpp @@ -50,14 +50,19 @@ class BaseAPI { if (parameters.generate_hints) { - return json::makeWaypoint(phantom.location, - facade.GetNameForID(phantom.name_id).to_string(), - Hint{phantom, facade.GetCheckSum()}); + // TODO: check forward/reverse + return json::makeWaypoint( + phantom.location, + facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)).to_string(), + Hint{phantom, facade.GetCheckSum()}); } else { - return json::makeWaypoint(phantom.location, - facade.GetNameForID(phantom.name_id).to_string()); + // TODO: check forward/reverse + return json::makeWaypoint( + phantom.location, + facade.GetNameForID(facade.GetNameIndex(phantom.forward_segment_id.id)) + .to_string()); } } diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index e79ec6038f5..34a9168d57d 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -374,14 +374,20 @@ template class GeospatialQuery EdgeDuration forward_duration_offset = 0, forward_duration = 0; EdgeDuration reverse_duration_offset = 0, reverse_duration = 0; + BOOST_ASSERT(data.forward_segment_id.enabled || data.reverse_segment_id.enabled); + BOOST_ASSERT(!data.reverse_segment_id.enabled || + datafacade.GetGeometryIndex(data.forward_segment_id.id).id == + datafacade.GetGeometryIndex(data.reverse_segment_id.id).id); + const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id; + const std::vector forward_weight_vector = - datafacade.GetUncompressedForwardWeights(data.packed_geometry_id); + datafacade.GetUncompressedForwardWeights(geometry_id); const std::vector reverse_weight_vector = - datafacade.GetUncompressedReverseWeights(data.packed_geometry_id); + datafacade.GetUncompressedReverseWeights(geometry_id); const std::vector forward_duration_vector = - datafacade.GetUncompressedForwardDurations(data.packed_geometry_id); + datafacade.GetUncompressedForwardDurations(geometry_id); const std::vector reverse_duration_vector = - datafacade.GetUncompressedReverseDurations(data.packed_geometry_id); + datafacade.GetUncompressedReverseDurations(geometry_id); for (std::size_t i = 0; i < data.fwd_segment_position; i++) { @@ -505,20 +511,25 @@ template class GeospatialQuery bool forward_edge_valid = false; bool reverse_edge_valid = false; + const auto &data = segment.data; + BOOST_ASSERT(data.forward_segment_id.enabled); + BOOST_ASSERT(data.forward_segment_id.id != SPECIAL_NODEID); + const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id; + const std::vector forward_weight_vector = - datafacade.GetUncompressedForwardWeights(segment.data.packed_geometry_id); + datafacade.GetUncompressedForwardWeights(geometry_id); - if (forward_weight_vector[segment.data.fwd_segment_position] != INVALID_EDGE_WEIGHT) + if (forward_weight_vector[data.fwd_segment_position] != INVALID_EDGE_WEIGHT) { - forward_edge_valid = segment.data.forward_segment_id.enabled; + forward_edge_valid = data.forward_segment_id.enabled; } const std::vector reverse_weight_vector = - datafacade.GetUncompressedReverseWeights(segment.data.packed_geometry_id); - if (reverse_weight_vector[reverse_weight_vector.size() - segment.data.fwd_segment_position - - 1] != INVALID_EDGE_WEIGHT) + datafacade.GetUncompressedReverseWeights(geometry_id); + if (reverse_weight_vector[reverse_weight_vector.size() - data.fwd_segment_position - 1] != + INVALID_EDGE_WEIGHT) { - reverse_edge_valid = segment.data.reverse_segment_id.enabled; + reverse_edge_valid = data.reverse_segment_id.enabled; } return std::make_pair(forward_edge_valid, reverse_edge_valid); diff --git a/include/engine/guidance/assemble_geometry.hpp b/include/engine/guidance/assemble_geometry.hpp index da86a96ee77..761f4c63756 100644 --- a/include/engine/guidance/assemble_geometry.hpp +++ b/include/engine/guidance/assemble_geometry.hpp @@ -51,8 +51,11 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, // source node rev: 2 0 <- 1 <- 2 const auto source_segment_start_coordinate = source_node.fwd_segment_position + (reversed_source ? 1 : 0); + const auto source_node_id = + reversed_source ? source_node.reverse_segment_id.id : source_node.forward_segment_id.id; + const auto source_gemetry_id = facade.GetGeometryIndex(source_node_id).id; const std::vector source_geometry = - facade.GetUncompressedForwardGeometry(source_node.packed_geometry_id); + facade.GetUncompressedForwardGeometry(source_gemetry_id); geometry.osm_node_ids.push_back( facade.GetOSMNodeIDOfNode(source_geometry[source_segment_start_coordinate])); @@ -89,8 +92,11 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, // segment leading to the target node geometry.segment_distances.push_back(cumulative_distance); + const auto target_node_id = + reversed_target ? target_node.reverse_segment_id.id : target_node.forward_segment_id.id; + const auto target_gemetry_id = facade.GetGeometryIndex(target_node_id).id; const std::vector forward_datasources = - facade.GetUncompressedForwardDatasources(target_node.packed_geometry_id); + facade.GetUncompressedForwardDatasources(target_gemetry_id); // FIXME if source and target phantoms are on the same segment then duration and weight // will be from one projected point till end of segment @@ -113,7 +119,7 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, const auto target_segment_end_coordinate = target_node.fwd_segment_position + (reversed_target ? 0 : 1); const std::vector target_geometry = - facade.GetUncompressedForwardGeometry(target_node.packed_geometry_id); + facade.GetUncompressedForwardGeometry(target_gemetry_id); geometry.osm_node_ids.push_back( facade.GetOSMNodeIDOfNode(target_geometry[target_segment_end_coordinate])); diff --git a/include/engine/guidance/assemble_leg.hpp b/include/engine/guidance/assemble_leg.hpp index 5e1e2d6f29b..5bd2cca0ec1 100644 --- a/include/engine/guidance/assemble_leg.hpp +++ b/include/engine/guidance/assemble_leg.hpp @@ -40,7 +40,8 @@ struct NamedSegment template -std::array summarizeRoute(const std::vector &route_data, +std::array summarizeRoute(const datafacade::BaseDataFacade &facade, + const std::vector &route_data, const PhantomNode &target_node, const bool target_traversed_in_reverse) { @@ -80,8 +81,10 @@ std::array summarizeRoute(const std::vector 1) - segments.push_back({target_duration, index++, target_node.name_id}); + segments.push_back({target_duration, index++, facade.GetNameIndex(target_node_id)}); // this makes sure that the segment with the lowest position comes first std::sort( segments.begin(), segments.end(), [](const NamedSegment &lhs, const NamedSegment &rhs) { @@ -183,7 +186,7 @@ inline RouteLeg assembleLeg(const datafacade::BaseDataFacade &facade, if (needs_summary) { auto summary_array = detail::summarizeRoute( - route_data, target_node, target_traversed_in_reverse); + facade, route_data, target_node, target_traversed_in_reverse); BOOST_ASSERT(detail::MAX_USED_SEGMENTS > 0); BOOST_ASSERT(summary_array.begin() != summary_array.end()); diff --git a/include/engine/guidance/assemble_steps.hpp b/include/engine/guidance/assemble_steps.hpp index ce007611723..66826e5c8b5 100644 --- a/include/engine/guidance/assemble_steps.hpp +++ b/include/engine/guidance/assemble_steps.hpp @@ -49,15 +49,19 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa source_traversed_in_reverse ? source_node.reverse_weight : source_node.forward_weight; const EdgeWeight source_duration = source_traversed_in_reverse ? source_node.reverse_duration : source_node.forward_duration; - const auto source_mode = source_traversed_in_reverse ? source_node.backward_travel_mode - : source_node.forward_travel_mode; + const auto source_node_id = source_traversed_in_reverse ? source_node.reverse_segment_id.id + : source_node.forward_segment_id.id; + const auto source_name_id = facade.GetNameIndex(source_node_id); + const auto source_mode = facade.GetTravelMode(source_node_id); const EdgeWeight target_duration = target_traversed_in_reverse ? target_node.reverse_duration : target_node.forward_duration; const EdgeWeight target_weight = target_traversed_in_reverse ? target_node.reverse_weight : target_node.forward_weight; - const auto target_mode = target_traversed_in_reverse ? target_node.backward_travel_mode - : target_node.forward_travel_mode; + const auto target_node_id = target_traversed_in_reverse ? target_node.reverse_segment_id.id + : target_node.forward_segment_id.id; + const auto target_name_id = facade.GetNameIndex(target_node_id); + const auto target_mode = facade.GetTravelMode(target_node_id); const auto number_of_segments = leg_geometry.GetNumberOfSegments(); @@ -95,7 +99,7 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa // some name changes are not announced in our processing. For these, we have to keep the // first name on the segment - auto step_name_id = source_node.name_id; + auto step_name_id = source_name_id; for (std::size_t leg_data_index = 0; leg_data_index < leg_data.size(); ++leg_data_index) { const auto &path_point = leg_data[leg_data_index]; @@ -134,7 +138,7 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa } else { - step_name_id = target_node.name_id; + step_name_id = facade.GetNameIndex(target_node_id); } // extract bearings @@ -230,11 +234,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa BOOST_ASSERT(target_duration >= source_duration || weight == 0); const EdgeWeight duration = std::max(0, target_duration - source_duration); - steps.push_back(RouteStep{source_node.name_id, - facade.GetNameForID(source_node.name_id).to_string(), - facade.GetRefForID(source_node.name_id).to_string(), - facade.GetPronunciationForID(source_node.name_id).to_string(), - facade.GetDestinationsForID(source_node.name_id).to_string(), + steps.push_back(RouteStep{source_name_id, + facade.GetNameForID(source_name_id).to_string(), + facade.GetRefForID(source_name_id).to_string(), + facade.GetPronunciationForID(source_name_id).to_string(), + facade.GetDestinationsForID(source_name_id).to_string(), NO_ROTARY_NAME, NO_ROTARY_NAME, duration / 10., @@ -268,11 +272,11 @@ inline std::vector assembleSteps(const datafacade::BaseDataFacade &fa 0}; BOOST_ASSERT(!leg_geometry.locations.empty()); - steps.push_back(RouteStep{target_node.name_id, - facade.GetNameForID(target_node.name_id).to_string(), - facade.GetRefForID(target_node.name_id).to_string(), - facade.GetPronunciationForID(target_node.name_id).to_string(), - facade.GetDestinationsForID(target_node.name_id).to_string(), + steps.push_back(RouteStep{target_name_id, + facade.GetNameForID(target_name_id).to_string(), + facade.GetRefForID(target_name_id).to_string(), + facade.GetPronunciationForID(target_name_id).to_string(), + facade.GetDestinationsForID(target_name_id).to_string(), NO_ROTARY_NAME, NO_ROTARY_NAME, ZERO_DURATION, diff --git a/include/engine/hint.hpp b/include/engine/hint.hpp index 12757e5f991..334a45fd9df 100644 --- a/include/engine/hint.hpp +++ b/include/engine/hint.hpp @@ -63,8 +63,8 @@ struct Hint friend std::ostream &operator<<(std::ostream &, const Hint &); }; -static_assert(sizeof(Hint) == 72 + 4, "Hint is bigger than expected"); -constexpr std::size_t ENCODED_HINT_SIZE = 104; +static_assert(sizeof(Hint) == 64 + 4, "Hint is bigger than expected"); +constexpr std::size_t ENCODED_HINT_SIZE = 92; static_assert(ENCODED_HINT_SIZE / 4 * 3 >= sizeof(Hint), "ENCODED_HINT_SIZE does not match size of Hint"); } diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 49ad24f84c9..0d420439641 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -48,16 +48,13 @@ struct PhantomNode { PhantomNode() : forward_segment_id{SPECIAL_SEGMENTID, false}, - reverse_segment_id{SPECIAL_SEGMENTID, false}, - name_id(std::numeric_limits::max()), forward_weight(INVALID_EDGE_WEIGHT), + reverse_segment_id{SPECIAL_SEGMENTID, false}, forward_weight(INVALID_EDGE_WEIGHT), reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0), forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), forward_duration_offset(0), reverse_duration_offset(0), - packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false}, - fwd_segment_position(0), forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), - backward_travel_mode(TRAVEL_MODE_INACCESSIBLE), is_valid_forward_source(false), - is_valid_forward_target(false), is_valid_reverse_source(false), - is_valid_reverse_target(false) + component{INVALID_COMPONENTID, false}, fwd_segment_position(0), + is_valid_forward_source(false), is_valid_forward_target(false), + is_valid_reverse_source(false), is_valid_reverse_target(false) { } @@ -95,7 +92,7 @@ struct PhantomNode (reverse_weight != INVALID_EDGE_WEIGHT)) && ((forward_duration != MAXIMAL_EDGE_DURATION) || (reverse_duration != MAXIMAL_EDGE_DURATION)) && - (component.id != INVALID_COMPONENTID) && (name_id != INVALID_NAMEID); + (component.id != INVALID_COMPONENTID); } bool IsValid(const unsigned number_of_nodes, const util::Coordinate queried_coordinate) const @@ -103,7 +100,7 @@ struct PhantomNode return queried_coordinate == input_location && IsValid(number_of_nodes); } - bool IsValid() const { return location.IsValid() && (name_id != INVALID_NAMEID); } + bool IsValid() const { return location.IsValid(); } bool IsValidForwardSource() const { @@ -141,17 +138,13 @@ struct PhantomNode const util::Coordinate location, const util::Coordinate input_location) : forward_segment_id{other.forward_segment_id}, - reverse_segment_id{other.reverse_segment_id}, name_id{other.name_id}, - forward_weight{forward_weight}, reverse_weight{reverse_weight}, - forward_weight_offset{forward_weight_offset}, + reverse_segment_id{other.reverse_segment_id}, forward_weight{forward_weight}, + reverse_weight{reverse_weight}, forward_weight_offset{forward_weight_offset}, reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration}, reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset}, reverse_duration_offset{reverse_duration_offset}, - packed_geometry_id{other.packed_geometry_id}, component{other.component.id, other.component.is_tiny}, location{location}, input_location{input_location}, fwd_segment_position{other.fwd_segment_position}, - forward_travel_mode{other.forward_travel_mode}, - backward_travel_mode{other.backward_travel_mode}, is_valid_forward_source{is_valid_forward_source}, is_valid_forward_target{is_valid_forward_target}, is_valid_reverse_source{is_valid_reverse_source}, @@ -161,7 +154,6 @@ struct PhantomNode SegmentID forward_segment_id; SegmentID reverse_segment_id; - unsigned name_id; EdgeWeight forward_weight; EdgeWeight reverse_weight; EdgeWeight forward_weight_offset; // TODO: try to remove -> requires path unpacking changes @@ -170,7 +162,6 @@ struct PhantomNode EdgeWeight reverse_duration; EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes - unsigned packed_geometry_id; struct ComponentType { std::uint32_t id : 31; @@ -181,10 +172,6 @@ struct PhantomNode util::Coordinate location; util::Coordinate input_location; unsigned short fwd_segment_position; - // note 4 bits would suffice for each, - // but the saved byte would be padding anyway - extractor::TravelMode forward_travel_mode : 4; - extractor::TravelMode backward_travel_mode : 4; // is phantom node valid to be used as source or target private: bool is_valid_forward_source : 1; @@ -193,7 +180,7 @@ struct PhantomNode bool is_valid_reverse_target : 1; }; -static_assert(sizeof(PhantomNode) == 72, "PhantomNode has more padding then expected"); +static_assert(sizeof(PhantomNode) == 64, "PhantomNode has more padding then expected"); using PhantomNodePair = std::pair; @@ -220,7 +207,6 @@ inline std::ostream &operator<<(std::ostream &out, const PhantomNode &pn) { out << "node1: " << pn.forward_segment_id.id << ", " << "node2: " << pn.reverse_segment_id.id << ", " - << "name: " << pn.name_id << ", " << "fwd-w: " << pn.forward_weight << ", " << "rev-w: " << pn.reverse_weight << ", " << "fwd-o: " << pn.forward_weight_offset << ", " @@ -229,7 +215,6 @@ inline std::ostream &operator<<(std::ostream &out, const PhantomNode &pn) << "rev-d: " << pn.reverse_duration << ", " << "fwd-do: " << pn.forward_duration_offset << ", " << "rev-do: " << pn.reverse_duration_offset << ", " - << "geom: " << pn.packed_geometry_id << ", " << "comp: " << pn.component.is_tiny << " / " << pn.component.id << ", " << "pos: " << pn.fwd_segment_position << ", " << "loc: " << pn.location; diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index e157652f96c..38cf95d961f 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -91,15 +91,17 @@ void annotatePath(const FacadeT &facade, BOOST_ASSERT(!unpacked_nodes.empty()); BOOST_ASSERT(unpacked_nodes.size() == unpacked_edges.size() + 1); + const auto source_node_id = unpacked_nodes.front(); + const auto target_node_id = unpacked_nodes.back(); const bool start_traversed_in_reverse = - phantom_node_pair.source_phantom.forward_segment_id.id != unpacked_nodes.front(); + phantom_node_pair.source_phantom.forward_segment_id.id != source_node_id; const bool target_traversed_in_reverse = - phantom_node_pair.target_phantom.forward_segment_id.id != unpacked_nodes.back(); + phantom_node_pair.target_phantom.forward_segment_id.id != target_node_id; - BOOST_ASSERT(phantom_node_pair.source_phantom.forward_segment_id.id == unpacked_nodes.front() || - phantom_node_pair.source_phantom.reverse_segment_id.id == unpacked_nodes.front()); - BOOST_ASSERT(phantom_node_pair.target_phantom.forward_segment_id.id == unpacked_nodes.back() || - phantom_node_pair.target_phantom.reverse_segment_id.id == unpacked_nodes.back()); + BOOST_ASSERT(phantom_node_pair.source_phantom.forward_segment_id.id == source_node_id || + phantom_node_pair.source_phantom.reverse_segment_id.id == source_node_id); + BOOST_ASSERT(phantom_node_pair.target_phantom.forward_segment_id.id == target_node_id || + phantom_node_pair.target_phantom.reverse_segment_id.id == target_node_id); auto node_from = unpacked_nodes.begin(), node_last = std::prev(unpacked_nodes.end()); for (auto edge = unpacked_edges.begin(); node_from != node_last; ++node_from, ++edge) @@ -109,10 +111,7 @@ void annotatePath(const FacadeT &facade, const auto node_id = *node_from; // edge-based graph node index const auto name_index = facade.GetNameIndex(node_id); const auto turn_instruction = facade.GetTurnInstructionForEdgeID(turn_id); - const extractor::TravelMode travel_mode = - (unpacked_path.empty() && start_traversed_in_reverse) - ? phantom_node_pair.source_phantom.backward_travel_mode - : facade.GetTravelMode(node_id); + const extractor::TravelMode travel_mode = facade.GetTravelMode(node_id); const auto geometry_index = facade.GetGeometryIndex(node_id); std::vector id_vector; @@ -181,23 +180,16 @@ void annotatePath(const FacadeT &facade, std::vector weight_vector; std::vector duration_vector; std::vector datasource_vector; - const bool is_local_path = (phantom_node_pair.source_phantom.packed_geometry_id == - phantom_node_pair.target_phantom.packed_geometry_id) && - unpacked_path.empty(); + const auto source_geometry_id = facade.GetGeometryIndex(source_node_id).id; + const auto target_geometry_id = facade.GetGeometryIndex(target_node_id).id; + const auto is_local_path = source_geometry_id == target_geometry_id && unpacked_path.empty(); if (target_traversed_in_reverse) { - id_vector = facade.GetUncompressedReverseGeometry( - phantom_node_pair.target_phantom.packed_geometry_id); - - weight_vector = facade.GetUncompressedReverseWeights( - phantom_node_pair.target_phantom.packed_geometry_id); - - duration_vector = facade.GetUncompressedReverseDurations( - phantom_node_pair.target_phantom.packed_geometry_id); - - datasource_vector = facade.GetUncompressedReverseDatasources( - phantom_node_pair.target_phantom.packed_geometry_id); + id_vector = facade.GetUncompressedReverseGeometry(target_geometry_id); + weight_vector = facade.GetUncompressedReverseWeights(target_geometry_id); + duration_vector = facade.GetUncompressedReverseDurations(target_geometry_id); + datasource_vector = facade.GetUncompressedReverseDatasources(target_geometry_id); if (is_local_path) { @@ -215,17 +207,10 @@ void annotatePath(const FacadeT &facade, } end_index = phantom_node_pair.target_phantom.fwd_segment_position; - id_vector = facade.GetUncompressedForwardGeometry( - phantom_node_pair.target_phantom.packed_geometry_id); - - weight_vector = facade.GetUncompressedForwardWeights( - phantom_node_pair.target_phantom.packed_geometry_id); - - duration_vector = facade.GetUncompressedForwardDurations( - phantom_node_pair.target_phantom.packed_geometry_id); - - datasource_vector = facade.GetUncompressedForwardDatasources( - phantom_node_pair.target_phantom.packed_geometry_id); + id_vector = facade.GetUncompressedForwardGeometry(target_geometry_id); + weight_vector = facade.GetUncompressedForwardWeights(target_geometry_id); + duration_vector = facade.GetUncompressedForwardDurations(target_geometry_id); + datasource_vector = facade.GetUncompressedForwardDatasources(target_geometry_id); } // Given the following compressed geometry: @@ -239,20 +224,19 @@ void annotatePath(const FacadeT &facade, (start_index < end_index ? ++segment_idx : --segment_idx)) { BOOST_ASSERT(segment_idx < id_vector.size() - 1); - BOOST_ASSERT(phantom_node_pair.target_phantom.forward_travel_mode > 0); - unpacked_path.push_back(PathData{ - id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1], - phantom_node_pair.target_phantom.name_id, - weight_vector[segment_idx], - duration_vector[segment_idx], - extractor::guidance::TurnInstruction::NO_TURN(), - {{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID}, - target_traversed_in_reverse ? phantom_node_pair.target_phantom.backward_travel_mode - : phantom_node_pair.target_phantom.forward_travel_mode, - INVALID_ENTRY_CLASSID, - datasource_vector[segment_idx], - util::guidance::TurnBearing(0), - util::guidance::TurnBearing(0)}); + BOOST_ASSERT(facade.GetTravelMode(target_node_id) > 0); + unpacked_path.push_back( + PathData{id_vector[start_index < end_index ? segment_idx + 1 : segment_idx - 1], + facade.GetNameIndex(target_node_id), + weight_vector[segment_idx], + duration_vector[segment_idx], + extractor::guidance::TurnInstruction::NO_TURN(), + {{0, INVALID_LANEID}, INVALID_LANE_DESCRIPTIONID}, + facade.GetTravelMode(target_node_id), + INVALID_ENTRY_CLASSID, + datasource_vector[segment_idx], + util::guidance::TurnBearing(0), + util::guidance::TurnBearing(0)}); } if (unpacked_path.size() > 0) diff --git a/include/extractor/edge_based_graph_factory.hpp b/include/extractor/edge_based_graph_factory.hpp index 00891c3aaf3..664dc6c36ea 100644 --- a/include/extractor/edge_based_graph_factory.hpp +++ b/include/extractor/edge_based_graph_factory.hpp @@ -7,11 +7,11 @@ #include "extractor/edge_based_edge.hpp" #include "extractor/edge_based_node.hpp" #include "extractor/extraction_turn.hpp" -#include "extractor/node_data_container.hpp" #include "extractor/guidance/turn_analysis.hpp" #include "extractor/guidance/turn_instruction.hpp" #include "extractor/guidance/turn_lane_types.hpp" #include "extractor/nbg_to_ebg.hpp" +#include "extractor/node_data_container.hpp" #include "extractor/original_edge_data.hpp" #include "extractor/packed_osm_ids.hpp" #include "extractor/profile_properties.hpp" diff --git a/include/extractor/edge_based_node.hpp b/include/extractor/edge_based_node.hpp index 07d41aaeb17..543560cba99 100644 --- a/include/extractor/edge_based_node.hpp +++ b/include/extractor/edge_based_node.hpp @@ -22,10 +22,8 @@ struct EdgeBasedNode EdgeBasedNode() : forward_segment_id{SPECIAL_SEGMENTID, false}, reverse_segment_id{SPECIAL_SEGMENTID, false}, u(SPECIAL_NODEID), v(SPECIAL_NODEID), - name_id(0), packed_geometry_id(SPECIAL_GEOMETRYID), component{INVALID_COMPONENTID, false}, - fwd_segment_position(std::numeric_limits::max()), - forward_travel_mode(TRAVEL_MODE_INACCESSIBLE), - backward_travel_mode(TRAVEL_MODE_INACCESSIBLE) + component{INVALID_COMPONENTID, false}, + fwd_segment_position(std::numeric_limits::max()) { } @@ -33,36 +31,27 @@ struct EdgeBasedNode const SegmentID reverse_segment_id_, NodeID u, NodeID v, - unsigned name_id, - unsigned packed_geometry_id_, bool is_tiny_component, unsigned component_id, - unsigned short fwd_segment_position, - TravelMode forward_travel_mode, - TravelMode backward_travel_mode) + unsigned short fwd_segment_position) : forward_segment_id(forward_segment_id_), reverse_segment_id(reverse_segment_id_), u(u), - v(v), name_id(name_id), packed_geometry_id(packed_geometry_id_), - component{component_id, is_tiny_component}, fwd_segment_position(fwd_segment_position), - forward_travel_mode(forward_travel_mode), backward_travel_mode(backward_travel_mode) + v(v), component{component_id, is_tiny_component}, + fwd_segment_position(fwd_segment_position) { BOOST_ASSERT(forward_segment_id.enabled || reverse_segment_id.enabled); } - SegmentID forward_segment_id; // needed for edge-expanded graph - SegmentID reverse_segment_id; // needed for edge-expanded graph - NodeID u; // indices into the coordinates array - NodeID v; // indices into the coordinates array - NameID name_id; // id of the edge name + SegmentID forward_segment_id; // edge-based graph node ID in forward direction (u->v) + SegmentID reverse_segment_id; // edge-based graph node ID in reverse direction (v->u if exists) + NodeID u; // node-based graph node ID of the start node + NodeID v; // node-based graph node ID of the target node - unsigned packed_geometry_id; struct { unsigned id : 31; bool is_tiny : 1; } component; unsigned short fwd_segment_position; // segment id in a compressed geometry - TravelMode forward_travel_mode : 4; - TravelMode backward_travel_mode : 4; }; } } diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index 4f9a99d0ef3..c5329b2b9c5 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -366,6 +366,10 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & return offset; }; + const auto get_geometry_id = [&facade](auto edge) { + return facade.GetGeometryIndex(edge.forward_segment_id.id).id; + }; + // Vector tiles encode feature properties as indexes into a lookup table. So, we need // to "pre-loop" over all the edges to create the lookup tables. Once we have those, we // can then encode the features, and we'll know the indexes that feature properties @@ -374,10 +378,11 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & { const auto &edge = edges[edge_index]; + const auto geometry_id = get_geometry_id(edge); const auto forward_datasource_vector = - facade.GetUncompressedForwardDatasources(edge.packed_geometry_id); + facade.GetUncompressedForwardDatasources(geometry_id); const auto reverse_datasource_vector = - facade.GetUncompressedReverseDatasources(edge.packed_geometry_id); + facade.GetUncompressedReverseDatasources(geometry_id); BOOST_ASSERT(edge.fwd_segment_position < forward_datasource_vector.size()); const auto forward_datasource = forward_datasource_vector[edge.fwd_segment_position]; @@ -421,12 +426,13 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & for (const auto &edge_index : sorted_edge_indexes) { const auto &edge = edges[edge_index]; + const auto geometry_id = get_geometry_id(edge); // Weight values const auto forward_weight_vector = - facade.GetUncompressedForwardWeights(edge.packed_geometry_id); + facade.GetUncompressedForwardWeights(geometry_id); const auto reverse_weight_vector = - facade.GetUncompressedReverseWeights(edge.packed_geometry_id); + facade.GetUncompressedReverseWeights(geometry_id); const auto forward_weight = forward_weight_vector[edge.fwd_segment_position]; const auto reverse_weight = reverse_weight_vector[reverse_weight_vector.size() - edge.fwd_segment_position - 1]; @@ -435,9 +441,9 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & // Duration values const auto forward_duration_vector = - facade.GetUncompressedForwardDurations(edge.packed_geometry_id); + facade.GetUncompressedForwardDurations(geometry_id); const auto reverse_duration_vector = - facade.GetUncompressedReverseDurations(edge.packed_geometry_id); + facade.GetUncompressedReverseDurations(geometry_id); const auto forward_duration = forward_duration_vector[edge.fwd_segment_position]; const auto reverse_duration = reverse_duration_vector[reverse_duration_vector.size() - @@ -453,6 +459,8 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & for (const auto &edge_index : sorted_edge_indexes) { const auto &edge = edges[edge_index]; + const auto geometry_id = get_geometry_id(edge); + // Get coordinates for start/end nodes of segment (NodeIDs u and v) const auto a = facade.GetCoordinateOfNode(edge.u); const auto b = facade.GetCoordinateOfNode(edge.v); @@ -461,17 +469,17 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & osrm::util::coordinate_calculation::haversineDistance(a, b); const auto forward_weight_vector = - facade.GetUncompressedForwardWeights(edge.packed_geometry_id); + facade.GetUncompressedForwardWeights(geometry_id); const auto reverse_weight_vector = - facade.GetUncompressedReverseWeights(edge.packed_geometry_id); + facade.GetUncompressedReverseWeights(geometry_id); const auto forward_duration_vector = - facade.GetUncompressedForwardDurations(edge.packed_geometry_id); + facade.GetUncompressedForwardDurations(geometry_id); const auto reverse_duration_vector = - facade.GetUncompressedReverseDurations(edge.packed_geometry_id); + facade.GetUncompressedReverseDurations(geometry_id); const auto forward_datasource_vector = - facade.GetUncompressedForwardDatasources(edge.packed_geometry_id); + facade.GetUncompressedForwardDatasources(geometry_id); const auto reverse_datasource_vector = - facade.GetUncompressedReverseDatasources(edge.packed_geometry_id); + facade.GetUncompressedReverseDatasources(geometry_id); const auto forward_weight = forward_weight_vector[edge.fwd_segment_position]; const auto reverse_weight = reverse_weight_vector[reverse_weight_vector.size() - @@ -487,7 +495,8 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & reverse_datasource_vector[reverse_datasource_vector.size() - edge.fwd_segment_position - 1]; - auto name = facade.GetNameForID(edge.name_id); + const auto name_id = facade.GetNameIndex(edge.forward_segment_id.id); + auto name = facade.GetNameForID(name_id); const auto name_offset = [&name, &names, &name_offsets]() { auto iter = name_offsets.find(name); diff --git a/src/engine/routing_algorithms/tile_turns.cpp b/src/engine/routing_algorithms/tile_turns.cpp index 8cac0d8f660..2fc80a74a71 100644 --- a/src/engine/routing_algorithms/tile_turns.cpp +++ b/src/engine/routing_algorithms/tile_turns.cpp @@ -37,6 +37,10 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade // it saves us a bunch of re-allocations during iteration. directed_graph.reserve(edges.size() * 2); + const auto get_geometry_id = [&facade](auto edge) { + return facade.GetGeometryIndex(edge.forward_segment_id.id).id; + }; + // Build an adjacency list for all the road segments visible in // the tile for (const auto &edge_index : sorted_edge_indexes) @@ -48,14 +52,14 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade directed_graph[edge.u].push_back({edge.v, edge.forward_segment_id.id}); if (edge_based_node_info.count(edge.forward_segment_id.id) == 0) { - edge_based_node_info[edge.forward_segment_id.id] = {true, edge.packed_geometry_id}; + edge_based_node_info[edge.forward_segment_id.id] = {true, get_geometry_id(edge)}; } else { BOOST_ASSERT(edge_based_node_info[edge.forward_segment_id.id].is_geometry_forward == true); BOOST_ASSERT(edge_based_node_info[edge.forward_segment_id.id].packed_geometry_id == - edge.packed_geometry_id); + get_geometry_id(edge)); } } if (edge.reverse_segment_id.enabled) @@ -63,14 +67,14 @@ getTileTurns(const datafacade::ContiguousInternalMemoryDataFacade directed_graph[edge.v].push_back({edge.u, edge.reverse_segment_id.id}); if (edge_based_node_info.count(edge.reverse_segment_id.id) == 0) { - edge_based_node_info[edge.reverse_segment_id.id] = {false, edge.packed_geometry_id}; + edge_based_node_info[edge.reverse_segment_id.id] = {false, get_geometry_id(edge)}; } else { BOOST_ASSERT(edge_based_node_info[edge.reverse_segment_id.id].is_geometry_forward == false); BOOST_ASSERT(edge_based_node_info[edge.reverse_segment_id.id].packed_geometry_id == - edge.packed_geometry_id); + get_geometry_id(edge)); } } } diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 08c0ad38129..598ef7e37af 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -163,13 +163,9 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N edge_id_to_segment_id(reverse_data.edge_id), current_edge_source_coordinate_id, current_edge_target_coordinate_id, - forward_data.name_id, - packed_geometry_id, false, INVALID_COMPONENTID, - i, - forward_data.travel_mode, - reverse_data.travel_mode); + i); m_edge_based_node_is_startpoint.push_back(forward_data.startpoint || reverse_data.startpoint); @@ -323,16 +319,18 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_fi BOOST_ASSERT(is_encoded_forwards || is_encoded_backwards); - auto geometry_id = - is_encoded_forwards - ? m_compressed_edge_container.GetZippedPositionForForwardID(nbg_edge_id) - : is_encoded_backwards - ? m_compressed_edge_container.GetZippedPositionForReverseID( - nbg_edge_id) - : SPECIAL_GEOMETRYID; - - BOOST_ASSERT(m_ebg_node_data_container.GetNameID(nbg_edge_data.edge_id) == nbg_edge_data.name_id); - BOOST_ASSERT(m_ebg_node_data_container.GetTravelMode(nbg_edge_data.edge_id) == nbg_edge_data.travel_mode); + // auto geometry_id = + // is_encoded_forwards + // ? m_compressed_edge_container.GetZippedPositionForForwardID(nbg_edge_id) + // : is_encoded_backwards + // ? m_compressed_edge_container.GetZippedPositionForReverseID( + // nbg_edge_id) + // : SPECIAL_GEOMETRYID; + + BOOST_ASSERT(m_ebg_node_data_container.GetNameID(nbg_edge_data.edge_id) == + nbg_edge_data.name_id); + BOOST_ASSERT(m_ebg_node_data_container.GetTravelMode(nbg_edge_data.edge_id) == + nbg_edge_data.travel_mode); // m_ebg_node_data_container.SetData(nbg_edge_data.edge_id, // GeometryID{geometry_id, is_encoded_forwards}, diff --git a/unit_tests/server/parameters_parser.cpp b/unit_tests/server/parameters_parser.cpp index abfe1c68ce1..8c572994035 100644 --- a/unit_tests/server/parameters_parser.cpp +++ b/unit_tests/server/parameters_parser.cpp @@ -86,9 +86,8 @@ BOOST_AUTO_TEST_CASE(invalid_table_urls) BOOST_AUTO_TEST_CASE(valid_route_hint) { - auto hint = engine::Hint::FromBase64("XAYAgP___3-" - "QAAAABQAAACgAAABMAAAAJQAAAAUAAAAoAAAATAAAACUAAAB7BQAAFAAA" - "AGpocQC3gpsCO2hxAMuCmwIFAAEBDJujEQ=="); + auto hint = engine::Hint::FromBase64("ZgYAgP___38EAAAAIAAAAD4AAAAdAAAABAAAACAAAAA-" + "AAAAHQAAABQAAABqaHEAt4KbAjtocQDLgpsCBQAPAJDIe3E="); BOOST_CHECK_EQUAL( hint.phantom.input_location, util::Coordinate(util::FloatLongitude{7.432251}, util::FloatLatitude{43.745995})); @@ -158,14 +157,12 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) CHECK_EQUAL_RANGE(reference_3.hints, result_3->hints); std::vector> hints_4 = { - engine::Hint::FromBase64("XAYAgP___3-" - "QAAAABQAAACgAAABMAAAAJQAAAAUAAAAoAAAATAAAACUAAAB7BQAAFAAAAGpocQC3" - "gpsCO2hxAMuCmwIFAAEBDJujEQ=="), - engine::Hint::FromBase64("lgQAgP___3-" - "QAAAAEwAAABgAAAAyAAAAOAAAABMAAAAYAAAAMgAAADgAAAA0AAAAFAAAAJphcQC-" - "c5sC3GFxALtzmwIEAAEBDJujEQ=="), - engine::Hint::FromBase64("OAUAgMUFAIAAAAAAHgAAAAUAAAAAAAAALQEAAB4AAAAFAAAAAAAAAC0BAAC8BAAAF" - "AAAAIM-cQBQVpsCiD5xAFBWmwIAAAEBDJujEQ==")}; + engine::Hint::FromBase64("ZgYAgP___38EAAAAIAAAAD4AAAAdAAAABAAAACAAAAA-AAAAHQAAABQAAA" + "BqaHEAt4KbAjtocQDLgpsCBQAPAJDIe3E="), + engine::Hint::FromBase64("ngQAgP___38TAAAAGAAAAC8AAAA4AAAAEwAAABgAAAAvAAAAOAAAABQAAA" + "CaYXEAvnObAtxhcQC7c5sCBAAPAJDIe3E="), + engine::Hint::FromBase64("QAUAgM0FAIAYAAAABAAAAAAAAADxAAAAGAAAAAQAAAAAAAAA8QAAABQAAA" + "CDPnEAUFabAog-cQBQVpsCAAAPAJDIe3E=")}; RouteParameters reference_4{false, false, false, @@ -178,13 +175,12 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) std::vector>{}}; auto result_4 = parseParameters( "1,2;3,4?steps=false&hints=" - "XAYAgP___3-" - "QAAAABQAAACgAAABMAAAAJQAAAAUAAAAoAAAATAAAACUAAAB7BQAAFAAAAGpocQC3gpsCO2hxAMuCmwIFAAEBDJujE" - "Q==;" - "lgQAgP___3-QAAAAEwAAABgAAAAyAAAAOAAAABMAAAAYAAAAMgAAADgAAAA0AAAAFAAAAJphcQC-" - "c5sC3GFxALtzmwIEAAEBDJujEQ==;" - "OAUAgMUFAIAAAAAAHgAAAAUAAAAAAAAALQEAAB4AAAAFAAAAAAAAAC0BAAC8BAAAFAAAAIM-" - "cQBQVpsCiD5xAFBWmwIAAAEBDJujEQ=="); + "ZgYAgP___38EAAAAIAAAAD4AAAAdAAAABAAAACAAAAA-" + "AAAAHQAAABQAAABqaHEAt4KbAjtocQDLgpsCBQAPAJDIe3E=;" + "ngQAgP___" + "38TAAAAGAAAAC8AAAA4AAAAEwAAABgAAAAvAAAAOAAAABQAAACaYXEAvnObAtxhcQC7c5sCBAAPAJDIe3E=;" + "QAUAgM0FAIAYAAAABAAAAAAAAADxAAAAGAAAAAQAAAAAAAAA8QAAABQAAACDPnEAUFabAog-" + "cQBQVpsCAAAPAJDIe3E="); BOOST_CHECK(result_4); BOOST_CHECK_EQUAL(reference_4.steps, result_4->steps); BOOST_CHECK_EQUAL(reference_4.alternatives, result_4->alternatives); @@ -279,12 +275,11 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) {util::FloatLongitude{5}, util::FloatLatitude{6}}, {util::FloatLongitude{7}, util::FloatLatitude{8}}}; std::vector> hints_10 = { - engine::Hint::FromBase64("XAYAgP___3-" - "QAAAABQAAACgAAABMAAAAJQAAAAUAAAAoAAAATAAAACUAAAB7BQAAFAAAAGpocQC3" - "gpsCO2hxAMuCmwIFAAEBDJujEQ=="), + engine::Hint::FromBase64("ZgYAgP___38EAAAAIAAAAD4AAAAdAAAABAAAACAAAAA-" + "AAAAHQAAABQAAABqaHEAt4KbAjtocQDLgpsCBQAPAJDIe3E="), boost::none, - engine::Hint::FromBase64("OAUAgMUFAIAAAAAAHgAAAAUAAAAAAAAALQEAAB4AAAAFAAAAAAAAAC0BAAC8BAAAF" - "AAAAIM-cQBQVpsCiD5xAFBWmwIAAAEBDJujEQ=="), + engine::Hint::FromBase64("QAUAgM0FAIAYAAAABAAAAAAAAADxAAAAGAAAAAQAAAAAAAAA8QAAABQAAACDPnEAU" + "FabAog-cQBQVpsCAAAPAJDIe3E="), boost::none}; RouteParameters reference_10{false, false, @@ -298,11 +293,10 @@ BOOST_AUTO_TEST_CASE(valid_route_urls) std::vector>{}}; auto result_10 = parseParameters("1,2;3,4;5,6;7,8?steps=false&hints=" - "XAYAgP___3-" - "QAAAABQAAACgAAABMAAAAJQAAAAUAAAAoAAAATAAAACUAAAB7BQAAFAAA" - "AGpocQC3gpsCO2hxAMuCmwIFAAEBDJujEQ==;;" - "OAUAgMUFAIAAAAAAHgAAAAUAAAAAAAAALQEAAB4AAAAFAAAAAAAAAC0BA" - "AC8BAAAFAAAAIM-cQBQVpsCiD5xAFBWmwIAAAEBDJujEQ==;"); + "ZgYAgP___38EAAAAIAAAAD4AAAAdAAAABAAAACAAAAA-" + "AAAAHQAAABQAAABqaHEAt4KbAjtocQDLgpsCBQAPAJDIe3E=;;" + "QAUAgM0FAIAYAAAABAAAAAAAAADxAAAAGAAAAAQAAAAAAAAA8QAAABQAA" + "ACDPnEAUFabAog-cQBQVpsCAAAPAJDIe3E=;"); BOOST_CHECK(result_10); BOOST_CHECK_EQUAL(reference_10.steps, result_10->steps); BOOST_CHECK_EQUAL(reference_10.alternatives, result_10->alternatives); diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index dc5e14155c6..72a3fa3eb48 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -171,7 +171,6 @@ struct GraphFixture d.forward_segment_id = {pair.second, true}; d.reverse_segment_id = {pair.first, true}; d.fwd_segment_position = 0; - d.packed_geometry_id = 0; edges.emplace_back(d); } } From 2b1158120ed7efb80488109416e6b8cda05de343 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 15 May 2017 11:04:32 +0200 Subject: [PATCH 3/9] Initialize unused bits in PhantomNode --- include/engine/phantom_node.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 0d420439641..6ce17032f30 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -53,8 +53,8 @@ struct PhantomNode forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), forward_duration_offset(0), reverse_duration_offset(0), component{INVALID_COMPONENTID, false}, fwd_segment_position(0), - is_valid_forward_source(false), is_valid_forward_target(false), - is_valid_reverse_source(false), is_valid_reverse_target(false) + is_valid_forward_source{false}, is_valid_forward_target{false}, + is_valid_reverse_source{false}, is_valid_reverse_target{false}, unused{0} { } @@ -148,7 +148,7 @@ struct PhantomNode is_valid_forward_source{is_valid_forward_source}, is_valid_forward_target{is_valid_forward_target}, is_valid_reverse_source{is_valid_reverse_source}, - is_valid_reverse_target{is_valid_reverse_target} + is_valid_reverse_target{is_valid_reverse_target}, unused{0} { } @@ -174,10 +174,11 @@ struct PhantomNode unsigned short fwd_segment_position; // is phantom node valid to be used as source or target private: - bool is_valid_forward_source : 1; - bool is_valid_forward_target : 1; - bool is_valid_reverse_source : 1; - bool is_valid_reverse_target : 1; + unsigned short is_valid_forward_source : 1; + unsigned short is_valid_forward_target : 1; + unsigned short is_valid_reverse_source : 1; + unsigned short is_valid_reverse_target : 1; + unsigned short unused : 12; }; static_assert(sizeof(PhantomNode) == 64, "PhantomNode has more padding then expected"); From bd22445c2adf580db03d105c200f3fe8e218ac54 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 15 May 2017 12:15:00 +0200 Subject: [PATCH 4/9] Move ComponentID to EdgeBasedNodeDataContainer --- include/contractor/contractor.hpp | 3 - .../contiguous_internalmem_datafacade.hpp | 16 ++++- include/engine/datafacade/datafacade_base.hpp | 2 + include/engine/geospatial_query.hpp | 42 +++++++----- include/engine/phantom_node.hpp | 13 ++-- .../extractor/edge_based_graph_factory.hpp | 6 +- include/extractor/edge_based_node.hpp | 12 +--- include/extractor/extractor.hpp | 3 +- include/extractor/node_data_container.hpp | 15 +++- include/extractor/serialization.hpp | 2 + include/storage/shared_datatype.hpp | 2 + include/util/typedefs.hpp | 7 ++ src/engine/plugins/tile.cpp | 4 +- src/extractor/edge_based_graph_factory.cpp | 61 +++-------------- src/extractor/extractor.cpp | 68 ++++++++----------- src/storage/storage.cpp | 14 +++- unit_tests/mocks/mock_datafacade.hpp | 4 ++ unit_tests/util/static_rtree.cpp | 1 - 18 files changed, 134 insertions(+), 141 deletions(-) diff --git a/include/contractor/contractor.hpp b/include/contractor/contractor.hpp index 1c6b5873665..96ed1befea7 100644 --- a/include/contractor/contractor.hpp +++ b/include/contractor/contractor.hpp @@ -68,9 +68,6 @@ class Contractor void WriteCoreNodeMarker(std::vector &&is_core_node) const; void WriteContractedGraph(unsigned number_of_edge_based_nodes, util::DeallocatingVector contracted_edge_list); - void FindComponents(unsigned max_edge_id, - const util::DeallocatingVector &edges, - std::vector &nodes) const; private: ContractorConfig config; diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index 9c5f2b93a6b..81fe6c30c18 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -330,13 +330,20 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::vector_view name_ids(name_id_list_ptr, layout.num_entries[storage::DataLayout::NAME_ID_LIST]); + const auto component_id_list_ptr = + layout.GetBlockPtr(memory_ptr, storage::DataLayout::COMPONENT_ID_LIST); + util::vector_view component_ids( + component_id_list_ptr, layout.num_entries[storage::DataLayout::COMPONENT_ID_LIST]); + const auto travel_mode_list_ptr = layout.GetBlockPtr( memory_ptr, storage::DataLayout::TRAVEL_MODE_LIST); util::vector_view travel_modes( travel_mode_list_ptr, layout.num_entries[storage::DataLayout::TRAVEL_MODE_LIST]); - edge_based_node_data = extractor::EdgeBasedNodeDataView( - std::move(geometry_ids), std::move(name_ids), std::move(travel_modes)); + edge_based_node_data = extractor::EdgeBasedNodeDataView(std::move(geometry_ids), + std::move(name_ids), + std::move(component_ids), + std::move(travel_modes)); } void InitializeEdgeInformationPointers(storage::DataLayout &layout, char *memory_ptr) @@ -742,6 +749,11 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade return edge_based_node_data.GetGeometryID(id); } + ComponentID GetComponentID(const NodeID id) const + { + return edge_based_node_data.GetComponentID(id); + } + extractor::TravelMode GetTravelMode(const NodeID id) const override final { return edge_based_node_data.GetTravelMode(id); diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 3473945f5fb..a6cc4a2eeb7 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -53,6 +53,8 @@ class BaseDataFacade virtual GeometryID GetGeometryIndex(const NodeID id) const = 0; + virtual ComponentID GetComponentID(const NodeID id) const = 0; + virtual std::vector GetUncompressedForwardGeometry(const EdgeID id) const = 0; virtual std::vector GetUncompressedReverseGeometry(const EdgeID id) const = 0; diff --git a/include/engine/geospatial_query.hpp b/include/engine/geospatial_query.hpp index 34a9168d57d..21c7014b2c9 100644 --- a/include/engine/geospatial_query.hpp +++ b/include/engine/geospatial_query.hpp @@ -176,15 +176,15 @@ template class GeospatialQuery auto results = rtree.Nearest( input_coordinate, [this, &has_big_component, &has_small_component](const CandidateSegment &segment) { - auto use_segment = (!has_small_component || - (!has_big_component && !segment.data.component.is_tiny)); + auto use_segment = + (!has_small_component || (!has_big_component && !IsTinyComponent(segment))); auto use_directions = std::make_pair(use_segment, use_segment); const auto valid_edges = HasValidEdge(segment); if (valid_edges.first || valid_edges.second) { - has_big_component = has_big_component || !segment.data.component.is_tiny; - has_small_component = has_small_component || segment.data.component.is_tiny; + has_big_component = has_big_component || !IsTinyComponent(segment); + has_small_component = has_small_component || IsTinyComponent(segment); } use_directions = boolPairAnd(use_directions, valid_edges); return use_directions; @@ -215,8 +215,8 @@ template class GeospatialQuery auto results = rtree.Nearest( input_coordinate, [this, &has_big_component, &has_small_component](const CandidateSegment &segment) { - auto use_segment = (!has_small_component || - (!has_big_component && !segment.data.component.is_tiny)); + auto use_segment = + (!has_small_component || (!has_big_component && !IsTinyComponent(segment))); auto use_directions = std::make_pair(use_segment, use_segment); if (!use_directions.first && !use_directions.second) return use_directions; @@ -225,8 +225,8 @@ template class GeospatialQuery if (valid_edges.first || valid_edges.second) { - has_big_component = has_big_component || !segment.data.component.is_tiny; - has_small_component = has_small_component || segment.data.component.is_tiny; + has_big_component = has_big_component || !IsTinyComponent(segment); + has_small_component = has_small_component || IsTinyComponent(segment); } use_directions = boolPairAnd(use_directions, valid_edges); @@ -257,8 +257,8 @@ template class GeospatialQuery input_coordinate, [this, bearing, bearing_range, &has_big_component, &has_small_component]( const CandidateSegment &segment) { - auto use_segment = (!has_small_component || - (!has_big_component && !segment.data.component.is_tiny)); + auto use_segment = + (!has_small_component || (!has_big_component && !IsTinyComponent(segment))); auto use_directions = std::make_pair(use_segment, use_segment); use_directions = boolPairAnd(use_directions, HasValidEdge(segment)); @@ -269,8 +269,8 @@ template class GeospatialQuery HasValidEdge(segment)); if (use_directions.first || use_directions.second) { - has_big_component = has_big_component || !segment.data.component.is_tiny; - has_small_component = has_small_component || segment.data.component.is_tiny; + has_big_component = has_big_component || !IsTinyComponent(segment); + has_small_component = has_small_component || IsTinyComponent(segment); } } @@ -304,8 +304,8 @@ template class GeospatialQuery input_coordinate, [this, bearing, bearing_range, &has_big_component, &has_small_component]( const CandidateSegment &segment) { - auto use_segment = (!has_small_component || - (!has_big_component && !segment.data.component.is_tiny)); + auto use_segment = + (!has_small_component || (!has_big_component && !IsTinyComponent(segment))); auto use_directions = std::make_pair(use_segment, use_segment); use_directions = boolPairAnd(use_directions, HasValidEdge(segment)); @@ -316,8 +316,8 @@ template class GeospatialQuery HasValidEdge(segment)); if (use_directions.first || use_directions.second) { - has_big_component = has_big_component || !segment.data.component.is_tiny; - has_small_component = has_small_component || segment.data.component.is_tiny; + has_big_component = has_big_component || !IsTinyComponent(segment); + has_small_component = has_small_component || IsTinyComponent(segment); } } @@ -379,6 +379,7 @@ template class GeospatialQuery datafacade.GetGeometryIndex(data.forward_segment_id.id).id == datafacade.GetGeometryIndex(data.reverse_segment_id.id).id); const auto geometry_id = datafacade.GetGeometryIndex(data.forward_segment_id.id).id; + const auto component_id = datafacade.GetComponentID(data.forward_segment_id.id); const std::vector forward_weight_vector = datafacade.GetUncompressedForwardWeights(geometry_id); @@ -437,6 +438,7 @@ template class GeospatialQuery reverse_weight_vector.begin(), reverse_weight_vector.end() - data.fwd_segment_position); auto transformed = PhantomNodeWithDistance{PhantomNode{data, + component_id, forward_weight, reverse_weight, forward_weight_offset, @@ -535,6 +537,14 @@ template class GeospatialQuery return std::make_pair(forward_edge_valid, reverse_edge_valid); } + bool IsTinyComponent(const CandidateSegment &segment) const + { + const auto &data = segment.data; + BOOST_ASSERT(data.forward_segment_id.enabled); + BOOST_ASSERT(data.forward_segment_id.id != SPECIAL_NODEID); + return datafacade.GetComponentID(data.forward_segment_id.id).is_tiny; + } + const RTreeT &rtree; const CoordinateList &coordinates; DataFacadeT &datafacade; diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 6ce17032f30..104087c2db6 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -51,8 +51,7 @@ struct PhantomNode reverse_segment_id{SPECIAL_SEGMENTID, false}, forward_weight(INVALID_EDGE_WEIGHT), reverse_weight(INVALID_EDGE_WEIGHT), forward_weight_offset(0), reverse_weight_offset(0), forward_duration(MAXIMAL_EDGE_DURATION), reverse_duration(MAXIMAL_EDGE_DURATION), - forward_duration_offset(0), reverse_duration_offset(0), - component{INVALID_COMPONENTID, false}, fwd_segment_position(0), + forward_duration_offset(0), reverse_duration_offset(0), fwd_segment_position(0), is_valid_forward_source{false}, is_valid_forward_target{false}, is_valid_reverse_source{false}, is_valid_reverse_target{false}, unused{0} { @@ -123,6 +122,7 @@ struct PhantomNode template explicit PhantomNode(const OtherT &other, + ComponentID component, EdgeWeight forward_weight, EdgeWeight reverse_weight, EdgeWeight forward_weight_offset, @@ -143,7 +143,7 @@ struct PhantomNode reverse_weight_offset{reverse_weight_offset}, forward_duration{forward_duration}, reverse_duration{reverse_duration}, forward_duration_offset{forward_duration_offset}, reverse_duration_offset{reverse_duration_offset}, - component{other.component.id, other.component.is_tiny}, location{location}, + component{component.id, component.is_tiny}, location{location}, input_location{input_location}, fwd_segment_position{other.fwd_segment_position}, is_valid_forward_source{is_valid_forward_source}, is_valid_forward_target{is_valid_forward_target}, @@ -162,12 +162,7 @@ struct PhantomNode EdgeWeight reverse_duration; EdgeWeight forward_duration_offset; // TODO: try to remove -> requires path unpacking changes EdgeWeight reverse_duration_offset; // TODO: try to remove -> requires path unpacking changes - struct ComponentType - { - std::uint32_t id : 31; - std::uint32_t is_tiny : 1; - } component; - static_assert(sizeof(ComponentType) == 4, "ComponentType needs to be 4 bytes big"); + ComponentID component; util::Coordinate location; util::Coordinate input_location; diff --git a/include/extractor/edge_based_graph_factory.hpp b/include/extractor/edge_based_graph_factory.hpp index 664dc6c36ea..1200a88e91c 100644 --- a/include/extractor/edge_based_graph_factory.hpp +++ b/include/extractor/edge_based_graph_factory.hpp @@ -84,7 +84,6 @@ class EdgeBasedGraphFactory guidance::LaneDescriptionMap &lane_description_map); void Run(ScriptingEnvironment &scripting_environment, - const std::string &nodes_data_filename, const std::string &turn_data_filename, const std::string &turn_lane_data_filename, const std::string &turn_weight_penalties_filename, @@ -94,7 +93,8 @@ class EdgeBasedGraphFactory // The following get access functions destroy the content in the factory void GetEdgeBasedEdges(util::DeallocatingVector &edges); - void GetEdgeBasedNodes(std::vector &nodes); + void GetEdgeBasedNodes(EdgeBasedNodeDataExternalContainer &ebg_node_data_container); + void GetNodeBasedEdges(std::vector &nodes); void GetStartPointMarkers(std::vector &node_is_startpoint); void GetEdgeBasedNodeWeights(std::vector &output_node_weights); @@ -152,7 +152,7 @@ class EdgeBasedGraphFactory unsigned RenumberEdges(); - std::vector GenerateEdgeExpandedNodes(const std::string &node_data_filename); + std::vector GenerateEdgeExpandedNodes(); void GenerateEdgeExpandedEdges(ScriptingEnvironment &scripting_environment, const std::string &original_edge_data_filename, diff --git a/include/extractor/edge_based_node.hpp b/include/extractor/edge_based_node.hpp index 543560cba99..fd4852c80c2 100644 --- a/include/extractor/edge_based_node.hpp +++ b/include/extractor/edge_based_node.hpp @@ -22,7 +22,6 @@ struct EdgeBasedNode EdgeBasedNode() : forward_segment_id{SPECIAL_SEGMENTID, false}, reverse_segment_id{SPECIAL_SEGMENTID, false}, u(SPECIAL_NODEID), v(SPECIAL_NODEID), - component{INVALID_COMPONENTID, false}, fwd_segment_position(std::numeric_limits::max()) { } @@ -31,12 +30,9 @@ struct EdgeBasedNode const SegmentID reverse_segment_id_, NodeID u, NodeID v, - bool is_tiny_component, - unsigned component_id, unsigned short fwd_segment_position) : forward_segment_id(forward_segment_id_), reverse_segment_id(reverse_segment_id_), u(u), - v(v), component{component_id, is_tiny_component}, - fwd_segment_position(fwd_segment_position) + v(v), fwd_segment_position(fwd_segment_position) { BOOST_ASSERT(forward_segment_id.enabled || reverse_segment_id.enabled); } @@ -45,12 +41,6 @@ struct EdgeBasedNode SegmentID reverse_segment_id; // edge-based graph node ID in reverse direction (v->u if exists) NodeID u; // node-based graph node ID of the start node NodeID v; // node-based graph node ID of the target node - - struct - { - unsigned id : 31; - bool is_tiny : 1; - } component; unsigned short fwd_segment_position; // segment id in a compressed geometry }; } diff --git a/include/extractor/extractor.hpp b/include/extractor/extractor.hpp index 95846a9d677..8871a81e6e5 100644 --- a/include/extractor/extractor.hpp +++ b/include/extractor/extractor.hpp @@ -63,6 +63,7 @@ class Extractor BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, std::vector &coordinates, extractor::PackedOSMIDs &osm_node_ids, + EdgeBasedNodeDataExternalContainer &ebg_node_data_container, std::vector &node_based_edge_list, std::vector &node_is_startpoint, std::vector &edge_based_node_weights, @@ -73,7 +74,7 @@ class Extractor const ProfileProperties &properties) const; void FindComponents(unsigned max_edge_id, const util::DeallocatingVector &edges, - std::vector &nodes) const; + EdgeBasedNodeDataExternalContainer &nodes) const; void BuildRTree(std::vector node_based_edge_list, std::vector node_is_startpoint, const std::vector &coordinates); diff --git a/include/extractor/node_data_container.hpp b/include/extractor/node_data_container.hpp index 17f5ffa6b1c..37d31346666 100644 --- a/include/extractor/node_data_container.hpp +++ b/include/extractor/node_data_container.hpp @@ -38,15 +38,16 @@ template class EdgeBasedNodeDataContainerImpl EdgeBasedNodeDataContainerImpl() = default; EdgeBasedNodeDataContainerImpl(std::size_t size) - : geometry_ids(size), name_ids(size), travel_modes(size) + : geometry_ids(size), name_ids(size), component_ids(size), travel_modes(size) { } EdgeBasedNodeDataContainerImpl(Vector geometry_ids, Vector name_ids, + Vector component_ids, Vector travel_modes) : geometry_ids(std::move(geometry_ids)), name_ids(std::move(name_ids)), - travel_modes(std::move(travel_modes)) + component_ids(std::move(component_ids)), travel_modes(std::move(travel_modes)) { } @@ -56,6 +57,8 @@ template class EdgeBasedNodeDataContainerImpl NameID GetNameID(const NodeID node_id) const { return name_ids[node_id]; } + ComponentID GetComponentID(const NodeID node_id) const { return component_ids[node_id]; } + // Used by EdgeBasedGraphFactory to fill data structure template > void SetData(NodeID node_id, GeometryID geometry_id, NameID name_id, TravelMode travel_mode) @@ -65,6 +68,13 @@ template class EdgeBasedNodeDataContainerImpl travel_modes[node_id] = travel_mode; } + // Used by EdgeBasedGraphFactory to fill data structure + template > + void SetData(NodeID node_id, ComponentID component_id) + { + component_ids[node_id] = component_id; + } + friend void serialization::read(storage::io::FileReader &reader, EdgeBasedNodeDataContainerImpl &ebn_data_container); friend void @@ -74,6 +84,7 @@ template class EdgeBasedNodeDataContainerImpl private: Vector geometry_ids; Vector name_ids; + Vector component_ids; Vector travel_modes; }; } diff --git a/include/extractor/serialization.hpp b/include/extractor/serialization.hpp index e94455a0f88..a69a45172fc 100644 --- a/include/extractor/serialization.hpp +++ b/include/extractor/serialization.hpp @@ -87,6 +87,7 @@ inline void read(storage::io::FileReader &reader, { storage::serialization::read(reader, node_data_container.geometry_ids); storage::serialization::read(reader, node_data_container.name_ids); + storage::serialization::read(reader, node_data_container.component_ids); storage::serialization::read(reader, node_data_container.travel_modes); } @@ -96,6 +97,7 @@ inline void write(storage::io::FileWriter &writer, { storage::serialization::write(writer, node_data_container.geometry_ids); storage::serialization::write(writer, node_data_container.name_ids); + storage::serialization::write(writer, node_data_container.component_ids); storage::serialization::write(writer, node_data_container.travel_modes); } diff --git a/include/storage/shared_datatype.hpp b/include/storage/shared_datatype.hpp index 16adfeec946..86f54a606ee 100644 --- a/include/storage/shared_datatype.hpp +++ b/include/storage/shared_datatype.hpp @@ -21,6 +21,7 @@ const constexpr char CANARY[4] = {'O', 'S', 'R', 'M'}; const constexpr char *block_id_to_name[] = {"NAME_CHAR_DATA", "GEOMETRY_ID_LIST", "NAME_ID_LIST", + "COMPONENT_ID_LIST", "TRAVEL_MODE_LIST", "CH_GRAPH_NODE_LIST", "CH_GRAPH_EDGE_LIST", @@ -74,6 +75,7 @@ struct DataLayout NAME_CHAR_DATA = 0, GEOMETRY_ID_LIST, NAME_ID_LIST, + COMPONENT_ID_LIST, TRAVEL_MODE_LIST, CH_GRAPH_NODE_LIST, CH_GRAPH_EDGE_LIST, diff --git a/include/util/typedefs.hpp b/include/util/typedefs.hpp index 954535ccb2c..bba5c541259 100644 --- a/include/util/typedefs.hpp +++ b/include/util/typedefs.hpp @@ -147,4 +147,11 @@ struct GeometryID static_assert(sizeof(SegmentID) == 4, "SegmentID needs to be 4 bytes big"); +// Strongly connected component ID of an edge-based node +struct ComponentID +{ + std::uint32_t id : 31; + std::uint32_t is_tiny : 1; +}; + #endif /* TYPEDEFS_H */ diff --git a/src/engine/plugins/tile.cpp b/src/engine/plugins/tile.cpp index c5329b2b9c5..bf04767561e 100644 --- a/src/engine/plugins/tile.cpp +++ b/src/engine/plugins/tile.cpp @@ -495,6 +495,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & reverse_datasource_vector[reverse_datasource_vector.size() - edge.fwd_segment_position - 1]; + const auto component_id = facade.GetComponentID(edge.forward_segment_id.id); const auto name_id = facade.GetNameIndex(edge.forward_segment_id.id); auto name = facade.GetNameForID(name_id); @@ -512,6 +513,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & const auto encode_tile_line = [&line_layer_writer, &edge, + &component_id, &id, &max_datasource_id, &used_line_ints](const FixedLine &tile_line, @@ -549,7 +551,7 @@ void encodeVectorTile(const datafacade::ContiguousInternalMemoryDataFacadeBase & std::min(speed_kmh, 127u)); // save the speed value, capped at 127 field.add_element(1); // "is_small" tag key offset field.add_element(128 + - (edge.component.is_tiny ? 0 : 1)); // is_small feature + (component_id.is_tiny ? 0 : 1)); // is_small feature field.add_element(2); // "datasource" tag key offset field.add_element(130 + datasource); // datasource value offset field.add_element(3); // "weight" tag key offset diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 598ef7e37af..8deb5b2f15d 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -66,7 +66,14 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges( swap(m_edge_based_edge_list, output_edge_list); } -void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector &nodes) +void EdgeBasedGraphFactory::GetEdgeBasedNodes( + EdgeBasedNodeDataExternalContainer &ebg_node_data_container) +{ + using std::swap; // Koenig swap + swap(ebg_node_data_container, m_ebg_node_data_container); +} + +void EdgeBasedGraphFactory::GetNodeBasedEdges(std::vector &nodes) { using std::swap; // Koenig swap swap(nodes, m_edge_based_node_list); @@ -163,8 +170,6 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N edge_id_to_segment_id(reverse_data.edge_id), current_edge_source_coordinate_id, current_edge_target_coordinate_id, - false, - INVALID_COMPONENTID, i); m_edge_based_node_is_startpoint.push_back(forward_data.startpoint || @@ -178,7 +183,6 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N } void EdgeBasedGraphFactory::Run(ScriptingEnvironment &scripting_environment, - const std::string &node_data_filename, const std::string &turn_data_filename, const std::string &turn_lane_data_filename, const std::string &turn_weight_penalties_filename, @@ -192,7 +196,7 @@ void EdgeBasedGraphFactory::Run(ScriptingEnvironment &scripting_environment, TIMER_START(generate_nodes); { - auto mapping = GenerateEdgeExpandedNodes(node_data_filename); + auto mapping = GenerateEdgeExpandedNodes(); files::writeNBGMapping(cnbg_ebg_mapping_path, mapping); } TIMER_STOP(generate_nodes); @@ -249,12 +253,11 @@ unsigned EdgeBasedGraphFactory::RenumberEdges() } /// Creates the nodes in the edge expanded graph from edges in the node-based graph. -std::vector -EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_filename) +std::vector EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() { std::vector mapping; - // TODO: make m_ebg_node_data_container local + // Allocate memory for edge-based nodes m_ebg_node_data_container = EdgeBasedNodeDataExternalContainer(m_max_edge_id + 1); util::Log() << "Generating edge expanded nodes ... "; @@ -301,50 +304,8 @@ EdgeBasedGraphFactory::GenerateEdgeExpandedNodes(const std::string &node_data_fi BOOST_ASSERT(m_edge_based_node_list.size() == m_edge_based_node_is_startpoint.size()); BOOST_ASSERT(m_max_edge_id + 1 == m_edge_based_node_weights.size()); - { - // TODO: refactor saving edge-based node data with InsertEdgeBasedNode - for (const auto nbg_node_id : util::irange(0u, m_node_based_graph->GetNumberOfNodes())) - { - for (const auto nbg_edge_id : m_node_based_graph->GetAdjacentEdgeRange(nbg_node_id)) - { - const auto &nbg_edge_data = m_node_based_graph->GetEdgeData(nbg_edge_id); - - if (nbg_edge_data.edge_id == SPECIAL_EDGEID) - continue; - - const bool is_encoded_forwards = - m_compressed_edge_container.HasZippedEntryForForwardID(nbg_edge_id); - const bool is_encoded_backwards = - m_compressed_edge_container.HasZippedEntryForReverseID(nbg_edge_id); - - BOOST_ASSERT(is_encoded_forwards || is_encoded_backwards); - - // auto geometry_id = - // is_encoded_forwards - // ? m_compressed_edge_container.GetZippedPositionForForwardID(nbg_edge_id) - // : is_encoded_backwards - // ? m_compressed_edge_container.GetZippedPositionForReverseID( - // nbg_edge_id) - // : SPECIAL_GEOMETRYID; - - BOOST_ASSERT(m_ebg_node_data_container.GetNameID(nbg_edge_data.edge_id) == - nbg_edge_data.name_id); - BOOST_ASSERT(m_ebg_node_data_container.GetTravelMode(nbg_edge_data.edge_id) == - nbg_edge_data.travel_mode); - - // m_ebg_node_data_container.SetData(nbg_edge_data.edge_id, - // GeometryID{geometry_id, is_encoded_forwards}, - // nbg_edge_data.name_id, - // nbg_edge_data.travel_mode); - } - } - } - util::Log() << "Generated " << m_edge_based_node_list.size() << " nodes in edge-expanded graph"; - files::writeNodeData(node_data_filename, m_ebg_node_data_container); - m_ebg_node_data_container = EdgeBasedNodeDataExternalContainer(); - return mapping; } diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 31080b86c0d..c31ac6e6a4a 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -130,7 +130,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) TIMER_START(expansion); - std::vector edge_based_node_list; + EdgeBasedNodeDataExternalContainer edge_based_nodes_container; + std::vector node_based_edges_list; util::DeallocatingVector edge_based_edge_list; std::vector node_is_startpoint; std::vector edge_based_node_weights; @@ -140,7 +141,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) auto graph_size = BuildEdgeExpandedGraph(scripting_environment, coordinates, osm_node_ids, - edge_based_node_list, + edge_based_nodes_container, + node_based_edges_list, node_is_startpoint, edge_based_node_weights, edge_based_edge_list, @@ -163,16 +165,17 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) util::Log() << "Done writing. (" << TIMER_SEC(timer_write_node_weights) << ")"; util::Log() << "Computing strictly connected components ..."; - FindComponents(max_edge_id, edge_based_edge_list, edge_based_node_list); + FindComponents(max_edge_id, edge_based_edge_list, edge_based_nodes_container); util::Log() << "Building r-tree ..."; TIMER_START(rtree); - BuildRTree(std::move(edge_based_node_list), std::move(node_is_startpoint), coordinates); + BuildRTree(std::move(node_based_edges_list), std::move(node_is_startpoint), coordinates); TIMER_STOP(rtree); - util::Log() << "Writing node map ..."; + util::Log() << "Writing nodes for nodes-based and edges-based graphs ..."; files::writeNodes(config.node_output_path, coordinates, osm_node_ids); + files::writeNodeData(config.edge_based_nodes_data_path, edge_based_nodes_container); WriteEdgeBasedGraph(config.edge_graph_output_path, max_edge_id, edge_based_edge_list); @@ -335,7 +338,7 @@ void Extractor::WriteProfileProperties(const std::string &output_path, void Extractor::FindComponents(unsigned max_edge_id, const util::DeallocatingVector &input_edge_list, - std::vector &input_nodes) const + EdgeBasedNodeDataExternalContainer &input_nodes) const { using InputEdge = util::static_graph_details::SortableEdgeWithData; using UncontractedGraph = util::StaticGraph; @@ -359,18 +362,6 @@ void Extractor::FindComponents(unsigned max_edge_id, } } - // connect forward and backward nodes of each edge - for (const auto &node : input_nodes) - { - if (node.reverse_segment_id.enabled) - { - BOOST_ASSERT(node.forward_segment_id.id <= max_edge_id); - BOOST_ASSERT(node.reverse_segment_id.id <= max_edge_id); - edges.push_back({node.forward_segment_id.id, node.reverse_segment_id.id}); - edges.push_back({node.reverse_segment_id.id, node.forward_segment_id.id}); - } - } - tbb::parallel_sort(edges.begin(), edges.end()); edges.erase(std::unique(edges.begin(), edges.end()), edges.end()); @@ -379,16 +370,14 @@ void Extractor::FindComponents(unsigned max_edge_id, TarjanSCC component_search(uncontracted_graph); component_search.Run(); - for (auto &node : input_nodes) + stxxl::vector component_ids; + component_ids.reserve(max_edge_id + 1); + for (NodeID node_id = 0; node_id <= max_edge_id; ++node_id) { - auto forward_component = component_search.GetComponentID(node.forward_segment_id.id); - BOOST_ASSERT(!node.reverse_segment_id.enabled || - forward_component == - component_search.GetComponentID(node.reverse_segment_id.id)); - - const unsigned component_size = component_search.GetComponentSize(forward_component); - node.component.is_tiny = component_size < config.small_component_size; - node.component.id = 1 + forward_component; + const auto forward_component = component_search.GetComponentID(node_id); + const auto component_size = component_search.GetComponentSize(forward_component); + const auto is_tiny = component_size < config.small_component_size; + input_nodes.SetData(node_id, {1 + forward_component, is_tiny}); } } @@ -432,7 +421,8 @@ std::pair Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, std::vector &coordinates, extractor::PackedOSMIDs &osm_node_ids, - std::vector &node_based_edge_list, + EdgeBasedNodeDataExternalContainer &ebg_node_data_container, + std::vector &node_based_edges_list, std::vector &node_is_startpoint, std::vector &edge_based_node_weights, util::DeallocatingVector &edge_based_edge_list, @@ -477,7 +467,6 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, turn_lane_map); edge_based_graph_factory.Run(scripting_environment, - config.edge_based_nodes_data_path, config.edge_output_path, config.turn_lane_data_file_name, config.turn_weight_penalties_path, @@ -512,7 +501,8 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, *compressed_edge_container.ToSegmentData()); edge_based_graph_factory.GetEdgeBasedEdges(edge_based_edge_list); - edge_based_graph_factory.GetEdgeBasedNodes(node_based_edge_list); + edge_based_graph_factory.GetEdgeBasedNodes(ebg_node_data_container); + edge_based_graph_factory.GetNodeBasedEdges(node_based_edges_list); edge_based_graph_factory.GetStartPointMarkers(node_is_startpoint); edge_based_graph_factory.GetEdgeBasedNodeWeights(edge_based_node_weights); auto max_edge_id = edge_based_graph_factory.GetHighestEdgeID(); @@ -532,21 +522,21 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, Saves tree into '.ramIndex' and leaves into '.fileIndex'. */ -void Extractor::BuildRTree(std::vector node_based_edge_list, +void Extractor::BuildRTree(std::vector node_based_edges_list, std::vector node_is_startpoint, const std::vector &coordinates) { - util::Log() << "constructing r-tree of " << node_based_edge_list.size() + util::Log() << "constructing r-tree of " << node_based_edges_list.size() << " edge elements build on-top of " << coordinates.size() << " coordinates"; - BOOST_ASSERT(node_is_startpoint.size() == node_based_edge_list.size()); + BOOST_ASSERT(node_is_startpoint.size() == node_based_edges_list.size()); // Filter node based edges based on startpoint - auto out_iter = node_based_edge_list.begin(); - auto in_iter = node_based_edge_list.begin(); + auto out_iter = node_based_edges_list.begin(); + auto in_iter = node_based_edges_list.begin(); for (auto index : util::irange(0UL, node_is_startpoint.size())) { - BOOST_ASSERT(in_iter != node_based_edge_list.end()); + BOOST_ASSERT(in_iter != node_based_edges_list.end()); if (node_is_startpoint[index]) { *out_iter = *in_iter; @@ -554,17 +544,17 @@ void Extractor::BuildRTree(std::vector node_based_edge_list, } in_iter++; } - auto new_size = out_iter - node_based_edge_list.begin(); + auto new_size = out_iter - node_based_edges_list.begin(); if (new_size == 0) { throw util::exception("There are no snappable edges left after processing. Are you " "setting travel modes correctly in the profile? Cannot continue." + SOURCE_REF); } - node_based_edge_list.resize(new_size); + node_based_edges_list.resize(new_size); TIMER_START(construction); - util::StaticRTree rtree(node_based_edge_list, + util::StaticRTree rtree(node_based_edges_list, config.rtree_nodes_output_path, config.rtree_leafs_output_path, coordinates); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 0612e5c911c..187b9dcc199 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -250,7 +250,8 @@ void Storage::PopulateLayout(DataLayout &layout) const auto nodes_number = nodes_data_file.ReadElementCount64(); layout.SetBlockSize(DataLayout::GEOMETRY_ID_LIST, nodes_number); - layout.SetBlockSize(DataLayout::NAME_ID_LIST, nodes_number); + layout.SetBlockSize(DataLayout::NAME_ID_LIST, nodes_number); + layout.SetBlockSize(DataLayout::COMPONENT_ID_LIST, nodes_number); layout.SetBlockSize(DataLayout::TRAVEL_MODE_LIST, nodes_number); } @@ -594,13 +595,20 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) util::vector_view name_ids(name_id_list_ptr, layout.num_entries[storage::DataLayout::NAME_ID_LIST]); + auto component_ids_ptr = layout.GetBlockPtr( + memory_ptr, storage::DataLayout::COMPONENT_ID_LIST); + util::vector_view component_ids( + component_ids_ptr, layout.num_entries[storage::DataLayout::COMPONENT_ID_LIST]); + auto travel_mode_list_ptr = layout.GetBlockPtr( memory_ptr, storage::DataLayout::TRAVEL_MODE_LIST); util::vector_view travel_modes( travel_mode_list_ptr, layout.num_entries[storage::DataLayout::TRAVEL_MODE_LIST]); - extractor::EdgeBasedNodeDataView node_data( - std::move(geometry_ids), std::move(name_ids), std::move(travel_modes)); + extractor::EdgeBasedNodeDataView node_data(std::move(geometry_ids), + std::move(name_ids), + std::move(component_ids), + std::move(travel_modes)); extractor::files::readNodeData(config.edge_based_nodes_data_path, node_data); } diff --git a/unit_tests/mocks/mock_datafacade.hpp b/unit_tests/mocks/mock_datafacade.hpp index d73b0bf4fb9..57b48f3ef9c 100644 --- a/unit_tests/mocks/mock_datafacade.hpp +++ b/unit_tests/mocks/mock_datafacade.hpp @@ -34,6 +34,10 @@ class MockBaseDataFacade : public engine::datafacade::BaseDataFacade { return GeometryID{SPECIAL_GEOMETRYID, false}; } + ComponentID GetComponentID(const NodeID /* id */) const override + { + return ComponentID{INVALID_COMPONENTID, false}; + } TurnPenalty GetWeightPenaltyForEdgeID(const unsigned /* id */) const override final { return 0; diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index 72a3fa3eb48..cc395cae576 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -137,7 +137,6 @@ template struct RandomGraphFixture if (used_edges.find(std::pair( std::min(data.u, data.v), std::max(data.u, data.v))) == used_edges.end()) { - data.component.id = 0; edges.emplace_back(data); used_edges.emplace(std::min(data.u, data.v), std::max(data.u, data.v)); } From afcacf5b6dbe87efef2dee00a5bb0fefd4ced8dd Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 15 May 2017 22:36:52 +0200 Subject: [PATCH 5/9] Change EdgeBasedNodeDataExternalContainer to EdgeBasedNodeDataContainer --- include/extractor/edge_based_graph_factory.hpp | 4 ++-- include/extractor/extractor.hpp | 4 ++-- src/extractor/edge_based_graph_factory.cpp | 5 ++--- src/extractor/extractor.cpp | 6 +++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/extractor/edge_based_graph_factory.hpp b/include/extractor/edge_based_graph_factory.hpp index 1200a88e91c..3ff5d795dbd 100644 --- a/include/extractor/edge_based_graph_factory.hpp +++ b/include/extractor/edge_based_graph_factory.hpp @@ -93,7 +93,7 @@ class EdgeBasedGraphFactory // The following get access functions destroy the content in the factory void GetEdgeBasedEdges(util::DeallocatingVector &edges); - void GetEdgeBasedNodes(EdgeBasedNodeDataExternalContainer &ebg_node_data_container); + void GetEdgeBasedNodes(EdgeBasedNodeDataContainer &ebg_node_data_container); void GetNodeBasedEdges(std::vector &nodes); void GetStartPointMarkers(std::vector &node_is_startpoint); void GetEdgeBasedNodeWeights(std::vector &output_node_weights); @@ -130,7 +130,7 @@ class EdgeBasedGraphFactory //! list of edge based nodes (compressed segments) std::vector m_edge_based_node_list; - EdgeBasedNodeDataExternalContainer m_ebg_node_data_container; + EdgeBasedNodeDataContainer m_ebg_node_data_container; util::DeallocatingVector m_edge_based_edge_list; EdgeID m_max_edge_id; diff --git a/include/extractor/extractor.hpp b/include/extractor/extractor.hpp index 8871a81e6e5..191dc34f9c8 100644 --- a/include/extractor/extractor.hpp +++ b/include/extractor/extractor.hpp @@ -63,7 +63,7 @@ class Extractor BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, std::vector &coordinates, extractor::PackedOSMIDs &osm_node_ids, - EdgeBasedNodeDataExternalContainer &ebg_node_data_container, + EdgeBasedNodeDataContainer &ebg_node_data_container, std::vector &node_based_edge_list, std::vector &node_is_startpoint, std::vector &edge_based_node_weights, @@ -74,7 +74,7 @@ class Extractor const ProfileProperties &properties) const; void FindComponents(unsigned max_edge_id, const util::DeallocatingVector &edges, - EdgeBasedNodeDataExternalContainer &nodes) const; + EdgeBasedNodeDataContainer &nodes) const; void BuildRTree(std::vector node_based_edge_list, std::vector node_is_startpoint, const std::vector &coordinates); diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 8deb5b2f15d..a51ec1520a5 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -66,8 +66,7 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges( swap(m_edge_based_edge_list, output_edge_list); } -void EdgeBasedGraphFactory::GetEdgeBasedNodes( - EdgeBasedNodeDataExternalContainer &ebg_node_data_container) +void EdgeBasedGraphFactory::GetEdgeBasedNodes(EdgeBasedNodeDataContainer &ebg_node_data_container) { using std::swap; // Koenig swap swap(ebg_node_data_container, m_ebg_node_data_container); @@ -258,7 +257,7 @@ std::vector EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() std::vector mapping; // Allocate memory for edge-based nodes - m_ebg_node_data_container = EdgeBasedNodeDataExternalContainer(m_max_edge_id + 1); + m_ebg_node_data_container = EdgeBasedNodeDataContainer(m_max_edge_id + 1); util::Log() << "Generating edge expanded nodes ... "; { diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index c31ac6e6a4a..956f53ab235 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -130,7 +130,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) TIMER_START(expansion); - EdgeBasedNodeDataExternalContainer edge_based_nodes_container; + EdgeBasedNodeDataContainer edge_based_nodes_container; std::vector node_based_edges_list; util::DeallocatingVector edge_based_edge_list; std::vector node_is_startpoint; @@ -338,7 +338,7 @@ void Extractor::WriteProfileProperties(const std::string &output_path, void Extractor::FindComponents(unsigned max_edge_id, const util::DeallocatingVector &input_edge_list, - EdgeBasedNodeDataExternalContainer &input_nodes) const + EdgeBasedNodeDataContainer &input_nodes) const { using InputEdge = util::static_graph_details::SortableEdgeWithData; using UncontractedGraph = util::StaticGraph; @@ -421,7 +421,7 @@ std::pair Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, std::vector &coordinates, extractor::PackedOSMIDs &osm_node_ids, - EdgeBasedNodeDataExternalContainer &ebg_node_data_container, + EdgeBasedNodeDataContainer &ebg_node_data_container, std::vector &node_based_edges_list, std::vector &node_is_startpoint, std::vector &edge_based_node_weights, From ecbeee66e2e7ef3a05c71660519d911b6af6b1f2 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 15 May 2017 23:49:02 +0200 Subject: [PATCH 6/9] Rename .nodes -> .nbg_nodes and .nodes_data -> .ebg_nodes --- include/extractor/extractor_config.hpp | 6 +-- include/storage/storage_config.hpp | 4 +- include/updater/updater_config.hpp | 8 ++-- src/engine/engine_config.cpp | 4 +- src/extractor/extractor.cpp | 2 +- src/storage/storage.cpp | 5 +- src/storage/storage_config.cpp | 13 +++--- src/tools/routed.cpp | 64 +++++++------------------- src/updater/updater.cpp | 10 ++-- 9 files changed, 44 insertions(+), 72 deletions(-) diff --git a/include/extractor/extractor_config.hpp b/include/extractor/extractor_config.hpp index cf0f28b5696..793a5f33ddf 100644 --- a/include/extractor/extractor_config.hpp +++ b/include/extractor/extractor_config.hpp @@ -65,7 +65,8 @@ struct ExtractorConfig turn_lane_data_file_name = basepath + ".osrm.tld"; timestamp_file_name = basepath + ".osrm.timestamp"; geometry_output_path = basepath + ".osrm.geometry"; - node_output_path = basepath + ".osrm.nodes"; + node_based_nodes_data_path = basepath + ".osrm.nbg_nodes"; + edge_based_nodes_data_path = basepath + ".osrm.ebg_nodes"; edge_output_path = basepath + ".osrm.edges"; edge_graph_output_path = basepath + ".osrm.ebg"; rtree_nodes_output_path = basepath + ".osrm.ramIndex"; @@ -74,7 +75,6 @@ struct ExtractorConfig turn_weight_penalties_path = basepath + ".osrm.turn_weight_penalties"; turn_penalties_index_path = basepath + ".osrm.turn_penalties_index"; edge_based_node_weights_output_path = basepath + ".osrm.enw"; - edge_based_nodes_data_path = basepath + ".osrm.nodes_data"; profile_properties_output_path = basepath + ".osrm.properties"; intersection_class_data_output_path = basepath + ".osrm.icd"; compressed_node_based_graph_output_path = basepath + ".osrm.cnbg"; @@ -93,9 +93,9 @@ struct ExtractorConfig std::string geometry_output_path; std::string edge_output_path; std::string edge_graph_output_path; + std::string node_based_nodes_data_path; std::string edge_based_nodes_data_path; std::string edge_based_node_weights_output_path; - std::string node_output_path; std::string rtree_nodes_output_path; std::string rtree_leafs_output_path; std::string profile_properties_output_path; diff --git a/include/storage/storage_config.hpp b/include/storage/storage_config.hpp index fa71a0291ef..2841ec64631 100644 --- a/include/storage/storage_config.hpp +++ b/include/storage/storage_config.hpp @@ -55,9 +55,9 @@ struct StorageConfig final boost::filesystem::path ram_index_path; boost::filesystem::path file_index_path; boost::filesystem::path hsgr_data_path; - boost::filesystem::path nodes_data_path; - boost::filesystem::path edges_data_path; + boost::filesystem::path node_based_nodes_data_path; boost::filesystem::path edge_based_nodes_data_path; + boost::filesystem::path edges_data_path; boost::filesystem::path core_data_path; boost::filesystem::path geometries_path; boost::filesystem::path timestamp_path; diff --git a/include/updater/updater_config.hpp b/include/updater/updater_config.hpp index 751a0e0f5de..93cdde453fd 100644 --- a/include/updater/updater_config.hpp +++ b/include/updater/updater_config.hpp @@ -47,9 +47,9 @@ struct UpdaterConfig final 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"; - node_based_graph_path = osrm_input_path.string() + ".nodes"; + node_based_nodes_data_path = osrm_input_path.string() + ".nbg_nodes"; + edge_based_nodes_data_path = osrm_input_path.string() + ".ebg_nodes"; edge_data_path = osrm_input_path.string() + ".edges"; - edge_based_nodes_data_path = osrm_input_path.string() + ".nodes_data"; geometry_path = osrm_input_path.string() + ".geometry"; rtree_leaf_path = osrm_input_path.string() + ".fileIndex"; datasource_names_path = osrm_input_path.string() + ".datasource_names"; @@ -64,9 +64,9 @@ struct UpdaterConfig final std::string turn_weight_penalties_path; std::string turn_duration_penalties_path; std::string turn_penalties_index_path; - std::string node_based_graph_path; - std::string edge_data_path; + std::string node_based_nodes_data_path; std::string edge_based_nodes_data_path; + std::string edge_data_path; std::string geometry_path; std::string rtree_leaf_path; diff --git a/src/engine/engine_config.cpp b/src/engine/engine_config.cpp index 9d322486fe9..357aeff4e28 100644 --- a/src/engine/engine_config.cpp +++ b/src/engine/engine_config.cpp @@ -9,7 +9,9 @@ bool EngineConfig::IsValid() const { const bool all_path_are_empty = storage_config.ram_index_path.empty() && storage_config.file_index_path.empty() && - storage_config.hsgr_data_path.empty() && storage_config.nodes_data_path.empty() && + storage_config.hsgr_data_path.empty() && + storage_config.node_based_nodes_data_path.empty() && + storage_config.edge_based_nodes_data_path.empty() && storage_config.edges_data_path.empty() && storage_config.core_data_path.empty() && storage_config.geometries_path.empty() && storage_config.timestamp_path.empty() && storage_config.datasource_names_path.empty() && diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index 956f53ab235..c4ee9ff00e7 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -174,7 +174,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) TIMER_STOP(rtree); util::Log() << "Writing nodes for nodes-based and edges-based graphs ..."; - files::writeNodes(config.node_output_path, coordinates, osm_node_ids); + files::writeNodes(config.node_based_nodes_data_path, coordinates, osm_node_ids); files::writeNodeData(config.edge_based_nodes_data_path, edge_based_nodes_container); WriteEdgeBasedGraph(config.edge_graph_output_path, max_edge_id, edge_based_edge_list); diff --git a/src/storage/storage.cpp b/src/storage/storage.cpp index 187b9dcc199..f97073ede35 100644 --- a/src/storage/storage.cpp +++ b/src/storage/storage.cpp @@ -327,7 +327,8 @@ void Storage::PopulateLayout(DataLayout &layout) // load coordinate size { - io::FileReader node_file(config.nodes_data_path, io::FileReader::VerifyFingerprint); + io::FileReader node_file(config.node_based_nodes_data_path, + io::FileReader::VerifyFingerprint); const auto coordinate_list_size = node_file.ReadElementCount64(); layout.SetBlockSize(DataLayout::COORDINATE_LIST, coordinate_list_size); node_file.Skip(coordinate_list_size); @@ -724,7 +725,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr) layout.num_entries[DataLayout::OSM_NODE_ID_LIST] * extractor::PackedOSMIDsView::BLOCK_ELEMENTS); - extractor::files::readNodes(config.nodes_data_path, coordinates, osm_node_ids); + extractor::files::readNodes(config.node_based_nodes_data_path, coordinates, osm_node_ids); } // load turn weight penalties diff --git a/src/storage/storage_config.cpp b/src/storage/storage_config.cpp index 2deca768147..968537b07fb 100644 --- a/src/storage/storage_config.cpp +++ b/src/storage/storage_config.cpp @@ -26,11 +26,11 @@ bool CheckFileList(const std::vector &files) StorageConfig::StorageConfig(const boost::filesystem::path &base) : ram_index_path{base.string() + ".ramIndex"}, file_index_path{base.string() + ".fileIndex"}, - hsgr_data_path{base.string() + ".hsgr"}, nodes_data_path{base.string() + ".nodes"}, - edges_data_path{base.string() + ".edges"}, - edge_based_nodes_data_path{base.string() + ".nodes_data"}, - core_data_path{base.string() + ".core"}, geometries_path{base.string() + ".geometry"}, - timestamp_path{base.string() + ".timestamp"}, + hsgr_data_path{base.string() + ".hsgr"}, + node_based_nodes_data_path{base.string() + ".nbg_nodes"}, + edge_based_nodes_data_path{base.string() + ".ebg_nodes"}, + edges_data_path{base.string() + ".edges"}, core_data_path{base.string() + ".core"}, + geometries_path{base.string() + ".geometry"}, timestamp_path{base.string() + ".timestamp"}, turn_weight_penalties_path{base.string() + ".turn_weight_penalties"}, turn_duration_penalties_path{base.string() + ".turn_duration_penalties"}, datasource_names_path{base.string() + ".datasource_names"}, @@ -47,7 +47,8 @@ bool StorageConfig::IsValid() const // Common files if (!CheckFileList({ram_index_path, file_index_path, - nodes_data_path, + node_based_nodes_data_path, + edge_based_nodes_data_path, edges_data_path, geometries_path, timestamp_path, diff --git a/src/tools/routed.cpp b/src/tools/routed.cpp index 9fa66b05453..e2510c5a2bc 100644 --- a/src/tools/routed.cpp +++ b/src/tools/routed.cpp @@ -229,55 +229,23 @@ int main(int argc, const char *argv[]) try } else { - if (!boost::filesystem::is_regular_file(config.storage_config.ram_index_path)) + auto required_files = {config.storage_config.ram_index_path, + config.storage_config.file_index_path, + config.storage_config.hsgr_data_path, + config.storage_config.node_based_nodes_data_path, + config.storage_config.edge_based_nodes_data_path, + config.storage_config.edges_data_path, + config.storage_config.core_data_path, + config.storage_config.geometries_path, + config.storage_config.datasource_indexes_path, + config.storage_config.names_data_path, + config.storage_config.properties_path}; + for (auto file : required_files) { - util::Log(logWARNING) << config.storage_config.ram_index_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.file_index_path)) - { - util::Log(logWARNING) << config.storage_config.file_index_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.hsgr_data_path)) - { - util::Log(logWARNING) << config.storage_config.hsgr_data_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.nodes_data_path)) - { - util::Log(logWARNING) << config.storage_config.nodes_data_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.edges_data_path)) - { - util::Log(logWARNING) << config.storage_config.edges_data_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.core_data_path)) - { - util::Log(logWARNING) << config.storage_config.core_data_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.geometries_path)) - { - util::Log(logWARNING) << config.storage_config.geometries_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.timestamp_path)) - { - util::Log(logWARNING) << config.storage_config.timestamp_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.datasource_names_path)) - { - util::Log(logWARNING) << config.storage_config.datasource_names_path - << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.datasource_indexes_path)) - { - util::Log(logWARNING) << config.storage_config.datasource_indexes_path - << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.names_data_path)) - { - util::Log(logWARNING) << config.storage_config.names_data_path << " is not found"; - } - if (!boost::filesystem::is_regular_file(config.storage_config.properties_path)) - { - util::Log(logWARNING) << config.storage_config.properties_path << " is not found"; + if (!boost::filesystem::is_regular_file(file)) + { + util::Log(logWARNING) << file << " is not found"; + } } } return EXIT_FAILURE; diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index 5bafe753448..97c86e81d99 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -100,7 +100,7 @@ void checkWeightsConsistency( extractor::files::readSegmentData(config.geometry_path, segment_data); extractor::EdgeBasedNodeDataContainer node_data; - extractor::files::readNodeData(config.osrm_input_path.string() + ".nodes_data", node_data); + extractor::files::readNodeData(config.osrm_input_path.string() + ".ebg_nodes", node_data); extractor::TurnDataContainer turn_data; extractor::files::readTurnData(config.osrm_input_path.string() + ".edges", turn_data); @@ -570,7 +570,7 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e TIMER_START(load_edges); EdgeID max_edge_id = 0; - std::vector node_coordinates; + std::vector coordinates; extractor::PackedOSMIDs osm_node_ids; { @@ -581,7 +581,7 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e max_edge_id = reader.ReadOne(); reader.ReadInto(edge_based_edge_list); - extractor::files::readNodes(config.node_based_graph_path, node_coordinates, osm_node_ids); + extractor::files::readNodes(config.node_based_nodes_data_path, coordinates, osm_node_ids); } const bool update_conditional_turns = @@ -664,7 +664,7 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e profile_properties, segment_speed_lookup, segment_data, - node_coordinates, + coordinates, osm_node_ids); // Now save out the updated compressed geometries extractor::files::writeSegmentData(config.geometry_path, segment_data); @@ -707,7 +707,7 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e auto updated_turn_penalties = updateConditionalTurns(config, turn_weight_penalties, conditional_turns, - node_coordinates, + coordinates, osm_node_ids, time_zone_handler); const auto offset = updated_segments.size(); From 96095656aa459598adfa1e81220e5b492667e168 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 16 May 2017 19:22:41 +0200 Subject: [PATCH 7/9] Renamed EdgeBasedNode to EdgeBasedNodeSegment --- include/contractor/contractor.hpp | 2 +- include/engine/datafacade/datafacade_base.hpp | 4 +- .../extractor/edge_based_graph_factory.hpp | 10 ++--- ...d_node.hpp => edge_based_node_segment.hpp} | 20 ++++----- include/extractor/extractor.hpp | 6 +-- include/extractor/node_data_container.hpp | 2 +- src/benchmarks/static_rtree.cpp | 4 +- src/extractor/edge_based_graph_factory.cpp | 43 +++++++++--------- src/extractor/extractor.cpp | 44 +++++++++---------- unit_tests/util/static_rtree.cpp | 4 +- 10 files changed, 69 insertions(+), 70 deletions(-) rename include/extractor/{edge_based_node.hpp => edge_based_node_segment.hpp} (70%) diff --git a/include/contractor/contractor.hpp b/include/contractor/contractor.hpp index 96ed1befea7..680cc1c9adc 100644 --- a/include/contractor/contractor.hpp +++ b/include/contractor/contractor.hpp @@ -31,7 +31,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "contractor/contractor_config.hpp" #include "contractor/query_edge.hpp" #include "extractor/edge_based_edge.hpp" -#include "extractor/edge_based_node.hpp" +#include "extractor/edge_based_node_segment.hpp" #include "util/deallocating_vector.hpp" #include "util/typedefs.hpp" diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index a6cc4a2eeb7..d94bfefe154 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -4,7 +4,7 @@ // Exposes all data access interfaces to the algorithms via base class ptr #include "contractor/query_edge.hpp" -#include "extractor/edge_based_node.hpp" +#include "extractor/edge_based_node_segment.hpp" #include "extractor/external_memory_node.hpp" #include "extractor/guidance/turn_instruction.hpp" #include "extractor/guidance/turn_lane_types.hpp" @@ -40,7 +40,7 @@ using StringView = util::StringView; class BaseDataFacade { public: - using RTreeLeaf = extractor::EdgeBasedNode; + using RTreeLeaf = extractor::EdgeBasedNodeSegment; BaseDataFacade() {} virtual ~BaseDataFacade() {} diff --git a/include/extractor/edge_based_graph_factory.hpp b/include/extractor/edge_based_graph_factory.hpp index 3ff5d795dbd..4c22363940a 100644 --- a/include/extractor/edge_based_graph_factory.hpp +++ b/include/extractor/edge_based_graph_factory.hpp @@ -5,7 +5,7 @@ #include "extractor/compressed_edge_container.hpp" #include "extractor/edge_based_edge.hpp" -#include "extractor/edge_based_node.hpp" +#include "extractor/edge_based_node_segment.hpp" #include "extractor/extraction_turn.hpp" #include "extractor/guidance/turn_analysis.hpp" #include "extractor/guidance/turn_instruction.hpp" @@ -93,8 +93,8 @@ class EdgeBasedGraphFactory // The following get access functions destroy the content in the factory void GetEdgeBasedEdges(util::DeallocatingVector &edges); - void GetEdgeBasedNodes(EdgeBasedNodeDataContainer &ebg_node_data_container); - void GetNodeBasedEdges(std::vector &nodes); + void GetEdgeBasedNodes(EdgeBasedNodeDataContainer &data_container); + void GetEdgeBasedNodeSegments(std::vector &nodes); void GetStartPointMarkers(std::vector &node_is_startpoint); void GetEdgeBasedNodeWeights(std::vector &output_node_weights); @@ -129,8 +129,8 @@ class EdgeBasedGraphFactory std::vector m_edge_based_node_weights; //! list of edge based nodes (compressed segments) - std::vector m_edge_based_node_list; - EdgeBasedNodeDataContainer m_ebg_node_data_container; + std::vector m_edge_based_node_segments; + EdgeBasedNodeDataContainer m_edge_based_node_container; util::DeallocatingVector m_edge_based_edge_list; EdgeID m_max_edge_id; diff --git a/include/extractor/edge_based_node.hpp b/include/extractor/edge_based_node_segment.hpp similarity index 70% rename from include/extractor/edge_based_node.hpp rename to include/extractor/edge_based_node_segment.hpp index fd4852c80c2..29bd8f7e114 100644 --- a/include/extractor/edge_based_node.hpp +++ b/include/extractor/edge_based_node_segment.hpp @@ -1,5 +1,5 @@ -#ifndef EDGE_BASED_NODE_HPP -#define EDGE_BASED_NODE_HPP +#ifndef OSRM_EXTRACT_EDGE_BASED_NODE_SEGMENT_HPP +#define OSRM_EXTRACT_EDGE_BASED_NODE_SEGMENT_HPP #include "extractor/travel_mode.hpp" #include "util/typedefs.hpp" @@ -17,20 +17,20 @@ namespace extractor /// This is what util::StaticRTree serialized and stores on disk /// It is generated in EdgeBasedGraphFactory. -struct EdgeBasedNode +struct EdgeBasedNodeSegment { - EdgeBasedNode() + EdgeBasedNodeSegment() : forward_segment_id{SPECIAL_SEGMENTID, false}, reverse_segment_id{SPECIAL_SEGMENTID, false}, u(SPECIAL_NODEID), v(SPECIAL_NODEID), fwd_segment_position(std::numeric_limits::max()) { } - explicit EdgeBasedNode(const SegmentID forward_segment_id_, - const SegmentID reverse_segment_id_, - NodeID u, - NodeID v, - unsigned short fwd_segment_position) + explicit EdgeBasedNodeSegment(const SegmentID forward_segment_id_, + const SegmentID reverse_segment_id_, + NodeID u, + NodeID v, + unsigned short fwd_segment_position) : forward_segment_id(forward_segment_id_), reverse_segment_id(reverse_segment_id_), u(u), v(v), fwd_segment_position(fwd_segment_position) { @@ -46,4 +46,4 @@ struct EdgeBasedNode } } -#endif // EDGE_BASED_NODE_HPP +#endif // OSRM_EXTRACT_EDGE_BASED_NODE_SEGMENT_HPP diff --git a/include/extractor/extractor.hpp b/include/extractor/extractor.hpp index 191dc34f9c8..a1b00118de2 100644 --- a/include/extractor/extractor.hpp +++ b/include/extractor/extractor.hpp @@ -63,8 +63,8 @@ class Extractor BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, std::vector &coordinates, extractor::PackedOSMIDs &osm_node_ids, - EdgeBasedNodeDataContainer &ebg_node_data_container, - std::vector &node_based_edge_list, + EdgeBasedNodeDataContainer &edge_based_nodes_container, + std::vector &edge_based_node_segments, std::vector &node_is_startpoint, std::vector &edge_based_node_weights, util::DeallocatingVector &edge_based_edge_list, @@ -75,7 +75,7 @@ class Extractor void FindComponents(unsigned max_edge_id, const util::DeallocatingVector &edges, EdgeBasedNodeDataContainer &nodes) const; - void BuildRTree(std::vector node_based_edge_list, + void BuildRTree(std::vector edge_based_node_segments, std::vector node_is_startpoint, const std::vector &coordinates); std::shared_ptr LoadRestrictionMap(); diff --git a/include/extractor/node_data_container.hpp b/include/extractor/node_data_container.hpp index 37d31346666..d89fe4835d3 100644 --- a/include/extractor/node_data_container.hpp +++ b/include/extractor/node_data_container.hpp @@ -70,7 +70,7 @@ template class EdgeBasedNodeDataContainerImpl // Used by EdgeBasedGraphFactory to fill data structure template > - void SetData(NodeID node_id, ComponentID component_id) + void SetComponentID(NodeID node_id, ComponentID component_id) { component_ids[node_id] = component_id; } diff --git a/src/benchmarks/static_rtree.cpp b/src/benchmarks/static_rtree.cpp index 1e421bf9ef8..56596a33076 100644 --- a/src/benchmarks/static_rtree.cpp +++ b/src/benchmarks/static_rtree.cpp @@ -1,5 +1,5 @@ #include "util/static_rtree.hpp" -#include "extractor/edge_based_node.hpp" +#include "extractor/edge_based_node_segment.hpp" #include "extractor/query_node.hpp" #include "mocks/mock_datafacade.hpp" #include "storage/io.hpp" @@ -26,7 +26,7 @@ constexpr int32_t WORLD_MAX_LAT = 90 * COORDINATE_PRECISION; constexpr int32_t WORLD_MIN_LON = -180 * COORDINATE_PRECISION; constexpr int32_t WORLD_MAX_LON = 180 * COORDINATE_PRECISION; -using RTreeLeaf = extractor::EdgeBasedNode; +using RTreeLeaf = extractor::EdgeBasedNodeSegment; using BenchStaticRTree = util::StaticRTree; std::vector loadCoordinates(const boost::filesystem::path &nodes_file) diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index a51ec1520a5..1a70946627d 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -66,16 +66,16 @@ void EdgeBasedGraphFactory::GetEdgeBasedEdges( swap(m_edge_based_edge_list, output_edge_list); } -void EdgeBasedGraphFactory::GetEdgeBasedNodes(EdgeBasedNodeDataContainer &ebg_node_data_container) +void EdgeBasedGraphFactory::GetEdgeBasedNodes(EdgeBasedNodeDataContainer &data_container) { using std::swap; // Koenig swap - swap(ebg_node_data_container, m_ebg_node_data_container); + swap(data_container, m_edge_based_node_container); } -void EdgeBasedGraphFactory::GetNodeBasedEdges(std::vector &nodes) +void EdgeBasedGraphFactory::GetEdgeBasedNodeSegments(std::vector &nodes) { using std::swap; // Koenig swap - swap(nodes, m_edge_based_node_list); + swap(nodes, m_edge_based_node_segments); } void EdgeBasedGraphFactory::GetStartPointMarkers(std::vector &node_is_startpoint) @@ -142,16 +142,16 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N // Add edge-based node data for forward and reverse nodes indexed by edge_id BOOST_ASSERT(forward_data.edge_id != SPECIAL_EDGEID); - m_ebg_node_data_container.SetData(forward_data.edge_id, - GeometryID{packed_geometry_id, true}, - forward_data.name_id, - forward_data.travel_mode); + m_edge_based_node_container.SetData(forward_data.edge_id, + GeometryID{packed_geometry_id, true}, + forward_data.name_id, + forward_data.travel_mode); if (reverse_data.edge_id != SPECIAL_EDGEID) { - m_ebg_node_data_container.SetData(reverse_data.edge_id, - GeometryID{packed_geometry_id, false}, - reverse_data.name_id, - reverse_data.travel_mode); + m_edge_based_node_container.SetData(reverse_data.edge_id, + GeometryID{packed_geometry_id, false}, + reverse_data.name_id, + reverse_data.travel_mode); } // Add segments of edge-based nodes @@ -165,11 +165,11 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N BOOST_ASSERT(current_edge_target_coordinate_id != current_edge_source_coordinate_id); // build edges - m_edge_based_node_list.emplace_back(edge_id_to_segment_id(forward_data.edge_id), - edge_id_to_segment_id(reverse_data.edge_id), - current_edge_source_coordinate_id, - current_edge_target_coordinate_id, - i); + m_edge_based_node_segments.emplace_back(edge_id_to_segment_id(forward_data.edge_id), + edge_id_to_segment_id(reverse_data.edge_id), + current_edge_source_coordinate_id, + current_edge_target_coordinate_id, + i); m_edge_based_node_is_startpoint.push_back(forward_data.startpoint || reverse_data.startpoint); @@ -257,7 +257,7 @@ std::vector EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() std::vector mapping; // Allocate memory for edge-based nodes - m_ebg_node_data_container = EdgeBasedNodeDataContainer(m_max_edge_id + 1); + m_edge_based_node_container = EdgeBasedNodeDataContainer(m_max_edge_id + 1); util::Log() << "Generating edge expanded nodes ... "; { @@ -300,10 +300,11 @@ std::vector EdgeBasedGraphFactory::GenerateEdgeExpandedNodes() } } - BOOST_ASSERT(m_edge_based_node_list.size() == m_edge_based_node_is_startpoint.size()); + BOOST_ASSERT(m_edge_based_node_segments.size() == m_edge_based_node_is_startpoint.size()); BOOST_ASSERT(m_max_edge_id + 1 == m_edge_based_node_weights.size()); - util::Log() << "Generated " << m_edge_based_node_list.size() << " nodes in edge-expanded graph"; + util::Log() << "Generated " << (m_max_edge_id + 1) << " nodes and " + << m_edge_based_node_segments.size() << " segments in edge-expanded graph"; return mapping; } @@ -576,7 +577,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges( files::writeTurnData(turn_data_filename, turn_data_container); - util::Log() << "Generated " << m_edge_based_node_list.size() << " edge based nodes"; + util::Log() << "Generated " << m_edge_based_node_segments.size() << " edge based node segments"; util::Log() << "Node-based graph contains " << node_based_edge_counter << " edges"; util::Log() << "Edge-expanded graph ..."; util::Log() << " contains " << m_edge_based_edge_list.size() << " edges"; diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index c4ee9ff00e7..e8e27b39b01 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -131,7 +131,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) TIMER_START(expansion); EdgeBasedNodeDataContainer edge_based_nodes_container; - std::vector node_based_edges_list; + std::vector edge_based_node_segments; util::DeallocatingVector edge_based_edge_list; std::vector node_is_startpoint; std::vector edge_based_node_weights; @@ -142,7 +142,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) coordinates, osm_node_ids, edge_based_nodes_container, - node_based_edges_list, + edge_based_node_segments, node_is_startpoint, edge_based_node_weights, edge_based_edge_list, @@ -169,7 +169,7 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) util::Log() << "Building r-tree ..."; TIMER_START(rtree); - BuildRTree(std::move(node_based_edges_list), std::move(node_is_startpoint), coordinates); + BuildRTree(std::move(edge_based_node_segments), std::move(node_is_startpoint), coordinates); TIMER_STOP(rtree); @@ -370,14 +370,12 @@ void Extractor::FindComponents(unsigned max_edge_id, TarjanSCC component_search(uncontracted_graph); component_search.Run(); - stxxl::vector component_ids; - component_ids.reserve(max_edge_id + 1); for (NodeID node_id = 0; node_id <= max_edge_id; ++node_id) { const auto forward_component = component_search.GetComponentID(node_id); const auto component_size = component_search.GetComponentSize(forward_component); const auto is_tiny = component_size < config.small_component_size; - input_nodes.SetData(node_id, {1 + forward_component, is_tiny}); + input_nodes.SetComponentID(node_id, {1 + forward_component, is_tiny}); } } @@ -421,8 +419,8 @@ std::pair Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, std::vector &coordinates, extractor::PackedOSMIDs &osm_node_ids, - EdgeBasedNodeDataContainer &ebg_node_data_container, - std::vector &node_based_edges_list, + EdgeBasedNodeDataContainer &edge_based_nodes_container, + std::vector &edge_based_node_segments, std::vector &node_is_startpoint, std::vector &edge_based_node_weights, util::DeallocatingVector &edge_based_edge_list, @@ -501,8 +499,8 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, *compressed_edge_container.ToSegmentData()); edge_based_graph_factory.GetEdgeBasedEdges(edge_based_edge_list); - edge_based_graph_factory.GetEdgeBasedNodes(ebg_node_data_container); - edge_based_graph_factory.GetNodeBasedEdges(node_based_edges_list); + edge_based_graph_factory.GetEdgeBasedNodes(edge_based_nodes_container); + edge_based_graph_factory.GetEdgeBasedNodeSegments(edge_based_node_segments); edge_based_graph_factory.GetStartPointMarkers(node_is_startpoint); edge_based_graph_factory.GetEdgeBasedNodeWeights(edge_based_node_weights); auto max_edge_id = edge_based_graph_factory.GetHighestEdgeID(); @@ -522,21 +520,21 @@ Extractor::BuildEdgeExpandedGraph(ScriptingEnvironment &scripting_environment, Saves tree into '.ramIndex' and leaves into '.fileIndex'. */ -void Extractor::BuildRTree(std::vector node_based_edges_list, +void Extractor::BuildRTree(std::vector edge_based_node_segments, std::vector node_is_startpoint, const std::vector &coordinates) { - util::Log() << "constructing r-tree of " << node_based_edges_list.size() - << " edge elements build on-top of " << coordinates.size() << " coordinates"; + util::Log() << "Constructing r-tree of " << edge_based_node_segments.size() + << " segments build on-top of " << coordinates.size() << " coordinates"; - BOOST_ASSERT(node_is_startpoint.size() == node_based_edges_list.size()); + BOOST_ASSERT(node_is_startpoint.size() == edge_based_node_segments.size()); // Filter node based edges based on startpoint - auto out_iter = node_based_edges_list.begin(); - auto in_iter = node_based_edges_list.begin(); + auto out_iter = edge_based_node_segments.begin(); + auto in_iter = edge_based_node_segments.begin(); for (auto index : util::irange(0UL, node_is_startpoint.size())) { - BOOST_ASSERT(in_iter != node_based_edges_list.end()); + BOOST_ASSERT(in_iter != edge_based_node_segments.end()); if (node_is_startpoint[index]) { *out_iter = *in_iter; @@ -544,20 +542,20 @@ void Extractor::BuildRTree(std::vector node_based_edges_list, } in_iter++; } - auto new_size = out_iter - node_based_edges_list.begin(); + auto new_size = out_iter - edge_based_node_segments.begin(); if (new_size == 0) { throw util::exception("There are no snappable edges left after processing. Are you " "setting travel modes correctly in the profile? Cannot continue." + SOURCE_REF); } - node_based_edges_list.resize(new_size); + edge_based_node_segments.resize(new_size); TIMER_START(construction); - util::StaticRTree rtree(node_based_edges_list, - config.rtree_nodes_output_path, - config.rtree_leafs_output_path, - coordinates); + util::StaticRTree rtree(edge_based_node_segments, + config.rtree_nodes_output_path, + config.rtree_leafs_output_path, + coordinates); TIMER_STOP(construction); util::Log() << "finished r-tree construction in " << TIMER_SEC(construction) << " seconds"; diff --git a/unit_tests/util/static_rtree.cpp b/unit_tests/util/static_rtree.cpp index cc395cae576..954788882f7 100644 --- a/unit_tests/util/static_rtree.cpp +++ b/unit_tests/util/static_rtree.cpp @@ -1,5 +1,5 @@ #include "util/static_rtree.hpp" -#include "extractor/edge_based_node.hpp" +#include "extractor/edge_based_node_segment.hpp" #include "engine/geospatial_query.hpp" #include "util/coordinate.hpp" #include "util/coordinate_calculation.hpp" @@ -39,7 +39,7 @@ using namespace osrm::test; constexpr uint32_t TEST_BRANCHING_FACTOR = 8; constexpr uint32_t TEST_LEAF_NODE_SIZE = 64; -using TestData = extractor::EdgeBasedNode; +using TestData = extractor::EdgeBasedNodeSegment; using TestStaticRTree = StaticRTree Date: Wed, 17 May 2017 07:54:23 +0200 Subject: [PATCH 8/9] Reverted connection of forward and backward nodes in one SCC --- include/extractor/extractor.hpp | 5 +++-- src/extractor/extractor.cpp | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/extractor/extractor.hpp b/include/extractor/extractor.hpp index a1b00118de2..4d9cd73f99a 100644 --- a/include/extractor/extractor.hpp +++ b/include/extractor/extractor.hpp @@ -73,8 +73,9 @@ class Extractor void WriteProfileProperties(const std::string &output_path, const ProfileProperties &properties) const; void FindComponents(unsigned max_edge_id, - const util::DeallocatingVector &edges, - EdgeBasedNodeDataContainer &nodes) const; + const util::DeallocatingVector &input_edge_list, + const std::vector &input_node_segments, + EdgeBasedNodeDataContainer &nodes_container) const; void BuildRTree(std::vector edge_based_node_segments, std::vector node_is_startpoint, const std::vector &coordinates); diff --git a/src/extractor/extractor.cpp b/src/extractor/extractor.cpp index e8e27b39b01..5c90b28df0f 100644 --- a/src/extractor/extractor.cpp +++ b/src/extractor/extractor.cpp @@ -165,7 +165,8 @@ int Extractor::run(ScriptingEnvironment &scripting_environment) util::Log() << "Done writing. (" << TIMER_SEC(timer_write_node_weights) << ")"; util::Log() << "Computing strictly connected components ..."; - FindComponents(max_edge_id, edge_based_edge_list, edge_based_nodes_container); + FindComponents( + max_edge_id, edge_based_edge_list, edge_based_node_segments, edge_based_nodes_container); util::Log() << "Building r-tree ..."; TIMER_START(rtree); @@ -338,7 +339,8 @@ void Extractor::WriteProfileProperties(const std::string &output_path, void Extractor::FindComponents(unsigned max_edge_id, const util::DeallocatingVector &input_edge_list, - EdgeBasedNodeDataContainer &input_nodes) const + const std::vector &input_node_segments, + EdgeBasedNodeDataContainer &nodes_container) const { using InputEdge = util::static_graph_details::SortableEdgeWithData; using UncontractedGraph = util::StaticGraph; @@ -362,6 +364,19 @@ void Extractor::FindComponents(unsigned max_edge_id, } } + // Connect forward and backward nodes of each edge to enforce + // forward and backward edge-based nodes be in one strongly-connected component + for (const auto &segment : input_node_segments) + { + if (segment.reverse_segment_id.enabled) + { + BOOST_ASSERT(segment.forward_segment_id.id <= max_edge_id); + BOOST_ASSERT(segment.reverse_segment_id.id <= max_edge_id); + edges.push_back({segment.forward_segment_id.id, segment.reverse_segment_id.id}); + edges.push_back({segment.reverse_segment_id.id, segment.forward_segment_id.id}); + } + } + tbb::parallel_sort(edges.begin(), edges.end()); edges.erase(std::unique(edges.begin(), edges.end()), edges.end()); @@ -375,7 +390,7 @@ void Extractor::FindComponents(unsigned max_edge_id, const auto forward_component = component_search.GetComponentID(node_id); const auto component_size = component_search.GetComponentSize(forward_component); const auto is_tiny = component_size < config.small_component_size; - input_nodes.SetComponentID(node_id, {1 + forward_component, is_tiny}); + nodes_container.SetComponentID(node_id, {1 + forward_component, is_tiny}); } } From 3ee629f882f3aa3a35d5dcc6b21642e4aea84324 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 15 May 2017 23:51:08 +0200 Subject: [PATCH 9/9] Added ChangeLog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aacf890e6ee..9b0332d9511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Changes from 5.7 - Features - Added conditional restriction support with `parse-conditional-restrictions=true|false` to osrm-extract. This option saves conditional turn restrictions to the .restrictions file for parsing by contract later. Added `parse-conditionals-from-now=utc time stamp` and `--time-zone-file=/path/to/file` to osrm-contract + - Files + - .osrm.nodes file was renamed to .nbg_nodes and .ebg_nodes was added # 5.7.0 - Changes from 5.6