Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: 158 - Ensure GTFS and RAPTOR router have the same stop set #159

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
@@ -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
Loading