@@ -71,7 +71,7 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
71
71
const auto to_distance = distance + node_distance;
72
72
73
73
// 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);
75
75
if (!toHeapNode)
76
76
{
77
77
query_heap.Insert (to, to_weight, {node, false , to_duration, to_distance});
@@ -93,11 +93,11 @@ void relaxBorderEdges(const DataFacade<mld::Algorithm> &facade,
93
93
94
94
template <bool DIRECTION, typename ... Args>
95
95
void relaxOutgoingEdges (const DataFacade<mld::Algorithm> &facade,
96
- const SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode,
96
+ const typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode,
97
97
typename SearchEngineData<mld::Algorithm>::ManyToManyQueryHeap &query_heap,
98
98
Args... args)
99
99
{
100
- BOOST_ASSERT (!facade.ExcludeNode (heapNode. node ));
100
+ BOOST_ASSERT (!facade.ExcludeNode (node));
101
101
102
102
const auto &partition = facade.GetMultiLevelPartition ();
103
103
@@ -109,40 +109,40 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
109
109
110
110
const auto &cells = facade.GetCellStorage ();
111
111
const auto &metric = facade.GetCellMetric ();
112
- const auto node=heapNode. node ;
112
+
113
113
114
114
if (level >= 1 && !heapNode.data .from_clique_arc )
115
115
{
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 ));
117
117
if (DIRECTION == FORWARD_DIRECTION)
118
118
{ // Shortcuts in forward direction
119
119
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 ))
123
123
{
124
124
BOOST_ASSERT (destination != cell.GetDestinationNodes ().end ());
125
125
BOOST_ASSERT (!shortcut_durations.empty ());
126
126
BOOST_ASSERT (!shortcut_distances.empty ());
127
127
const NodeID to = *destination;
128
128
129
- if (shortcut_weight != INVALID_EDGE_WEIGHT && node != to)
129
+ if (shortcut_weight != INVALID_EDGE_WEIGHT && heapNode. node != to)
130
130
{
131
131
const auto to_weight = heapNode.weight + shortcut_weight;
132
132
const auto to_duration = heapNode.data .duration + shortcut_durations.front ();
133
133
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);
135
135
if (!toHeapNode)
136
136
{
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});
138
138
}
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 ) <
140
140
std::tie (toHeapNode->weight ,
141
141
toHeapNode->data .duration ,
142
142
toHeapNode->data .distance ,
143
143
toHeapNode->data .parent ))
144
144
{
145
- toHeapNode->data = {node, true , to_duration, to_distance};
145
+ toHeapNode->data = {heapNode. node , true , to_duration, to_distance};
146
146
toHeapNode->weight =to_weight;
147
147
query_heap.DecreaseKey (*toHeapNode);
148
148
}
@@ -157,32 +157,32 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
157
157
else
158
158
{ // Shortcuts in backward direction
159
159
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 ))
163
163
{
164
164
BOOST_ASSERT (source != cell.GetSourceNodes ().end ());
165
165
BOOST_ASSERT (!shortcut_durations.empty ());
166
166
BOOST_ASSERT (!shortcut_distances.empty ());
167
167
const NodeID to = *source;
168
168
169
- if (shortcut_weight != INVALID_EDGE_WEIGHT && node != to)
169
+ if (shortcut_weight != INVALID_EDGE_WEIGHT && heapNode. node != to)
170
170
{
171
171
const auto to_weight = heapNode.weight + shortcut_weight;
172
172
const auto to_duration = heapNode.data .duration + shortcut_durations.front ();
173
173
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);
175
175
if (!toHeapNode)
176
176
{
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});
178
178
}
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 ) <
180
180
std::tie (toHeapNode->weight ,
181
181
toHeapNode->data .duration ,
182
182
toHeapNode->data .distance ,
183
183
toHeapNode->data .parent ))
184
184
{
185
- toHeapNode->data = {node, true , to_duration, to_distance};
185
+ toHeapNode->data = {heapNode. node , true , to_duration, to_distance};
186
186
toHeapNode->weight =to_weight;
187
187
query_heap.DecreaseKey (*toHeapNode);
188
188
}
@@ -196,7 +196,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
196
196
}
197
197
}
198
198
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);
200
200
}
201
201
202
202
//
@@ -371,14 +371,12 @@ oneToManySearch(SearchEngineData<Algorithm> &engine_working_data,
371
371
372
372
while (!query_heap.Empty () && !target_nodes_index.empty ())
373
373
{
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 ();
379
377
380
378
// Update values
381
- update_values (heapNode.node , weight, duration, distance);
379
+ update_values (heapNode.node , heapNode. weight , heapNode. data . duration , heapNode. data . distance );
382
380
383
381
// Relax outgoing edges
384
382
relaxOutgoingEdges<DIRECTION>(facade,
@@ -408,10 +406,8 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
408
406
std::vector<NodeID> &middle_nodes_table,
409
407
const PhantomNode &phantom_node)
410
408
{
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 ();
415
411
416
412
// Check if each encountered node has an entry
417
413
const auto &bucket_list = std::equal_range (search_space_with_buckets.begin (),
@@ -439,9 +435,9 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
439
435
auto ¤t_distance = distances_table.empty () ? nulldistance : distances_table[location];
440
436
441
437
// 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;
445
441
446
442
if (new_weight >= 0 &&
447
443
std::tie (new_weight, new_duration, new_distance) <
@@ -465,16 +461,12 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
465
461
std::vector<NodeBucket> &search_space_with_buckets,
466
462
const PhantomNode &phantom_node)
467
463
{
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 ();
474
466
475
467
// Store settled nodes in search space bucket
476
468
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 );
478
470
479
471
const auto &partition = facade.GetMultiLevelPartition ();
480
472
const auto maximal_level = partition.GetNumberOfLevels () - 1 ;
0 commit comments