Skip to content

Commit 078daf3

Browse files
committed
fix: ensure range-raptor queries can return multiple paths
1 parent c344fab commit 078daf3

File tree

6 files changed

+50
-9
lines changed

6 files changed

+50
-9
lines changed

raptor/src/main/java/org/opentripplanner/raptor/rangeraptor/DefaultRangeRaptorWorker.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void findTransitForRound() {
169169
}
170170

171171
@Override
172-
public void findOnBoardAccessForRound() {
172+
public void findOnBoardAccessForRound(int iterationDepartureTime) {
173173
// For an on-board access, we don't count a ride until we alight, meaning that we will have
174174
// n rides in round n + 1.
175175
// TODO consider increasing numberOfRounds to 1 as a more proper fix?
@@ -195,8 +195,10 @@ public void findOnBoardAccessForRound() {
195195
return;
196196
}
197197

198-
var boardTime = trip.arrival(accessPath.stopPositionInPattern());
199-
transitWorker.registerOnBoardAccessStopArrival(accessPath, boardTime, trip);
198+
var boardTime = trip.departure(accessPath.stopPositionInPattern());
199+
if (calculator.isInIteration(boardTime, iterationDepartureTime)) {
200+
transitWorker.registerOnBoardAccessStopArrival(accessPath, boardTime, trip);
201+
}
200202
}
201203
}
202204

raptor/src/main/java/org/opentripplanner/raptor/rangeraptor/RangeRaptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public RaptorRouterResult<T> route() {
125125
private void runRaptorForMinute(int iterationDepartureTime) {
126126
setupIteration(iterationDepartureTime);
127127
worker.findAccessOnStreetForRound();
128-
worker.findOnBoardAccessForRound();
128+
worker.findOnBoardAccessForRound(iterationDepartureTime);
129129

130130
while (hasMoreRounds()) {
131131
lifeCycle.prepareForNextRound(roundTracker.nextRound());

raptor/src/main/java/org/opentripplanner/raptor/rangeraptor/RangeRaptorWorkerComposite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public void findTransitForRound() {
8383
}
8484

8585
@Override
86-
public void findOnBoardAccessForRound() {
86+
public void findOnBoardAccessForRound(int iterationDepartureTime) {
8787
for (RangeRaptorWorker<T> child : children) {
88-
child.findOnBoardAccessForRound();
88+
child.findOnBoardAccessForRound(iterationDepartureTime);
8989
}
9090
}
9191

raptor/src/main/java/org/opentripplanner/raptor/rangeraptor/internalapi/RangeRaptorWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface RangeRaptorWorker<T extends RaptorTripSchedule> {
2727
/**
2828
* Find on-board access for round (accesses on-board an already started trip)
2929
*/
30-
void findOnBoardAccessForRound();
30+
void findOnBoardAccessForRound(int iterationDepartureTime);
3131

3232
/**
3333
* Perform on-board (accesses on-board an already started trip) transit search for boardings and

raptor/src/main/java/org/opentripplanner/raptor/rangeraptor/transit/AccessEgressFunctions.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.function.ToIntFunction;
1111
import java.util.stream.Collectors;
1212
import org.opentripplanner.raptor.api.model.RaptorAccessEgress;
13+
import org.opentripplanner.raptor.api.model.RaptorOnBoardAccess;
1314
import org.opentripplanner.raptor.util.paretoset.ParetoComparator;
1415
import org.opentripplanner.raptor.util.paretoset.ParetoSet;
1516
import org.slf4j.Logger;
@@ -50,13 +51,19 @@ public final class AccessEgressFunctions {
5051
* No opening hours is better than being restricted
5152
* </li>
5253
* <li>
53-
* If Both have opening hours, both need to be accepted
54+
* If both have opening hours, both need to be accepted
55+
* </li>
56+
* <li>
57+
* If both are on-board access, both need to be accepted. This is because the
58+
* pareto-optimality of a path started with an on-board access depends on the specific
59+
* trip boarded and cannot be determined from the access-path alone.
5460
* </li>
5561
* </ol>
5662
*/
5763
private static final ParetoComparator<RaptorAccessEgress> STANDARD_COMPARATOR = (l, r) ->
5864
((l.stopReachedOnBoard() && !r.stopReachedOnBoard()) ||
5965
r.hasOpeningHours() ||
66+
r instanceof RaptorOnBoardAccess ||
6067
l.numberOfRides() < r.numberOfRides() ||
6168
l.durationInSeconds() < r.durationInSeconds() ||
6269
l.numberOfViaLocationsVisited() > r.numberOfViaLocationsVisited());

raptor/src/test/java/org/opentripplanner/raptor/moduletests/M01_OnBoardAccessTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private RaptorRequestBuilder<TestTripSchedule> prepareRequest() {
4242
.searchParams()
4343
.earliestDepartureTime(T00_00)
4444
.latestArrivalTime(T01_00)
45-
.searchWindow(Duration.ofMinutes(2))
45+
.searchWindow(Duration.ofMinutes(60))
4646
.timetable(true);
4747

4848
return builder;
@@ -319,4 +319,36 @@ void walkAndOnBoard() {
319319
pathsToString(raptorResponse)
320320
);
321321
}
322+
323+
@Test
324+
@DisplayName("Range query results in multiple consecutive paths")
325+
void rangeQuery() {
326+
data
327+
.access(
328+
new TestRaptorOnBoardAccess(0, 0, 1, STOP_B, 0),
329+
new TestRaptorOnBoardAccess(0, 1, 1, STOP_B, 0)
330+
)
331+
.withRoutes()
332+
.withTimetables(
333+
"""
334+
-- R1
335+
A B C D
336+
0:00 0:05:05 0:10 0:15
337+
0:05 0:10 0:15 0:20
338+
"""
339+
)
340+
.egress("D ~ Walk 30s");
341+
342+
var requestBuilder = prepareRequest();
343+
344+
var raptorResponse = raptorService.route(requestBuilder.build(), data);
345+
346+
// The result of the range query should include a path for each access
347+
assertEquals(
348+
"""
349+
B ~ BUS R1 0:05:05 0:15 ~ D ~ Walk 30s [0:05:05 0:15:30 10m25s Tₙ0 C₁1_255]
350+
B ~ BUS R1 0:10 0:20 ~ D ~ Walk 30s [0:10 0:20:30 10m30s Tₙ0 C₁1_260]""",
351+
pathsToString(raptorResponse)
352+
);
353+
}
322354
}

0 commit comments

Comments
 (0)