Skip to content

Commit

Permalink
Use correct upper bound condition for MLD routing
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Mar 15, 2017
1 parent 5789089 commit 7907cf3
Showing 1 changed file with 33 additions and 57 deletions.
90 changes: 33 additions & 57 deletions include/engine/routing_algorithms/routing_base_mld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,35 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
const std::pair<LevelID, CellID> &parent_cell,
const std::function<LevelID(const NodeID)> &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();

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;
}
};
}

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));
Expand All @@ -63,9 +63,6 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
(node_data.parent == node || // is the first point of the path
node_data.edge_id != SPECIAL_EDGEID); // or an overlay entreé point

// Edge case: single node path
update_upper_bounds(node, weight, 0);

if (check_overlay_edges)
{
if (DIRECTION == FORWARD_DIRECTION)
Expand All @@ -83,13 +80,11 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
if (!forward_heap.WasInserted(to))
{
forward_heap.Insert(to, to_weight, {node});
update_upper_bounds(to, weight, shortcut_weight);
}
else if (to_weight < forward_heap.GetKey(to))
{
forward_heap.GetData(to) = {node};
forward_heap.DecreaseKey(to, to_weight);
update_upper_bounds(to, weight, shortcut_weight);
}
}
++destination;
Expand All @@ -110,13 +105,11 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
if (!forward_heap.WasInserted(to))
{
forward_heap.Insert(to, to_weight, {node});
update_upper_bounds(to, weight, shortcut_weight);
}
else if (to_weight < forward_heap.GetKey(to))
{
forward_heap.GetData(to) = {node};
forward_heap.DecreaseKey(to, to_weight);
update_upper_bounds(to, weight, shortcut_weight);
}
}
++source;
Expand Down Expand Up @@ -146,13 +139,11 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
if (!forward_heap.WasInserted(to))
{
forward_heap.Insert(to, to_weight, {node, edge});
update_upper_bounds(to, weight, edge_data.weight);
}
else if (to_weight < forward_heap.GetKey(to))
{
forward_heap.GetData(to) = {node, edge};
forward_heap.DecreaseKey(to, to_weight);
update_upper_bounds(to, weight, edge_data.weight);
}
}
}
Expand All @@ -165,44 +156,29 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
const std::pair<LevelID, CellID> &parent_cell,
const std::function<LevelID(const NodeID)> &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<FORWARD_DIRECTION>(facade,
forward_heap,
reverse_heap,
parent_cell,
get_query_level,
middle,
weight,
forward_search_radius,
reverse_search_radius);
routingStep<FORWARD_DIRECTION>(
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<REVERSE_DIRECTION>(facade,
reverse_heap,
forward_heap,
parent_cell,
get_query_level,
middle,
weight,
reverse_search_radius,
forward_search_radius);
routingStep<REVERSE_DIRECTION>(
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)
Expand Down

0 comments on commit 7907cf3

Please sign in to comment.