Skip to content

Commit

Permalink
Implement in-seat transfers per GTFS draft
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesj committed Feb 8, 2022
1 parent 2974ca9 commit 5b2eccf
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ class TransferMapper {
*/
private static final int FORBIDDEN = 3;

/**
* Passengers can transfer from one trip to another by staying onboard the same vehicle.
*/
private static final int STAY_SEATED = 4;

/**
* In-seat transfers are not allowed between sequential trips. The passenger must alight from the
* vehicle and re-board.
*/
private static final int NO_STAY_SEATED = 5;


private final RouteMapper routeMapper;

Expand Down Expand Up @@ -98,9 +109,12 @@ static TransferPriority mapTypeToPriority(int type) {
return TransferPriority.NOT_ALLOWED;
case GUARANTEED:
case MIN_TIME:
case NO_STAY_SEATED:
return TransferPriority.ALLOWED;
case RECOMMENDED:
return TransferPriority.RECOMMENDED;
case STAY_SEATED:
return TransferPriority.PREFERRED;
}
throw new IllegalArgumentException("Mapping missing for type: " + type);
}
Expand All @@ -125,6 +139,11 @@ ConstrainedTransfer map(org.onebusaway.gtfs.model.Transfer rhs) {
return null;
}

if (constraint.isStaySeated() && (fromTrip == null || toTrip == null)) {
LOG.warn("Transfer skipped - from_trip_id and to_trip_id must exist for in-seat transfer");
return null;
}

TransferPoint fromPoint = mapTransferPoint(rhs.getFromStop(), rhs.getFromRoute(), fromTrip, false);
TransferPoint toPoint = mapTransferPoint(rhs.getToStop(), rhs.getToRoute(), toTrip, true);

Expand All @@ -143,7 +162,15 @@ private TransferConstraint mapConstraint(Transfer rhs, Trip fromTrip, Trip toTri
var builder = TransferConstraint.create();

builder.guaranteed(rhs.getTransferType() == GUARANTEED);
builder.staySeated(sameBlockId(fromTrip, toTrip));

// A transfer is stay seated, if it is either explicitly mapped as such, or in the same block
// and not explicitly disallowed.
builder.staySeated(
rhs.getTransferType() == STAY_SEATED ||
(rhs.getTransferType() != NO_STAY_SEATED && sameBlockId(fromTrip, toTrip))

);

builder.priority(mapTypeToPriority(rhs.getTransferType()));

if(rhs.isMinTransferTimeSet()) {
Expand Down

0 comments on commit 5b2eccf

Please sign in to comment.