From 721f319909876b04d0ddad4340768752f4d5476a Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Tue, 4 Apr 2017 11:04:30 +0000 Subject: [PATCH] Don't scan back clique arcs --- include/customizer/cell_customizer.hpp | 51 +++++++++++++++++--------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/include/customizer/cell_customizer.hpp b/include/customizer/cell_customizer.hpp index aa6e12268..08a4fc34b 100644 --- a/include/customizer/cell_customizer.hpp +++ b/include/customizer/cell_customizer.hpp @@ -30,7 +30,7 @@ class CellCustomizer { std::unordered_set destinations_set(destinations.begin(), destinations.end()); Heap heap(graph.GetNumberOfNodes()); - heap.Insert(source, 0, {}); + heap.Insert(source, 0, {false}); // explore search space while (!heap.Empty() && !destinations_set.empty()) @@ -75,6 +75,7 @@ class CellCustomizer private: struct HeapData { + bool from_clique; }; using Heap = util:: BinaryHeap>; @@ -88,29 +89,42 @@ class CellCustomizer NodeID node, EdgeWeight weight) const { + BOOST_ASSERT(heap.WasInserted(node)); + if (!first_level) { - // Relax sub-cell nodes - auto subcell_id = partition.GetCell(level - 1, node); - auto subcell = cells.GetCell(level - 1, subcell_id); - auto subcell_destination = subcell.GetDestinationNodes().begin(); - for (auto subcell_weight : subcell.GetOutWeight(node)) + // if we reaches this node from a clique arc we don't need to scan + // the clique arcs again because of the triangle inequality + // + // d(parent, node) + d(node, v) >= d(parent, v) + // + // And if there is a path (parent, node, v) there must also be a + // clique arc (parent, v) with d(parent, v). + if (!heap.GetData(node).from_clique) { - if (subcell_weight != INVALID_EDGE_WEIGHT) + // Relax sub-cell nodes + auto subcell_id = partition.GetCell(level - 1, node); + auto subcell = cells.GetCell(level - 1, subcell_id); + auto subcell_destination = subcell.GetDestinationNodes().begin(); + for (auto subcell_weight : subcell.GetOutWeight(node)) { - const NodeID to = *subcell_destination; - const EdgeWeight to_weight = subcell_weight + weight; - if (!heap.WasInserted(to)) + if (subcell_weight != INVALID_EDGE_WEIGHT) { - heap.Insert(to, to_weight, {}); + const NodeID to = *subcell_destination; + const EdgeWeight to_weight = subcell_weight + weight; + if (!heap.WasInserted(to)) + { + heap.Insert(to, to_weight, {true}); + } + else if (to_weight < heap.GetKey(to)) + { + heap.DecreaseKey(to, to_weight); + heap.GetData(to).from_clique = true; + } } - else if (to_weight < heap.GetKey(to)) - { - heap.DecreaseKey(to, to_weight); - } - } - ++subcell_destination; + ++subcell_destination; + } } } @@ -126,11 +140,12 @@ class CellCustomizer const EdgeWeight to_weight = data.weight + weight; if (!heap.WasInserted(to)) { - heap.Insert(to, to_weight, {}); + heap.Insert(to, to_weight, {false}); } else if (to_weight < heap.GetKey(to)) { heap.DecreaseKey(to, to_weight); + heap.GetData(to).from_clique = false; } } }