Skip to content

Commit

Permalink
Remove MultiLayerDijkstraHeap and use QueryHeap
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Mar 15, 2017
1 parent 7907cf3 commit 223b65f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 68 deletions.
3 changes: 3 additions & 0 deletions include/engine/datafacade/algorithm_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ template <> class AlgorithmDataFacade<algorithm::MLD>
virtual const partition::MultiLevelPartitionView &GetMultiLevelPartition() const = 0;

virtual const partition::CellStorageView &GetCellStorage() const = 0;

// searches for a specific edge
virtual EdgeID FindEdge(const NodeID from, const NodeID to) const = 0;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,12 @@ class ContiguousInternalMemoryDataFacade<algorithm::MLD>
{
return m_query_graph->GetAdjacentEdgeRange(node);
}

// searches for a specific edge
EdgeID FindEdge(const NodeID from, const NodeID to) const override final
{
return m_query_graph->FindEdge(from, to);
}
};
}
}
Expand Down
34 changes: 14 additions & 20 deletions include/engine/routing_algorithms/routing_base_mld.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ namespace mld

template <bool DIRECTION>
void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
const std::pair<LevelID, CellID> &parent_cell,
const std::function<LevelID(const NodeID)> &get_query_level,
NodeID &middle_node,
Expand Down Expand Up @@ -56,14 +56,9 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
return;
}

const auto &node_data = forward_heap.GetData(node);
const auto level = std::min(parent_cell.first, 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
node_data.edge_id != SPECIAL_EDGEID); // or an overlay entreé point

if (check_overlay_edges)
if (level >= 1)
{
if (DIRECTION == FORWARD_DIRECTION)
{
Expand Down Expand Up @@ -138,11 +133,11 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:

if (!forward_heap.WasInserted(to))
{
forward_heap.Insert(to, to_weight, {node, edge});
forward_heap.Insert(to, to_weight, {node});
}
else if (to_weight < forward_heap.GetKey(to))
{
forward_heap.GetData(to) = {node, edge};
forward_heap.GetData(to) = {node};
forward_heap.DecreaseKey(to, to_weight);
}
}
Expand All @@ -151,8 +146,8 @@ void routingStep(const datafacade::ContiguousInternalMemoryDataFacade<algorithm:
}

auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
SearchEngineData::MultiLayerDijkstraHeap &forward_heap,
SearchEngineData::MultiLayerDijkstraHeap &reverse_heap,
SearchEngineData::QueryHeap &forward_heap,
SearchEngineData::QueryHeap &reverse_heap,
const std::pair<LevelID, CellID> &parent_cell,
const std::function<LevelID(const NodeID)> &get_query_level)
{
Expand Down Expand Up @@ -187,13 +182,12 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
INVALID_EDGE_WEIGHT, SPECIAL_NODEID, SPECIAL_NODEID, std::vector<EdgeID>());
}

// Get packed path as edges {from node ID, to node ID, edge ID}
std::vector<std::tuple<NodeID, NodeID, EdgeID>> packed_path;
// Get packed path as edges {from node ID, to node ID}
std::vector<std::tuple<NodeID, NodeID>> packed_path;
NodeID current_node = middle, parent_node = forward_heap.GetData(middle).parent;
while (parent_node != current_node)
{
const auto &data = forward_heap.GetData(current_node);
packed_path.push_back(std::make_tuple(parent_node, current_node, data.edge_id));
packed_path.push_back(std::make_tuple(parent_node, current_node));
current_node = parent_node;
parent_node = forward_heap.GetData(parent_node).parent;
}
Expand All @@ -203,8 +197,7 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
current_node = middle, parent_node = reverse_heap.GetData(middle).parent;
while (parent_node != current_node)
{
const auto &data = reverse_heap.GetData(current_node);
packed_path.push_back(std::make_tuple(current_node, parent_node, data.edge_id));
packed_path.push_back(std::make_tuple(current_node, parent_node));
current_node = parent_node;
parent_node = reverse_heap.GetData(parent_node).parent;
}
Expand All @@ -216,8 +209,9 @@ auto search(const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD>
for (auto &packed_edge : packed_path)
{
NodeID source, target;
EdgeID edge_id;
std::tie(source, target, edge_id) = packed_edge;
std::tie(source, target) = packed_edge;
EdgeID edge_id = facade.FindEdge(source, target);

if (edge_id != SPECIAL_EDGEID)
{ // a base graph edge
unpacked_path.push_back(edge_id);
Expand Down
19 changes: 0 additions & 19 deletions include/engine/search_engine_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ struct ManyToManyHeapData : HeapData
ManyToManyHeapData(NodeID p, EdgeWeight duration) : HeapData(p), duration(duration) {}
};

struct MultiLayerDijkstraHeapData : HeapData
{
EdgeID edge_id; // edge id if parent -> node is a boundary edge
MultiLayerDijkstraHeapData(NodeID p) : HeapData(p), edge_id(SPECIAL_EDGEID) {}
MultiLayerDijkstraHeapData(NodeID p, EdgeID edge_id) : HeapData(p), edge_id(edge_id) {}
};

struct SearchEngineData
{
using QueryHeap = util::
Expand All @@ -45,23 +38,13 @@ struct SearchEngineData

using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;

using MultiLayerDijkstraHeap = util::BinaryHeap<NodeID,
NodeID,
EdgeWeight,
MultiLayerDijkstraHeapData,
util::UnorderedMapStorage<NodeID, int>>;

using MultiLayerDijkstraHeapPtr = boost::thread_specific_ptr<MultiLayerDijkstraHeap>;

static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
static SearchEngineHeapPtr forward_heap_2;
static SearchEngineHeapPtr reverse_heap_2;
static SearchEngineHeapPtr forward_heap_3;
static SearchEngineHeapPtr reverse_heap_3;
static ManyToManyHeapPtr many_to_many_heap;
static MultiLayerDijkstraHeapPtr mld_forward_heap;
static MultiLayerDijkstraHeapPtr mld_reverse_heap;

void InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes);

Expand All @@ -70,8 +53,6 @@ struct SearchEngineData
void InitializeOrClearThirdThreadLocalStorage(const unsigned number_of_nodes);

void InitializeOrClearManyToManyThreadLocalStorage(const unsigned number_of_nodes);

void InitializeOrClearMultiLayerDijkstraThreadLocalStorage(const unsigned number_of_nodes);
};
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/engine/routing_algorithms/direct_shortest_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ InternalRouteResult directShortestPathSearch(
const datafacade::ContiguousInternalMemoryDataFacade<algorithm::MLD> &facade,
const PhantomNodes &phantom_nodes)
{
engine_working_data.InitializeOrClearMultiLayerDijkstraThreadLocalStorage(
facade.GetNumberOfNodes());
auto &forward_heap = *(engine_working_data.mld_forward_heap);
auto &reverse_heap = *(engine_working_data.mld_reverse_heap);
engine_working_data.InitializeOrClearFirstThreadLocalStorage(facade.GetNumberOfNodes());
auto &forward_heap = *(engine_working_data.forward_heap_1);
auto &reverse_heap = *(engine_working_data.reverse_heap_1);
forward_heap.Clear();
reverse_heap.Clear();
insertNodesInHeaps(forward_heap, reverse_heap, phantom_nodes);
Expand Down
25 changes: 0 additions & 25 deletions src/engine/search_engine_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3;
SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3;
SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap;

SearchEngineData::MultiLayerDijkstraHeapPtr SearchEngineData::mld_forward_heap;
SearchEngineData::MultiLayerDijkstraHeapPtr SearchEngineData::mld_reverse_heap;

void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(const unsigned number_of_nodes)
{
if (forward_heap_1.get())
Expand Down Expand Up @@ -92,27 +89,5 @@ void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(const unsig
many_to_many_heap.reset(new ManyToManyQueryHeap(number_of_nodes));
}
}

void SearchEngineData::InitializeOrClearMultiLayerDijkstraThreadLocalStorage(
const unsigned number_of_nodes)
{
if (mld_forward_heap.get())
{
mld_forward_heap->Clear();
}
else
{
mld_forward_heap.reset(new MultiLayerDijkstraHeap(number_of_nodes));
}

if (mld_reverse_heap.get())
{
mld_reverse_heap->Clear();
}
else
{
mld_reverse_heap.reset(new MultiLayerDijkstraHeap(number_of_nodes));
}
}
}
}

0 comments on commit 223b65f

Please sign in to comment.