diff --git a/include/contractor/contractor_graph.hpp b/include/contractor/contractor_graph.hpp index 3424568a6..d4d011887 100644 --- a/include/contractor/contractor_graph.hpp +++ b/include/contractor/contractor_graph.hpp @@ -12,23 +12,25 @@ namespace contractor struct ContractorEdgeData { ContractorEdgeData() - : weight(0), duration(0), id(0), originalEdges(0), shortcut(0), forward(0), backward(0) + : weight(0), duration(0), distance(0), id(0), originalEdges(0), shortcut(0), forward(0), backward(0) { } ContractorEdgeData(EdgeWeight weight, EdgeWeight duration, + EdgeDistance distance, unsigned original_edges, unsigned id, bool shortcut, bool forward, bool backward) - : weight(weight), duration(duration), id(id), + : weight(weight), duration(duration), distance(distance), id(id), originalEdges(std::min((1u << 29) - 1u, original_edges)), shortcut(shortcut), forward(forward), backward(backward) { } EdgeWeight weight; EdgeWeight duration; + EdgeDistance distance; unsigned id; unsigned originalEdges : 29; bool shortcut : 1; diff --git a/include/contractor/graph_contractor_adaptors.hpp b/include/contractor/graph_contractor_adaptors.hpp index 11d96af58..b061d97dc 100644 --- a/include/contractor/graph_contractor_adaptors.hpp +++ b/include/contractor/graph_contractor_adaptors.hpp @@ -41,6 +41,7 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp input_edge.target, std::max(input_edge.data.weight, 1), input_edge.data.duration, + input_edge.data.distance, 1, input_edge.data.turn_id, false, @@ -51,6 +52,7 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp input_edge.source, std::max(input_edge.data.weight, 1), input_edge.data.duration, + input_edge.data.distance, 1, input_edge.data.turn_id, false, @@ -82,6 +84,7 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp forward_edge.data.originalEdges = reverse_edge.data.originalEdges = 1; forward_edge.data.weight = reverse_edge.data.weight = INVALID_EDGE_WEIGHT; forward_edge.data.duration = reverse_edge.data.duration = MAXIMAL_EDGE_DURATION; + forward_edge.data.distance = reverse_edge.data.distance = MAXIMAL_EDGE_DURATION; // remove parallel edges while (i < edges.size() && edges[i].source == source && edges[i].target == target) { @@ -90,12 +93,16 @@ ContractorGraph toContractorGraph(NodeID number_of_nodes, InputEdgeContainer inp forward_edge.data.weight = std::min(edges[i].data.weight, forward_edge.data.weight); forward_edge.data.duration = std::min(edges[i].data.duration, forward_edge.data.duration); + forward_edge.data.distance = + std::min(edges[i].data.distance, forward_edge.data.distance); } if (edges[i].data.backward) { reverse_edge.data.weight = std::min(edges[i].data.weight, reverse_edge.data.weight); reverse_edge.data.duration = std::min(edges[i].data.duration, reverse_edge.data.duration); + reverse_edge.data.distance = + std::min(edges[i].data.distance, reverse_edge.data.distance); } ++i; } @@ -151,6 +158,7 @@ template inline std::vector toEdges(GraphT g BOOST_ASSERT_MSG(SPECIAL_NODEID != new_edge.target, "Target id invalid"); new_edge.data.weight = data.weight; new_edge.data.duration = data.duration; + new_edge.data.distance = data.distance; new_edge.data.shortcut = data.shortcut; new_edge.data.turn_id = data.id; BOOST_ASSERT_MSG(new_edge.data.turn_id != INT_MAX, // 2^31 diff --git a/include/contractor/query_edge.hpp b/include/contractor/query_edge.hpp index a1d24f861..dfd2d77ce 100644 --- a/include/contractor/query_edge.hpp +++ b/include/contractor/query_edge.hpp @@ -17,7 +17,7 @@ struct QueryEdge struct EdgeData { explicit EdgeData() - : turn_id(0), shortcut(false), weight(0), duration(0), forward(false), backward(false) + : turn_id(0), shortcut(false), weight(0), duration(0), forward(false), backward(false), distance(0) { } @@ -25,10 +25,11 @@ struct QueryEdge const bool shortcut, const EdgeWeight weight, const EdgeWeight duration, + const EdgeDistance distance, const bool forward, const bool backward) : turn_id(turn_id), shortcut(shortcut), weight(weight), duration(duration), - forward(forward), backward(backward) + forward(forward), backward(backward), distance(distance) { } @@ -40,6 +41,7 @@ struct QueryEdge turn_id = other.id; forward = other.forward; backward = other.backward; + distance = other.distance; } // this ID is either the middle node of the shortcut, or the ID of the edge based node (node // based edge) storing the appropriate data. If `shortcut` is set to true, we get the middle @@ -50,6 +52,7 @@ struct QueryEdge EdgeWeight duration : 30; std::uint32_t forward : 1; std::uint32_t backward : 1; + EdgeDistance distance; } data; QueryEdge() : source(SPECIAL_NODEID), target(SPECIAL_NODEID) {} @@ -69,10 +72,11 @@ struct QueryEdge return (source == right.source && target == right.target && data.weight == right.data.weight && data.duration == right.data.duration && data.shortcut == right.data.shortcut && data.forward == right.data.forward && - data.backward == right.data.backward && data.turn_id == right.data.turn_id); + data.backward == right.data.backward && data.turn_id == right.data.turn_id && + data.distance == right.data.distance ); } }; -} -} +} // namespace contractor +} // namespace osrm #endif // QUERYEDGE_HPP diff --git a/include/engine/phantom_node.hpp b/include/engine/phantom_node.hpp index 3cb0b9593..a88c03818 100644 --- a/include/engine/phantom_node.hpp +++ b/include/engine/phantom_node.hpp @@ -34,6 +34,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "util/coordinate.hpp" #include "util/typedefs.hpp" +#include + #include namespace osrm @@ -91,6 +93,9 @@ struct PhantomNode // x <-- this is PhantomNode.location // 0----1----2----3----4 <-- EdgeBasedGraph Node segments BOOST_ASSERT(forward_segment_id.enabled); + std::cout << "forward_distance: " << forward_distance; + std::cout << " forward_distance_offset: " << forward_distance_offset; + std::cout << std::endl; return forward_distance + forward_distance_offset; } @@ -102,6 +107,9 @@ struct PhantomNode // x <-- this is PhantomNode.location // 0----1----2----3----4 <-- EdgeBasedGraph Node segments BOOST_ASSERT(reverse_segment_id.enabled); + std::cout << "reverse_distance: " << reverse_distance; + std::cout << " reverse_distance_offset: " << reverse_distance_offset; + std::cout << std::endl; return reverse_distance + reverse_distance_offset; } @@ -234,7 +242,7 @@ struct PhantomNodes PhantomNode source_phantom; PhantomNode target_phantom; }; -} -} +} // namespace engine +} // namespace osrm #endif // PHANTOM_NODES_H diff --git a/include/engine/routing_algorithms/many_to_many.hpp b/include/engine/routing_algorithms/many_to_many.hpp index 281844abd..23c8902df 100644 --- a/include/engine/routing_algorithms/many_to_many.hpp +++ b/include/engine/routing_algorithms/many_to_many.hpp @@ -25,15 +25,17 @@ struct NodeBucket unsigned from_clique_arc : 1; EdgeWeight weight; EdgeDuration duration; + EdgeDistance distance; NodeBucket(NodeID middle_node, NodeID parent_node, bool from_clique_arc, unsigned column_index, EdgeWeight weight, - EdgeDuration duration) + EdgeDuration duration, + EdgeDistance distance) : middle_node(middle_node), parent_node(parent_node), column_index(column_index), - from_clique_arc(from_clique_arc), weight(weight), duration(duration) + from_clique_arc(from_clique_arc), weight(weight), duration(duration), distance(distance) { } @@ -41,9 +43,10 @@ struct NodeBucket NodeID parent_node, unsigned column_index, EdgeWeight weight, - EdgeDuration duration) + EdgeDuration duration, + EdgeDistance distance) : middle_node(middle_node), parent_node(parent_node), column_index(column_index), - from_clique_arc(false), weight(weight), duration(duration) + from_clique_arc(false), weight(weight), duration(duration), distance(distance) { } diff --git a/include/engine/routing_algorithms/routing_base.hpp b/include/engine/routing_algorithms/routing_base.hpp index 0c0808a3f..4afaae71f 100644 --- a/include/engine/routing_algorithms/routing_base.hpp +++ b/include/engine/routing_algorithms/routing_base.hpp @@ -85,13 +85,17 @@ void insertSourceInHeap(ManyToManyQueryHeap &heap, const PhantomNode &phantom_no { heap.Insert(phantom_node.forward_segment_id.id, -phantom_node.GetForwardWeightPlusOffset(), - {phantom_node.forward_segment_id.id, -phantom_node.GetForwardDuration()}); + {phantom_node.forward_segment_id.id, + -phantom_node.GetForwardDuration(), + -phantom_node.GetForwardDistance()}); } if (phantom_node.IsValidReverseSource()) { heap.Insert(phantom_node.reverse_segment_id.id, -phantom_node.GetReverseWeightPlusOffset(), - {phantom_node.reverse_segment_id.id, -phantom_node.GetReverseDuration()}); + {phantom_node.reverse_segment_id.id, + -phantom_node.GetReverseDuration(), + -phantom_node.GetReverseDistance()}); } } @@ -102,13 +106,17 @@ void insertTargetInHeap(ManyToManyQueryHeap &heap, const PhantomNode &phantom_no { heap.Insert(phantom_node.forward_segment_id.id, phantom_node.GetForwardWeightPlusOffset(), - {phantom_node.forward_segment_id.id, phantom_node.GetForwardDuration()}); + {phantom_node.forward_segment_id.id, + phantom_node.GetForwardDuration(), + phantom_node.GetForwardDistance()}); } if (phantom_node.IsValidReverseTarget()) { heap.Insert(phantom_node.reverse_segment_id.id, phantom_node.GetReverseWeightPlusOffset(), - {phantom_node.reverse_segment_id.id, phantom_node.GetReverseDuration()}); + {phantom_node.reverse_segment_id.id, + phantom_node.GetReverseDuration(), + phantom_node.GetReverseDistance()}); } } diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index 051b5f8c4..1d5448232 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -186,9 +186,10 @@ void routingStep(const DataFacade &facade, } template -EdgeWeight getLoopWeight(const DataFacade &facade, NodeID node) +std::tuple getLoopWeight(const DataFacade &facade, NodeID node) { EdgeWeight loop_weight = UseDuration ? MAXIMAL_EDGE_DURATION : INVALID_EDGE_WEIGHT; + EdgeDistance loop_distance = MAXIMAL_EDGE_DISTANCE; for (auto edge : facade.GetAdjacentEdgeRange(node)) { const auto &data = facade.GetEdgeData(edge); @@ -198,11 +199,15 @@ EdgeWeight getLoopWeight(const DataFacade &facade, NodeID node) if (to == node) { const auto value = UseDuration ? data.duration : data.weight; - loop_weight = std::min(loop_weight, value); + if (value < loop_weight) + { + loop_weight = value; + loop_distance = data.distance; + } } } } - return loop_weight; + return std::make_tuple(loop_weight, loop_distance); } /** diff --git a/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index db2c51224..4dafdd1a2 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -30,7 +30,11 @@ struct HeapData struct ManyToManyHeapData : HeapData { EdgeWeight duration; - ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {} + EdgeDistance distance; + ManyToManyHeapData(NodeID p, EdgeWeight duration, EdgeDistance distance) + : HeapData(p), duration(duration), distance(distance) + { + } }; template <> struct SearchEngineData @@ -75,12 +79,16 @@ struct MultiLayerDijkstraHeapData struct ManyToManyMultiLayerDijkstraHeapData : MultiLayerDijkstraHeapData { EdgeWeight duration; - ManyToManyMultiLayerDijkstraHeapData(NodeID p, EdgeWeight duration) - : MultiLayerDijkstraHeapData(p), duration(duration) + EdgeDistance distance; + ManyToManyMultiLayerDijkstraHeapData(NodeID p, EdgeWeight duration, EdgeDistance distance) + : MultiLayerDijkstraHeapData(p), duration(duration), distance(distance) { } - ManyToManyMultiLayerDijkstraHeapData(NodeID p, bool from, EdgeWeight duration) - : MultiLayerDijkstraHeapData(p, from), duration(duration) + ManyToManyMultiLayerDijkstraHeapData(NodeID p, + bool from, + EdgeWeight duration, + EdgeDistance distance) + : MultiLayerDijkstraHeapData(p, from), duration(duration), distance(distance) { } }; @@ -112,7 +120,7 @@ template <> struct SearchEngineData void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes, unsigned number_of_boundary_nodes); }; -} -} +} // namespace engine +} // namespace osrm #endif // SEARCH_ENGINE_DATA_HPP diff --git a/include/extractor/compressed_edge_container.hpp b/include/extractor/compressed_edge_container.hpp index 5b570e724..ec9e1f9ea 100644 --- a/include/extractor/compressed_edge_container.hpp +++ b/include/extractor/compressed_edge_container.hpp @@ -82,7 +82,7 @@ class CompressedEdgeContainer std::unordered_map m_reverse_edge_id_to_zipped_index_map; std::unique_ptr segment_data; }; -} -} +} // namespace extractor +} // namespace osrm #endif // GEOMETRY_COMPRESSOR_HPP_ diff --git a/include/extractor/edge_based_edge.hpp b/include/extractor/edge_based_edge.hpp index 1a58fc2b7..6c9aaa974 100644 --- a/include/extractor/edge_based_edge.hpp +++ b/include/extractor/edge_based_edge.hpp @@ -15,20 +15,25 @@ struct EdgeBasedEdge public: struct EdgeData { - EdgeData() : turn_id(0), weight(0), duration(0), forward(false), backward(false) {} + EdgeData() + : turn_id(0), weight(0), distance(0), duration(0), forward(false), backward(false) + { + } EdgeData(const NodeID turn_id, const EdgeWeight weight, + const EdgeDistance distance, const EdgeWeight duration, const bool forward, const bool backward) - : turn_id(turn_id), weight(weight), duration(duration), forward(forward), - backward(backward) + : turn_id(turn_id), weight(weight), distance(distance), duration(duration), + forward(forward), backward(backward) { } NodeID turn_id; // ID of the edge based node (node based edge) EdgeWeight weight; + EdgeDistance distance; EdgeWeight duration : 30; std::uint32_t forward : 1; std::uint32_t backward : 1; @@ -43,6 +48,7 @@ struct EdgeBasedEdge const NodeID edge_id, const EdgeWeight weight, const EdgeWeight duration, + const EdgeDistance distance, const bool forward, const bool backward); EdgeBasedEdge(const NodeID source, const NodeID target, const EdgeBasedEdge::EdgeData &data); @@ -53,7 +59,7 @@ struct EdgeBasedEdge NodeID target; EdgeData data; }; -static_assert(sizeof(extractor::EdgeBasedEdge) == 20, +static_assert(sizeof(extractor::EdgeBasedEdge) == 24, "Size of extractor::EdgeBasedEdge type is " "bigger than expected. This will influence " "memory consumption."); @@ -67,9 +73,10 @@ inline EdgeBasedEdge::EdgeBasedEdge(const NodeID source, const NodeID turn_id, const EdgeWeight weight, const EdgeWeight duration, + const EdgeDistance distance, const bool forward, const bool backward) - : source(source), target(target), data{turn_id, weight, duration, forward, backward} + : source(source), target(target), data{turn_id, weight, distance, duration, forward, backward} { } @@ -89,7 +96,7 @@ inline bool EdgeBasedEdge::operator<(const EdgeBasedEdge &other) const return std::tie(source, target, data.weight, unidirectional) < std::tie(other.source, other.target, other.data.weight, other_is_unidirectional); } -} // ns extractor -} // ns osrm +} // namespace extractor +} // namespace osrm #endif /* EDGE_BASED_EDGE_HPP */ diff --git a/include/extractor/internal_extractor_edge.hpp b/include/extractor/internal_extractor_edge.hpp index ef296b4f9..cba7f1361 100644 --- a/include/extractor/internal_extractor_edge.hpp +++ b/include/extractor/internal_extractor_edge.hpp @@ -49,7 +49,7 @@ struct ByEdgeOrByMeterValue using value_type = float; value_type value; }; -} +} // namespace detail struct InternalExtractorEdge { @@ -63,7 +63,7 @@ struct InternalExtractorEdge WeightData weight_data, DurationData duration_data, util::Coordinate source_coordinate) - : result(source, target, 0, 0, {}, -1, {}), weight_data(std::move(weight_data)), + : result(source, target, 0, 0, 0, {}, -1, {}), weight_data(std::move(weight_data)), duration_data(std::move(duration_data)), source_coordinate(std::move(source_coordinate)) { } @@ -113,7 +113,7 @@ struct InternalExtractorEdge return v; } }; -} -} +} // namespace extractor +} // namespace osrm #endif // INTERNAL_EXTRACTOR_EDGE_HPP diff --git a/include/extractor/node_based_edge.hpp b/include/extractor/node_based_edge.hpp index 6ac0d0343..de29a1e32 100644 --- a/include/extractor/node_based_edge.hpp +++ b/include/extractor/node_based_edge.hpp @@ -97,6 +97,7 @@ struct NodeBasedEdge NodeID target, EdgeWeight weight, EdgeDuration duration, + EdgeDistance distance, GeometryID geometry_id, AnnotationID annotation_data, NodeBasedEdgeClassification flags); @@ -107,6 +108,7 @@ struct NodeBasedEdge NodeID target; // 32 4 EdgeWeight weight; // 32 4 EdgeDuration duration; // 32 4 + EdgeDistance distance; // 32 4 GeometryID geometry_id; // 32 4 AnnotationID annotation_data; // 32 4 NodeBasedEdgeClassification flags; // 32 4 @@ -120,6 +122,7 @@ struct NodeBasedEdgeWithOSM : NodeBasedEdge OSMNodeID target, EdgeWeight weight, EdgeDuration duration, + EdgeDistance distance, GeometryID geometry_id, AnnotationID annotation_data, NodeBasedEdgeClassification flags); @@ -137,7 +140,7 @@ inline NodeBasedEdgeClassification::NodeBasedEdgeClassification() } inline NodeBasedEdge::NodeBasedEdge() - : source(SPECIAL_NODEID), target(SPECIAL_NODEID), weight(0), duration(0), annotation_data(-1) + : source(SPECIAL_NODEID), target(SPECIAL_NODEID), weight(0), duration(0), distance(0), annotation_data(-1) { } @@ -145,11 +148,12 @@ inline NodeBasedEdge::NodeBasedEdge(NodeID source, NodeID target, EdgeWeight weight, EdgeDuration duration, + EdgeDistance distance, GeometryID geometry_id, AnnotationID annotation_data, NodeBasedEdgeClassification flags) - : source(source), target(target), weight(weight), duration(duration), geometry_id(geometry_id), - annotation_data(annotation_data), flags(flags) + : source(source), target(target), weight(weight), duration(duration), distance(distance), + geometry_id(geometry_id), annotation_data(annotation_data), flags(flags) { } @@ -175,11 +179,18 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM(OSMNodeID source, OSMNodeID target, EdgeWeight weight, EdgeDuration duration, + EdgeDistance distance, GeometryID geometry_id, AnnotationID annotation_data, NodeBasedEdgeClassification flags) - : NodeBasedEdge( - SPECIAL_NODEID, SPECIAL_NODEID, weight, duration, geometry_id, annotation_data, flags), + : NodeBasedEdge(SPECIAL_NODEID, + SPECIAL_NODEID, + weight, + duration, + distance, + geometry_id, + annotation_data, + flags), osm_source_id(std::move(source)), osm_target_id(std::move(target)) { } @@ -189,12 +200,12 @@ inline NodeBasedEdgeWithOSM::NodeBasedEdgeWithOSM() { } -static_assert(sizeof(extractor::NodeBasedEdge) == 28, +static_assert(sizeof(extractor::NodeBasedEdge) == 32, "Size of extractor::NodeBasedEdge type is " "bigger than expected. This will influence " "memory consumption."); -} // ns extractor -} // ns osrm +} // namespace extractor +} // namespace osrm #endif /* NODE_BASED_EDGE_HPP */ diff --git a/include/partitioner/edge_based_graph_reader.hpp b/include/partitioner/edge_based_graph_reader.hpp index 9480112d0..ca9da18e3 100644 --- a/include/partitioner/edge_based_graph_reader.hpp +++ b/include/partitioner/edge_based_graph_reader.hpp @@ -14,6 +14,8 @@ #include #include +#include + #include #include @@ -38,11 +40,23 @@ splitBidirectionalEdges(const std::vector &edges) if (edge.data.weight == INVALID_EDGE_WEIGHT) continue; + std::cout << " EdgeBasedEdge {"; + std::cout << " source " << edge.source << ", target: " << edge.target; + std::cout << " EdgeBasedEdgeData data {"; + std::cout << " turn_id: " << edge.data.turn_id << ", weight: " << edge.data.weight; + std::cout << " distance: " << edge.data.distance << ", duration: " << edge.data.duration; + std::cout << " forward: " << (edge.data.forward == 0 ? "false" : "true") + << ", backward: " << (edge.data.backward == 0 ? "false" : "true"); + std::cout << " }"; + std::cout << "}" << std::endl; + + directed.emplace_back(edge.source, edge.target, edge.data.turn_id, std::max(edge.data.weight, 1), edge.data.duration, + edge.data.distance, edge.data.forward, edge.data.backward); @@ -51,10 +65,26 @@ splitBidirectionalEdges(const std::vector &edges) edge.data.turn_id, std::max(edge.data.weight, 1), edge.data.duration, + edge.data.distance, edge.data.backward, edge.data.forward); } + std::cout << "Directed edges" << std::endl; + for (const auto &edge : directed) + { + std::cout << " EdgeBasedEdge {"; + std::cout << " source " << edge.source << ", target: " << edge.target; + std::cout << " EdgeBasedEdgeData data {"; + std::cout << " turn_id: " << edge.data.turn_id << ", weight: " << edge.data.weight; + std::cout << " distance: " << edge.data.distance << ", duration: " << edge.data.duration; + std::cout << " forward: " << (edge.data.forward == 0 ? "false" : "true") + << ", backward: " << (edge.data.backward == 0 ? "false" : "true"); + std::cout << " }"; + std::cout << "}" << std::endl; + } + std::cout << "Done directed edges" << std::endl; + return directed; } @@ -69,6 +99,21 @@ std::vector prepareEdgesForUsageInGraph(std::vector output_edges; output_edges.reserve(edges.size()); @@ -90,6 +135,18 @@ std::vector prepareEdgesForUsageInGraph(std::vectorsource << ", target: " << begin_interval->target; + std::cout << " EdgeBasedEdgeData data {"; + std::cout << " turn_id: " << begin_interval->data.turn_id + << ", weight: " << begin_interval->data.weight; + std::cout << " distance: " << begin_interval->data.distance + << ", duration: " << begin_interval->data.duration; + std::cout << " forward: " << (begin_interval->data.forward == 0 ? "false" : "true") + << ", backward: " << (begin_interval->data.backward == 0 ? "false" : "true"); + std::cout << " }"; + std::cout << "}" << std::endl; + BOOST_ASSERT_MSG(begin_interval->data.forward != begin_interval->data.backward, "The forward and backward flag need to be mutally exclusive"); @@ -196,7 +253,7 @@ inline DynamicEdgeBasedGraph LoadEdgeBasedGraph(const boost::filesystem::path &p return DynamicEdgeBasedGraph(number_of_edge_based_nodes, std::move(tidied), checksum); } -} // ns partition -} // ns osrm +} // namespace partitioner +} // namespace osrm #endif