@@ -71,7 +71,7 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
7171 const auto to_distance = distance + node_distance;
7272
7373 // New Node discovered -> Add to Heap + Node Info Storage
74- const auto & toHeapNode= query_heap.GetHeapNodeIfWasInserted (to);
74+ const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted (to);
7575 if (!toHeapNode)
7676 {
7777 query_heap.Insert (to, to_weight, {node, false , to_duration, to_distance});
@@ -93,11 +93,11 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
9393
9494template <bool DIRECTION, typename ... Args>
9595void relaxOutgoingEdges (const DataFacade<mld::Algorithm> &facade,
96- const SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode,
96+ const typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode,
9797 typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap &query_heap,
9898 Args... args)
9999{
100- BOOST_ASSERT (!facade.ExcludeNode (heapNode. node ));
100+ BOOST_ASSERT (!facade.ExcludeNode (node));
101101
102102 const auto &partition = facade.GetMultiLevelPartition ();
103103
@@ -109,40 +109,40 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
109109
110110 const auto &cells = facade.GetCellStorage ();
111111 const auto &metric = facade.GetCellMetric ();
112- const auto node=heapNode. node ;
112+
113113
114114 if (level >= 1 && !heapNode.data .from_clique_arc )
115115 {
116- const auto &cell = cells.GetCell (metric, level, partition.GetCell (level, node));
116+ const auto &cell = cells.GetCell (metric, level, partition.GetCell (level, heapNode. node ));
117117 if (DIRECTION == FORWARD_DIRECTION)
118118 { // Shortcuts in forward direction
119119 auto destination = cell.GetDestinationNodes ().begin ();
120- auto shortcut_durations = cell.GetOutDuration (node);
121- auto shortcut_distances = cell.GetOutDistance (node);
122- for (auto shortcut_weight : cell.GetOutWeight (node))
120+ auto shortcut_durations = cell.GetOutDuration (heapNode. node );
121+ auto shortcut_distances = cell.GetOutDistance (heapNode. node );
122+ for (auto shortcut_weight : cell.GetOutWeight (heapNode. node ))
123123 {
124124 BOOST_ASSERT (destination != cell.GetDestinationNodes ().end ());
125125 BOOST_ASSERT (!shortcut_durations.empty ());
126126 BOOST_ASSERT (!shortcut_distances.empty ());
127127 const NodeID to = *destination;
128128
129- if (shortcut_weight != INVALID_EDGE_WEIGHT && node != to)
129+ if (shortcut_weight != INVALID_EDGE_WEIGHT && heapNode. node != to)
130130 {
131131 const auto to_weight = heapNode.weight + shortcut_weight;
132132 const auto to_duration = heapNode.data .duration + shortcut_durations.front ();
133133 const auto to_distance = heapNode.data .distance + shortcut_distances.front ();
134- const auto & toHeapNode= query_heap.GetHeapNodeIfWasInserted (to);
134+ const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted (to);
135135 if (!toHeapNode)
136136 {
137- query_heap.Insert (to, to_weight, {node, true , to_duration, to_distance});
137+ query_heap.Insert (to, to_weight, {heapNode. node , true , to_duration, to_distance});
138138 }
139- else if (std::tie (to_weight, to_duration, to_distance, node) <
139+ else if (std::tie (to_weight, to_duration, to_distance, heapNode. node ) <
140140 std::tie (toHeapNode->weight ,
141141 toHeapNode->data .duration ,
142142 toHeapNode->data .distance ,
143143 toHeapNode->data .parent ))
144144 {
145- toHeapNode->data = {node, true , to_duration, to_distance};
145+ toHeapNode->data = {heapNode. node , true , to_duration, to_distance};
146146 toHeapNode->weight =to_weight;
147147 query_heap.DecreaseKey (*toHeapNode);
148148 }
@@ -157,32 +157,32 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
157157 else
158158 { // Shortcuts in backward direction
159159 auto source = cell.GetSourceNodes ().begin ();
160- auto shortcut_durations = cell.GetInDuration (node);
161- auto shortcut_distances = cell.GetInDistance (node);
162- for (auto shortcut_weight : cell.GetInWeight (node))
160+ auto shortcut_durations = cell.GetInDuration (heapNode. node );
161+ auto shortcut_distances = cell.GetInDistance (heapNode. node );
162+ for (auto shortcut_weight : cell.GetInWeight (heapNode. node ))
163163 {
164164 BOOST_ASSERT (source != cell.GetSourceNodes ().end ());
165165 BOOST_ASSERT (!shortcut_durations.empty ());
166166 BOOST_ASSERT (!shortcut_distances.empty ());
167167 const NodeID to = *source;
168168
169- if (shortcut_weight != INVALID_EDGE_WEIGHT && node != to)
169+ if (shortcut_weight != INVALID_EDGE_WEIGHT && heapNode. node != to)
170170 {
171171 const auto to_weight = heapNode.weight + shortcut_weight;
172172 const auto to_duration = heapNode.data .duration + shortcut_durations.front ();
173173 const auto to_distance = heapNode.data .distance + shortcut_distances.front ();
174- const auto & toHeapNode= query_heap.GetHeapNodeIfWasInserted (to);
174+ const auto toHeapNode= query_heap.GetHeapNodeIfWasInserted (to);
175175 if (!toHeapNode)
176176 {
177- query_heap.Insert (to, to_weight, {node, true , to_duration, to_distance});
177+ query_heap.Insert (to, to_weight, {heapNode. node , true , to_duration, to_distance});
178178 }
179- else if (std::tie (to_weight, to_duration, to_distance, node) <
179+ else if (std::tie (to_weight, to_duration, to_distance, heapNode. node ) <
180180 std::tie (toHeapNode->weight ,
181181 toHeapNode->data .duration ,
182182 toHeapNode->data .distance ,
183183 toHeapNode->data .parent ))
184184 {
185- toHeapNode->data = {node, true , to_duration, to_distance};
185+ toHeapNode->data = {heapNode. node , true , to_duration, to_distance};
186186 toHeapNode->weight =to_weight;
187187 query_heap.DecreaseKey (*toHeapNode);
188188 }
@@ -196,7 +196,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
196196 }
197197 }
198198
199- relaxBorderEdges<DIRECTION>(facade, node, heapNode.weight , heapNode.data .duration , heapNode.data .distance , query_heap, level);
199+ relaxBorderEdges<DIRECTION>(facade, heapNode. node , heapNode.weight , heapNode.data .duration , heapNode.data .distance , query_heap, level);
200200}
201201
202202//
@@ -371,14 +371,12 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
371371
372372 while (!query_heap.Empty () && !target_nodes_index.empty ())
373373 {
374- // Extract node from the heap
375- const auto & heapNode=query_heap.DeleteMinGetHeapNode ();
376- const auto weight = heapNode.weight ;
377- const auto duration = heapNode.data .duration ;
378- const auto distance = heapNode.data .distance ;
374+ // Extract node from the heap. Take a copy (no ref) because otherwise can be modified later
375+ // if toHeapNode is the same
376+ const auto heapNode=query_heap.DeleteMinGetHeapNode ();
379377
380378 // Update values
381- update_values (heapNode.node , weight, duration, distance);
379+ update_values (heapNode.node , heapNode. weight , heapNode. data . duration , heapNode. data . distance );
382380
383381 // Relax outgoing edges
384382 relaxOutgoingEdges<DIRECTION>(facade,
@@ -408,10 +406,8 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
408406 std::vector<NodeID> &middle_nodes_table,
409407 const PhantomNode &phantom_node)
410408{
411- const auto & heapNode=query_heap.DeleteMinGetHeapNode ();
412- const auto source_weight = heapNode.weight ;
413- const auto source_duration = heapNode.data .duration ;
414- const auto source_distance = heapNode.data .distance ;
409+ // Take a copy of the extracted node because otherwise could be modified later if toHeapNode is the same
410+ const auto heapNode=query_heap.DeleteMinGetHeapNode ();
415411
416412 // Check if each encountered node has an entry
417413 const auto &bucket_list = std::equal_range (search_space_with_buckets.begin (),
@@ -439,9 +435,9 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
439435 auto ¤t_distance = distances_table.empty () ? nulldistance : distances_table[location];
440436
441437 // Check if new weight is better
442- auto new_weight = source_weight + target_weight;
443- auto new_duration = source_duration + target_duration;
444- auto new_distance = source_distance + target_distance;
438+ auto new_weight = heapNode. weight + target_weight;
439+ auto new_duration = heapNode. data . duration + target_duration;
440+ auto new_distance = heapNode. data . distance + target_distance;
445441
446442 if (new_weight >= 0 &&
447443 std::tie (new_weight, new_duration, new_distance) <
@@ -465,16 +461,12 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
465461 std::vector<NodeBucket> &search_space_with_buckets,
466462 const PhantomNode &phantom_node)
467463{
468- const auto & heapNode=query_heap.DeleteMinGetHeapNode ();
469- const auto target_weight = heapNode.weight ;
470- const auto target_duration = heapNode.data .duration ;
471- const auto target_distance = heapNode.data .distance ;
472- const auto parent = heapNode.data .parent ;
473- const auto from_clique_arc = heapNode.data .from_clique_arc ;
464+ // Take a copy of the extracted node because otherwise could be modified later if toHeapNode is the same
465+ const auto heapNode=query_heap.DeleteMinGetHeapNode ();
474466
475467 // Store settled nodes in search space bucket
476468 search_space_with_buckets.emplace_back (
477- heapNode.node , parent, from_clique_arc, column_idx, target_weight, target_duration, target_distance );
469+ heapNode.node , heapNode. data . parent , heapNode. data . from_clique_arc , column_idx, heapNode. weight , heapNode. data . duration , heapNode. data . distance );
478470
479471 const auto &partition = facade.GetMultiLevelPartition ();
480472 const auto maximal_level = partition.GetNumberOfLevels () - 1 ;
0 commit comments