diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index 352f42d40..7ac0530d8 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -27,7 +27,7 @@ bool stallAtNode(const DataFacade &facade, const NodeID to = facade.GetTarget(edge); const EdgeWeight edge_weight = data.weight; 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->weight + edge_weight < heapNode.weight) @@ -56,7 +56,7 @@ void relaxOutgoingEdges(const DataFacade &facade, BOOST_ASSERT_MSG(edge_weight > EdgeWeight{0}, "edge_weight invalid"); 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 if (!toHeapNode) { @@ -67,7 +67,7 @@ void relaxOutgoingEdges(const DataFacade &facade, { // new parent toHeapNode->data.parent = heapNode.node; - toHeapNode.value().weight = to_weight; + toHeapNode->weight = to_weight; heap.DecreaseKey(*toHeapNode); } } diff --git a/include/engine/routing_algorithms/routing_base_mld.hpp b/include/engine/routing_algorithms/routing_base_mld.hpp index 42cb3eab2..39e93c5df 100644 --- a/include/engine/routing_algorithms/routing_base_mld.hpp +++ b/include/engine/routing_algorithms/routing_base_mld.hpp @@ -291,7 +291,7 @@ void relaxOutgoingEdges(const DataFacade &facade, { const EdgeWeight to_weight = heapNode.weight + shortcut_weight; BOOST_ASSERT(to_weight >= heapNode.weight); - auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); + const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); if (!toHeapNode) { forward_heap.Insert(to, to_weight, {heapNode.node, true}); @@ -300,7 +300,7 @@ void relaxOutgoingEdges(const DataFacade &facade, { toHeapNode->data = {heapNode.node, true}; toHeapNode->weight = to_weight; - forward_heap.DecreaseKey(heapNode); + forward_heap.DecreaseKey(*toHeapNode); } } ++destination; @@ -321,7 +321,7 @@ void relaxOutgoingEdges(const DataFacade &facade, { const EdgeWeight to_weight = heapNode.weight + shortcut_weight; BOOST_ASSERT(to_weight >= heapNode.weight); - auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); + const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); if (!toHeapNode) { forward_heap.Insert(to, to_weight, {heapNode.node, true}); @@ -360,16 +360,16 @@ void relaxOutgoingEdges(const DataFacade &facade, const EdgeWeight to_weight = heapNode.weight + node_weight + alias_cast(turn_penalty); - auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); + const auto toHeapNode = forward_heap.GetHeapNodeIfWasInserted(to); if (!toHeapNode) { 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.value().weight = to_weight; - forward_heap.DecreaseKey(toHeapNode.value()); + toHeapNode->data = {heapNode.node, false}; + toHeapNode->weight = to_weight; + forward_heap.DecreaseKey(*toHeapNode); } } } diff --git a/include/util/query_heap.hpp b/include/util/query_heap.hpp index a0d2c723f..b26991ba0 100644 --- a/include/util/query_heap.hpp +++ b/include/util/query_heap.hpp @@ -289,26 +289,26 @@ class QueryHeap return inserted_nodes[index].node == node; } - std::optional GetHeapNodeIfWasInserted(NodeID node) + HeapNode *GetHeapNodeIfWasInserted(const NodeID node) { const auto index = node_index.peek_index(node); if (index >= static_cast(inserted_nodes.size()) || inserted_nodes[index].node != node) { - return {}; + return nullptr; } - return inserted_nodes[index]; + return &inserted_nodes[index]; } - std::optional GetHeapNodeIfWasInserted(const NodeID node) const + const HeapNode *GetHeapNodeIfWasInserted(const NodeID node) const { const auto index = node_index.peek_index(node); if (index >= static_cast(inserted_nodes.size()) || inserted_nodes[index].node != node) { - return {}; + return 0; } - return inserted_nodes[index]; + return &inserted_nodes[index]; } NodeID Min() const diff --git a/src/contractor/contractor_search.cpp b/src/contractor/contractor_search.cpp index 524f3fe27..6fa860f46 100644 --- a/src/contractor/contractor_search.cpp +++ b/src/contractor/contractor_search.cpp @@ -30,7 +30,7 @@ void relaxNode(ContractorHeap &heap, } 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 if (!toHeapNode) { diff --git a/src/engine/routing_algorithms/alternative_path_ch.cpp b/src/engine/routing_algorithms/alternative_path_ch.cpp index 81e034561..10ccfe28c 100644 --- a/src/engine/routing_algorithms/alternative_path_ch.cpp +++ b/src/engine/routing_algorithms/alternative_path_ch.cpp @@ -112,19 +112,19 @@ void alternativeRoutingStep(const DataFacade &facade, BOOST_ASSERT(edge_weight > EdgeWeight{0}); 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 if (!toHeapNode) { forward_heap.Insert(to, to_weight, heapNode.node); } // Found a shorter Path -> Update weight - else if (to_weight < toHeapNode.value().weight) + else if (to_weight < toHeapNode->weight) { // new parent - toHeapNode.value().data.parent = heapNode.node; + toHeapNode->data.parent = heapNode.node; // decreased weight - toHeapNode.value().weight = to_weight; + toHeapNode->weight = to_weight; forward_heap.DecreaseKey(*toHeapNode); } } diff --git a/src/engine/routing_algorithms/many_to_many_ch.cpp b/src/engine/routing_algorithms/many_to_many_ch.cpp index 6f24b8474..d021a52e7 100644 --- a/src/engine/routing_algorithms/many_to_many_ch.cpp +++ b/src/engine/routing_algorithms/many_to_many_ch.cpp @@ -68,7 +68,7 @@ void relaxOutgoingEdges( const auto to_duration = heapNode.data.duration + to_alias(edge_duration); 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 if (!toHeapNode) { @@ -76,10 +76,10 @@ void relaxOutgoingEdges( } // Found a shorter Path -> Update weight and set new parent 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.value().weight = to_weight; + toHeapNode->data = {heapNode.node, to_duration, to_distance}; + toHeapNode->weight = to_weight; query_heap.DecreaseKey(*toHeapNode); } } @@ -158,7 +158,7 @@ void backwardRoutingStep(const DataFacade &facade, { // Take a copy (no ref &) of the extracted node because otherwise could be modified later if // toHeapNode is the same - auto heapNode = query_heap.DeleteMinGetHeapNode(); + const auto heapNode = query_heap.DeleteMinGetHeapNode(); // Store settled nodes in search space bucket search_space_with_buckets.emplace_back(heapNode.node, diff --git a/src/engine/routing_algorithms/many_to_many_mld.cpp b/src/engine/routing_algorithms/many_to_many_mld.cpp index 74dd41190..500b7d2f4 100644 --- a/src/engine/routing_algorithms/many_to_many_mld.cpp +++ b/src/engine/routing_algorithms/many_to_many_mld.cpp @@ -70,20 +70,20 @@ void relaxBorderEdges(const DataFacade &facade, const auto to_distance = distance + node_distance; // New Node discovered -> Add to Heap + Node Info Storage - auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to); + const auto toHeapNode = query_heap.GetHeapNodeIfWasInserted(to); if (!toHeapNode) { query_heap.Insert(to, to_weight, {node, false, to_duration, to_distance}); } // Found a shorter Path -> Update weight and set new parent else if (std::tie(to_weight, to_duration, to_distance, node) < - std::tie(toHeapNode.value().weight, - toHeapNode.value().data.duration, - toHeapNode.value().data.distance, - toHeapNode.value().data.parent)) + std::tie(toHeapNode->weight, + toHeapNode->data.duration, + toHeapNode->data.distance, + toHeapNode->data.parent)) { - toHeapNode.value().data = {node, false, to_duration, to_distance}; - toHeapNode.value().weight = to_weight; + toHeapNode->data = {node, false, to_duration, to_distance}; + toHeapNode->weight = to_weight; query_heap.DecreaseKey(*toHeapNode); } } @@ -130,20 +130,20 @@ void relaxOutgoingEdges( const auto to_weight = heapNode.weight + shortcut_weight; const auto to_duration = heapNode.data.duration + shortcut_durations.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) { 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) < - std::tie(toHeapNode.value().weight, - toHeapNode.value().data.duration, - toHeapNode.value().data.distance, - toHeapNode.value().data.parent)) + std::tie(toHeapNode->weight, + toHeapNode->data.duration, + toHeapNode->data.distance, + toHeapNode->data.parent)) { - toHeapNode.value().data = {heapNode.node, true, to_duration, to_distance}; - toHeapNode.value().weight = to_weight; + toHeapNode->data = {heapNode.node, true, to_duration, to_distance}; + toHeapNode->weight = to_weight; query_heap.DecreaseKey(*toHeapNode); } } @@ -171,20 +171,20 @@ void relaxOutgoingEdges( const auto to_weight = heapNode.weight + shortcut_weight; const auto to_duration = heapNode.data.duration + shortcut_durations.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) { 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) < - std::tie(toHeapNode.value().weight, - toHeapNode.value().data.duration, - toHeapNode.value().data.distance, - toHeapNode.value().data.parent)) + std::tie(toHeapNode->weight, + toHeapNode->data.duration, + toHeapNode->data.distance, + toHeapNode->data.parent)) { - toHeapNode.value().data = {heapNode.node, true, to_duration, to_distance}; - toHeapNode.value().weight = to_weight; + toHeapNode->data = {heapNode.node, true, to_duration, to_distance}; + toHeapNode->weight = to_weight; query_heap.DecreaseKey(*toHeapNode); } }