format code

This commit is contained in:
xlaussel 2020-11-25 12:42:01 +01:00
parent aa06029801
commit fcb7dd2a21
7 changed files with 110 additions and 98 deletions

View File

@ -24,7 +24,7 @@ namespace ch
// Stalling // Stalling
template <bool DIRECTION, typename HeapT> template <bool DIRECTION, typename HeapT>
bool stallAtNode(const DataFacade<Algorithm> &facade, bool stallAtNode(const DataFacade<Algorithm> &facade,
const typename HeapT::HeapNode& heapNode, const typename HeapT::HeapNode &heapNode,
const HeapT &query_heap) const HeapT &query_heap)
{ {
for (auto edge : facade.GetAdjacentEdgeRange(heapNode.node)) for (auto edge : facade.GetAdjacentEdgeRange(heapNode.node))
@ -35,7 +35,7 @@ bool stallAtNode(const DataFacade<Algorithm> &facade,
const NodeID to = facade.GetTarget(edge); const NodeID to = facade.GetTarget(edge);
const EdgeWeight edge_weight = data.weight; const EdgeWeight edge_weight = data.weight;
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid"); BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
if (toHeapNode) if (toHeapNode)
{ {
if (toHeapNode->weight + edge_weight < heapNode.weight) if (toHeapNode->weight + edge_weight < heapNode.weight)
@ -50,7 +50,7 @@ bool stallAtNode(const DataFacade<Algorithm> &facade,
template <bool DIRECTION> template <bool DIRECTION>
void relaxOutgoingEdges(const DataFacade<Algorithm> &facade, void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
const SearchEngineData<Algorithm>::QueryHeap::HeapNode& heapNode, const SearchEngineData<Algorithm>::QueryHeap::HeapNode &heapNode,
SearchEngineData<Algorithm>::QueryHeap &heap) SearchEngineData<Algorithm>::QueryHeap &heap)
{ {
for (const auto edge : facade.GetAdjacentEdgeRange(heapNode.node)) for (const auto edge : facade.GetAdjacentEdgeRange(heapNode.node))
@ -75,7 +75,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
{ {
// new parent // new parent
toHeapNode->data.parent = heapNode.node; toHeapNode->data.parent = heapNode.node;
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
heap.DecreaseKey(*toHeapNode); heap.DecreaseKey(*toHeapNode);
} }
} }

View File

@ -97,7 +97,6 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
const std::vector<std::size_t> &phantom_indices) const std::vector<std::size_t> &phantom_indices)
{ {
auto min_level = [&partition, node](const PhantomNode &phantom_node) { auto min_level = [&partition, node](const PhantomNode &phantom_node) {
const auto &forward_segment = phantom_node.forward_segment_id; const auto &forward_segment = phantom_node.forward_segment_id;
const auto forward_level = const auto forward_level =
forward_segment.enabled ? partition.GetHighestDifferentLevel(node, forward_segment.id) forward_segment.enabled ? partition.GetHighestDifferentLevel(node, forward_segment.id)
@ -120,7 +119,7 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
} }
return result; return result;
} }
} } // namespace
// Heaps only record for each node its predecessor ("parent") on the shortest path. // Heaps only record for each node its predecessor ("parent") on the shortest path.
// For re-constructing the actual path we need to trace back all parent "pointers". // For re-constructing the actual path we need to trace back all parent "pointers".
@ -229,7 +228,7 @@ retrievePackedPathFromHeap(const SearchEngineData<Algorithm>::QueryHeap &forward
template <bool DIRECTION, typename Algorithm, typename... Args> template <bool DIRECTION, typename Algorithm, typename... Args>
void relaxOutgoingEdges(const DataFacade<Algorithm> &facade, void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
typename SearchEngineData<Algorithm>::QueryHeap &forward_heap, typename SearchEngineData<Algorithm>::QueryHeap &forward_heap,
const typename SearchEngineData<Algorithm>::QueryHeap::HeapNode& heapNode, const typename SearchEngineData<Algorithm>::QueryHeap::HeapNode &heapNode,
Args... args) Args... args)
{ {
const auto &partition = facade.GetMultiLevelPartition(); const auto &partition = facade.GetMultiLevelPartition();
@ -243,7 +242,8 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
if (DIRECTION == FORWARD_DIRECTION) if (DIRECTION == FORWARD_DIRECTION)
{ {
// Shortcuts in forward direction // Shortcuts in forward direction
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, heapNode.node)); const auto &cell =
cells.GetCell(metric, level, partition.GetCell(level, heapNode.node));
auto destination = cell.GetDestinationNodes().begin(); auto destination = cell.GetDestinationNodes().begin();
for (auto shortcut_weight : cell.GetOutWeight(heapNode.node)) for (auto shortcut_weight : cell.GetOutWeight(heapNode.node))
{ {
@ -262,7 +262,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
else if (to_weight < toHeapNode->weight) else if (to_weight < toHeapNode->weight)
{ {
toHeapNode->data = {heapNode.node, true}; toHeapNode->data = {heapNode.node, true};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
forward_heap.DecreaseKey(*toHeapNode); forward_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -272,7 +272,8 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
else else
{ {
// Shortcuts in backward direction // Shortcuts in backward direction
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, heapNode.node)); const auto &cell =
cells.GetCell(metric, level, partition.GetCell(level, heapNode.node));
auto source = cell.GetSourceNodes().begin(); auto source = cell.GetSourceNodes().begin();
for (auto shortcut_weight : cell.GetInWeight(heapNode.node)) for (auto shortcut_weight : cell.GetInWeight(heapNode.node))
{ {
@ -291,7 +292,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
else if (to_weight < toHeapNode->weight) else if (to_weight < toHeapNode->weight)
{ {
toHeapNode->data = {heapNode.node, true}; toHeapNode->data = {heapNode.node, true};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
forward_heap.DecreaseKey(*toHeapNode); forward_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -329,7 +330,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
else if (to_weight < toHeapNode->weight) else if (to_weight < toHeapNode->weight)
{ {
toHeapNode->data = {heapNode.node, false}; toHeapNode->data = {heapNode.node, false};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
forward_heap.DecreaseKey(*toHeapNode); forward_heap.DecreaseKey(*toHeapNode);
} }
} }

View File

@ -2,8 +2,8 @@
#define OSRM_UTIL_QUERY_HEAP_HPP #define OSRM_UTIL_QUERY_HEAP_HPP
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/optional.hpp>
#include <boost/heap/d_ary_heap.hpp> #include <boost/heap/d_ary_heap.hpp>
#include <boost/optional.hpp>
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
@ -196,7 +196,6 @@ template <typename NodeID,
class QueryHeap class QueryHeap
{ {
private: private:
using HeapData = std::pair<Weight, Key>; using HeapData = std::pair<Weight, Key>;
using HeapContainer = boost::heap::d_ary_heap<HeapData, using HeapContainer = boost::heap::d_ary_heap<HeapData,
boost::heap::arity<4>, boost::heap::arity<4>,
@ -248,7 +247,7 @@ class QueryHeap
return inserted_nodes[index].data; return inserted_nodes[index].data;
} }
HeapNode& getHeapNode(NodeID node) HeapNode &getHeapNode(NodeID node)
{ {
const auto index = node_index.peek_index(node); const auto index = node_index.peek_index(node);
BOOST_ASSERT((int)index >= 0 && (int)index < (int)inserted_nodes.size()); BOOST_ASSERT((int)index >= 0 && (int)index < (int)inserted_nodes.size());
@ -294,28 +293,28 @@ class QueryHeap
return inserted_nodes[index].node == node; return inserted_nodes[index].node == node;
} }
boost::optional<HeapNode&> GetHeapNodeIfWasInserted(const NodeID node) boost::optional<HeapNode &> GetHeapNodeIfWasInserted(const NodeID node)
{ {
const auto index = node_index.peek_index(node); const auto index = node_index.peek_index(node);
if (index >= static_cast<decltype(index)>(inserted_nodes.size()) || inserted_nodes[index].node!=node) if (index >= static_cast<decltype(index)>(inserted_nodes.size()) ||
inserted_nodes[index].node != node)
{ {
return {}; return {};
} }
return inserted_nodes[index]; return inserted_nodes[index];
} }
boost::optional<const HeapNode&> GetHeapNodeIfWasInserted(const NodeID node) const boost::optional<const HeapNode &> GetHeapNodeIfWasInserted(const NodeID node) const
{ {
const auto index = node_index.peek_index(node); const auto index = node_index.peek_index(node);
if (index >= static_cast<decltype(index)>(inserted_nodes.size()) || inserted_nodes[index].node!=node) if (index >= static_cast<decltype(index)>(inserted_nodes.size()) ||
inserted_nodes[index].node != node)
{ {
return {}; return {};
} }
return inserted_nodes[index]; return inserted_nodes[index];
} }
NodeID Min() const NodeID Min() const
{ {
BOOST_ASSERT(!heap.empty()); BOOST_ASSERT(!heap.empty());
@ -337,7 +336,7 @@ class QueryHeap
return inserted_nodes[removedIndex].node; return inserted_nodes[removedIndex].node;
} }
HeapNode& DeleteMinGetHeapNode() HeapNode &DeleteMinGetHeapNode()
{ {
BOOST_ASSERT(!heap.empty()); BOOST_ASSERT(!heap.empty());
const Key removedIndex = heap.top().second; const Key removedIndex = heap.top().second;
@ -364,7 +363,7 @@ class QueryHeap
heap.increase(reference.handle, std::make_pair(weight, index)); heap.increase(reference.handle, std::make_pair(weight, index));
} }
void DecreaseKey(const HeapNode& heapNode) void DecreaseKey(const HeapNode &heapNode)
{ {
BOOST_ASSERT(!WasRemoved(heapNode.node)); BOOST_ASSERT(!WasRemoved(heapNode.node));
heap.increase(heapNode.handle, std::make_pair(heapNode.weight, (*heapNode.handle).second)); heap.increase(heapNode.handle, std::make_pair(heapNode.weight, (*heapNode.handle).second));
@ -375,7 +374,7 @@ class QueryHeap
HeapContainer heap; HeapContainer heap;
IndexStorage node_index; IndexStorage node_index;
}; };
} } // namespace util
} } // namespace osrm
#endif // OSRM_UTIL_QUERY_HEAP_HPP #endif // OSRM_UTIL_QUERY_HEAP_HPP

View File

@ -32,7 +32,7 @@ void relaxNode(ContractorHeap &heap,
} }
const EdgeWeight to_weight = node_weight + data.weight; const EdgeWeight to_weight = node_weight + data.weight;
const auto toHeapNode= heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = heap.GetHeapNodeIfWasInserted(to);
// New Node discovered -> Add to Heap + Node Info Storage // New Node discovered -> Add to Heap + Node Info Storage
if (!toHeapNode) if (!toHeapNode)
{ {
@ -41,13 +41,13 @@ void relaxNode(ContractorHeap &heap,
// Found a shorter Path -> Update weight // Found a shorter Path -> Update weight
else if (to_weight < toHeapNode->weight) else if (to_weight < toHeapNode->weight)
{ {
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
heap.DecreaseKey(*toHeapNode); heap.DecreaseKey(*toHeapNode);
toHeapNode->data.hop = current_hop; toHeapNode->data.hop = current_hop;
} }
} }
} }
} } // namespace
void search(ContractorHeap &heap, void search(ContractorHeap &heap,
const ContractorGraph &graph, const ContractorGraph &graph,
@ -85,5 +85,5 @@ void search(ContractorHeap &heap,
relaxNode(heap, graph, node, node_weight, forbidden_node); relaxNode(heap, graph, node, node_weight, forbidden_node);
} }
} }
} } // namespace contractor
} } // namespace osrm

View File

@ -62,8 +62,9 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
QueryHeap &forward_heap = DIRECTION == FORWARD_DIRECTION ? heap1 : heap2; QueryHeap &forward_heap = DIRECTION == FORWARD_DIRECTION ? heap1 : heap2;
QueryHeap &reverse_heap = DIRECTION == FORWARD_DIRECTION ? heap2 : heap1; QueryHeap &reverse_heap = DIRECTION == FORWARD_DIRECTION ? heap2 : heap1;
// Take a copy (no ref &) of the extracted node because otherwise could be modified later if toHeapNode is the same // Take a copy (no ref &) of the extracted node because otherwise could be modified later if
const auto heapNode=forward_heap.DeleteMinGetHeapNode(); // toHeapNode is the same
const auto heapNode = forward_heap.DeleteMinGetHeapNode();
const auto scaled_weight = const auto scaled_weight =
static_cast<EdgeWeight>((heapNode.weight + min_edge_offset) / (1. + VIAPATH_EPSILON)); static_cast<EdgeWeight>((heapNode.weight + min_edge_offset) / (1. + VIAPATH_EPSILON));
@ -76,7 +77,7 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
search_space.emplace_back(heapNode.data.parent, heapNode.node); search_space.emplace_back(heapNode.data.parent, heapNode.node);
const auto reverseHeapNode= reverse_heap.GetHeapNodeIfWasInserted(heapNode.node); const auto reverseHeapNode = reverse_heap.GetHeapNodeIfWasInserted(heapNode.node);
if (reverseHeapNode) if (reverseHeapNode)
{ {
search_space_intersection.emplace_back(heapNode.node); search_space_intersection.emplace_back(heapNode.node);
@ -114,7 +115,7 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
BOOST_ASSERT(edge_weight > 0); BOOST_ASSERT(edge_weight > 0);
const EdgeWeight to_weight = heapNode.weight + edge_weight; const EdgeWeight to_weight = heapNode.weight + edge_weight;
const auto toHeapNode= forward_heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
// New Node discovered -> Add to Heap + Node Info Storage // New Node discovered -> Add to Heap + Node Info Storage
if (!toHeapNode) if (!toHeapNode)
{ {
@ -126,7 +127,7 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
// new parent // new parent
toHeapNode->data.parent = heapNode.node; toHeapNode->data.parent = heapNode.node;
// decreased weight // decreased weight
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
forward_heap.DecreaseKey(*toHeapNode); forward_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -561,7 +562,7 @@ bool viaNodeCandidatePassesTTest(SearchEngineData<Algorithm> &engine_working_dat
} }
return (upper_bound <= t_test_path_weight); return (upper_bound <= t_test_path_weight);
} }
} // anon. namespace } // namespace
InternalManyRoutesResult alternativePathSearch(SearchEngineData<Algorithm> &engine_working_data, InternalManyRoutesResult alternativePathSearch(SearchEngineData<Algorithm> &engine_working_data,
const DataFacade<Algorithm> &facade, const DataFacade<Algorithm> &facade,
@ -856,4 +857,4 @@ InternalManyRoutesResult alternativePathSearch(SearchEngineData<Algorithm> &engi
} // namespace routing_algorithms } // namespace routing_algorithms
} // namespace engine } // namespace engine
} // namespace osrm} } // namespace osrm

View File

@ -45,8 +45,9 @@ inline bool addLoopWeight(const DataFacade<ch::Algorithm> &facade,
} }
template <bool DIRECTION> template <bool DIRECTION>
void relaxOutgoingEdges(const DataFacade<Algorithm> &facade, void relaxOutgoingEdges(
const typename SearchEngineData<Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode, const DataFacade<Algorithm> &facade,
const typename SearchEngineData<Algorithm>::ManyToManyQueryHeap::HeapNode &heapNode,
typename SearchEngineData<Algorithm>::ManyToManyQueryHeap &query_heap, typename SearchEngineData<Algorithm>::ManyToManyQueryHeap &query_heap,
const PhantomNode &) const PhantomNode &)
{ {
@ -71,7 +72,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
const auto to_duration = heapNode.data.duration + edge_duration; const auto to_duration = heapNode.data.duration + edge_duration;
const auto to_distance = heapNode.data.distance + edge_distance; const auto to_distance = heapNode.data.distance + edge_distance;
const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
// New Node discovered -> Add to Heap + Node Info Storage // New Node discovered -> Add to Heap + Node Info Storage
if (!toHeapNode) if (!toHeapNode)
{ {
@ -82,7 +83,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
std::tie(toHeapNode->weight, toHeapNode->data.duration)) std::tie(toHeapNode->weight, toHeapNode->data.duration))
{ {
toHeapNode->data = {heapNode.node, to_duration, to_distance}; toHeapNode->data = {heapNode.node, to_duration, to_distance};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
query_heap.DecreaseKey(*toHeapNode); query_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -100,8 +101,9 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
std::vector<NodeID> &middle_nodes_table, std::vector<NodeID> &middle_nodes_table,
const PhantomNode &phantom_node) const PhantomNode &phantom_node)
{ {
// Take a copy of the extracted node because otherwise could be modified later if toHeapNode is the same // Take a copy of the extracted node because otherwise could be modified later if toHeapNode is
const auto heapNode=query_heap.DeleteMinGetHeapNode(); // the same
const auto heapNode = query_heap.DeleteMinGetHeapNode();
// Check if each encountered node has an entry // Check if each encountered node has an entry
const auto &bucket_list = std::equal_range(search_space_with_buckets.begin(), const auto &bucket_list = std::equal_range(search_space_with_buckets.begin(),
@ -149,8 +151,7 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
} }
} }
relaxOutgoingEdges<FORWARD_DIRECTION>( relaxOutgoingEdges<FORWARD_DIRECTION>(facade, heapNode, query_heap, phantom_node);
facade, heapNode, query_heap, phantom_node);
} }
void backwardRoutingStep(const DataFacade<Algorithm> &facade, void backwardRoutingStep(const DataFacade<Algorithm> &facade,
@ -159,15 +160,19 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
std::vector<NodeBucket> &search_space_with_buckets, std::vector<NodeBucket> &search_space_with_buckets,
const PhantomNode &phantom_node) const PhantomNode &phantom_node)
{ {
// Take a copy (no ref &) of the extracted node because otherwise could be modified later if toHeapNode is the same // Take a copy (no ref &) of the extracted node because otherwise could be modified later if
const auto heapNode=query_heap.DeleteMinGetHeapNode(); // toHeapNode is the same
const auto heapNode = query_heap.DeleteMinGetHeapNode();
// Store settled nodes in search space bucket // Store settled nodes in search space bucket
search_space_with_buckets.emplace_back( search_space_with_buckets.emplace_back(heapNode.node,
heapNode.node, heapNode.data.parent, column_index, heapNode.weight, heapNode.data.duration, heapNode.data.distance); heapNode.data.parent,
column_index,
heapNode.weight,
heapNode.data.duration,
heapNode.data.distance);
relaxOutgoingEdges<REVERSE_DIRECTION>( relaxOutgoingEdges<REVERSE_DIRECTION>(facade, heapNode, query_heap, phantom_node);
facade, heapNode, query_heap, phantom_node);
} }
} // namespace ch } // namespace ch

View File

@ -71,7 +71,7 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
const auto to_distance = distance + node_distance; const auto to_distance = distance + node_distance;
// New Node discovered -> Add to Heap + Node Info Storage // New Node discovered -> Add to Heap + Node Info Storage
const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
if (!toHeapNode) if (!toHeapNode)
{ {
query_heap.Insert(to, to_weight, {node, false, to_duration, to_distance}); query_heap.Insert(to, to_weight, {node, false, to_duration, to_distance});
@ -84,7 +84,7 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
toHeapNode->data.parent)) toHeapNode->data.parent))
{ {
toHeapNode->data = {node, false, to_duration, to_distance}; toHeapNode->data = {node, false, to_duration, to_distance};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
query_heap.DecreaseKey(*toHeapNode); query_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -92,8 +92,9 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
} }
template <bool DIRECTION, typename... Args> template <bool DIRECTION, typename... Args>
void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade, void relaxOutgoingEdges(
const typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode, const DataFacade<mld::Algorithm> &facade,
const typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap::HeapNode &heapNode,
typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap &query_heap, typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap &query_heap,
Args... args) Args... args)
{ {
@ -110,7 +111,6 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
const auto &cells = facade.GetCellStorage(); const auto &cells = facade.GetCellStorage();
const auto &metric = facade.GetCellMetric(); const auto &metric = facade.GetCellMetric();
if (level >= 1 && !heapNode.data.from_clique_arc) if (level >= 1 && !heapNode.data.from_clique_arc)
{ {
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, heapNode.node)); const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, heapNode.node));
@ -131,10 +131,11 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
const auto to_weight = heapNode.weight + shortcut_weight; const auto to_weight = heapNode.weight + shortcut_weight;
const auto to_duration = heapNode.data.duration + shortcut_durations.front(); const auto to_duration = heapNode.data.duration + shortcut_durations.front();
const auto to_distance = heapNode.data.distance + shortcut_distances.front(); const auto to_distance = heapNode.data.distance + shortcut_distances.front();
const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
if (!toHeapNode) if (!toHeapNode)
{ {
query_heap.Insert(to, to_weight, {heapNode.node, true, to_duration, to_distance}); query_heap.Insert(
to, to_weight, {heapNode.node, true, to_duration, to_distance});
} }
else if (std::tie(to_weight, to_duration, to_distance, heapNode.node) < else if (std::tie(to_weight, to_duration, to_distance, heapNode.node) <
std::tie(toHeapNode->weight, std::tie(toHeapNode->weight,
@ -143,7 +144,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
toHeapNode->data.parent)) toHeapNode->data.parent))
{ {
toHeapNode->data = {heapNode.node, true, to_duration, to_distance}; toHeapNode->data = {heapNode.node, true, to_duration, to_distance};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
query_heap.DecreaseKey(*toHeapNode); query_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -171,10 +172,11 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
const auto to_weight = heapNode.weight + shortcut_weight; const auto to_weight = heapNode.weight + shortcut_weight;
const auto to_duration = heapNode.data.duration + shortcut_durations.front(); const auto to_duration = heapNode.data.duration + shortcut_durations.front();
const auto to_distance = heapNode.data.distance + shortcut_distances.front(); const auto to_distance = heapNode.data.distance + shortcut_distances.front();
const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted(to); const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
if (!toHeapNode) if (!toHeapNode)
{ {
query_heap.Insert(to, to_weight, {heapNode.node, true, to_duration, to_distance}); query_heap.Insert(
to, to_weight, {heapNode.node, true, to_duration, to_distance});
} }
else if (std::tie(to_weight, to_duration, to_distance, heapNode.node) < else if (std::tie(to_weight, to_duration, to_distance, heapNode.node) <
std::tie(toHeapNode->weight, std::tie(toHeapNode->weight,
@ -183,7 +185,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
toHeapNode->data.parent)) toHeapNode->data.parent))
{ {
toHeapNode->data = {heapNode.node, true, to_duration, to_distance}; toHeapNode->data = {heapNode.node, true, to_duration, to_distance};
toHeapNode->weight=to_weight; toHeapNode->weight = to_weight;
query_heap.DecreaseKey(*toHeapNode); query_heap.DecreaseKey(*toHeapNode);
} }
} }
@ -196,7 +198,13 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
} }
} }
relaxBorderEdges<DIRECTION>(facade, heapNode.node, heapNode.weight, heapNode.data.duration, heapNode.data.distance, query_heap, level); relaxBorderEdges<DIRECTION>(facade,
heapNode.node,
heapNode.weight,
heapNode.data.duration,
heapNode.data.distance,
query_heap,
level);
} }
// //
@ -373,18 +381,15 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
{ {
// Extract node from the heap. Take a copy (no ref) because otherwise can be modified later // Extract node from the heap. Take a copy (no ref) because otherwise can be modified later
// if toHeapNode is the same // if toHeapNode is the same
const auto heapNode=query_heap.DeleteMinGetHeapNode(); const auto heapNode = query_heap.DeleteMinGetHeapNode();
// Update values // Update values
update_values(heapNode.node, heapNode.weight, heapNode.data.duration, heapNode.data.distance); update_values(
heapNode.node, heapNode.weight, heapNode.data.duration, heapNode.data.distance);
// Relax outgoing edges // Relax outgoing edges
relaxOutgoingEdges<DIRECTION>(facade, relaxOutgoingEdges<DIRECTION>(
heapNode, facade, heapNode, query_heap, phantom_nodes, phantom_index, phantom_indices);
query_heap,
phantom_nodes,
phantom_index,
phantom_indices);
} }
return std::make_pair(durations, distances_table); return std::make_pair(durations, distances_table);
@ -406,8 +411,9 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
std::vector<NodeID> &middle_nodes_table, std::vector<NodeID> &middle_nodes_table,
const PhantomNode &phantom_node) const PhantomNode &phantom_node)
{ {
// Take a copy of the extracted node because otherwise could be modified later if toHeapNode is the same // Take a copy of the extracted node because otherwise could be modified later if toHeapNode is
const auto heapNode=query_heap.DeleteMinGetHeapNode(); // the same
const auto heapNode = query_heap.DeleteMinGetHeapNode();
// Check if each encountered node has an entry // Check if each encountered node has an entry
const auto &bucket_list = std::equal_range(search_space_with_buckets.begin(), const auto &bucket_list = std::equal_range(search_space_with_buckets.begin(),
@ -439,8 +445,7 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
auto new_duration = heapNode.data.duration + target_duration; auto new_duration = heapNode.data.duration + target_duration;
auto new_distance = heapNode.data.distance + target_distance; auto new_distance = heapNode.data.distance + target_distance;
if (new_weight >= 0 && if (new_weight >= 0 && std::tie(new_weight, new_duration, new_distance) <
std::tie(new_weight, new_duration, new_distance) <
std::tie(current_weight, current_duration, current_distance)) std::tie(current_weight, current_duration, current_distance))
{ {
current_weight = new_weight; current_weight = new_weight;
@ -450,8 +455,7 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
} }
} }
relaxOutgoingEdges<DIRECTION>( relaxOutgoingEdges<DIRECTION>(facade, heapNode, query_heap, phantom_node);
facade, heapNode, query_heap, phantom_node);
} }
template <bool DIRECTION> template <bool DIRECTION>
@ -461,21 +465,23 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
std::vector<NodeBucket> &search_space_with_buckets, std::vector<NodeBucket> &search_space_with_buckets,
const PhantomNode &phantom_node) const PhantomNode &phantom_node)
{ {
// Take a copy of the extracted node because otherwise could be modified later if toHeapNode is the same // Take a copy of the extracted node because otherwise could be modified later if toHeapNode is
const auto heapNode=query_heap.DeleteMinGetHeapNode(); // the same
const auto heapNode = query_heap.DeleteMinGetHeapNode();
// Store settled nodes in search space bucket // Store settled nodes in search space bucket
search_space_with_buckets.emplace_back( search_space_with_buckets.emplace_back(heapNode.node,
heapNode.node, heapNode.data.parent, heapNode.data.from_clique_arc, column_idx, heapNode.weight, heapNode.data.duration, heapNode.data.distance); heapNode.data.parent,
heapNode.data.from_clique_arc,
column_idx,
heapNode.weight,
heapNode.data.duration,
heapNode.data.distance);
const auto &partition = facade.GetMultiLevelPartition(); const auto &partition = facade.GetMultiLevelPartition();
const auto maximal_level = partition.GetNumberOfLevels() - 1; const auto maximal_level = partition.GetNumberOfLevels() - 1;
relaxOutgoingEdges<!DIRECTION>(facade, relaxOutgoingEdges<!DIRECTION>(facade, heapNode, query_heap, phantom_node, maximal_level);
heapNode,
query_heap,
phantom_node,
maximal_level);
} }
template <bool DIRECTION> template <bool DIRECTION>