Skip to content

Commit

Permalink
Implement MLD routingStep with cell restriction and without
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Mar 17, 2017
1 parent 1311525 commit 2e4dc3c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
50 changes: 30 additions & 20 deletions include/engine/routing_algorithms/routing_base_mld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,29 @@ namespace routing_algorithms
namespace mld
{

template <bool DIRECTION>
namespace
{
// Unrestricted search (Args is std::function<LevelID(const NodeID)>):
// * use `query_level` closure of partition.GetQueryLevel to find the query level
// * allow to traverse all cells
using QueryLevelFunction = std::function<LevelID(const NodeID)>;
LevelID getNodeQureyLevel(NodeID node, const QueryLevelFunction &functor) { return functor(node); }
bool checkParentCellRestriction(CellID, const QueryLevelFunction &) { return true; }

// Restricted search (Args is LevelID, CellID):
// * use the fixed level for queries
// * check if the node cell is the same as the specified parent onr
LevelID getNodeQureyLevel(NodeID, LevelID level, CellID) { return level; }
bool checkParentCellRestriction(CellID cell, LevelID, CellID parent) { return cell == parent; }
}

template <bool DIRECTION, typename... Args>
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap,
const std::pair<LevelID, CellID> &parent_cell,
const std::function<LevelID(const NodeID)> &get_query_level,
NodeID &middle_node,
EdgeWeight &path_upper_bound)
EdgeWeight &path_upper_bound,
Args... args)
{
const auto &partition = facade.GetMultiLevelPartition();
const auto &cells = facade.GetCellStorage();
Expand All @@ -50,8 +65,8 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
}
}

const auto level = getNodeQureyLevel(node, args...);
const auto &node_data = forward_heap.GetData(node);
const auto level = get_query_level(node);
const auto check_overlay_edges =
(level >= 1) && // only if at least the first level and
(node_data.parent == node || // is the first point of the path
Expand Down Expand Up @@ -118,14 +133,9 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
if (DIRECTION == FORWARD_DIRECTION ? edge_data.forward : edge_data.backward)
{
const NodeID to = facade.GetTarget(edge);
const auto to_level =
std::min(parent_cell.first, partition.GetHighestDifferentLevel(node, to));

if ( // Routing is unrestricted or restricted to the highest level cell
(parent_cell.second == INVALID_CELL_ID ||
parent_cell.second == partition.GetCell(parent_cell.first + 1, to)) &&
// "Never-go-down" at border edges
to_level >= level)
if (checkParentCellRestriction(partition.GetCell(level + 1, to), args...) &&
partition.GetHighestDifferentLevel(node, to) >= level)
{
BOOST_ASSERT_MSG(edge_data.weight > 0, "edge_weight invalid");
const EdgeWeight to_weight = weight + edge_data.weight;
Expand All @@ -144,11 +154,11 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
}
}

template <typename... Args>
auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap,
const std::pair<LevelID, CellID> &parent_cell,
const std::function<LevelID(const NodeID)> &get_query_level)
Args... args)
{

const auto &partition = facade.GetMultiLevelPartition();
Expand All @@ -167,14 +177,14 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
if (!forward_heap.Empty())
{
routingStep<FORWARD_DIRECTION>(
facade, forward_heap, reverse_heap, parent_cell, get_query_level, middle, weight);
facade, forward_heap, reverse_heap, middle, weight, args...);
if (!forward_heap.Empty())
forward_heap_min = forward_heap.MinKey();
}
if (!reverse_heap.Empty())
{
routingStep<REVERSE_DIRECTION>(
facade, reverse_heap, forward_heap, parent_cell, get_query_level, middle, weight);
facade, reverse_heap, forward_heap, middle, weight, args...);
if (!reverse_heap.Empty())
reverse_heap_min = reverse_heap.MinKey();
}
Expand Down Expand Up @@ -213,7 +223,7 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
// Unpack path
std::vector<EdgeID> unpacked_path;
unpacked_path.reserve(packed_path.size());
for (auto &packed_edge : packed_path)
for (auto const &packed_edge : packed_path)
{
NodeID source, target;
EdgeID edge_id;
Expand All @@ -224,7 +234,7 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
}
else
{ // an overlay graph edge
LevelID level = std::min(parent_cell.first, get_query_level(source));
LevelID level = getNodeQureyLevel(source, args...);
CellID parent_cell_id = partition.GetCell(level, source);
BOOST_ASSERT(parent_cell_id == partition.GetCell(level, target));

Expand All @@ -241,8 +251,8 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
EdgeWeight subpath_weight;
NodeID subpath_source, subpath_target;
std::vector<EdgeID> subpath;
std::tie(subpath_weight, subpath_source, subpath_target, subpath) = search(
facade, forward_heap, reverse_heap, {sublevel, parent_cell_id}, get_query_level);
std::tie(subpath_weight, subpath_source, subpath_target, subpath) =
search(facade, forward_heap, reverse_heap, sublevel, parent_cell_id);
BOOST_ASSERT(!subpath.empty());
BOOST_ASSERT(subpath_source == source);
BOOST_ASSERT(subpath_target == target);
Expand Down
4 changes: 2 additions & 2 deletions src/engine/routing_algorithms/direct_shortest_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ InternalRouteResult directShortestPathSearch(
EdgeWeight weight;
NodeID source_node, target_node;
std::vector<EdgeID> unpacked_edges;
std::tie(weight, source_node, target_node, unpacked_edges) = mld::search(
facade, forward_heap, reverse_heap, {INVALID_LEVEL_ID, INVALID_CELL_ID}, get_query_level);
std::tie(weight, source_node, target_node, unpacked_edges) =
mld::search(facade, forward_heap, reverse_heap, get_query_level);

return extractRoute(facade, weight, source_node, target_node, unpacked_edges, phantom_nodes);
}
Expand Down

0 comments on commit 2e4dc3c

Please sign in to comment.