Skip to content

Commit 41af961

Browse files
committed
Improvements
1 parent 1306784 commit 41af961

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

include/engine/routing_algorithms/routing_base_ch.hpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ namespace ch
2424
// Stalling
2525
template <bool DIRECTION, typename HeapT>
2626
bool stallAtNode(const DataFacade<Algorithm> &facade,
27-
const NodeID node,
28-
const EdgeWeight weight,
27+
const typename HeapT::HeapNode& heapNode,
2928
const HeapT &query_heap)
3029
{
31-
for (auto edge : facade.GetAdjacentEdgeRange(node))
30+
for (auto edge : facade.GetAdjacentEdgeRange(heapNode.node))
3231
{
3332
const auto &data = facade.GetEdgeData(edge);
3433
if (DIRECTION == REVERSE_DIRECTION ? data.forward : data.backward)
3534
{
3635
const NodeID to = facade.GetTarget(edge);
3736
const EdgeWeight edge_weight = data.weight;
3837
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
39-
const auto& toHeapNode= query_heap.WasInsertedGetHeapNode(to);
38+
const auto& toHeapNode= query_heap.GetHeapNodeIfWasInserted(to);
4039
if (toHeapNode)
4140
{
42-
if (toHeapNode->weight + edge_weight < weight)
41+
if (toHeapNode->weight + edge_weight < heapNode.weight)
4342
{
4443
return true;
4544
}
@@ -51,11 +50,10 @@ bool stallAtNode(const DataFacade<Algorithm> &facade,
5150

5251
template <bool DIRECTION>
5352
void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
54-
const NodeID node,
55-
const EdgeWeight weight,
53+
const SearchEngineData<Algorithm>::QueryHeap::HeapNode& heapNode,
5654
SearchEngineData<Algorithm>::QueryHeap &heap)
5755
{
58-
for (const auto edge : facade.GetAdjacentEdgeRange(node))
56+
for (const auto edge : facade.GetAdjacentEdgeRange(heapNode.node))
5957
{
6058
const auto &data = facade.GetEdgeData(edge);
6159
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
@@ -64,21 +62,21 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
6462
const EdgeWeight edge_weight = data.weight;
6563

6664
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
67-
const EdgeWeight to_weight = weight + edge_weight;
65+
const EdgeWeight to_weight = heapNode.weight + edge_weight;
6866

69-
auto toData= heap.WasInsertedGetHeapNode(to);
67+
auto toHeapNode = heap.GetHeapNodeIfWasInserted(to);
7068
// New Node discovered -> Add to Heap + Node Info Storage
71-
if (!toData)
69+
if (!toHeapNode)
7270
{
73-
heap.Insert(to, to_weight, node);
71+
heap.Insert(to, to_weight, heapNode.node);
7472
}
7573
// Found a shorter Path -> Update weight
76-
else if (to_weight < toData->weight)
74+
else if (to_weight < toHeapNode->weight)
7775
{
7876
// new parent
79-
toData->data.parent = node;
80-
toData->weight=to_weight;
81-
heap.DecreaseKey(*toData);
77+
toHeapNode->data.parent = heapNode.node;
78+
toHeapNode->weight=to_weight;
79+
heap.DecreaseKey(*toHeapNode);
8280
}
8381
}
8482
}
@@ -125,36 +123,35 @@ void routingStep(const DataFacade<Algorithm> &facade,
125123
const bool force_loop_forward,
126124
const bool force_loop_reverse)
127125
{
128-
auto nodeData = forward_heap.DeleteMinGetHeapNode();
129-
const EdgeWeight weight = nodeData.weight;
126+
auto heapNode = forward_heap.DeleteMinGetHeapNode();
127+
auto reverseHeapNode = reverse_heap.GetHeapNodeIfWasInserted(heapNode.node);
130128

131-
auto reverseNodeData= reverse_heap.WasInsertedGetHeapNode(nodeData.node);
132-
if (reverseNodeData)
129+
if (reverseHeapNode)
133130
{
134-
const EdgeWeight new_weight = reverseNodeData->weight + weight;
131+
const EdgeWeight new_weight = reverseHeapNode->weight + heapNode.weight;
135132
if (new_weight < upper_bound)
136133
{
137134
// if loops are forced, they are so at the source
138-
if ((force_loop_forward && nodeData.data.parent == nodeData.node) ||
139-
(force_loop_reverse && reverseNodeData->data.parent == nodeData.node) ||
135+
if ((force_loop_forward && heapNode.data.parent == heapNode.node) ||
136+
(force_loop_reverse && reverseHeapNode->data.parent == heapNode.node) ||
140137
// in this case we are looking at a bi-directional way where the source
141138
// and target phantom are on the same edge based node
142139
new_weight < 0)
143140
{
144141
// check whether there is a loop present at the node
145-
for (const auto edge : facade.GetAdjacentEdgeRange(nodeData.node))
142+
for (const auto edge : facade.GetAdjacentEdgeRange(heapNode.node))
146143
{
147144
const auto &data = facade.GetEdgeData(edge);
148145
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
149146
{
150147
const NodeID to = facade.GetTarget(edge);
151-
if (to == nodeData.node)
148+
if (to == heapNode.node)
152149
{
153150
const EdgeWeight edge_weight = data.weight;
154151
const EdgeWeight loop_weight = new_weight + edge_weight;
155152
if (loop_weight >= 0 && loop_weight < upper_bound)
156153
{
157-
middle_node_id = nodeData.node;
154+
middle_node_id = heapNode.node;
158155
upper_bound = loop_weight;
159156
}
160157
}
@@ -165,7 +162,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
165162
{
166163
BOOST_ASSERT(new_weight >= 0);
167164

168-
middle_node_id = nodeData.node;
165+
middle_node_id = heapNode.node;
169166
upper_bound = new_weight;
170167
}
171168
}
@@ -174,19 +171,19 @@ void routingStep(const DataFacade<Algorithm> &facade,
174171
// make sure we don't terminate too early if we initialize the weight
175172
// for the nodes in the forward heap with the forward/reverse offset
176173
BOOST_ASSERT(min_edge_offset <= 0);
177-
if (weight + min_edge_offset > upper_bound)
174+
if (heapNode.weight + min_edge_offset > upper_bound)
178175
{
179176
forward_heap.DeleteAll();
180177
return;
181178
}
182179

183180
// Stalling
184-
if (STALLING && stallAtNode<DIRECTION>(facade, nodeData.node, weight, forward_heap))
181+
if (STALLING && stallAtNode<DIRECTION>(facade, heapNode, forward_heap))
185182
{
186183
return;
187184
}
188185

189-
relaxOutgoingEdges<DIRECTION>(facade, nodeData.node, weight, forward_heap);
186+
relaxOutgoingEdges<DIRECTION>(facade, heapNode, forward_heap);
190187
}
191188

192189
template <bool UseDuration>

include/engine/routing_algorithms/routing_base_mld.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
255255
{
256256
const EdgeWeight to_weight = weight + shortcut_weight;
257257
BOOST_ASSERT(to_weight >= weight);
258-
auto toNodeData= forward_heap.WasInsertedGetHeapNode(to);
258+
auto toNodeData= forward_heap.GetHeapNodeIfWasInserted(to);
259259
if (!toNodeData)
260260
{
261261
forward_heap.Insert(to, to_weight, {heapNode.node, true});
@@ -284,7 +284,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
284284
{
285285
const EdgeWeight to_weight = weight + shortcut_weight;
286286
BOOST_ASSERT(to_weight >= weight);
287-
auto toNodeData= forward_heap.WasInsertedGetHeapNode(to);
287+
auto toNodeData= forward_heap.GetHeapNodeIfWasInserted(to);
288288
if (!toNodeData)
289289
{
290290
forward_heap.Insert(to, to_weight, {heapNode.node, true});
@@ -322,7 +322,7 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
322322

323323
const EdgeWeight to_weight = weight + node_weight + turn_penalty;
324324

325-
auto toNodeData= forward_heap.WasInsertedGetHeapNode(to);
325+
auto toNodeData= forward_heap.GetHeapNodeIfWasInserted(to);
326326
if (!toNodeData)
327327
{
328328
forward_heap.Insert(to, to_weight, {heapNode.node, false});
@@ -358,7 +358,7 @@ void routingStep(const DataFacade<Algorithm> &facade,
358358
// is weight + reverse_weight
359359
// More tighter upper bound requires additional condition reverse_heap.WasRemoved(to)
360360
// with weight(to -> target) = reverse_weight and all weights ≥ 0
361-
auto reverveNodeData= reverse_heap.WasInsertedGetHeapNode(heapNode.node);
361+
auto reverveNodeData= reverse_heap.GetHeapNodeIfWasInserted(heapNode.node);
362362
if (reverveNodeData)
363363
{
364364
auto reverse_weight = reverveNodeData->weight;

include/util/query_heap.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class QueryHeap
294294
return inserted_nodes[index].node == node;
295295
}
296296

297-
boost::optional<HeapNode&> WasInsertedGetHeapNode(const NodeID node)
297+
boost::optional<HeapNode&> GetHeapNodeIfWasInserted(const NodeID node)
298298
{
299299
const auto index = node_index.peek_index(node);
300300
if (index >= static_cast<decltype(index)>(inserted_nodes.size()))
@@ -304,7 +304,7 @@ class QueryHeap
304304
return inserted_nodes[index];
305305
}
306306

307-
const boost::optional<const HeapNode&> WasInsertedGetHeapNode(const NodeID node) const
307+
const boost::optional<const HeapNode&> GetHeapNodeIfWasInserted(const NodeID node) const
308308
{
309309
const auto index = node_index.peek_index(node);
310310
if (index >= static_cast<decltype(index)>(inserted_nodes.size()))

src/contractor/contractor_search.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void relaxNode(ContractorHeap &heap,
3232
}
3333
const EdgeWeight to_weight = node_weight + data.weight;
3434

35-
const auto& toHeapNode=heap.WasInsertedGetHeapNode(to);
35+
const auto& toHeapNode= heap.GetHeapNodeIfWasInserted(to);
3636
// New Node discovered -> Add to Heap + Node Info Storage
3737
if (!toHeapNode)
3838
{

src/engine/routing_algorithms/alternative_path_ch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
7676

7777
search_space.emplace_back(heapNode.data.parent, heapNode.node);
7878

79-
const auto& reverseHeapNode=reverse_heap.WasInsertedGetHeapNode(heapNode.node);
79+
const auto& reverseHeapNode= reverse_heap.GetHeapNodeIfWasInserted(heapNode.node);
8080
if (reverseHeapNode)
8181
{
8282
search_space_intersection.emplace_back(heapNode.node);
@@ -114,7 +114,7 @@ void alternativeRoutingStep(const DataFacade<Algorithm> &facade,
114114
BOOST_ASSERT(edge_weight > 0);
115115
const EdgeWeight to_weight = weight + edge_weight;
116116

117-
const auto& toHeapNode=forward_heap.WasInsertedGetHeapNode(to);
117+
const auto& toHeapNode= forward_heap.GetHeapNodeIfWasInserted(to);
118118
// New Node discovered -> Add to Heap + Node Info Storage
119119
if (!toHeapNode)
120120
{

src/engine/routing_algorithms/many_to_many_ch.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,16 @@ inline bool addLoopWeight(const DataFacade<ch::Algorithm> &facade,
4646

4747
template <bool DIRECTION>
4848
void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
49-
const NodeID node,
50-
const EdgeWeight weight,
51-
const EdgeDuration duration,
52-
const EdgeDistance distance,
49+
const typename SearchEngineData<Algorithm>::ManyToManyQueryHeap::HeapNode& heapNode,
5350
typename SearchEngineData<Algorithm>::ManyToManyQueryHeap &query_heap,
5451
const PhantomNode &)
5552
{
56-
if (stallAtNode<DIRECTION>(facade, node, weight, query_heap))
53+
if (stallAtNode<DIRECTION>(facade, heapNode, query_heap))
5754
{
5855
return;
5956
}
6057

61-
for (auto edge : facade.GetAdjacentEdgeRange(node))
58+
for (auto edge : facade.GetAdjacentEdgeRange(heapNode.node))
6259
{
6360
const auto &data = facade.GetEdgeData(edge);
6461
if (DIRECTION == FORWARD_DIRECTION ? data.forward : data.backward)
@@ -70,21 +67,21 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
7067
const auto edge_distance = data.distance;
7168

7269
BOOST_ASSERT_MSG(edge_weight > 0, "edge_weight invalid");
73-
const auto to_weight = weight + edge_weight;
74-
const auto to_duration = duration + edge_duration;
75-
const auto to_distance = distance + edge_distance;
70+
const auto to_weight = heapNode.weight + edge_weight;
71+
const auto to_duration = heapNode.data.duration + edge_duration;
72+
const auto to_distance = heapNode.data.distance + edge_distance;
7673

77-
const auto& toHeapNode=query_heap.WasInsertedGetHeapNode(to);
74+
const auto& toHeapNode= query_heap.GetHeapNodeIfWasInserted(to);
7875
// New Node discovered -> Add to Heap + Node Info Storage
7976
if (!toHeapNode)
8077
{
81-
query_heap.Insert(to, to_weight, {node, to_duration, to_distance});
78+
query_heap.Insert(to, to_weight, {heapNode.node, to_duration, to_distance});
8279
}
8380
// Found a shorter Path -> Update weight and set new parent
8481
else if (std::tie(to_weight, to_duration) <
8582
std::tie(query_heap.GetKey(to), query_heap.GetData(to).duration))
8683
{
87-
toHeapNode->data = {node, to_duration, to_distance};
84+
toHeapNode->data = {heapNode.node, to_duration, to_distance};
8885
toHeapNode->weight=to_weight;
8986
query_heap.DecreaseKey(*toHeapNode);
9087
}
@@ -155,7 +152,7 @@ void forwardRoutingStep(const DataFacade<Algorithm> &facade,
155152
}
156153

157154
relaxOutgoingEdges<FORWARD_DIRECTION>(
158-
facade, heapNode.node, source_weight, source_duration, source_distance, query_heap, phantom_node);
155+
facade, heapNode, query_heap, phantom_node);
159156
}
160157

161158
void backwardRoutingStep(const DataFacade<Algorithm> &facade,
@@ -175,7 +172,7 @@ void backwardRoutingStep(const DataFacade<Algorithm> &facade,
175172
heapNode.node, parent, column_index, target_weight, target_duration, target_distance);
176173

177174
relaxOutgoingEdges<REVERSE_DIRECTION>(
178-
facade, heapNode.node, target_weight, target_duration, target_distance, query_heap, phantom_node);
175+
facade, heapNode, query_heap, phantom_node);
179176
}
180177

181178
} // namespace ch

src/engine/routing_algorithms/many_to_many_mld.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.WasInsertedGetHeapNode(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});
@@ -134,7 +134,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
134134
const auto to_weight = weight + shortcut_weight;
135135
const auto to_duration = duration + shortcut_durations.front();
136136
const auto to_distance = distance + shortcut_distances.front();
137-
const auto& toHeapNode=query_heap.WasInsertedGetHeapNode(to);
137+
const auto& toHeapNode= query_heap.GetHeapNodeIfWasInserted(to);
138138
if (!toHeapNode)
139139
{
140140
query_heap.Insert(to, to_weight, {node, true, to_duration, to_distance});
@@ -174,7 +174,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
174174
const auto to_weight = weight + shortcut_weight;
175175
const auto to_duration = duration + shortcut_durations.front();
176176
const auto to_distance = distance + shortcut_distances.front();
177-
const auto& toHeapNode=query_heap.WasInsertedGetHeapNode(to);
177+
const auto& toHeapNode= query_heap.GetHeapNodeIfWasInserted(to);
178178
if (!toHeapNode)
179179
{
180180
query_heap.Insert(to, to_weight, {node, true, to_duration, to_distance});

0 commit comments

Comments
 (0)