diff --git a/include/customizer/edge_based_graph.hpp b/include/customizer/edge_based_graph.hpp index 075e69277..e2526f163 100644 --- a/include/customizer/edge_based_graph.hpp +++ b/include/customizer/edge_based_graph.hpp @@ -16,8 +16,10 @@ namespace osrm namespace customizer { -// TODO: Change to turn_id only -using EdgeBasedGraphEdgeData = partitioner::EdgeBasedGraphEdgeData; +struct EdgeBasedGraphEdgeData +{ + NodeID turn_id; // ID of the edge based node (node based edge) +}; template class MultiLevelGraph; @@ -39,8 +41,8 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph; - using SuperC = partitioner::MultiLevelGraph; + using PartitionerGraphT = partitioner::MultiLevelGraph; template using Vector = util::ViewOrVector; public: @@ -50,34 +52,49 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph node_weights_, Vector node_durations_) : node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_)) { + util::ViewOrVector + original_edge_array; + std::tie(SuperT::node_array, - SuperT::edge_array, + original_edge_array, SuperT::node_to_edge_offset, SuperT::connectivity_checksum) = std::move(graph).data(); - // TODO: add EdgeArrayEntry shaving + + SuperT::edge_array.reserve(original_edge_array.size()); + for (const auto &edge : original_edge_array) + { + SuperT::edge_array.push_back({edge.target, {edge.data.turn_id}}); + is_forward_edge.push_back(edge.data.forward); + is_backward_edge.push_back(edge.data.backward); + } } MultiLevelGraph(Vector node_array_, Vector edge_array_, Vector node_to_edge_offset_, Vector node_weights_, - Vector node_durations_) + Vector node_durations_, + Vector is_forward_edge_, + Vector is_backward_edge_) : SuperT(std::move(node_array_), std::move(edge_array_), std::move(node_to_edge_offset_)), - node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_)) + node_weights(std::move(node_weights_)), node_durations(std::move(node_durations_)), + is_forward_edge(is_forward_edge_), is_backward_edge(is_backward_edge_) { - // TODO: add EdgeArrayEntry shaving } EdgeWeight GetNodeWeight(NodeID node) const { return node_weights[node]; } EdgeWeight GetNodeDuration(NodeID node) const { return node_durations[node]; } + bool IsForwardEdge(EdgeID edge) const { return is_forward_edge[edge]; } + + bool IsBackwardEdge(EdgeID edge) const { return is_backward_edge[edge]; } + friend void serialization::read(storage::tar::FileReader &reader, const std::string &name, @@ -90,6 +107,8 @@ class MultiLevelGraph : public partitioner::MultiLevelGraph node_weights; Vector node_durations; + Vector is_forward_edge; + Vector is_backward_edge; }; using MultiLevelEdgeBasedGraph = diff --git a/include/customizer/serialization.hpp b/include/customizer/serialization.hpp index 803f905a4..c5c5fdee2 100644 --- a/include/customizer/serialization.hpp +++ b/include/customizer/serialization.hpp @@ -43,6 +43,8 @@ inline void read(storage::tar::FileReader &reader, storage::serialization::read(reader, name + "/node_weights", graph.node_weights); storage::serialization::read(reader, name + "/node_durations", graph.node_durations); storage::serialization::read(reader, name + "/edge_array", graph.edge_array); + storage::serialization::read(reader, name + "/is_forward_edge", graph.is_forward_edge); + storage::serialization::read(reader, name + "/is_backward_edge", graph.is_backward_edge); storage::serialization::read(reader, name + "/node_to_edge_offset", graph.node_to_edge_offset); } @@ -55,6 +57,8 @@ inline void write(storage::tar::FileWriter &writer, storage::serialization::write(writer, name + "/node_weights", graph.node_weights); storage::serialization::write(writer, name + "/node_durations", graph.node_durations); storage::serialization::write(writer, name + "/edge_array", graph.edge_array); + storage::serialization::write(writer, name + "/is_forward_edge", graph.is_forward_edge); + storage::serialization::write(writer, name + "/is_backward_edge", graph.is_backward_edge); storage::serialization::write(writer, name + "/node_to_edge_offset", graph.node_to_edge_offset); } } diff --git a/include/engine/datafacade/algorithm_datafacade.hpp b/include/engine/datafacade/algorithm_datafacade.hpp index 0e13796ed..ef910d4ac 100644 --- a/include/engine/datafacade/algorithm_datafacade.hpp +++ b/include/engine/datafacade/algorithm_datafacade.hpp @@ -2,6 +2,7 @@ #define OSRM_ENGINE_DATAFACADE_ALGORITHM_DATAFACADE_HPP #include "contractor/query_edge.hpp" +#include "customizer/edge_based_graph.hpp" #include "extractor/edge_based_edge.hpp" #include "engine/algorithm.hpp" @@ -59,7 +60,7 @@ template <> class AlgorithmDataFacade template <> class AlgorithmDataFacade { public: - using EdgeData = extractor::EdgeBasedEdge::EdgeData; + using EdgeData = customizer::EdgeBasedGraphEdgeData; using EdgeRange = util::range; // search graph access @@ -77,6 +78,10 @@ template <> class AlgorithmDataFacade virtual EdgeWeight GetNodeDuration(const NodeID node) const = 0; // TODO: to be removed + virtual bool IsForwardEdge(EdgeID edge) const = 0; + + virtual bool IsBackwardEdge(EdgeID edge) const = 0; + virtual NodeID GetTarget(const EdgeID e) const = 0; virtual const EdgeData &GetEdgeData(const EdgeID e) const = 0; diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index c5549c285..6befce6d0 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -697,6 +697,16 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade : public Algo return query_graph.GetNodeDuration(node); } + bool IsForwardEdge(const NodeID node) const override final + { + return query_graph.IsForwardEdge(node); + } + + bool IsBackwardEdge(const NodeID node) const override final + { + return query_graph.IsBackwardEdge(node); + } + NodeID GetTarget(const EdgeID e) const override final { return query_graph.GetTarget(e); } const EdgeData &GetEdgeData(const EdgeID e) const override final diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index 195702fea..53d285432 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -207,7 +207,8 @@ void relaxOutgoingEdges(const DataFacade &facade, { const auto &edge_data = facade.GetEdgeData(edge); - if (DIRECTION == FORWARD_DIRECTION ? edge_data.forward : edge_data.backward) + if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge) + : facade.IsBackwardEdge(edge)) { const NodeID to = facade.GetTarget(edge); @@ -218,7 +219,7 @@ void relaxOutgoingEdges(const DataFacade &facade, facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to); const auto turn_penalty = facade.GetWeightPenaltyForEdgeID(edge_data.turn_id); - BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty); + // TODO: BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty); const EdgeWeight to_weight = weight + node_weight + turn_penalty; diff --git a/include/storage/view_factory.hpp b/include/storage/view_factory.hpp index cb4d58302..f6c8e2137 100644 --- a/include/storage/view_factory.hpp +++ b/include/storage/view_factory.hpp @@ -332,12 +332,16 @@ inline auto make_multi_level_graph_view(const SharedDataIndex &index, const std: index, name + "/node_to_edge_offset"); auto node_weights = make_vector_view(index, name + "/node_weights"); auto node_durations = make_vector_view(index, name + "/node_durations"); + auto is_forward_edge = make_vector_view(index, name + "/is_forward_edge"); + auto is_backward_edge = make_vector_view(index, name + "/is_backward_edge"); return customizer::MultiLevelEdgeBasedGraphView(std::move(node_list), std::move(edge_list), std::move(node_to_offset), std::move(node_weights), - std::move(node_durations)); + std::move(node_durations), + std::move(is_forward_edge), + std::move(is_backward_edge)); } inline auto make_maneuver_overrides_views(const SharedDataIndex &index, const std::string &name) diff --git a/src/engine/routing_algorithms/many_to_many_mld.cpp b/src/engine/routing_algorithms/many_to_many_mld.cpp index b92200336..6f8300d9a 100644 --- a/src/engine/routing_algorithms/many_to_many_mld.cpp +++ b/src/engine/routing_algorithms/many_to_many_mld.cpp @@ -172,7 +172,8 @@ void relaxOutgoingEdges(const DataFacade &facade, for (const auto edge : facade.GetBorderEdgeRange(level, node)) { const auto &data = facade.GetEdgeData(edge); - if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward) + if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge) + : facade.IsBackwardEdge(edge)) { const NodeID to = facade.GetTarget(edge); if (facade.ExcludeNode(to)) @@ -310,7 +311,8 @@ oneToManySearch(SearchEngineData &engine_working_data, for (auto edge : facade.GetAdjacentEdgeRange(node)) { const auto &data = facade.GetEdgeData(edge); - if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward) + if ((DIRECTION == FORWARD_DIRECTION) ? facade.IsForwardEdge(edge) + : facade.IsBackwardEdge(edge)) { const auto turn_id = data.turn_id; const auto edge_weight = diff --git a/src/engine/routing_algorithms/tile_turns.cpp b/src/engine/routing_algorithms/tile_turns.cpp index 6fb419c6b..d8d28523d 100644 --- a/src/engine/routing_algorithms/tile_turns.cpp +++ b/src/engine/routing_algorithms/tile_turns.cpp @@ -145,42 +145,8 @@ std::vector generateTurns(const datafacade &facade, const auto &data = facade.GetEdgeData(edge_based_edge_id); // Now, calculate the sum of the weight of all the segments. - const auto &geometry = - edge_based_node_info.find(approachedge.edge_based_node_id)->second; - EdgeWeight sum_node_weight = 0; - EdgeDuration sum_node_duration = 0; - if (geometry.is_geometry_forward) - { - const auto approach_weight = - facade.GetUncompressedForwardWeights(geometry.packed_geometry_id); - const auto approach_duration = - facade.GetUncompressedForwardDurations(geometry.packed_geometry_id); - sum_node_weight = std::accumulate( - approach_weight.begin(), approach_weight.end(), EdgeWeight{0}); - sum_node_duration = std::accumulate( - approach_duration.begin(), approach_duration.end(), EdgeDuration{0}); - } - else - { - const auto approach_weight = - facade.GetUncompressedReverseWeights(geometry.packed_geometry_id); - const auto approach_duration = - facade.GetUncompressedReverseDurations(geometry.packed_geometry_id); - sum_node_weight = std::accumulate( - approach_weight.begin(), approach_weight.end(), EdgeWeight{0}); - sum_node_duration = std::accumulate( - approach_duration.begin(), approach_duration.end(), EdgeDuration{0}); - } - - // The edge.weight is the whole edge weight, which includes the turn - // cost. - // The turn cost is the edge.weight minus the sum of the individual road - // segment weights. This might not be 100% accurate, because some - // intersections include stop signs, traffic signals and other - // penalties, but at this stage, we can't divide those out, so we just - // treat the whole lot as the "turn cost" that we'll stick on the map. - const auto turn_weight = data.weight - sum_node_weight; - const auto turn_duration = data.duration - sum_node_duration; + const auto turn_weight = facade.GetWeightPenaltyForEdgeID(data.turn_id); + const auto turn_duration = facade.GetDurationPenaltyForEdgeID(data.turn_id); const auto turn_instruction = facade.GetTurnInstructionForEdgeID(data.turn_id); // Find the three nodes that make up the turn movement) diff --git a/unit_tests/engine/offline_facade.cpp b/unit_tests/engine/offline_facade.cpp index 0ab2d1070..6314b3a7c 100644 --- a/unit_tests/engine/offline_facade.cpp +++ b/unit_tests/engine/offline_facade.cpp @@ -325,10 +325,11 @@ class ContiguousInternalMemoryDataFacade return {}; } - EdgeWeight GetNodeWeight(const NodeID /*node*/) const - { - return 0; - } + EdgeWeight GetNodeWeight(const NodeID /*node*/) const { return 0; } + + bool IsForwardEdge(const NodeID /*edge*/) const { return true; } + + bool IsBackwardEdge(const NodeID /*edge*/) const { return true; } bool HasLaneData(const EdgeID /*id*/) const override { return false; } NameID GetNameIndex(const NodeID /*nodeID*/) const override { return EMPTY_NAMEID; }