Skip to content

Commit

Permalink
FIX: 158 - Ensure GTFS and RAPTOR router have the same stop set
Browse files Browse the repository at this point in the history
- Add all stops to RAPTOR, even if they have no departures / stopping trips.
- When transfers are generated, it could be that connections from or to stops with no trips are available via a footpath / transfer as first or last leg.
  • Loading branch information
munterfi committed Dec 9, 2024
1 parent 38651a8 commit 189d7e5
Showing 1 changed file with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ch.naviqore.service.gtfs.raptor.convert;

import ch.naviqore.gtfs.schedule.model.GtfsSchedule;
import ch.naviqore.gtfs.schedule.model.Stop;
import ch.naviqore.gtfs.schedule.model.StopTime;
import ch.naviqore.gtfs.schedule.model.Transfer;
import ch.naviqore.gtfs.schedule.model.*;
import ch.naviqore.gtfs.schedule.type.TransferType;
import ch.naviqore.raptor.router.RaptorConfig;
import ch.naviqore.raptor.router.RaptorRouter;
Expand Down Expand Up @@ -47,7 +44,13 @@ public GtfsToRaptorConverter(GtfsSchedule schedule, List<TransferGenerator.Trans
public RaptorRouter convert() {
log.info("Converting {} trips from GTFS schedule to Raptor data model", schedule.getTrips().size());

for (var route : schedule.getRoutes().values()) {
for (Stop stop : schedule.getStops().values()) {
String stopId = stop.getId();
builder.addStop(stopId);
addedStops.add(stopId);
}

for (Route route : schedule.getRoutes().values()) {
for (GtfsRoutePartitioner.SubRoute subRoute : partitioner.getSubRoutes(route)) {
addRoute(subRoute);
}
Expand All @@ -60,17 +63,8 @@ public RaptorRouter convert() {

// add raptor route for each sub route of the gtfs routes
private void addRoute(GtfsRoutePartitioner.SubRoute subRoute) {

// add stops of sub route that are not already added
List<String> stopIds = subRoute.getStopsSequence().stream().map(Stop::getId).toList();
for (String stopId : stopIds) {
if (!addedStops.contains(stopId)) {
builder.addStop(stopId);
addedStops.add(stopId);
}
}

// add sub route as raptor route
List<String> stopIds = subRoute.getStopsSequence().stream().map(Stop::getId).toList();
builder.addRoute(subRoute.getId(), stopIds);

// add trips of sub route
Expand All @@ -88,11 +82,11 @@ private void addRoute(GtfsRoutePartitioner.SubRoute subRoute) {
/**
* Processes all types of transfers, ensuring the correct order of precedence:
* <p>
* 1. Additional transfers: These transfers have the lowest priority and are processed first.
* 2. Parent-child derived transfers: If a transfer is defined between two parent stops (e.g., A to B), this method
* derives corresponding transfers for their child stops (e.g., A1, A2, ... to B1, B2, ...).
* 3. GTFS schedule-defined transfers: Transfers explicitly defined in the GTFS schedule (e.g., A1 to B2) take the
* highest priority and are applied last, thereby overwriting transfers previously derived from parent stops.
* 1. Additional transfers: These transfers have the lowest priority and are processed first. 2. Parent-child
* derived transfers: If a transfer is defined between two parent stops (e.g., A to B), this method derives
* corresponding transfers for their child stops (e.g., A1, A2, ... to B1, B2, ...). 3. GTFS schedule-defined
* transfers: Transfers explicitly defined in the GTFS schedule (e.g., A1 to B2) take the highest priority and are
* applied last, thereby overwriting transfers previously derived from parent stops.
* <p>
* The method ensures that all transfers, whether additional, derived, or explicitly defined, are handled in the
* correct priority order.
Expand Down

0 comments on commit 189d7e5

Please sign in to comment.