Skip to content

Commit f20eb7c

Browse files
Remove unnecessary footpathIndex from calculation
The iterator that was used in the loop was pointing to the same position as the footpath index. Benchmarks seems to show a small perf improvement in most cases Tested in transition, results are not effected
1 parent 36bcf6e commit f20eb7c

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

connection_scan_algorithm/src/forward_calculation.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace TrRouting
2121
short connectionMinWaitingTimeSeconds {-1};
2222
//long long footpathsRangeStart {-1};
2323
//long long footpathsRangeEnd {-1};
24-
int footpathIndex {-1};
2524
int footpathTravelTime {-1};
2625
int footpathDistance {-1};
2726
int tentativeEgressNodeArrivalTime {MAX_INT};
@@ -110,7 +109,6 @@ namespace TrRouting
110109
tentativeEgressNodeArrivalTime = connectionArrivalTime;
111110
}
112111

113-
footpathIndex = 0;
114112
for (const NodeTimeDistance & transferableNode : nodeArrival.transferableNodes)
115113
{
116114
// Extract tentative time for current transferable node if found
@@ -119,18 +117,17 @@ namespace TrRouting
119117
if (nodeArrival != transferableNode.node &&
120118
currentTransferablenNodesTentativeTime < connectionArrivalTime)
121119
{
122-
footpathIndex++;
123120
continue;
124121
}
125122

126123
//TODO We should not do a direct == with float values
127-
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeArrival.transferableNodes[footpathIndex].time : (int)ceil((float)nodeArrival.transferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor());
124+
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor());
128125

129126
if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds())
130127
{
131128
if (footpathTravelTime + connectionArrivalTime < currentTransferablenNodesTentativeTime)
132129
{
133-
footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance;
130+
footpathDistance = transferableNode.distance;
134131
nodesTentativeTime[transferableNode.node.uid] = footpathTravelTime + connectionArrivalTime;
135132

136133
//TODO DO we need a make_optional here??
@@ -148,11 +145,10 @@ namespace TrRouting
148145
)
149146
)
150147
{
151-
footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance;
148+
footpathDistance = transferableNode.distance;
152149
forwardEgressJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, true, footpathDistance));
153150
}
154151
}
155-
footpathIndex++;
156152
}
157153
}
158154
reachableConnectionsCount++;
@@ -212,7 +208,6 @@ namespace TrRouting
212208
short connectionMinWaitingTimeSeconds {-1};
213209
//long long footpathsRangeStart {-1};
214210
//long long footpathsRangeEnd {-1};
215-
int footpathIndex {-1};
216211
int footpathTravelTime {-1};
217212
int footpathDistance {-1};
218213
bool nodeWasAccessedFromOrigin {false};
@@ -286,7 +281,6 @@ namespace TrRouting
286281
const Node &nodeArrival = (*connection).get().getArrivalNode();
287282
connectionArrivalTime = (*connection).get().getArrivalTime();
288283

289-
footpathIndex = 0;
290284
for (const NodeTimeDistance & transferableNode : nodeArrival.transferableNodes)
291285
{
292286
// Extract tentative time for current transferable node if found
@@ -295,18 +289,17 @@ namespace TrRouting
295289
if (nodeArrival != transferableNode.node &&
296290
currentTransferablenNodesTentativeTime < connectionArrivalTime)
297291
{
298-
footpathIndex++;
299292
continue;
300293
}
301294

302295
//TODO We should not do a direct == with float values
303-
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeArrival.transferableNodes[footpathIndex].time : (int)ceil((float)nodeArrival.transferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor());
296+
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor());
304297

305298
if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds())
306299
{
307300
if (footpathTravelTime + connectionArrivalTime < currentTransferablenNodesTentativeTime)
308301
{
309-
footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance;
302+
footpathDistance = transferableNode.distance;
310303
nodesTentativeTime[transferableNode.node.uid] = footpathTravelTime + connectionArrivalTime;
311304

312305
//TODO DO we need a make_optional here??
@@ -324,11 +317,10 @@ namespace TrRouting
324317
)
325318
)
326319
{
327-
footpathDistance = nodeArrival.transferableNodes[footpathIndex].distance;
320+
footpathDistance = transferableNode.distance;
328321
forwardEgressJourneysSteps.insert_or_assign(transferableNode.node.uid, JourneyStep(currentTripQueryOverlay.enterConnection, *connection, std::cref(trip), footpathTravelTime, true, footpathDistance));
329322
}
330323
}
331-
footpathIndex++;
332324
}
333325
}
334326
reachableConnectionsCount++;

connection_scan_algorithm/src/reverse_calculation.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace TrRouting
120120
tentativeAccessNodeDepartureTime = connectionDepartureTime;
121121

122122
}
123-
footpathIndex = 0;
123+
124124
for (const NodeTimeDistance & transferableNode : nodeDeparture.reverseTransferableNodes)
125125
{
126126

@@ -131,13 +131,13 @@ namespace TrRouting
131131
}
132132

133133
//TODO We should not do a direct == with float values
134-
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeDeparture.reverseTransferableNodes[footpathIndex].time : (int)ceil((float)nodeDeparture.reverseTransferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor());
134+
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor());
135135

136136
if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds())
137137
{
138138
if (connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= nodesReverseTentativeTime.at(transferableNode.node.uid))
139139
{
140-
footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance;
140+
footpathDistance = transferableNode.distance;
141141
nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds;
142142
//TODO Do we need a make_optional<...>(connection) ??
143143
reverseJourneysSteps.at(transferableNode.node.uid) = JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance);
@@ -173,7 +173,6 @@ namespace TrRouting
173173
}
174174
}
175175
}
176-
footpathIndex++;
177176
}
178177
}
179178
reachableConnectionsCount++;
@@ -232,7 +231,6 @@ namespace TrRouting
232231
short journeyConnectionMinWaitingTimeSeconds {-1};
233232
//long long footpathsRangeStart {-1};
234233
//long long footpathsRangeEnd {-1};
235-
int footpathIndex {-1};
236234
int footpathTravelTime {-1};
237235
int footpathDistance {-1};
238236

@@ -317,24 +315,22 @@ namespace TrRouting
317315
connectionMinWaitingTimeSeconds = (*connection).get().getMinWaitingTimeOrDefault(parameters.getMinWaitingTimeSeconds());
318316

319317
auto nodeDepartureInNodesAccessIte = nodesAccess.find(nodeDeparture.uid);
320-
footpathIndex = 0;
321318
for (const NodeTimeDistance & transferableNode : nodeDeparture.reverseTransferableNodes)
322319
{
323320

324321
if (nodeDeparture != transferableNode.node && nodesReverseTentativeTime.at(transferableNode.node.uid) > connectionDepartureTime - connectionMinWaitingTimeSeconds)
325322
{
326-
footpathIndex++;
327323
continue;
328324
}
329325

330326
//TODO We should not do a direct == with float values
331-
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? nodeDeparture.reverseTransferableNodes[footpathIndex].time : (int)ceil((float)nodeDeparture.reverseTransferableNodes[footpathIndex].time / parameters.getWalkingSpeedFactor());
327+
footpathTravelTime = parameters.getWalkingSpeedFactor() == 1.0 ? transferableNode.time : (int)ceil((float)transferableNode.time / parameters.getWalkingSpeedFactor());
332328

333329
if (footpathTravelTime <= parameters.getMaxTransferWalkingTravelTimeSeconds())
334330
{
335331
if (connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds >= nodesReverseTentativeTime.at(transferableNode.node.uid))
336332
{
337-
footpathDistance = nodeDeparture.reverseTransferableNodes.at(footpathIndex).distance;
333+
footpathDistance = transferableNode.distance;
338334
nodesReverseTentativeTime[transferableNode.node.uid] = connectionDepartureTime - footpathTravelTime - connectionMinWaitingTimeSeconds;
339335
//TODO Do we need a make_optional<...>(connection) ??
340336
reverseJourneysSteps.at(transferableNode.node.uid) = JourneyStep(*connection, currentTripQueryOverlay.exitConnection, std::cref(trip), footpathTravelTime, (nodeDeparture == transferableNode.node), footpathDistance);
@@ -370,7 +366,6 @@ namespace TrRouting
370366
}
371367
}
372368
}
373-
footpathIndex++;
374369
}
375370
}
376371
reachableConnectionsCount++;

0 commit comments

Comments
 (0)