Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6f18026
Rename DirectStreetRouter -> DefaultDirectStreetRouter
optionsome Nov 24, 2025
a142c80
Refactor direct street router to use template method pattern
optionsome Nov 24, 2025
8916625
Add support for direct routing with coordinate via locations
optionsome Nov 29, 2025
90ded76
Add test for the direct street routers
leonardehrenfried May 11, 2026
b86a96a
Improve ViaDirectStreetRouter tests
optionsome May 12, 2026
b253ac5
Make tests beautiful
leonardehrenfried May 13, 2026
a5744a9
Add tests for arrive by
optionsome May 15, 2026
176f1c3
Merge remote-tracking branch 'upstream/dev-2.x' into HEAD
optionsome May 15, 2026
c83db73
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome May 18, 2026
6a27cbd
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Jul 1, 2026
cc6c2bb
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Jul 2, 2026
2670367
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Jul 31, 2026
2c6ab05
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Aug 24, 2026
2bbac89
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Sep 1, 2026
647691c
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Sep 3, 2026
9142f44
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Sep 22, 2026
664e6b3
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Oct 2, 2026
bc62b7d
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Nov 3, 2026
70790ef
Fix taxi logic
optionsome Nov 9, 2026
651170e
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Nov 9, 2026
916e2af
Merge remote-tracking branch 'upstream/dev-2.x' into direct-via-routing
optionsome Dec 4, 2026
4e69fa2
Refactor RoutingAccessEgress to have a list of last states instead of…
optionsome Apr 17, 2026
97424b8
Refactor NearbyStop to support multiple last states
optionsome Dec 1, 2025
03daf9b
Rename AccessEgressRouter -> DefaultAccessEgressRouter
optionsome Dec 1, 2025
bb7ac0b
Refactor AccessEgressRouter to use template method pattern
optionsome Dec 1, 2025
073fb63
Implement numberOfViaLocationsVisited in DefaultAccessEgress
optionsome Dec 3, 2025
c1f0955
Add support for via locations in access/egress
optionsome Dec 5, 2025
e4bb126
Fix taxi logic
optionsome Nov 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void filter() {
private static Collection<ClosestTrip> closestTrips(Matcher<Trip> matcher) {
return ClosestTrip.of(
ADAPTER,
List.of(new NearbyStop(STOP.getId(), 100, List.of(), null)),
List.of(new NearbyStop(STOP.getId(), 100, List.of(), List.of())),
matcher,
List.of(FSD),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
import org.opentripplanner.routing.linking.VertexLinkerTestFactory;
import org.opentripplanner.routing.linking.mapping.LinkingContextRequestMapper;
import org.opentripplanner.service.shape.dataimport.ShapeDataImport;
import org.opentripplanner.service.vehiclerental.VehicleRentalService;
import org.opentripplanner.standalone.api.TestServerContext;
import org.opentripplanner.standalone.config.RouterConfig;
import org.opentripplanner.street.graph.Graph;
import org.opentripplanner.street.linking.TemporaryVerticesContainer;
import org.opentripplanner.street.service.StreetLimitationParametersService;
import org.opentripplanner.transfer.regular.TransferRepository;
import org.opentripplanner.transfer.regular.TransferServiceTestFactory;
import org.opentripplanner.transit.dataimport.TimetableDataImport;
Expand Down Expand Up @@ -250,6 +252,8 @@ private static List<Itinerary> getItineraries(
TestServerContext.createStreetDetailsService(),
TransferServiceTestFactory.transferService(transferRepository),
TestServerContext.createRegularTransfers(graph, transitRepository, timetableDataImport),
VehicleRentalService.EMPTY,
StreetLimitationParametersService.DEFAULT,
RouterConfig.DEFAULT.flexParameters(),
List.of(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,6 @@ void decorateAccessEgressLegsLeavesCarLegUntouchedWhenNoRouteCoversLogicalCoordi
}

private static NearbyStop nearbyStop(RegularStop stop) {
return new NearbyStop(stop.getId(), 0, null, null);
return new NearbyStop(stop.getId(), 0, List.of(), List.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import static org.opentripplanner.street.model.StreetModelForTest.intersectionVertex;
import static org.opentripplanner.street.model.StreetModelForTest.streetEdge;

import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Polygon;
import org.opentripplanner._support.geometry.Polygons;
Expand All @@ -23,11 +26,13 @@
import org.opentripplanner.model.plan.leg.StreetLeg;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.request.request.StreetRequest;
import org.opentripplanner.routing.api.request.via.VisitViaLocation;
import org.opentripplanner.routing.linking.LinkingContext;
import org.opentripplanner.standalone.api.TestServerContext;
import org.opentripplanner.street.geometry.WgsCoordinate;
import org.opentripplanner.street.graph.Graph;
import org.opentripplanner.street.model.StreetMode;
import org.opentripplanner.street.search.TraverseMode;
import org.opentripplanner.transit.dataimport.TimetableDataImport;
import org.opentripplanner.transit.model._data.TransitRepositoryForTest;
import org.opentripplanner.transit.model.network.Route;
Expand Down Expand Up @@ -136,6 +141,67 @@ void routeReturnsEmptyWithoutRoutingWhenOriginAndDestinationDoNotShareARoute() {
assertThat(itineraries).isEmpty();
}

/**
* A taxi is only used from the origin to the first via location, after that the rest of the
* journey is walked.
*/
@ParameterizedTest
@ValueSource(booleans = { false, true })
void routeWithViaUsesTaxiOnlyToTheFirstVia(boolean arriveBy) {
// The segments are long enough (> 500 m) for driving to be clearly faster than walking
var fromVertex = intersectionVertex("from", 59.900, 10.700);
var viaVertex = intersectionVertex("via", 59.905, 10.700);
var toVertex = intersectionVertex("to", 59.905, 10.720);
streetEdge(fromVertex, viaVertex);
streetEdge(viaVertex, fromVertex);
streetEdge(viaVertex, toVertex);
streetEdge(toVertex, viaVertex);

var fromLocation = GenericLocation.fromCoordinate(59.900, 10.700);
var toLocation = GenericLocation.fromCoordinate(59.905, 10.720);
var via = new VisitViaLocation(
"via",
Duration.ZERO,
List.of(),
new WgsCoordinate(59.905, 10.700)
);

var request = RouteRequest.of()
.withDateTime(OffsetDateTime.parse("2026-05-13T12:00Z").toInstant())
.withArriveBy(arriveBy)
.withFrom(fromLocation)
.withTo(toLocation)
.withViaLocations(List.of(via))
.withJourney(jb -> jb.withDirect(new StreetRequest(StreetMode.TAXI)))
.buildRequest();

var linkingContext = new LinkingContext(
Map.of(
fromLocation,
Set.of(fromVertex),
via.coordinateLocation(),
Set.of(viaVertex),
toLocation,
Set.of(toVertex)
),
Set.of(),
Set.of()
);

var itineraries = routeDirect(List.of(COVERING_ROUTE), request, linkingContext);

assertThat(itineraries).hasSize(1);
var legs = itineraries.getFirst().legs();
var taxiLegs = legs.stream().filter(TaxiLeg.class::isInstance).toList();
assertThat(taxiLegs).hasSize(1);
assertThat(taxiLegs.getFirst().to().coordinate.latitude()).isWithin(1e-6).of(59.905);
assertThat(taxiLegs.getFirst().to().coordinate.longitude()).isWithin(1e-6).of(10.700);
var lastLeg = (StreetLeg) legs.getLast();
assertThat(lastLeg.getMode()).isEqualTo(TraverseMode.WALK);
assertThat(lastLeg.from().coordinate.longitude()).isWithin(1e-6).of(10.700);
assertThat(lastLeg.to().coordinate.longitude()).isWithin(1e-6).of(10.720);
}

/**
* Routes a direct {@link StreetMode#TAXI} request through {@link TaxiRouter#routeDirect} on a
* minimal synthetic street graph, decorating the result with the given routes.
Expand Down Expand Up @@ -163,6 +229,14 @@ private static List<Itinerary> routeDirect(List<TaxiRoute> routes) {
Set.of()
);

return routeDirect(routes, request, linkingContext);
}

private static List<Itinerary> routeDirect(
List<TaxiRoute> routes,
RouteRequest request,
LinkingContext linkingContext
) {
var transitService = TestServerContext.createTransitService(
new TransitRepository(),
new TimetableDataImport()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.ext.flex;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
Expand Down Expand Up @@ -144,7 +145,8 @@ public List<Itinerary> createFlexOnlyItineraries(boolean arriveBy, RouteRequest
for (DirectFlexPath it : directFlexPaths) {
var startTime = startOfTime.plusSeconds(it.startTime());
var path = new StreetPath(it.state());
var legs = streetLegMapper.map(path, request, startTime);
var delay = Duration.between(path.startTime(), startTime);
var legs = streetLegMapper.map(path, request, delay);
var itinerary = LegsToItineraryMapper.map(legs, false, path.calculateElevations());
itinerary.ifPresent(itineraries::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Stream<FlexAccessEgress> createFlexAccessEgressStream(FlexAccessEgressCallbackAd
else {
double maxDistanceMeters =
flexParameters.maxTransferDuration().getSeconds() *
accessEgress.state().getRequest().walk().speed();
accessEgress.finalStates.getFirst().getRequest().walk().speed();

return getTransfersFromTransferStop(callback)
.stream()
Expand Down Expand Up @@ -194,7 +194,10 @@ private FlexAccessEgress createFlexAccessEgress(
// this code is a little repetitive but needed as a performance improvement. previously
// the flex path was checked before this method was called. this meant that every path
// was traversed twice, leading to a noticeable slowdown.
final var afterFlexState = flexEdge.traverse(accessEgress.state());

// TODO flex routing doesn't support via locations yet
var lastState = accessEgress.finalStates.getFirst();
final var afterFlexState = flexEdge.traverse(lastState);
if (State.isEmpty(afterFlexState)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected Vertex getFlexVertex(Edge edge) {
}

protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, State state) {
int preFlexTime = (int) accessEgress.state().getElapsedTimeSeconds();
int preFlexTime = (int) accessEgress.duration().getSeconds();
int edgeTimeInSeconds = flexEdge.getTimeInSeconds();
int postFlexTime = (int) state.getElapsedTimeSeconds() - preFlexTime - edgeTimeInSeconds;
return new FlexPathDurations(
Expand All @@ -71,8 +71,10 @@ protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, St
}

protected FlexTripEdge getFlexEdge(Vertex flexToVertex, FeedScopedId transferStopId) {
// TODO flex doesn't support via locations yet
var lastVertex = accessEgress.finalStates.getLast().getVertex();
var flexPath = calculator.calculateFlexPath(
accessEgress.state().getVertex(),
lastVertex,
flexToVertex,
boardStopPosition,
alightStopPosition
Expand All @@ -83,7 +85,7 @@ protected FlexTripEdge getFlexEdge(Vertex flexToVertex, FeedScopedId transferSto
}

return new FlexTripEdge(
accessEgress.state().getVertex(),
lastVertex,
flexToVertex,
accessEgress.stopId(),
transferStopId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private Optional<DirectFlexPath> createDirectGraphPath(
int accessAlightStopPosition = accessTemplate.alightStopPosition;
int requestedBookingTime = accessTemplate.requestedBookingTime;

var flexToVertex = egress.state().getVertex();
// TODO flex doesn't support via locations yet
var flexToVertex = egress.finalStates.getLast().getVertex();

if (!isRouteable(accessTemplate, flexToVertex)) {
return Optional.empty();
Expand All @@ -117,7 +118,9 @@ private Optional<DirectFlexPath> createDirectGraphPath(
return Optional.empty();
}

final State[] afterFlexState = flexEdge.traverse(accessNearbyStop.state());
// TODO flex doesn't support via locations yet
var lastState = accessNearbyStop.finalStates.getLast();
final State[] afterFlexState = flexEdge.traverse(lastState);

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

Expand Down Expand Up @@ -183,12 +186,14 @@ private Optional<DirectFlexPath> createDirectGraphPath(
}

protected boolean isRouteable(FlexAccessTemplate accessTemplate, Vertex flexVertex) {
if (accessTemplate.accessEgress.state().getVertex() == flexVertex) {
// TODO flex doesn't support via locations yet
var lastVertex = accessTemplate.accessEgress.finalStates.getLast().getVertex();
if (lastVertex == flexVertex) {
return false;
} else {
return (
accessTemplate.calculator.calculateFlexPath(
accessTemplate.accessEgress.state().getVertex(),
lastVertex,
flexVertex,
accessTemplate.boardStopPosition,
accessTemplate.alightStopPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected Vertex getFlexVertex(Edge edge) {
}

protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, State state) {
int postFlexTime = (int) accessEgress.state().getElapsedTimeSeconds();
int postFlexTime = (int) accessEgress.duration().getSeconds();
int edgeTimeInSeconds = flexEdge.getTimeInSeconds();
int preFlexTime = (int) state.getElapsedTimeSeconds() - postFlexTime - edgeTimeInSeconds;
return new FlexPathDurations(
Expand All @@ -71,9 +71,11 @@ protected FlexPathDurations calculateFlexPathDurations(FlexTripEdge flexEdge, St
}

protected FlexTripEdge getFlexEdge(Vertex flexFromVertex, FeedScopedId transferStopId) {
// TODO flex doesn't support via locations yet
var lastVertex = accessEgress.finalStates.getLast().getVertex();
var flexPath = calculator.calculateFlexPath(
flexFromVertex,
accessEgress.state().getVertex(),
lastVertex,
boardStopPosition,
alightStopPosition
);
Expand All @@ -84,7 +86,7 @@ protected FlexTripEdge getFlexEdge(Vertex flexFromVertex, FeedScopedId transferS

return new FlexTripEdge(
flexFromVertex,
accessEgress.state().getVertex(),
lastVertex,
transferStopId,
accessEgress.stopId(),
trip,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ Collection<NearbyStop> filterNearbyStops(
RouteRequest request
);

/**
* Returns {@code true} if a single taxi provider covers both the {@code pickup} and the
* {@code dropoff} coordinates. This is used to check if a taxi can be used for an access/egress
* segment that doesn't end at a stop, for example the segment between the origin and a via
* location.
*/
boolean isCoveredByCommonProvider(WgsCoordinate pickup, WgsCoordinate dropoff);

/**
* Decorates the {@link TraverseMode#CAR} leg among an access or egress leg chain with taxi
* provider information, looking up the provider using the given logical {@code pickup} and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public Collection<NearbyStop> filterNearbyStops(
return taxiRouter.filterNearbyStops(transitService, nearbyStops, type, request);
}

@Override
public boolean isCoveredByCommonProvider(WgsCoordinate pickup, WgsCoordinate dropoff) {
return taxiRouteIndex.findFirstRoute(pickup, dropoff).isPresent();
}

@Override
public List<Leg> decorateAccessEgressLegs(
List<Leg> legs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.opentripplanner.place.api.NearbyStop;
import org.opentripplanner.routing.algorithm.raptoradapter.router.street.AccessEgressType;
import org.opentripplanner.routing.algorithm.raptoradapter.router.street.DirectStreetRouter;
import org.opentripplanner.routing.algorithm.raptoradapter.router.street.DirectStreetRouterFactory;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.linking.LinkingContext;
import org.opentripplanner.service.vehiclerental.VehicleRentalService;
Expand Down Expand Up @@ -63,7 +64,8 @@ public TaxiRouter(TaxiRouteIndex taxiRouteIndex) {

/**
* Routes a direct taxi itinerary by delegating to {@link DirectStreetRouter} and decorating the
* resulting itineraries with taxi provider information.
* resulting itineraries with taxi provider information. If the request has via locations, the
* taxi is only used from the origin to the first via location, and the rest is walked.
*/
public List<Itinerary> routeDirect(
Graph graph,
Expand All @@ -75,9 +77,17 @@ public List<Itinerary> routeDirect(
RouteRequest request,
LinkingContext linkingContext
) {
if (
request.isViaSearch() &&
request.listViaLocations().size() != request.listViaLocationsWithCoordinates().size()
) {
return List.of();
}
var siteResolver = new TransitServiceResolver(transitService);
var pickupOptional = siteResolver.findCoordinate(request.from());
var dropoffOptional = siteResolver.findCoordinate(request.to());
var dropoffOptional = request.isViaSearch()
? request.listVisitViaLocations().getFirst().coordinate()
: siteResolver.findCoordinate(request.to());
if (pickupOptional.isEmpty() || dropoffOptional.isEmpty()) {
return List.of();
}
Expand All @@ -88,7 +98,8 @@ public List<Itinerary> routeDirect(
return List.of();
}

var itineraries = DirectStreetRouter.route(
var router = DirectStreetRouterFactory.create(request);
var itineraries = router.route(
graph,
transitService,
streetLimitationParametersService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public DataFetcher<Object> node() {
var stopId = FeedScopedId.parseStrict(parts[1]);

// TODO: Add geometry
return new NearbyStop(stopId, Integer.parseInt(parts[0]), null, null);
return new NearbyStop(stopId, Integer.parseInt(parts[0]), List.of(), List.of());
}
case "TicketType":
// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,12 @@ private static Stream<NearbyStop> findTransfers(
.stream()
.filter(transfer -> transfer.to instanceof RegularStop)
.map(transfer ->
new NearbyStop(transfer.to.getId(), transfer.getDistanceMeters(), transfer.getEdges(), null)
new NearbyStop(
transfer.to.getId(),
transfer.getDistanceMeters(),
transfer.getEdges(),
List.of()
)
);
}

Expand Down
Loading