Switched to not using std::optional for query_heap.hpp
This commit is contained in:
parent
f98d73cc06
commit
fb0400f4b1
@ -27,7 +27,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 > EdgeWeight{0}, "edge_weight invalid");
|
BOOST_ASSERT_MSG(edge_weight > EdgeWeight{0}, "edge_weight invalid");
|
||||||
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)
|
||||||
@ -56,7 +56,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
BOOST_ASSERT_MSG(edge_weight > EdgeWeight{0}, "edge_weight invalid");
|
BOOST_ASSERT_MSG(edge_weight > EdgeWeight{0}, "edge_weight invalid");
|
||||||
const EdgeWeight to_weight = heapNode.weight + edge_weight;
|
const EdgeWeight to_weight = heapNode.weight + edge_weight;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -67,7 +67,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
{
|
{
|
||||||
// new parent
|
// new parent
|
||||||
toHeapNode->data.parent = heapNode.node;
|
toHeapNode->data.parent = heapNode.node;
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
heap.DecreaseKey(*toHeapNode);
|
heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -291,7 +291,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
{
|
{
|
||||||
const EdgeWeight to_weight = heapNode.weight + shortcut_weight;
|
const EdgeWeight to_weight = heapNode.weight + shortcut_weight;
|
||||||
BOOST_ASSERT(to_weight >= heapNode.weight);
|
BOOST_ASSERT(to_weight >= heapNode.weight);
|
||||||
auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
|
const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
|
||||||
if (!toHeapNode)
|
if (!toHeapNode)
|
||||||
{
|
{
|
||||||
forward_heap.Insert(to, to_weight, {heapNode.node, true});
|
forward_heap.Insert(to, to_weight, {heapNode.node, true});
|
||||||
@ -300,7 +300,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
{
|
{
|
||||||
toHeapNode->data = {heapNode.node, true};
|
toHeapNode->data = {heapNode.node, true};
|
||||||
toHeapNode->weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
forward_heap.DecreaseKey(heapNode);
|
forward_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++destination;
|
++destination;
|
||||||
@ -321,7 +321,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
{
|
{
|
||||||
const EdgeWeight to_weight = heapNode.weight + shortcut_weight;
|
const EdgeWeight to_weight = heapNode.weight + shortcut_weight;
|
||||||
BOOST_ASSERT(to_weight >= heapNode.weight);
|
BOOST_ASSERT(to_weight >= heapNode.weight);
|
||||||
auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
|
const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
|
||||||
if (!toHeapNode)
|
if (!toHeapNode)
|
||||||
{
|
{
|
||||||
forward_heap.Insert(to, to_weight, {heapNode.node, true});
|
forward_heap.Insert(to, to_weight, {heapNode.node, true});
|
||||||
@ -360,16 +360,16 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
|||||||
const EdgeWeight to_weight =
|
const EdgeWeight to_weight =
|
||||||
heapNode.weight + node_weight + alias_cast<EdgeWeight>(turn_penalty);
|
heapNode.weight + node_weight + alias_cast<EdgeWeight>(turn_penalty);
|
||||||
|
|
||||||
auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
|
const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to);
|
||||||
if (!toHeapNode)
|
if (!toHeapNode)
|
||||||
{
|
{
|
||||||
forward_heap.Insert(to, to_weight, {heapNode.node, false});
|
forward_heap.Insert(to, to_weight, {heapNode.node, false});
|
||||||
}
|
}
|
||||||
else if (to_weight < toHeapNode.value().weight)
|
else if (to_weight < toHeapNode->weight)
|
||||||
{
|
{
|
||||||
toHeapNode.value().data = {heapNode.node, false};
|
toHeapNode->data = {heapNode.node, false};
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
forward_heap.DecreaseKey(toHeapNode.value());
|
forward_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -289,26 +289,26 @@ class QueryHeap
|
|||||||
return inserted_nodes[index].node == node;
|
return inserted_nodes[index].node == node;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<HeapNode> GetHeapNodeIfWasInserted(NodeID node)
|
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()) ||
|
if (index >= static_cast<decltype(index)>(inserted_nodes.size()) ||
|
||||||
inserted_nodes[index].node != node)
|
inserted_nodes[index].node != node)
|
||||||
{
|
{
|
||||||
return {};
|
return nullptr;
|
||||||
}
|
}
|
||||||
return inserted_nodes[index];
|
return &inserted_nodes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<HeapNode> GetHeapNodeIfWasInserted(const NodeID node) const
|
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()) ||
|
if (index >= static_cast<decltype(index)>(inserted_nodes.size()) ||
|
||||||
inserted_nodes[index].node != node)
|
inserted_nodes[index].node != node)
|
||||||
{
|
{
|
||||||
return {};
|
return 0;
|
||||||
}
|
}
|
||||||
return inserted_nodes[index];
|
return &inserted_nodes[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeID Min() const
|
NodeID Min() const
|
||||||
|
|||||||
@ -30,7 +30,7 @@ void relaxNode(ContractorHeap &heap,
|
|||||||
}
|
}
|
||||||
const EdgeWeight to_weight = node_weight + data.weight;
|
const EdgeWeight to_weight = node_weight + data.weight;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -112,19 +112,19 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
|
|||||||
BOOST_ASSERT(edge_weight > EdgeWeight{0});
|
BOOST_ASSERT(edge_weight > EdgeWeight{0});
|
||||||
const EdgeWeight to_weight = heapNode.weight + edge_weight;
|
const EdgeWeight to_weight = heapNode.weight + edge_weight;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
forward_heap.Insert(to, to_weight, heapNode.node);
|
forward_heap.Insert(to, to_weight, heapNode.node);
|
||||||
}
|
}
|
||||||
// Found a shorter Path -> Update weight
|
// Found a shorter Path -> Update weight
|
||||||
else if (to_weight < toHeapNode.value().weight)
|
else if (to_weight < toHeapNode->weight)
|
||||||
{
|
{
|
||||||
// new parent
|
// new parent
|
||||||
toHeapNode.value().data.parent = heapNode.node;
|
toHeapNode->data.parent = heapNode.node;
|
||||||
// decreased weight
|
// decreased weight
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
forward_heap.DecreaseKey(*toHeapNode);
|
forward_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,7 @@ void relaxOutgoingEdges(
|
|||||||
const auto to_duration = heapNode.data.duration + to_alias<EdgeDuration>(edge_duration);
|
const auto to_duration = heapNode.data.duration + to_alias<EdgeDuration>(edge_duration);
|
||||||
const auto to_distance = heapNode.data.distance + edge_distance;
|
const auto to_distance = heapNode.data.distance + edge_distance;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -76,10 +76,10 @@ void relaxOutgoingEdges(
|
|||||||
}
|
}
|
||||||
// Found a shorter Path -> Update weight and set new parent
|
// Found a shorter Path -> Update weight and set new parent
|
||||||
else if (std::tie(to_weight, to_duration) <
|
else if (std::tie(to_weight, to_duration) <
|
||||||
std::tie(toHeapNode.value().weight, toHeapNode.value().data.duration))
|
std::tie(toHeapNode->weight, toHeapNode->data.duration))
|
||||||
{
|
{
|
||||||
toHeapNode.value().data = {heapNode.node, to_duration, to_distance};
|
toHeapNode->data = {heapNode.node, to_duration, to_distance};
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
query_heap.DecreaseKey(*toHeapNode);
|
query_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
|
|||||||
{
|
{
|
||||||
// Take a copy (no ref &) of the extracted node because otherwise could be modified later if
|
// Take a copy (no ref &) of the extracted node because otherwise could be modified later if
|
||||||
// toHeapNode is the same
|
// toHeapNode is the same
|
||||||
auto heapNode = query_heap.DeleteMinGetHeapNode();
|
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(heapNode.node,
|
search_space_with_buckets.emplace_back(heapNode.node,
|
||||||
|
|||||||
@ -70,20 +70,20 @@ 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
|
||||||
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});
|
||||||
}
|
}
|
||||||
// Found a shorter Path -> Update weight and set new parent
|
// Found a shorter Path -> Update weight and set new parent
|
||||||
else if (std::tie(to_weight, to_duration, to_distance, node) <
|
else if (std::tie(to_weight, to_duration, to_distance, node) <
|
||||||
std::tie(toHeapNode.value().weight,
|
std::tie(toHeapNode->weight,
|
||||||
toHeapNode.value().data.duration,
|
toHeapNode->data.duration,
|
||||||
toHeapNode.value().data.distance,
|
toHeapNode->data.distance,
|
||||||
toHeapNode.value().data.parent))
|
toHeapNode->data.parent))
|
||||||
{
|
{
|
||||||
toHeapNode.value().data = {node, false, to_duration, to_distance};
|
toHeapNode->data = {node, false, to_duration, to_distance};
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
query_heap.DecreaseKey(*toHeapNode);
|
query_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,20 +130,20 @@ void relaxOutgoingEdges(
|
|||||||
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();
|
||||||
auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
|
const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
|
||||||
if (!toHeapNode)
|
if (!toHeapNode)
|
||||||
{
|
{
|
||||||
query_heap.Insert(
|
query_heap.Insert(
|
||||||
to, to_weight, {heapNode.node, true, to_duration, to_distance});
|
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.value().weight,
|
std::tie(toHeapNode->weight,
|
||||||
toHeapNode.value().data.duration,
|
toHeapNode->data.duration,
|
||||||
toHeapNode.value().data.distance,
|
toHeapNode->data.distance,
|
||||||
toHeapNode.value().data.parent))
|
toHeapNode->data.parent))
|
||||||
{
|
{
|
||||||
toHeapNode.value().data = {heapNode.node, true, to_duration, to_distance};
|
toHeapNode->data = {heapNode.node, true, to_duration, to_distance};
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
query_heap.DecreaseKey(*toHeapNode);
|
query_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,20 +171,20 @@ void relaxOutgoingEdges(
|
|||||||
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();
|
||||||
auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
|
const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to);
|
||||||
if (!toHeapNode)
|
if (!toHeapNode)
|
||||||
{
|
{
|
||||||
query_heap.Insert(
|
query_heap.Insert(
|
||||||
to, to_weight, {heapNode.node, true, to_duration, to_distance});
|
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.value().weight,
|
std::tie(toHeapNode->weight,
|
||||||
toHeapNode.value().data.duration,
|
toHeapNode->data.duration,
|
||||||
toHeapNode.value().data.distance,
|
toHeapNode->data.distance,
|
||||||
toHeapNode.value().data.parent))
|
toHeapNode->data.parent))
|
||||||
{
|
{
|
||||||
toHeapNode.value().data = {heapNode.node, true, to_duration, to_distance};
|
toHeapNode->data = {heapNode.node, true, to_duration, to_distance};
|
||||||
toHeapNode.value().weight = to_weight;
|
toHeapNode->weight = to_weight;
|
||||||
query_heap.DecreaseKey(*toHeapNode);
|
query_heap.DecreaseKey(*toHeapNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user