Don't scan back clique arcs

This commit is contained in:
Patrick Niklaus 2017-04-04 11:04:30 +00:00 committed by Patrick Niklaus
parent a3621f3655
commit 721f319909

View File

@ -30,7 +30,7 @@ class CellCustomizer
{ {
std::unordered_set<NodeID> destinations_set(destinations.begin(), destinations.end()); std::unordered_set<NodeID> destinations_set(destinations.begin(), destinations.end());
Heap heap(graph.GetNumberOfNodes()); Heap heap(graph.GetNumberOfNodes());
heap.Insert(source, 0, {}); heap.Insert(source, 0, {false});
// explore search space // explore search space
while (!heap.Empty() && !destinations_set.empty()) while (!heap.Empty() && !destinations_set.empty())
@ -75,6 +75,7 @@ class CellCustomizer
private: private:
struct HeapData struct HeapData
{ {
bool from_clique;
}; };
using Heap = util:: using Heap = util::
BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>; BinaryHeap<NodeID, NodeID, EdgeWeight, HeapData, util::UnorderedMapStorage<NodeID, int>>;
@ -88,7 +89,18 @@ class CellCustomizer
NodeID node, NodeID node,
EdgeWeight weight) const EdgeWeight weight) const
{ {
BOOST_ASSERT(heap.WasInserted(node));
if (!first_level) if (!first_level)
{
// 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)
{ {
// Relax sub-cell nodes // Relax sub-cell nodes
auto subcell_id = partition.GetCell(level - 1, node); auto subcell_id = partition.GetCell(level - 1, node);
@ -102,17 +114,19 @@ class CellCustomizer
const EdgeWeight to_weight = subcell_weight + weight; const EdgeWeight to_weight = subcell_weight + weight;
if (!heap.WasInserted(to)) if (!heap.WasInserted(to))
{ {
heap.Insert(to, to_weight, {}); heap.Insert(to, to_weight, {true});
} }
else if (to_weight < heap.GetKey(to)) else if (to_weight < heap.GetKey(to))
{ {
heap.DecreaseKey(to, to_weight); heap.DecreaseKey(to, to_weight);
heap.GetData(to).from_clique = true;
} }
} }
++subcell_destination; ++subcell_destination;
} }
} }
}
// Relax base graph edges if a sub-cell border edge // Relax base graph edges if a sub-cell border edge
for (auto edge : graph.GetInternalEdgeRange(level, node)) for (auto edge : graph.GetInternalEdgeRange(level, node))
@ -126,11 +140,12 @@ class CellCustomizer
const EdgeWeight to_weight = data.weight + weight; const EdgeWeight to_weight = data.weight + weight;
if (!heap.WasInserted(to)) if (!heap.WasInserted(to))
{ {
heap.Insert(to, to_weight, {}); heap.Insert(to, to_weight, {false});
} }
else if (to_weight < heap.GetKey(to)) else if (to_weight < heap.GetKey(to))
{ {
heap.DecreaseKey(to, to_weight); heap.DecreaseKey(to, to_weight);
heap.GetData(to).from_clique = false;
} }
} }
} }