Skip to content

Commit 5e6eae5

Browse files
committed
Refactor NearbyStop to support multiple last states
1 parent 9ba66b8 commit 5e6eae5

18 files changed

Lines changed: 95 additions & 53 deletions

File tree

application/src/ext-test/java/org/opentripplanner/ext/flex/template/ClosestTripTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void filter() {
9494
private static Collection<ClosestTrip> closestTrips(Matcher<Trip> matcher) {
9595
return ClosestTrip.of(
9696
ADAPTER,
97-
List.of(new NearbyStop(STOP, 100, List.of(), null)),
97+
List.of(new NearbyStop(STOP, 100, List.of(), List.of())),
9898
matcher,
9999
List.of(FSD),
100100
true

application/src/ext/java/org/opentripplanner/ext/flex/template/AbstractFlexTemplate.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ Stream<FlexAccessEgress> createFlexAccessEgressStream(FlexAccessEgressCallbackAd
107107
// transferStop is Location Area/Line
108108
else {
109109
double maxDistanceMeters =
110-
maxTransferDuration.getSeconds() * accessEgress.state.getRequest().walk().speed();
110+
maxTransferDuration.getSeconds() *
111+
accessEgress.lastStates.getFirst().getRequest().walk().speed();
111112

112113
return getTransfersFromTransferStop(callback)
113114
.stream()
@@ -192,7 +193,10 @@ private FlexAccessEgress createFlexAccessEgress(
192193
// this code is a little repetitive but needed as a performance improvement. previously
193194
// the flex path was checked before this method was called. this meant that every path
194195
// was traversed twice, leading to a noticeable slowdown.
195-
final var afterFlexState = flexEdge.traverse(accessEgress.state);
196+
197+
// TODO flex routing doesn't support via locations yet
198+
var lastState = accessEgress.lastStates.getFirst();
199+
final var afterFlexState = flexEdge.traverse(lastState);
196200
if (State.isEmpty(afterFlexState)) {
197201
return null;
198202
}

application/src/ext/java/org/opentripplanner/ext/flex/template/FlexAccessTemplate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected Vertex getFlexVertex(Edge edge) {
5858
}
5959

6060
protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, State state) {
61-
int preFlexTime = (int) accessEgress.state.getElapsedTimeSeconds();
61+
int preFlexTime = (int) accessEgress.duration().getSeconds();
6262
int edgeTimeInSeconds = flexEdge.getTimeInSeconds();
6363
int postFlexTime = (int) state.getElapsedTimeSeconds() - preFlexTime - edgeTimeInSeconds;
6464
return new FlexPathDurations(
@@ -70,8 +70,10 @@ protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, St
7070
}
7171

7272
protected FlexTripEdge getFlexEdge(Vertex flexToVertex, StopLocation transferStop) {
73+
// TODO flex doesn't support via locations yet
74+
var lastVertex = accessEgress.lastStates.getLast().getVertex();
7375
var flexPath = calculator.calculateFlexPath(
74-
accessEgress.state.getVertex(),
76+
lastVertex,
7577
flexToVertex,
7678
boardStopPosition,
7779
alightStopPosition
@@ -82,7 +84,7 @@ protected FlexTripEdge getFlexEdge(Vertex flexToVertex, StopLocation transferSto
8284
}
8385

8486
return new FlexTripEdge(
85-
accessEgress.state.getVertex(),
87+
lastVertex,
8688
flexToVertex,
8789
accessEgress.stop,
8890
transferStop,

application/src/ext/java/org/opentripplanner/ext/flex/template/FlexDirectPathFactory.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ private Optional<DirectFlexPath> createDirectGraphPath(
105105
int accessAlightStopPosition = accessTemplate.alightStopPosition;
106106
int requestedBookingTime = accessTemplate.requestedBookingTime;
107107

108-
var flexToVertex = egress.state.getVertex();
108+
// TODO flex doesn't support via locations yet
109+
var flexToVertex = egress.lastStates.getLast().getVertex();
109110

110111
if (!isRouteable(accessTemplate, flexToVertex)) {
111112
return Optional.empty();
@@ -117,7 +118,9 @@ private Optional<DirectFlexPath> createDirectGraphPath(
117118
return Optional.empty();
118119
}
119120

120-
final State[] afterFlexState = flexEdge.traverse(accessNearbyStop.state);
121+
// TODO flex doesn't support via locations yet
122+
var lastState = accessNearbyStop.lastStates.getLast();
123+
final State[] afterFlexState = flexEdge.traverse(lastState);
121124

122125
var finalStateOpt = EdgeTraverser.traverseEdges(afterFlexState[0], egress.edges);
123126

@@ -183,12 +186,14 @@ private Optional<DirectFlexPath> createDirectGraphPath(
183186
}
184187

185188
protected boolean isRouteable(FlexAccessTemplate accessTemplate, Vertex flexVertex) {
186-
if (accessTemplate.accessEgress.state.getVertex() == flexVertex) {
189+
// TODO flex doesn't support via locations yet
190+
var lastVertex = accessTemplate.accessEgress.lastStates.getLast().getVertex();
191+
if (lastVertex == flexVertex) {
187192
return false;
188193
} else {
189194
return (
190195
accessTemplate.calculator.calculateFlexPath(
191-
accessTemplate.accessEgress.state.getVertex(),
196+
lastVertex,
192197
flexVertex,
193198
accessTemplate.boardStopPosition,
194199
accessTemplate.alightStopPosition

application/src/ext/java/org/opentripplanner/ext/flex/template/FlexEgressTemplate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected Vertex getFlexVertex(Edge edge) {
5959
}
6060

6161
protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, State state) {
62-
int postFlexTime = (int) accessEgress.state.getElapsedTimeSeconds();
62+
int postFlexTime = (int) accessEgress.duration().getSeconds();
6363
int edgeTimeInSeconds = flexEdge.getTimeInSeconds();
6464
int preFlexTime = (int) state.getElapsedTimeSeconds() - postFlexTime - edgeTimeInSeconds;
6565
return new FlexPathDurations(
@@ -71,9 +71,11 @@ protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, St
7171
}
7272

7373
protected FlexTripEdge getFlexEdge(Vertex flexFromVertex, StopLocation transferStop) {
74+
// TODO flex doesn't support via locations yet
75+
var lastVertex = accessEgress.lastStates.getLast().getVertex();
7476
var flexPath = calculator.calculateFlexPath(
7577
flexFromVertex,
76-
accessEgress.state.getVertex(),
78+
lastVertex,
7779
boardStopPosition,
7880
alightStopPosition
7981
);
@@ -84,7 +86,7 @@ protected FlexTripEdge getFlexEdge(Vertex flexFromVertex, StopLocation transferS
8486

8587
return new FlexTripEdge(
8688
flexFromVertex,
87-
accessEgress.state.getVertex(),
89+
lastVertex,
8890
transferStop,
8991
accessEgress.stop,
9092
trip,

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/QueryTypeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public DataFetcher<Object> node() {
461461
var stop = transitService.getRegularStop(FeedScopedId.parse(parts[1]));
462462

463463
// TODO: Add geometry
464-
return new NearbyStop(stop, Integer.parseInt(parts[0]), null, null);
464+
return new NearbyStop(stop, Integer.parseInt(parts[0]), List.of(), List.of());
465465
}
466466
case "TicketType":
467467
// TODO

application/src/main/java/org/opentripplanner/apis/gtfs/datafetchers/StopImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,12 @@ public DataFetcher<Iterable<NearbyStop>> transfers() {
444444
.filter(transfer -> maxDistance == null || transfer.getDistanceMeters() < maxDistance)
445445
.filter(transfer -> transfer.to instanceof RegularStop)
446446
.map(transfer ->
447-
new NearbyStop(transfer.to, transfer.getDistanceMeters(), transfer.getEdges(), null)
447+
new NearbyStop(
448+
transfer.to,
449+
transfer.getDistanceMeters(),
450+
transfer.getEdges(),
451+
List.of()
452+
)
448453
)
449454
.collect(Collectors.toList());
450455
},

application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/router/street/AccessEgressRouter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Collection<NearbyStop> findAccessEgresses(
5858
// When looking for street accesses/egresses we ignore the already found direct accesses/egresses
5959
var ignoreVertices = zeroDistanceAccessEgress
6060
.stream()
61-
.map(nearbyStop -> nearbyStop.state.getVertex())
61+
.map(nearbyStop -> nearbyStop.lastStates.getLast().getVertex())
6262
.collect(Collectors.toSet());
6363

6464
var originVertices = accessOrEgress.isAccess()

application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/transit/mappers/AccessEgressMapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.opentripplanner.routing.algorithm.raptoradapter.transit.FlexAccessEgressAdapter;
1111
import org.opentripplanner.routing.algorithm.raptoradapter.transit.RoutingAccessEgress;
1212
import org.opentripplanner.routing.graphfinder.NearbyStop;
13+
import org.opentripplanner.street.search.state.State;
1314
import org.opentripplanner.transit.model.site.RegularStop;
1415

1516
public class AccessEgressMapper {
@@ -45,7 +46,9 @@ private static RoutingAccessEgress mapNearbyStop(
4546

4647
return new DefaultAccessEgress(
4748
nearbyStop.stop.getIndex(),
48-
accessOrEgress.isEgress() ? nearbyStop.state.reverse() : nearbyStop.state
49+
accessOrEgress.isEgress()
50+
? nearbyStop.lastStates.stream().map(State::reverse).toList().reversed()
51+
: nearbyStop.lastStates
4952
);
5053
}
5154
}

application/src/main/java/org/opentripplanner/routing/graphfinder/DirectGraphFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public List<NearbyStop> findClosestStops(Coordinate coordinate, double radiusMet
4141
SphericalDistanceLibrary.distance(coordinate, it.getCoordinate().asJtsCoordinate())
4242
);
4343
if (distance < radiusMeters) {
44-
NearbyStop sd = new NearbyStop(it, distance, null, null);
44+
NearbyStop sd = new NearbyStop(it, distance, List.of(), List.of());
4545
stopsFound.add(sd);
4646
}
4747
}

0 commit comments

Comments
 (0)