From cdc7e5f021d6876bcd837ee69671115f372229d4 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Mon, 23 Apr 2018 10:00:30 +0200 Subject: [PATCH] Fix for updating node weights in contraction hierarchy --- src/contractor/contractor.cpp | 6 ++++++ src/extractor/edge_based_graph_factory.cpp | 5 ++++- src/updater/updater.cpp | 11 +++++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/contractor/contractor.cpp b/src/contractor/contractor.cpp index 416f4a62b..266367080 100644 --- a/src/contractor/contractor.cpp +++ b/src/contractor/contractor.cpp @@ -75,6 +75,12 @@ int Contractor::Run() EdgeID number_of_edge_based_nodes = updater.LoadAndUpdateEdgeExpandedGraph( edge_based_edge_list, node_weights, connectivity_checksum); + // Convert node weights for oneway streets to INVALID_EDGE_WEIGHT + for (auto &weight : node_weights) + { + weight = (weight & 0x80000000) ? INVALID_EDGE_WEIGHT : weight; + } + // Contracting the edge-expanded graph TIMER_START(contraction); diff --git a/src/extractor/edge_based_graph_factory.cpp b/src/extractor/edge_based_graph_factory.cpp index 2db06188b..931a96876 100644 --- a/src/extractor/edge_based_graph_factory.cpp +++ b/src/extractor/edge_based_graph_factory.cpp @@ -138,9 +138,12 @@ NBGToEBG EdgeBasedGraphFactory::InsertEdgeBasedNode(const NodeID node_u, const N BOOST_ASSERT(nbe_to_ebn_mapping[edge_id_1] != SPECIAL_NODEID || nbe_to_ebn_mapping[edge_id_2] != SPECIAL_NODEID); + // TODO: use the sign bit to distinguish oneway streets that must + // have INVALID_EDGE_WEIGHT node weight values to enforce loop edges + // in contraction if (nbe_to_ebn_mapping[edge_id_1] != SPECIAL_NODEID && nbe_to_ebn_mapping[edge_id_2] == SPECIAL_NODEID) - m_edge_based_node_weights[nbe_to_ebn_mapping[edge_id_1]] = INVALID_EDGE_WEIGHT; + m_edge_based_node_weights[nbe_to_ebn_mapping[edge_id_1]] |= 0x80000000; BOOST_ASSERT(m_compressed_edge_container.HasEntryForID(edge_id_1) == m_compressed_edge_container.HasEntryForID(edge_id_2)); diff --git a/src/updater/updater.cpp b/src/updater/updater.cpp index b9e5356fc..22a372b14 100644 --- a/src/updater/updater.cpp +++ b/src/updater/updater.cpp @@ -743,12 +743,11 @@ Updater::LoadAndUpdateEdgeExpandedGraph(std::vector &e accumulated_segment_data[updated_iter - updated_segments.begin()]; // Update the node-weight cache. This is the weight of the edge-based-node - // only, - // it doesn't include the turn. We may visit the same node multiple times, - // but - // we should always assign the same value here. - if (node_weights.size() > 0) - node_weights[edge.source] = new_weight; + // only, it doesn't include the turn. We may visit the same node multiple times, + // but we should always assign the same value here. + BOOST_ASSERT(edge.source < node_weights.size()); + node_weights[edge.source] = + node_weights[edge.source] & 0x80000000 ? new_weight | 0x80000000 : new_weight; // We found a zero-speed edge, so we'll skip this whole edge-based-edge // which