Skip to content

Commit

Permalink
ENH: 158 - Reuse existing logic for GTFS to RAPTOR conversion
Browse files Browse the repository at this point in the history
- The RAPTOR should not contain all stops, due to the parent stops, which often have not got any departures but would increase the stop array size significantly.
  • Loading branch information
munterfi committed Jan 10, 2025
1 parent e293533 commit 8dbf6aa
Showing 1 changed file with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ 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 (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 @@ -63,12 +57,21 @@ public RaptorRouter convert() {

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

// 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
builder.addRoute(subRoute.getId(), stopIds);

// add trips of sub route
for (var trip : subRoute.getTrips()) {
for (Trip trip : subRoute.getTrips()) {
builder.addTrip(trip.getId(), subRoute.getId());
List<StopTime> stopTimes = trip.getStopTimes();
for (int i = 0; i < stopTimes.size(); i++) {
Expand All @@ -81,21 +84,12 @@ private void addRoute(GtfsRoutePartitioner.SubRoute subRoute) {

/**
* Processes all types of transfers, ensuring the correct order of precedence:
* <ol>
* <li>
* <b>Additional transfers:</b> These transfers have the lowest priority and are processed first.
* </li>
* <li>
* <b>Parent-child derived transfers:</b> 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, ...).
* </li>
* <li>
* <b>GTFS schedule-defined transfers:</b> Transfers explicitly defined in the GTFS schedule
* (e.g., A1 to B2) take the highest priority. These transfers are applied last,
* overwriting any transfers previously derived from parent stops.
* </li>
* </ol>
* <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.
* <p>
* The method ensures that all transfers, whether additional, derived, or explicitly defined, are handled in the
* correct priority order.
Expand Down Expand Up @@ -251,4 +245,4 @@ private Collection<TransferGenerator.Transfer> expandTransfersFromStop(Stop stop
return parentTransfers.values();
}

}
}

0 comments on commit 8dbf6aa

Please sign in to comment.