From 8582c3d8a57e72cad2b5d840211d4988e154cd56 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Tue, 14 Mar 2017 16:04:15 +0100 Subject: [PATCH] Simplify upper bound condition for MLD routing --- .../routing_algorithms/routing_base_mld.hpp | 87 +++++++------------ 1 file changed, 29 insertions(+), 58 deletions(-) diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index 2af6ab7475e..daea5dd1933 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -27,30 +27,24 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade &parent_cell, NodeID &middle_node, - EdgeWeight &path_upper_bound, - EdgeWeight &forward_upper_bound, - EdgeWeight &reverse_upper_bound) + EdgeWeight &path_upper_bound) { const auto node = forward_heap.DeleteMin(); const auto weight = forward_heap.GetKey(node); - auto update_upper_bounds = [&](NodeID to, EdgeWeight forward_weight, EdgeWeight edge_weight) { - // Upper bound for the path source -> 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; } }; @@ -61,9 +55,6 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade SearchEngineData::MultiLayerDijkstraHeap &reverse_heap, const std::pair &parent_cell) { + 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 + EdgeWeight forward_heap_min = forward_heap.MinKey(); + EdgeWeight reverse_heap_min = reverse_heap.MinKey(); + while ((forward_heap_min + reverse_heap_min <= weight) && + (forward_heap.Size() + reverse_heap.Size() > 0)) { - progress = false; - if (!forward_heap.Empty() && (forward_heap.MinKey() < forward_search_radius)) + if (!forward_heap.Empty()) { - progress = true; - routingStep(facade, - partition, - cells, - forward_heap, - reverse_heap, - parent_cell, - middle, - weight, - forward_search_radius, - reverse_search_radius); + forward_heap_min = forward_heap.MinKey(); + routingStep( + facade, partition, cells, forward_heap, reverse_heap, parent_cell, middle, weight); } - if (!reverse_heap.Empty() && (reverse_heap.MinKey() < reverse_search_radius)) + if (!reverse_heap.Empty()) { - progress = true; - routingStep(facade, - partition, - cells, - reverse_heap, - forward_heap, - parent_cell, - middle, - weight, - reverse_search_radius, - forward_search_radius); + reverse_heap_min = reverse_heap.MinKey(); + routingStep( + facade, partition, cells, reverse_heap, forward_heap, parent_cell, middle, weight); } - } while (progress); + }; // No path found for both target nodes? if (weight == INVALID_EDGE_WEIGHT || SPECIAL_NODEID == middle)