Skip to content

Commit 1306784

Browse files
committed
Changes made
1 parent a3f1c2a commit 1306784

File tree

7 files changed

+216
-145
lines changed

7 files changed

+216
-145
lines changed

include/engine/routing_algorithms/routing_base_ch.hpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ bool stallAtNode(const DataFacade<Algorithm> &facade,
3636
const NodeID to = facade.GetTarget(edge);
3737
const EdgeWeight edge_weight = data.weight;
3838
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
39-
if (query_heap.WasInserted(to))
39+
const auto& toHeapNode= query_heap.WasInsertedGetHeapNode(to);
40+
if (toHeapNode)
4041
{
41-
if (query_heap.GetKey(to) + edge_weight < weight)
42+
if (toHeapNode->weight + edge_weight < weight)
4243
{
4344
return true;
4445
}
@@ -65,17 +66,19 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
6566
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
6667
const EdgeWeight to_weight = weight + edge_weight;
6768

69+
auto toData= heap.WasInsertedGetHeapNode(to);
6870
// New Node discovered -> Add to Heap + Node Info Storage
69-
if (!heap.WasInserted(to))
71+
if (!toData)
7072
{
7173
heap.Insert(to, to_weight, node);
7274
}
7375
// Found a shorter Path -> Update weight
74-
else if (to_weight < heap.GetKey(to))
76+
else if (to_weight < toData->weight)
7577
{
7678
// new parent
77-
heap.GetData(to).parent = node;
78-
heap.DecreaseKey(to, to_weight);
79+
toData->data.parent = node;
80+
toData->weight=to_weight;
81+
heap.DecreaseKey(*toData);
7982
}
8083
}
8184
}
@@ -122,35 +125,36 @@ void routingStep(const DataFacade<Algorithm> &facade,
122125
const bool force_loop_forward,
123126
const bool force_loop_reverse)
124127
{
125-
const NodeID node = forward_heap.DeleteMin();
126-
const EdgeWeight weight = forward_heap.GetKey(node);
128+
auto nodeData = forward_heap.DeleteMinGetHeapNode();
129+
const EdgeWeight weight = nodeData.weight;
127130

128-
if (reverse_heap.WasInserted(node))
131+
auto reverseNodeData= reverse_heap.WasInsertedGetHeapNode(nodeData.node);
132+
if (reverseNodeData)
129133
{
130-
const EdgeWeight new_weight = reverse_heap.GetKey(node) + weight;
134+
const EdgeWeight new_weight = reverseNodeData->weight + weight;
131135
if (new_weight < upper_bound)
132136
{
133137
// if loops are forced, they are so at the source
134-
if ((force_loop_forward && forward_heap.GetData(node).parent == node) ||
135-
(force_loop_reverse && reverse_heap.GetData(node).parent == node) ||
138+
if ((force_loop_forward && nodeData.data.parent == nodeData.node) ||
139+
(force_loop_reverse && reverseNodeData->data.parent == nodeData.node) ||
136140
// in this case we are looking at a bi-directional way where the source
137141
// and target phantom are on the same edge based node
138142
new_weight < 0)
139143
{
140144
// check whether there is a loop present at the node
141-
for (const auto edge : facade.GetAdjacentEdgeRange(node))
145+
for (const auto edge : facade.GetAdjacentEdgeRange(nodeData.node))
142146
{
143147
const auto &data = facade.GetEdgeData(edge);
144148
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
145149
{
146150
const NodeID to = facade.GetTarget(edge);
147-
if (to == node)
151+
if (to == nodeData.node)
148152
{
149153
const EdgeWeight edge_weight = data.weight;
150154
const EdgeWeight loop_weight = new_weight + edge_weight;
151155
if (loop_weight >= 0 && loop_weight < upper_bound)
152156
{
153-
middle_node_id = node;
157+
middle_node_id = nodeData.node;
154158
upper_bound = loop_weight;
155159
}
156160
}
@@ -161,7 +165,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
161165
{
162166
BOOST_ASSERT(new_weight >= 0);
163167

164-
middle_node_id = node;
168+
middle_node_id = nodeData.node;
165169
upper_bound = new_weight;
166170
}
167171
}
@@ -177,12 +181,12 @@ void routingStep(const DataFacade<Algorithm> &facade,
177181
}
178182

179183
// Stalling
180-
if (STALLING && stallAtNode<DIRECTION>(facade, node, weight, forward_heap))
184+
if (STALLING && stallAtNode<DIRECTION>(facade, nodeData.node, weight, forward_heap))
181185
{
182186
return;
183187
}
184188

185-
relaxOutgoingEdges<DIRECTION>(facade, node, weight, forward_heap);
189+
relaxOutgoingEdges<DIRECTION>(facade, nodeData.node, weight, forward_heap);
186190
}
187191

188192
template <bool UseDuration>

include/engine/routing_algorithms/routing_base_mld.hpp

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -229,40 +229,42 @@ retrievePackedPathFromHeap(const SearchEngineData<Algorithm>::QueryHeap &forward
229229
template <bool DIRECTION, typename Algorithm, typename... Args>
230230
void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
231231
typename SearchEngineData<Algorithm>::QueryHeap &forward_heap,
232-
const NodeID node,
232+
const typename SearchEngineData<Algorithm>::QueryHeap::HeapNode& heapNode,
233233
const EdgeWeight weight,
234234
Args... args)
235235
{
236236
const auto &partition = facade.GetMultiLevelPartition();
237237
const auto &cells = facade.GetCellStorage();
238238
const auto &metric = facade.GetCellMetric();
239239

240-
const auto level = getNodeQueryLevel(partition, node, args...);
240+
const auto level = getNodeQueryLevel(partition, heapNode.node, args...);
241241

242-
if (level >= 1 && !forward_heap.GetData(node).from_clique_arc)
242+
if (level >= 1 && !heapNode.data.from_clique_arc)
243243
{
244244
if (DIRECTION == FORWARD_DIRECTION)
245245
{
246246
// Shortcuts in forward direction
247-
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, node));
247+
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, heapNode.node));
248248
auto destination = cell.GetDestinationNodes().begin();
249-
for (auto shortcut_weight : cell.GetOutWeight(node))
249+
for (auto shortcut_weight : cell.GetOutWeight(heapNode.node))
250250
{
251251
BOOST_ASSERT(destination != cell.GetDestinationNodes().end());
252252
const NodeID to = *destination;
253253

254-
if (shortcut_weight != INVALID_EDGE_WEIGHT && node != to)
254+
if (shortcut_weight != INVALID_EDGE_WEIGHT && heapNode.node != to)
255255
{
256256
const EdgeWeight to_weight = weight + shortcut_weight;
257257
BOOST_ASSERT(to_weight >= weight);
258-
if (!forward_heap.WasInserted(to))
258+
auto toNodeData= forward_heap.WasInsertedGetHeapNode(to);
259+
if (!toNodeData)
259260
{
260-
forward_heap.Insert(to, to_weight, {node, true});
261+
forward_heap.Insert(to, to_weight, {heapNode.node, true});
261262
}
262263
else if (to_weight < forward_heap.GetKey(to))
263264
{
264-
forward_heap.GetData(to) = {node, true};
265-
forward_heap.DecreaseKey(to, to_weight);
265+
toNodeData->data = {heapNode.node, true};
266+
toNodeData->weight=to_weight;
267+
forward_heap.DecreaseKey(*toNodeData);
266268
}
267269
}
268270
++destination;
@@ -271,25 +273,27 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
271273
else
272274
{
273275
// Shortcuts in backward direction
274-
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, node));
276+
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, heapNode.node));
275277
auto source = cell.GetSourceNodes().begin();
276-
for (auto shortcut_weight : cell.GetInWeight(node))
278+
for (auto shortcut_weight : cell.GetInWeight(heapNode.node))
277279
{
278280
BOOST_ASSERT(source != cell.GetSourceNodes().end());
279281
const NodeID to = *source;
280282

281-
if (shortcut_weight != INVALID_EDGE_WEIGHT && node != to)
283+
if (shortcut_weight != INVALID_EDGE_WEIGHT && heapNode.node != to)
282284
{
283285
const EdgeWeight to_weight = weight + shortcut_weight;
284286
BOOST_ASSERT(to_weight >= weight);
285-
if (!forward_heap.WasInserted(to))
287+
auto toNodeData= forward_heap.WasInsertedGetHeapNode(to);
288+
if (!toNodeData)
286289
{
287-
forward_heap.Insert(to, to_weight, {node, true});
290+
forward_heap.Insert(to, to_weight, {heapNode.node, true});
288291
}
289292
else if (to_weight < forward_heap.GetKey(to))
290293
{
291-
forward_heap.GetData(to) = {node, true};
292-
forward_heap.DecreaseKey(to, to_weight);
294+
toNodeData->data = {heapNode.node, true};
295+
toNodeData->weight=to_weight;
296+
forward_heap.DecreaseKey(*toNodeData);
293297
}
294298
}
295299
++source;
@@ -298,7 +302,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
298302
}
299303

300304
// Boundary edges
301-
for (const auto edge : facade.GetBorderEdgeRange(level, node))
305+
for (const auto edge : facade.GetBorderEdgeRange(level, heapNode.node))
302306
{
303307
const auto &edge_data = facade.GetEdgeData(edge);
304308

@@ -311,21 +315,23 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
311315
checkParentCellRestriction(partition.GetCell(level + 1, to), args...))
312316
{
313317
const auto node_weight =
314-
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? node : to);
318+
facade.GetNodeWeight(DIRECTION == FORWARD_DIRECTION ? heapNode.node : to);
315319
const auto turn_penalty = facade.GetWeightPenaltyForEdgeID(edge_data.turn_id);
316320

317321
// TODO: BOOST_ASSERT(edge_data.weight == node_weight + turn_penalty);
318322

319323
const EdgeWeight to_weight = weight + node_weight + turn_penalty;
320324

321-
if (!forward_heap.WasInserted(to))
325+
auto toNodeData= forward_heap.WasInsertedGetHeapNode(to);
326+
if (!toNodeData)
322327
{
323-
forward_heap.Insert(to, to_weight, {node, false});
328+
forward_heap.Insert(to, to_weight, {heapNode.node, false});
324329
}
325330
else if (to_weight < forward_heap.GetKey(to))
326331
{
327-
forward_heap.GetData(to) = {node, false};
328-
forward_heap.DecreaseKey(to, to_weight);
332+
toNodeData->data = {heapNode.node, false};
333+
toNodeData->weight=to_weight;
334+
forward_heap.DecreaseKey(*toNodeData);
329335
}
330336
}
331337
}
@@ -342,34 +348,35 @@ void routingStep(const DataFacade<Algorithm> &facade,
342348
const bool force_loop_reverse,
343349
Args... args)
344350
{
345-
const auto node = forward_heap.DeleteMin();
346-
const auto weight = forward_heap.GetKey(node);
351+
const auto heapNode = forward_heap.DeleteMinGetHeapNode();
352+
const auto weight = heapNode.weight;
347353

348-
BOOST_ASSERT(!facade.ExcludeNode(node));
354+
BOOST_ASSERT(!facade.ExcludeNode(heapNode.node));
349355

350356
// Upper bound for the path source -> target with
351357
// weight(source -> node) = weight weight(to -> target) ≤ reverse_weight
352358
// is weight + reverse_weight
353359
// More tighter upper bound requires additional condition reverse_heap.WasRemoved(to)
354360
// with weight(to -> target) = reverse_weight and all weights ≥ 0
355-
if (reverse_heap.WasInserted(node))
361+
auto reverveNodeData= reverse_heap.WasInsertedGetHeapNode(heapNode.node);
362+
if (reverveNodeData)
356363
{
357-
auto reverse_weight = reverse_heap.GetKey(node);
364+
auto reverse_weight = reverveNodeData->weight;
358365
auto path_weight = weight + reverse_weight;
359366

360367
// MLD uses loops forcing only to prune single node paths in forward and/or
361368
// backward direction (there is no need to force loops in MLD but in CH)
362-
if (!(force_loop_forward && forward_heap.GetData(node).parent == node) &&
363-
!(force_loop_reverse && reverse_heap.GetData(node).parent == node) &&
369+
if (!(force_loop_forward && heapNode.data.parent == heapNode.node) &&
370+
!(force_loop_reverse && reverveNodeData->data.parent == heapNode.node) &&
364371
(path_weight >= 0) && (path_weight < path_upper_bound))
365372
{
366-
middle_node = node;
373+
middle_node = heapNode.node;
367374
path_upper_bound = path_weight;
368375
}
369376
}
370377

371378
// Relax outgoing edges from node
372-
relaxOutgoingEdges<DIRECTION>(facade, forward_heap, node, weight, args...);
379+
relaxOutgoingEdges<DIRECTION>(facade, forward_heap, heapNode, weight, args...);
373380
}
374381

375382
// With (s, middle, t) we trace back the paths middle -> s and middle -> t.

0 commit comments

Comments
 (0)