Skip to content

Commit ddc84b9

Browse files
committed
Merge branch 'access-egress-via-routing' into v2
2 parents c0ba19c + b72d1f9 commit ddc84b9

51 files changed

Lines changed: 1181 additions & 389 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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
@@ -96,7 +96,7 @@ void filter() {
9696
private static Collection<ClosestTrip> closestTrips(Matcher<Trip> matcher) {
9797
return ClosestTrip.of(
9898
ADAPTER,
99-
List.of(new NearbyStop(STOP.getId(), 100, List.of(), null)),
99+
List.of(new NearbyStop(STOP.getId(), 100, List.of(), List.of())),
100100
matcher,
101101
List.of(FSD),
102102
true

application/src/ext/java/org/opentripplanner/ext/carpooling/routing/CarpoolAccessEgress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public RoutingAccessEgress withPenalty(TimeAndCost penalty) {
119119
It is never used for instances of CarpoolAccessEgress, but this might change in the future.
120120
*/
121121
@Override
122-
public State getFinalState() {
122+
public List<State> getFinalStates() {
123123
throw new UnsupportedOperationException(
124124
"Fetching last state of CarpoolAccessEgress is not yet implemented"
125125
);

application/src/ext/java/org/opentripplanner/ext/carpooling/routing/CarpoolStreetRouter.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.opentripplanner.routing.api.request.request.StreetRequest;
77
import org.opentripplanner.street.model.StreetMode;
88
import org.opentripplanner.street.model.edge.Edge;
9+
import org.opentripplanner.street.model.path.StreetPath;
910
import org.opentripplanner.street.model.vertex.Vertex;
1011
import org.opentripplanner.street.search.EuclideanRemainingWeightHeuristic;
1112
import org.opentripplanner.street.search.StreetSearchBuilder;
@@ -105,12 +106,6 @@ private GraphPath<State, Edge, Vertex> carpoolRouting(
105106
.withFrom(fromVertex)
106107
.withTo(toVertex);
107108

108-
var paths = streetSearch.getPathsToTarget();
109-
110-
if (paths.isEmpty()) {
111-
return null;
112-
}
113-
114-
return paths.getFirst().toGraphPath();
109+
return streetSearch.getPathToTarget().map(StreetPath::toGraphPath).orElse(null);
115110
}
116111
}

application/src/ext/java/org/opentripplanner/ext/carpooling/service/DefaultCarpoolingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public List<CarpoolAccessEgress> routeAccessEgress(
389389

390390
var nearbyStopsWithVertices = new HashMap<NearbyStop, Vertex>();
391391
for (var stop : nearbyStops) {
392-
nearbyStopsWithVertices.put(stop, stop.state.getVertex());
392+
nearbyStopsWithVertices.put(stop, stop.finalStates.getFirst().getVertex());
393393
}
394394

395395
var candidateTripsWithVertices = candidateTrips

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
@@ -108,7 +108,8 @@ Stream<FlexAccessEgress> createFlexAccessEgressStream(FlexAccessEgressCallbackAd
108108
// transferStop is Location Area/Line
109109
else {
110110
double maxDistanceMeters =
111-
maxTransferDuration.getSeconds() * accessEgress.state.getRequest().walk().speed();
111+
maxTransferDuration.getSeconds() *
112+
accessEgress.finalStates.getFirst().getRequest().walk().speed();
112113

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

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
@@ -59,7 +59,7 @@ protected Vertex getFlexVertex(Edge edge) {
5959
}
6060

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

7373
protected FlexTripEdge getFlexEdge(Vertex flexToVertex, FeedScopedId transferStopId) {
74+
// TODO flex doesn't support via locations yet
75+
var lastVertex = accessEgress.finalStates.getLast().getVertex();
7476
var flexPath = calculator.calculateFlexPath(
75-
accessEgress.state.getVertex(),
77+
lastVertex,
7678
flexToVertex,
7779
boardStopPosition,
7880
alightStopPosition
@@ -83,7 +85,7 @@ protected FlexTripEdge getFlexEdge(Vertex flexToVertex, FeedScopedId transferSto
8385
}
8486

8587
return new FlexTripEdge(
86-
accessEgress.state.getVertex(),
88+
lastVertex,
8789
flexToVertex,
8890
accessEgress.stopId,
8991
transferStopId,

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.finalStates.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.finalStates.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.finalStates.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
@@ -60,7 +60,7 @@ protected Vertex getFlexVertex(Edge edge) {
6060
}
6161

6262
protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, State state) {
63-
int postFlexTime = (int) accessEgress.state.getElapsedTimeSeconds();
63+
int postFlexTime = (int) accessEgress.duration().getSeconds();
6464
int edgeTimeInSeconds = flexEdge.getTimeInSeconds();
6565
int preFlexTime = (int) state.getElapsedTimeSeconds() - postFlexTime - edgeTimeInSeconds;
6666
return new FlexPathDurations(
@@ -72,9 +72,11 @@ protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, St
7272
}
7373

7474
protected FlexTripEdge getFlexEdge(Vertex flexFromVertex, FeedScopedId transferStopId) {
75+
// TODO flex doesn't support via locations yet
76+
var lastVertex = accessEgress.finalStates.getLast().getVertex();
7577
var flexPath = calculator.calculateFlexPath(
7678
flexFromVertex,
77-
accessEgress.state.getVertex(),
79+
lastVertex,
7880
boardStopPosition,
7981
alightStopPosition
8082
);
@@ -85,7 +87,7 @@ protected FlexTripEdge getFlexEdge(Vertex flexFromVertex, FeedScopedId transferS
8587

8688
return new FlexTripEdge(
8789
flexFromVertex,
88-
accessEgress.state.getVertex(),
90+
lastVertex,
8991
transferStopId,
9092
accessEgress.stopId,
9193
trip,

application/src/ext/java/org/opentripplanner/ext/ridehailing/RideHailingAccessAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public final class RideHailingAccessAdapter extends DefaultAccessEgress {
1414
private final Duration arrival;
1515

1616
public RideHailingAccessAdapter(RoutingAccessEgress access, Duration arrival) {
17-
super(access.stop(), access.getFinalState());
17+
super(access.stop(), access.getFinalStates());
1818
this.arrival = arrival;
1919
}
2020

application/src/ext/java/org/opentripplanner/ext/ridehailing/RideHailingAccessShifter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.opentripplanner.routing.api.request.RouteRequest;
1313
import org.opentripplanner.street.geometry.WgsCoordinate;
1414
import org.opentripplanner.street.model.StreetMode;
15+
import org.opentripplanner.street.search.state.State;
1516
import org.opentripplanner.transit.model.framework.Result;
1617
import org.slf4j.Logger;
1718
import org.slf4j.LoggerFactory;
@@ -45,7 +46,7 @@ public static List<RoutingAccessEgress> shiftAccesses(
4546
.map(ae -> {
4647
// only time-shift access legs on a car
4748
// (there could be walk-only accesses if you're close to the stop)
48-
if (isAccess && ae.getFinalState().containsModeCar()) {
49+
if (isAccess && ae.getFinalStates().stream().allMatch(State::containsModeCar)) {
4950
var duration = fetchArrivalDelay(services, request, now);
5051
if (duration.isSuccess()) {
5152
return new RideHailingAccessAdapter(ae, duration.successValue());

0 commit comments

Comments
 (0)