From 7907cf3089eb381054ab5a3d1f39650932b26cc0 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 14 Mar 2017 16:04:15 +0100 Subject: [PATCH] Use correct upper bound condition for MLD routing --- .../routing_algorithms/routing_base_mld.hpp | 90 +++++++------------ 1 file changed, 33 insertions(+), 57 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index f65aa21953..1b3533b3cc 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -26,9 +26,7 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &parent_cell, const std::function &get_query_level, NodeID &middle_node, - EdgeWeight &path_upper_bound, - EdgeWeight &forward_upper_bound, - EdgeWeight &reverse_upper_bound) + EdgeWeight &path_upper_bound) { const auto &partition = facade.GetMultiLevelPartition(); const auto &cells = facade.GetCellStorage(); @@ -36,25 +34,27 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade target with - // weight(source -> node) = forward_weight, weight(node -> to) = edge_weight and - // weight(to -> target) ≤ reverse_weight is forward_weight + edge_weight + reverse_weight - // More tighter upper bound requires additional condition reverse_heap.WasRemoved(to) - // with weight(to -> target) = reverse_weight and all weights ≥ 0 - if (reverse_heap.WasInserted(to)) + // Upper bound for the path source -> target with + // weight(source -> node) = weight weight(to -> target) ≤ reverse_weight + // is weight + reverse_weight + // More tighter upper bound requires additional condition reverse_heap.WasRemoved(to) + // with weight(to -> target) = reverse_weight and all weights ≥ 0 + if (reverse_heap.WasInserted(node)) + { + auto reverse_weight = reverse_heap.GetKey(node); + auto path_weight = weight + reverse_weight; + if (path_weight >= 0 && path_weight < path_upper_bound) { - auto reverse_weight = reverse_heap.GetKey(to); - auto path_weight = forward_weight + edge_weight + reverse_weight; - if (path_weight >= 0 && path_weight < path_upper_bound) - { - middle_node = to; - path_upper_bound = path_weight; - forward_upper_bound = forward_weight + edge_weight; - reverse_upper_bound = reverse_weight + edge_weight; - } + middle_node = node; + path_upper_bound = path_weight; } - }; + } + + if (weight > path_upper_bound) + { + forward_heap.DeleteAll(); + return; + } const auto &node_data = forward_heap.GetData(node); const auto level = std::min(parent_cell.first, get_query_level(node)); @@ -63,9 +63,6 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade const std::pair &parent_cell, const std::function &get_query_level) { + const auto &partition = facade.GetMultiLevelPartition(); + BOOST_ASSERT(!forward_heap.Empty() && forward_heap.MinKey() < INVALID_EDGE_WEIGHT); + BOOST_ASSERT(!reverse_heap.Empty() && reverse_heap.MinKey() < INVALID_EDGE_WEIGHT); + // run two-Target Dijkstra routing step. NodeID middle = SPECIAL_NODEID; EdgeWeight weight = INVALID_EDGE_WEIGHT; - EdgeWeight forward_search_radius = INVALID_EDGE_WEIGHT; - EdgeWeight reverse_search_radius = INVALID_EDGE_WEIGHT; - bool progress; - do + while (forward_heap.Size() + reverse_heap.Size() > 0 && + forward_heap.MinKey() + reverse_heap.MinKey() < weight) { - progress = false; - if (!forward_heap.Empty() && (forward_heap.MinKey() < forward_search_radius)) + if (!forward_heap.Empty()) { - progress = true; - routingStep(facade, - forward_heap, - reverse_heap, - parent_cell, - get_query_level, - middle, - weight, - forward_search_radius, - reverse_search_radius); + routingStep( + facade, forward_heap, reverse_heap, parent_cell, get_query_level, middle, weight); } - if (!reverse_heap.Empty() && (reverse_heap.MinKey() < reverse_search_radius)) + if (!reverse_heap.Empty()) { - progress = true; - routingStep(facade, - reverse_heap, - forward_heap, - parent_cell, - get_query_level, - middle, - weight, - reverse_search_radius, - forward_search_radius); + routingStep( + facade, reverse_heap, forward_heap, parent_cell, get_query_level, middle, weight); } - } while (progress); + }; // No path found for both target nodes? if (weight == INVALID_EDGE_WEIGHT || SPECIAL_NODEID == middle)