minotor 11.2.2 → 11.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/README.md +28 -0
- package/dist/cli.mjs +378 -127
- package/dist/cli.mjs.map +1 -1
- package/dist/gtfs/parser.d.ts +3 -1
- package/dist/gtfs/routes.d.ts +1 -2
- package/dist/gtfs/trips.d.ts +2 -1
- package/dist/parser.cjs.js +225 -81
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.d.ts +6 -2
- package/dist/parser.esm.js +224 -82
- package/dist/parser.esm.js.map +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +5 -3
- package/dist/router.esm.js +1 -1
- package/dist/router.esm.js.map +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/dist/routing/query.d.ts +20 -0
- package/dist/routing/rangeState.d.ts +1 -0
- package/dist/routing/raptor.d.ts +2 -0
- package/dist/routing/result.d.ts +1 -4
- package/dist/routing/route.d.ts +9 -5
- package/dist/routing/state.d.ts +11 -1
- package/dist/timetable/route.d.ts +9 -5
- package/dist/timetable/timetable.d.ts +24 -2
- package/dist/transfers/__tests__/straightLineTransferGenerator.test.d.ts +1 -0
- package/dist/transfers/generator.d.ts +40 -0
- package/dist/transfers/straightLineTransferGenerator.d.ts +58 -0
- package/dist/utils/map.d.ts +10 -0
- package/package.json +1 -1
- package/src/__e2e__/router.test.ts +6 -2
- package/src/cli/minotor.ts +21 -1
- package/src/cli/perf.ts +4 -2
- package/src/cli/repl.ts +55 -35
- package/src/gtfs/__tests__/parser.test.ts +29 -1
- package/src/gtfs/__tests__/routes.test.ts +4 -3
- package/src/gtfs/__tests__/transfers.test.ts +8 -8
- package/src/gtfs/__tests__/trips.test.ts +60 -24
- package/src/gtfs/parser.ts +50 -1
- package/src/gtfs/profiles/__tests__/extended.test.ts +2 -1
- package/src/gtfs/profiles/extended.ts +14 -14
- package/src/gtfs/profiles/standard.ts +11 -10
- package/src/gtfs/routes.ts +5 -2
- package/src/gtfs/transfers.ts +6 -5
- package/src/gtfs/trips.ts +7 -14
- package/src/parser.ts +20 -2
- package/src/router.ts +15 -6
- package/src/routing/__tests__/access.test.ts +14 -6
- package/src/routing/__tests__/plainRouter.test.ts +47 -23
- package/src/routing/__tests__/plotter.test.ts +8 -3
- package/src/routing/__tests__/rangeResult.test.ts +6 -2
- package/src/routing/__tests__/rangeRouter.test.ts +32 -6
- package/src/routing/__tests__/raptor.test.ts +157 -9
- package/src/routing/__tests__/result.test.ts +9 -4
- package/src/routing/__tests__/route.test.ts +3 -4
- package/src/routing/__tests__/router.test.ts +2 -1
- package/src/routing/access.ts +7 -4
- package/src/routing/plainRouter.ts +1 -0
- package/src/routing/plotter.ts +8 -3
- package/src/routing/query.ts +18 -0
- package/src/routing/rangeRouter.ts +2 -0
- package/src/routing/rangeState.ts +4 -0
- package/src/routing/raptor.ts +19 -9
- package/src/routing/result.ts +32 -14
- package/src/routing/route.ts +13 -10
- package/src/routing/state.ts +30 -0
- package/src/timetable/__tests__/io.test.ts +22 -10
- package/src/timetable/__tests__/route.test.ts +18 -24
- package/src/timetable/__tests__/timetable.test.ts +17 -11
- package/src/timetable/io.ts +30 -28
- package/src/timetable/route.ts +14 -7
- package/src/timetable/timetable.ts +77 -31
- package/src/transfers/README.md +97 -0
- package/src/transfers/__tests__/straightLineTransferGenerator.test.ts +204 -0
- package/src/transfers/generator.ts +45 -0
- package/src/transfers/straightLineTransferGenerator.ts +143 -0
- package/src/utils/map.ts +22 -0
package/dist/cli.mjs
CHANGED
|
@@ -15310,6 +15310,11 @@ function haverSinDist(lng1, lat1, lng2, lat2, cosLat1) {
|
|
|
15310
15310
|
return haverSinDistPartial(haverSinDLng, cosLat1, lat1, lat2);
|
|
15311
15311
|
}
|
|
15312
15312
|
|
|
15313
|
+
function distance(lng1, lat1, lng2, lat2) {
|
|
15314
|
+
const h = haverSinDist(lng1, lat1, lng2, lat2, Math.cos(lat1 * rad));
|
|
15315
|
+
return 2 * earthRadius * Math.asin(Math.sqrt(h));
|
|
15316
|
+
}
|
|
15317
|
+
|
|
15313
15318
|
function vertexLat(lat, haverSinDLng) {
|
|
15314
15319
|
const cosDLng = 1 - 2 * haverSinDLng;
|
|
15315
15320
|
if (cosDLng <= 0) return lat > 0 ? 90 : -90;
|
|
@@ -17109,10 +17114,12 @@ const durationToString = (duration) => {
|
|
|
17109
17114
|
}
|
|
17110
17115
|
};
|
|
17111
17116
|
|
|
17112
|
-
const
|
|
17113
|
-
|
|
17114
|
-
|
|
17115
|
-
|
|
17117
|
+
const PickUpDropOffTypes = {
|
|
17118
|
+
REGULAR: 0,
|
|
17119
|
+
NOT_AVAILABLE: 1,
|
|
17120
|
+
MUST_PHONE_AGENCY: 2,
|
|
17121
|
+
MUST_COORDINATE_WITH_DRIVER: 3,
|
|
17122
|
+
};
|
|
17116
17123
|
/**
|
|
17117
17124
|
* A route identifies all trips of a given service route sharing the same list of stops.
|
|
17118
17125
|
*/
|
|
@@ -17192,8 +17199,8 @@ let Route$1 = class Route {
|
|
|
17192
17199
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17193
17200
|
const stop = trip.stops[stopIndex];
|
|
17194
17201
|
const globalIndex = tripIndex * numStops + stopIndex;
|
|
17195
|
-
const pickUp = (_a = stop.pickUpType) !== null && _a !== void 0 ? _a : REGULAR;
|
|
17196
|
-
const dropOff = (_b = stop.dropOffType) !== null && _b !== void 0 ? _b : REGULAR;
|
|
17202
|
+
const pickUp = (_a = stop.pickUpType) !== null && _a !== void 0 ? _a : PickUpDropOffTypes.REGULAR;
|
|
17203
|
+
const dropOff = (_b = stop.dropOffType) !== null && _b !== void 0 ? _b : PickUpDropOffTypes.REGULAR;
|
|
17197
17204
|
const byteIndex = Math.floor(globalIndex / 2);
|
|
17198
17205
|
const isSecondPair = globalIndex % 2 === 1;
|
|
17199
17206
|
if (isSecondPair) {
|
|
@@ -17627,26 +17634,26 @@ const parseTransferType = (type) => {
|
|
|
17627
17634
|
case TransferType.TRANSFER_TYPE_UNSPECIFIED:
|
|
17628
17635
|
throw new Error('Unspecified protobuf transfer type.');
|
|
17629
17636
|
case TransferType.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:
|
|
17630
|
-
return
|
|
17637
|
+
return TransferTypes.RECOMMENDED;
|
|
17631
17638
|
case TransferType.TRANSFER_TYPE_TIMED_TRANSFER:
|
|
17632
|
-
return
|
|
17639
|
+
return TransferTypes.GUARANTEED;
|
|
17633
17640
|
case TransferType.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:
|
|
17634
|
-
return
|
|
17641
|
+
return TransferTypes.REQUIRES_MINIMAL_TIME;
|
|
17635
17642
|
case TransferType.TRANSFER_TYPE_IN_SEAT_TRANSFER:
|
|
17636
|
-
return
|
|
17643
|
+
return TransferTypes.IN_SEAT;
|
|
17637
17644
|
case TransferType.UNRECOGNIZED:
|
|
17638
17645
|
throw new Error('Unrecognized protobuf transfer type.');
|
|
17639
17646
|
}
|
|
17640
17647
|
};
|
|
17641
17648
|
const serializeTransferType = (type) => {
|
|
17642
17649
|
switch (type) {
|
|
17643
|
-
case
|
|
17650
|
+
case TransferTypes.RECOMMENDED:
|
|
17644
17651
|
return TransferType.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;
|
|
17645
|
-
case
|
|
17652
|
+
case TransferTypes.GUARANTEED:
|
|
17646
17653
|
return TransferType.TRANSFER_TYPE_TIMED_TRANSFER;
|
|
17647
|
-
case
|
|
17654
|
+
case TransferTypes.REQUIRES_MINIMAL_TIME:
|
|
17648
17655
|
return TransferType.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;
|
|
17649
|
-
case
|
|
17656
|
+
case TransferTypes.IN_SEAT:
|
|
17650
17657
|
return TransferType.TRANSFER_TYPE_IN_SEAT_TRANSFER;
|
|
17651
17658
|
}
|
|
17652
17659
|
};
|
|
@@ -17655,25 +17662,25 @@ const parseRouteType = (type) => {
|
|
|
17655
17662
|
case RouteType.ROUTE_TYPE_UNSPECIFIED:
|
|
17656
17663
|
throw new Error('Unspecified protobuf route type.');
|
|
17657
17664
|
case RouteType.ROUTE_TYPE_TRAM:
|
|
17658
|
-
return
|
|
17665
|
+
return RouteTypes.TRAM;
|
|
17659
17666
|
case RouteType.ROUTE_TYPE_SUBWAY:
|
|
17660
|
-
return
|
|
17667
|
+
return RouteTypes.SUBWAY;
|
|
17661
17668
|
case RouteType.ROUTE_TYPE_RAIL:
|
|
17662
|
-
return
|
|
17669
|
+
return RouteTypes.RAIL;
|
|
17663
17670
|
case RouteType.ROUTE_TYPE_BUS:
|
|
17664
|
-
return
|
|
17671
|
+
return RouteTypes.BUS;
|
|
17665
17672
|
case RouteType.ROUTE_TYPE_FERRY:
|
|
17666
|
-
return
|
|
17673
|
+
return RouteTypes.FERRY;
|
|
17667
17674
|
case RouteType.ROUTE_TYPE_CABLE_TRAM:
|
|
17668
|
-
return
|
|
17675
|
+
return RouteTypes.CABLE_TRAM;
|
|
17669
17676
|
case RouteType.ROUTE_TYPE_AERIAL_LIFT:
|
|
17670
|
-
return
|
|
17677
|
+
return RouteTypes.AERIAL_LIFT;
|
|
17671
17678
|
case RouteType.ROUTE_TYPE_FUNICULAR:
|
|
17672
|
-
return
|
|
17679
|
+
return RouteTypes.FUNICULAR;
|
|
17673
17680
|
case RouteType.ROUTE_TYPE_TROLLEYBUS:
|
|
17674
|
-
return
|
|
17681
|
+
return RouteTypes.TROLLEYBUS;
|
|
17675
17682
|
case RouteType.ROUTE_TYPE_MONORAIL:
|
|
17676
|
-
return
|
|
17683
|
+
return RouteTypes.MONORAIL;
|
|
17677
17684
|
case RouteType.UNRECOGNIZED:
|
|
17678
17685
|
default:
|
|
17679
17686
|
throw new Error('Unrecognized protobuf route type.');
|
|
@@ -17681,25 +17688,25 @@ const parseRouteType = (type) => {
|
|
|
17681
17688
|
};
|
|
17682
17689
|
const serializeRouteType = (type) => {
|
|
17683
17690
|
switch (type) {
|
|
17684
|
-
case
|
|
17691
|
+
case RouteTypes.TRAM:
|
|
17685
17692
|
return RouteType.ROUTE_TYPE_TRAM;
|
|
17686
|
-
case
|
|
17693
|
+
case RouteTypes.SUBWAY:
|
|
17687
17694
|
return RouteType.ROUTE_TYPE_SUBWAY;
|
|
17688
|
-
case
|
|
17695
|
+
case RouteTypes.RAIL:
|
|
17689
17696
|
return RouteType.ROUTE_TYPE_RAIL;
|
|
17690
|
-
case
|
|
17697
|
+
case RouteTypes.BUS:
|
|
17691
17698
|
return RouteType.ROUTE_TYPE_BUS;
|
|
17692
|
-
case
|
|
17699
|
+
case RouteTypes.FERRY:
|
|
17693
17700
|
return RouteType.ROUTE_TYPE_FERRY;
|
|
17694
|
-
case
|
|
17701
|
+
case RouteTypes.CABLE_TRAM:
|
|
17695
17702
|
return RouteType.ROUTE_TYPE_CABLE_TRAM;
|
|
17696
|
-
case
|
|
17703
|
+
case RouteTypes.AERIAL_LIFT:
|
|
17697
17704
|
return RouteType.ROUTE_TYPE_AERIAL_LIFT;
|
|
17698
|
-
case
|
|
17705
|
+
case RouteTypes.FUNICULAR:
|
|
17699
17706
|
return RouteType.ROUTE_TYPE_FUNICULAR;
|
|
17700
|
-
case
|
|
17707
|
+
case RouteTypes.TROLLEYBUS:
|
|
17701
17708
|
return RouteType.ROUTE_TYPE_TROLLEYBUS;
|
|
17702
|
-
case
|
|
17709
|
+
case RouteTypes.MONORAIL:
|
|
17703
17710
|
return RouteType.ROUTE_TYPE_MONORAIL;
|
|
17704
17711
|
}
|
|
17705
17712
|
};
|
|
@@ -17741,18 +17748,25 @@ const deserializeTripTransfers = (protoTripTransfer) => {
|
|
|
17741
17748
|
};
|
|
17742
17749
|
|
|
17743
17750
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
17744
|
-
const
|
|
17745
|
-
|
|
17746
|
-
|
|
17747
|
-
|
|
17748
|
-
|
|
17749
|
-
|
|
17750
|
-
|
|
17751
|
-
|
|
17752
|
-
|
|
17753
|
-
|
|
17754
|
-
|
|
17755
|
-
|
|
17751
|
+
const TransferTypes = {
|
|
17752
|
+
RECOMMENDED: 1,
|
|
17753
|
+
GUARANTEED: 2,
|
|
17754
|
+
REQUIRES_MINIMAL_TIME: 3,
|
|
17755
|
+
IN_SEAT: 4,
|
|
17756
|
+
};
|
|
17757
|
+
const RouteTypes = {
|
|
17758
|
+
TRAM: 1,
|
|
17759
|
+
SUBWAY: 2,
|
|
17760
|
+
RAIL: 3,
|
|
17761
|
+
BUS: 4,
|
|
17762
|
+
FERRY: 5,
|
|
17763
|
+
CABLE_TRAM: 6,
|
|
17764
|
+
AERIAL_LIFT: 7,
|
|
17765
|
+
FUNICULAR: 8,
|
|
17766
|
+
TROLLEYBUS: 9,
|
|
17767
|
+
MONORAIL: 10,
|
|
17768
|
+
};
|
|
17769
|
+
const ALL_TRANSPORT_MODES = new Set(Object.values(RouteTypes));
|
|
17756
17770
|
const EMPTY_TRIP_BOARDINGS = [];
|
|
17757
17771
|
/**
|
|
17758
17772
|
* The internal transit timetable format.
|
|
@@ -17977,7 +17991,7 @@ class Timetable {
|
|
|
17977
17991
|
const nbTrips = route.getNbTrips();
|
|
17978
17992
|
for (let t = earliestTrip; t < (beforeTrip !== null && beforeTrip !== void 0 ? beforeTrip : nbTrips); t++) {
|
|
17979
17993
|
const pickup = route.pickUpTypeFrom(stopIndex, t);
|
|
17980
|
-
if (pickup === NOT_AVAILABLE) {
|
|
17994
|
+
if (pickup === PickUpDropOffTypes.NOT_AVAILABLE) {
|
|
17981
17995
|
continue;
|
|
17982
17996
|
}
|
|
17983
17997
|
if (fromTripStop === undefined) {
|
|
@@ -18016,6 +18030,61 @@ class Timetable {
|
|
|
18016
18030
|
return guaranteedTripTransfers;
|
|
18017
18031
|
}
|
|
18018
18032
|
}
|
|
18033
|
+
const routeTypeToString = (type) => {
|
|
18034
|
+
switch (type) {
|
|
18035
|
+
case RouteTypes.TRAM:
|
|
18036
|
+
return 'TRAM';
|
|
18037
|
+
case RouteTypes.SUBWAY:
|
|
18038
|
+
return 'SUBWAY';
|
|
18039
|
+
case RouteTypes.RAIL:
|
|
18040
|
+
return 'RAIL';
|
|
18041
|
+
case RouteTypes.BUS:
|
|
18042
|
+
return 'BUS';
|
|
18043
|
+
case RouteTypes.FERRY:
|
|
18044
|
+
return 'FERRY';
|
|
18045
|
+
case RouteTypes.CABLE_TRAM:
|
|
18046
|
+
return 'CABLE_TRAM';
|
|
18047
|
+
case RouteTypes.AERIAL_LIFT:
|
|
18048
|
+
return 'AERIAL_LIFT';
|
|
18049
|
+
case RouteTypes.FUNICULAR:
|
|
18050
|
+
return 'FUNICULAR';
|
|
18051
|
+
case RouteTypes.TROLLEYBUS:
|
|
18052
|
+
return 'TROLLEYBUS';
|
|
18053
|
+
case RouteTypes.MONORAIL:
|
|
18054
|
+
return 'MONORAIL';
|
|
18055
|
+
}
|
|
18056
|
+
};
|
|
18057
|
+
const transferTypeToString = (type) => {
|
|
18058
|
+
switch (type) {
|
|
18059
|
+
case TransferTypes.RECOMMENDED:
|
|
18060
|
+
return 'RECOMMENDED';
|
|
18061
|
+
case TransferTypes.GUARANTEED:
|
|
18062
|
+
return 'GUARANTEED';
|
|
18063
|
+
case TransferTypes.REQUIRES_MINIMAL_TIME:
|
|
18064
|
+
return 'REQUIRES_MINIMAL_TIME';
|
|
18065
|
+
case TransferTypes.IN_SEAT:
|
|
18066
|
+
return 'IN_SEAT';
|
|
18067
|
+
}
|
|
18068
|
+
};
|
|
18069
|
+
|
|
18070
|
+
/**
|
|
18071
|
+
* Returns the value stored under `key`, inserting and returning `defaultValue`
|
|
18072
|
+
* when the key is absent. Mirrors the TC39 `Map.prototype.getOrInsert`
|
|
18073
|
+
* proposal.
|
|
18074
|
+
*
|
|
18075
|
+
* TODO: remove this helper and call `map.getOrInsert(key, defaultValue)`
|
|
18076
|
+
* directly once we only target Node 26+ (where the method is built in).
|
|
18077
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/getOrInsert
|
|
18078
|
+
*/
|
|
18079
|
+
const getOrInsert = (map, key, defaultValue) => {
|
|
18080
|
+
if (map.has(key)) {
|
|
18081
|
+
// Key is present, so `get` returns the stored value (which may itself be a
|
|
18082
|
+
// legitimately-stored `undefined`).
|
|
18083
|
+
return map.get(key);
|
|
18084
|
+
}
|
|
18085
|
+
map.set(key, defaultValue);
|
|
18086
|
+
return defaultValue;
|
|
18087
|
+
};
|
|
18019
18088
|
|
|
18020
18089
|
const toGtfsDate = (date) => {
|
|
18021
18090
|
return parseInt(date.toFormat('yyyyLLdd'));
|
|
@@ -20028,25 +20097,25 @@ const standardGtfsProfile = {
|
|
|
20028
20097
|
routeTypeParser: (routeType) => {
|
|
20029
20098
|
switch (routeType) {
|
|
20030
20099
|
case 0:
|
|
20031
|
-
return
|
|
20100
|
+
return RouteTypes.TRAM;
|
|
20032
20101
|
case 1:
|
|
20033
|
-
return
|
|
20102
|
+
return RouteTypes.SUBWAY;
|
|
20034
20103
|
case 2:
|
|
20035
|
-
return
|
|
20104
|
+
return RouteTypes.RAIL;
|
|
20036
20105
|
case 3:
|
|
20037
|
-
return
|
|
20106
|
+
return RouteTypes.BUS;
|
|
20038
20107
|
case 4:
|
|
20039
|
-
return
|
|
20108
|
+
return RouteTypes.FERRY;
|
|
20040
20109
|
case 5:
|
|
20041
|
-
return
|
|
20110
|
+
return RouteTypes.CABLE_TRAM;
|
|
20042
20111
|
case 6:
|
|
20043
|
-
return
|
|
20112
|
+
return RouteTypes.AERIAL_LIFT;
|
|
20044
20113
|
case 7:
|
|
20045
|
-
return
|
|
20114
|
+
return RouteTypes.FUNICULAR;
|
|
20046
20115
|
case 11:
|
|
20047
|
-
return
|
|
20116
|
+
return RouteTypes.TROLLEYBUS;
|
|
20048
20117
|
case 12:
|
|
20049
|
-
return
|
|
20118
|
+
return RouteTypes.MONORAIL;
|
|
20050
20119
|
default:
|
|
20051
20120
|
return undefined;
|
|
20052
20121
|
}
|
|
@@ -20320,7 +20389,7 @@ const processGuaranteedStopTransfer = (transferEntry, fromStop, toStop, transfer
|
|
|
20320
20389
|
log.warn(`Unsupported transfer of type ${transferEntry.transfer_type} between routes ${transferEntry.from_route_id} and ${transferEntry.to_route_id}.`);
|
|
20321
20390
|
return;
|
|
20322
20391
|
}
|
|
20323
|
-
const transfer = Object.assign({ destination: toStop, type:
|
|
20392
|
+
const transfer = Object.assign({ destination: toStop, type: TransferTypes.GUARANTEED }, (transferEntry.min_transfer_time !== undefined && {
|
|
20324
20393
|
minTransferTime: durationFromSeconds(transferEntry.min_transfer_time),
|
|
20325
20394
|
}));
|
|
20326
20395
|
const fromStopTransfers = transfers.get(fromStop) || [];
|
|
@@ -20510,13 +20579,13 @@ const parseGtfsTransferType = (gtfsTransferType) => {
|
|
|
20510
20579
|
switch (gtfsTransferType) {
|
|
20511
20580
|
case 0:
|
|
20512
20581
|
default:
|
|
20513
|
-
return
|
|
20582
|
+
return TransferTypes.RECOMMENDED;
|
|
20514
20583
|
case 1:
|
|
20515
|
-
return
|
|
20584
|
+
return TransferTypes.GUARANTEED;
|
|
20516
20585
|
case 2:
|
|
20517
|
-
return
|
|
20586
|
+
return TransferTypes.REQUIRES_MINIMAL_TIME;
|
|
20518
20587
|
case 4:
|
|
20519
|
-
return
|
|
20588
|
+
return TransferTypes.IN_SEAT;
|
|
20520
20589
|
}
|
|
20521
20590
|
};
|
|
20522
20591
|
|
|
@@ -20865,15 +20934,15 @@ const parseStopTimes = (stopTimesStream, stopsMap, activeTripIds, activeStopIds,
|
|
|
20865
20934
|
const parsePickupDropOffType = (gtfsType) => {
|
|
20866
20935
|
switch (gtfsType) {
|
|
20867
20936
|
default:
|
|
20868
|
-
return REGULAR;
|
|
20937
|
+
return PickUpDropOffTypes.REGULAR;
|
|
20869
20938
|
case '0':
|
|
20870
|
-
return REGULAR;
|
|
20939
|
+
return PickUpDropOffTypes.REGULAR;
|
|
20871
20940
|
case '1':
|
|
20872
|
-
return NOT_AVAILABLE;
|
|
20941
|
+
return PickUpDropOffTypes.NOT_AVAILABLE;
|
|
20873
20942
|
case '2':
|
|
20874
|
-
return MUST_PHONE_AGENCY;
|
|
20943
|
+
return PickUpDropOffTypes.MUST_PHONE_AGENCY;
|
|
20875
20944
|
case '3':
|
|
20876
|
-
return MUST_COORDINATE_WITH_DRIVER;
|
|
20945
|
+
return PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER;
|
|
20877
20946
|
}
|
|
20878
20947
|
};
|
|
20879
20948
|
|
|
@@ -20886,10 +20955,11 @@ const STOP_TIMES_FILE = 'stop_times.txt';
|
|
|
20886
20955
|
const STOPS_FILE = 'stops.txt';
|
|
20887
20956
|
const TRANSFERS_FILE = 'transfers.txt';
|
|
20888
20957
|
class GtfsParser {
|
|
20889
|
-
constructor(path, profile = standardGtfsProfile) {
|
|
20958
|
+
constructor(path, profile = standardGtfsProfile, transferGenerator) {
|
|
20890
20959
|
// TODO: support input from multiple sources
|
|
20891
20960
|
this.path = path;
|
|
20892
20961
|
this.profile = profile;
|
|
20962
|
+
this.transferGenerator = transferGenerator;
|
|
20893
20963
|
}
|
|
20894
20964
|
/**
|
|
20895
20965
|
* Parses a GTFS feed to extract all the data relevant to a given day in a transit-planner friendly format.
|
|
@@ -20969,6 +21039,35 @@ class GtfsParser {
|
|
|
20969
21039
|
const serviceRoutes = indexRoutes(validGtfsRoutes, serviceRoutesMap);
|
|
20970
21040
|
const stopTimesEnd = performance.now();
|
|
20971
21041
|
log.info(`${routes.length} valid unique routes. (${(stopTimesEnd - stopTimesStart).toFixed(2)}ms)`);
|
|
21042
|
+
if (this.transferGenerator) {
|
|
21043
|
+
log.info('Generating virtual transfers');
|
|
21044
|
+
const virtualTransfersStart = performance.now();
|
|
21045
|
+
// Only route-served stops with coordinates are worth connecting: a
|
|
21046
|
+
// transfer to a stop no route calls at is a dead end for the router.
|
|
21047
|
+
const originStops = Array.from(parsedStops.values()).filter((stop) => activeStopIds.has(stop.id) &&
|
|
21048
|
+
stop.lat !== undefined &&
|
|
21049
|
+
stop.lon !== undefined);
|
|
21050
|
+
const stopsIndex = new StopsIndex(Array.from(parsedStops.values()));
|
|
21051
|
+
const generatedTransfers = yield this.transferGenerator.generate(originStops, stopsIndex);
|
|
21052
|
+
let addedTransfers = 0;
|
|
21053
|
+
for (const [fromStop, newTransfers] of generatedTransfers) {
|
|
21054
|
+
const existing = getOrInsert(transfers, fromStop, []);
|
|
21055
|
+
// Deduplicate per directed pair against existing (feed) transfers, and
|
|
21056
|
+
// only keep transfers into stops a route actually calls at.
|
|
21057
|
+
const connected = new Set(existing.map((t) => t.destination));
|
|
21058
|
+
for (const transfer of newTransfers) {
|
|
21059
|
+
if (!activeStopIds.has(transfer.destination) ||
|
|
21060
|
+
connected.has(transfer.destination)) {
|
|
21061
|
+
continue;
|
|
21062
|
+
}
|
|
21063
|
+
connected.add(transfer.destination);
|
|
21064
|
+
existing.push(transfer);
|
|
21065
|
+
addedTransfers += 1;
|
|
21066
|
+
}
|
|
21067
|
+
}
|
|
21068
|
+
const virtualTransfersEnd = performance.now();
|
|
21069
|
+
log.info(`${addedTransfers} virtual transfers added. (${(virtualTransfersEnd - virtualTransfersStart).toFixed(2)}ms)`);
|
|
21070
|
+
}
|
|
20972
21071
|
log.info('Building stops adjacency structure');
|
|
20973
21072
|
const stopsAdjacencyStart = performance.now();
|
|
20974
21073
|
const stopsAdjacency = buildStopsAdjacencyStructure(serviceRoutes, routes, transfers, parsedStops.size, activeStopIds);
|
|
@@ -21041,7 +21140,7 @@ const routeTypeParser = (routeType) => {
|
|
|
21041
21140
|
case 115: // Vehicle Transport Rail Service
|
|
21042
21141
|
case 116: // Rack and Pinion Railway (Rochers de Naye, Dolderbahn)
|
|
21043
21142
|
case 117: // Additional Rail Service
|
|
21044
|
-
return
|
|
21143
|
+
return RouteTypes.RAIL;
|
|
21045
21144
|
// Coach Service (200-299)
|
|
21046
21145
|
case 200: // Coach Service
|
|
21047
21146
|
case 201: // International Coach Service (EuroLine, Touring)
|
|
@@ -21053,16 +21152,16 @@ const routeTypeParser = (routeType) => {
|
|
|
21053
21152
|
case 207: // Tourist Coach Service
|
|
21054
21153
|
case 208: // Commuter Coach Service
|
|
21055
21154
|
case 209: // All Coach Services
|
|
21056
|
-
return
|
|
21155
|
+
return RouteTypes.BUS;
|
|
21057
21156
|
// Urban Railway Service (400-499)
|
|
21058
21157
|
case 400: // Urban Railway Service
|
|
21059
21158
|
case 401: // Metro Service (Métro de Paris)
|
|
21060
21159
|
case 402: // Underground Service (London Underground, U-Bahn)
|
|
21061
21160
|
case 403: // Urban Railway Service
|
|
21062
21161
|
case 404: // All Urban Railway Services
|
|
21063
|
-
return
|
|
21162
|
+
return RouteTypes.SUBWAY;
|
|
21064
21163
|
case 405: // Monorail
|
|
21065
|
-
return
|
|
21164
|
+
return RouteTypes.MONORAIL;
|
|
21066
21165
|
// Bus Service (700-799)
|
|
21067
21166
|
case 700: // Bus Service
|
|
21068
21167
|
case 701: // Regional Bus Service (Eastbourne-Maidstone)
|
|
@@ -21081,10 +21180,10 @@ const routeTypeParser = (routeType) => {
|
|
|
21081
21180
|
case 714: // Rail Replacement Bus Service
|
|
21082
21181
|
case 715: // Demand and Response Bus Service
|
|
21083
21182
|
case 716: // All Bus Services
|
|
21084
|
-
return
|
|
21183
|
+
return RouteTypes.BUS;
|
|
21085
21184
|
// Trolleybus Service (800-899)
|
|
21086
21185
|
case 800: // Trolleybus Service
|
|
21087
|
-
return
|
|
21186
|
+
return RouteTypes.TROLLEYBUS;
|
|
21088
21187
|
// Tram Service (900-999)
|
|
21089
21188
|
case 900: // Tram Service
|
|
21090
21189
|
case 901: // City Tram Service
|
|
@@ -21093,16 +21192,16 @@ const routeTypeParser = (routeType) => {
|
|
|
21093
21192
|
case 904: // Sightseeing Tram Service (Blackpool Seafront)
|
|
21094
21193
|
case 905: // Shuttle Tram Service
|
|
21095
21194
|
case 906: // All Tram Services
|
|
21096
|
-
return
|
|
21195
|
+
return RouteTypes.TRAM;
|
|
21097
21196
|
// Water Transport Service (1000-1099)
|
|
21098
21197
|
case 1000: // Water Transport Service
|
|
21099
|
-
return
|
|
21198
|
+
return RouteTypes.FERRY;
|
|
21100
21199
|
// Air Service (1100-1199)
|
|
21101
21200
|
case 1100: // Air Service
|
|
21102
21201
|
return undefined;
|
|
21103
21202
|
// Ferry Service (1200-1299)
|
|
21104
21203
|
case 1200: // Ferry Service
|
|
21105
|
-
return
|
|
21204
|
+
return RouteTypes.FERRY;
|
|
21106
21205
|
// Aerial Lift Service (1300-1399)
|
|
21107
21206
|
case 1300: // Aerial Lift Service (Telefèric de Montjuïc, Roosevelt Island Tramway)
|
|
21108
21207
|
case 1301: // Telecabin Service
|
|
@@ -21111,10 +21210,10 @@ const routeTypeParser = (routeType) => {
|
|
|
21111
21210
|
case 1305: // Drag Lift Service
|
|
21112
21211
|
case 1306: // Small Telecabin Service
|
|
21113
21212
|
case 1307: // All Telecabin Services
|
|
21114
|
-
return
|
|
21213
|
+
return RouteTypes.AERIAL_LIFT;
|
|
21115
21214
|
case 1303: // Elevator Service (Ascenseur, Aufzug)
|
|
21116
21215
|
case 1400: // Funicular Service (Rigiblick)
|
|
21117
|
-
return
|
|
21216
|
+
return RouteTypes.FUNICULAR;
|
|
21118
21217
|
// Taxi Service (1500-1599)
|
|
21119
21218
|
case 1500: // Taxi Service
|
|
21120
21219
|
case 1502: // Water Taxi Service
|
|
@@ -21125,12 +21224,12 @@ const routeTypeParser = (routeType) => {
|
|
|
21125
21224
|
case 1507: // All Taxi Services
|
|
21126
21225
|
return undefined;
|
|
21127
21226
|
case 1501: // Communal Taxi Service (Marshrutka, dolmuş)
|
|
21128
|
-
return
|
|
21227
|
+
return RouteTypes.BUS;
|
|
21129
21228
|
// Miscellaneous Service (1700-1799)
|
|
21130
21229
|
case 1700: // Miscellaneous Service / Unknown mode
|
|
21131
21230
|
return undefined;
|
|
21132
21231
|
case 1702: // Horse-drawn Carriage
|
|
21133
|
-
return
|
|
21232
|
+
return RouteTypes.BUS;
|
|
21134
21233
|
default:
|
|
21135
21234
|
return undefined;
|
|
21136
21235
|
}
|
|
@@ -21139,6 +21238,85 @@ const extendedGtfsProfile = {
|
|
|
21139
21238
|
routeTypeParser,
|
|
21140
21239
|
};
|
|
21141
21240
|
|
|
21241
|
+
const DEFAULT_MAX_DISTANCE_METERS = 500;
|
|
21242
|
+
const DEFAULT_WALKING_SPEED_KMH = 4;
|
|
21243
|
+
const DEFAULT_DETOUR_FACTOR = 1.3;
|
|
21244
|
+
const DEFAULT_CHANGE_PENALTY_MINUTES = 3;
|
|
21245
|
+
/**
|
|
21246
|
+
* A {@link TransferGenerator} that connects geographically close stops with
|
|
21247
|
+
* virtual walking transfers.
|
|
21248
|
+
*
|
|
21249
|
+
* The transfer time is derived from the straight-line (great-circle / haversine)
|
|
21250
|
+
* distance between two stops, scaled up by a detour factor to approximate the
|
|
21251
|
+
* real walking path and divided by an assumed walking speed. This is a
|
|
21252
|
+
* deliberately crude heuristic meant to fill in footpaths for feeds that
|
|
21253
|
+
* under-specify `transfers.txt` (e.g. large interchanges where subway, tram and
|
|
21254
|
+
* bus stops sit close together but are left unconnected).
|
|
21255
|
+
*
|
|
21256
|
+
* Generated transfers use {@link TransferTypes.REQUIRES_MINIMAL_TIME} so they
|
|
21257
|
+
* are treated as walking connections by both the router's transfer step and
|
|
21258
|
+
* its access/egress computation. Each origin is connected to its nearby stops
|
|
21259
|
+
* with a single directed edge; the reverse edge is produced when the neighbor
|
|
21260
|
+
* is itself visited as an origin.
|
|
21261
|
+
*
|
|
21262
|
+
* On top of the walking time, a flat `changePenaltyMinutes` is added for the
|
|
21263
|
+
* general overhead of any change. It is symmetric, so the two directions of a
|
|
21264
|
+
* transfer share the same minimum time.
|
|
21265
|
+
*/
|
|
21266
|
+
class StraightLineTransferGenerator {
|
|
21267
|
+
constructor(options = {}) {
|
|
21268
|
+
var _a, _b, _c, _d;
|
|
21269
|
+
this.maxDistanceMeters =
|
|
21270
|
+
(_a = options.maxDistanceMeters) !== null && _a !== void 0 ? _a : DEFAULT_MAX_DISTANCE_METERS;
|
|
21271
|
+
this.walkingSpeedKmh = (_b = options.walkingSpeedKmh) !== null && _b !== void 0 ? _b : DEFAULT_WALKING_SPEED_KMH;
|
|
21272
|
+
this.detourFactor = (_c = options.detourFactor) !== null && _c !== void 0 ? _c : DEFAULT_DETOUR_FACTOR;
|
|
21273
|
+
this.changePenaltyMinutes =
|
|
21274
|
+
(_d = options.changePenaltyMinutes) !== null && _d !== void 0 ? _d : DEFAULT_CHANGE_PENALTY_MINUTES;
|
|
21275
|
+
}
|
|
21276
|
+
generate(originStops, stops) {
|
|
21277
|
+
const generated = new Map();
|
|
21278
|
+
const maxDistanceKm = this.maxDistanceMeters / 1000;
|
|
21279
|
+
for (const origin of originStops) {
|
|
21280
|
+
const { id, lat, lon } = origin;
|
|
21281
|
+
if (lat === undefined || lon === undefined) {
|
|
21282
|
+
continue;
|
|
21283
|
+
}
|
|
21284
|
+
const neighbors = stops.findStopsByLocation(lat, lon, Infinity, maxDistanceKm);
|
|
21285
|
+
for (const neighbor of neighbors) {
|
|
21286
|
+
const { id: neighborId, lat: neighborLat, lon: neighborLon } = neighbor;
|
|
21287
|
+
if (neighborId === id ||
|
|
21288
|
+
neighborLat === undefined ||
|
|
21289
|
+
neighborLon === undefined) {
|
|
21290
|
+
continue;
|
|
21291
|
+
}
|
|
21292
|
+
const walkingTime = this.walkingDuration(lon, lat, neighborLon, neighborLat);
|
|
21293
|
+
// Emit a single directed edge; the reverse edge is emitted when the
|
|
21294
|
+
// neighbor is itself visited as an origin. The penalty is symmetric, so
|
|
21295
|
+
// both directions end up with the same minimum time.
|
|
21296
|
+
const minTransferTime = walkingTime + this.changePenaltyMinutes;
|
|
21297
|
+
this.addTransfer(generated, id, neighborId, minTransferTime);
|
|
21298
|
+
}
|
|
21299
|
+
}
|
|
21300
|
+
return generated;
|
|
21301
|
+
}
|
|
21302
|
+
addTransfer(transfers, from, to, minTransferTime) {
|
|
21303
|
+
const transfer = {
|
|
21304
|
+
destination: to,
|
|
21305
|
+
type: TransferTypes.REQUIRES_MINIMAL_TIME,
|
|
21306
|
+
minTransferTime,
|
|
21307
|
+
};
|
|
21308
|
+
getOrInsert(transfers, from, []).push(transfer);
|
|
21309
|
+
}
|
|
21310
|
+
/**
|
|
21311
|
+
* Estimates the walking time between two coordinates, in whole minutes.
|
|
21312
|
+
*/
|
|
21313
|
+
walkingDuration(lon1, lat1, lon2, lat2) {
|
|
21314
|
+
const straightLineKm = distance(lon1, lat1, lon2, lat2);
|
|
21315
|
+
const walkingKm = straightLineKm * this.detourFactor;
|
|
21316
|
+
return Math.round((walkingKm / this.walkingSpeedKmh) * 60);
|
|
21317
|
+
}
|
|
21318
|
+
}
|
|
21319
|
+
|
|
21142
21320
|
/**
|
|
21143
21321
|
* Configuration for DOT graph styling.
|
|
21144
21322
|
*/
|
|
@@ -21393,7 +21571,7 @@ class Plotter {
|
|
|
21393
21571
|
const routeOvalId = this.vehicleEdgeNodeId(fromStopId, toStopId, edge.routeId, round);
|
|
21394
21572
|
const serviceRouteInfo = this.result.timetable.getServiceRouteInfo(route);
|
|
21395
21573
|
const routeName = serviceRouteInfo.name;
|
|
21396
|
-
const routeType = serviceRouteInfo.type;
|
|
21574
|
+
const routeType = routeTypeToString(serviceRouteInfo.type);
|
|
21397
21575
|
const departureTime = timeToString(route.departureFrom(edge.stopIndex, edge.tripIndex));
|
|
21398
21576
|
const arrivalTime = timeToString(edge.arrival);
|
|
21399
21577
|
const escapedRouteName = this.escapeDotString(routeName);
|
|
@@ -21465,8 +21643,12 @@ class Plotter {
|
|
|
21465
21643
|
: null;
|
|
21466
21644
|
const fromRouteName = (_a = fromServiceRouteInfo === null || fromServiceRouteInfo === void 0 ? void 0 : fromServiceRouteInfo.name) !== null && _a !== void 0 ? _a : `Route ${String(fromEdge.routeId)}`;
|
|
21467
21645
|
const toRouteName = (_b = toServiceRouteInfo === null || toServiceRouteInfo === void 0 ? void 0 : toServiceRouteInfo.name) !== null && _b !== void 0 ? _b : `Route ${String(toEdge.routeId)}`;
|
|
21468
|
-
const fromRouteType =
|
|
21469
|
-
|
|
21646
|
+
const fromRouteType = fromServiceRouteInfo
|
|
21647
|
+
? routeTypeToString(fromServiceRouteInfo.type)
|
|
21648
|
+
: 'UNKNOWN';
|
|
21649
|
+
const toRouteType = toServiceRouteInfo
|
|
21650
|
+
? routeTypeToString(toServiceRouteInfo.type)
|
|
21651
|
+
: 'UNKNOWN';
|
|
21470
21652
|
const fromArrivalTime = timeToString(fromEdge.arrival);
|
|
21471
21653
|
const toDepartureTime = toRoute
|
|
21472
21654
|
? timeToString(toRoute.departureFrom(toEdge.stopIndex, toEdge.tripIndex))
|
|
@@ -21659,6 +21841,15 @@ Query.Builder = class {
|
|
|
21659
21841
|
this.optionsValue.transportModes = transportModes;
|
|
21660
21842
|
return this;
|
|
21661
21843
|
}
|
|
21844
|
+
/**
|
|
21845
|
+
* Sets the maximum total journey duration (in minutes) from the query
|
|
21846
|
+
* departure time. The limit includes initial access, waiting time, transit
|
|
21847
|
+
* legs, and transfers.
|
|
21848
|
+
*/
|
|
21849
|
+
maxDuration(maxDuration) {
|
|
21850
|
+
this.optionsValue.maxDuration = maxDuration;
|
|
21851
|
+
return this;
|
|
21852
|
+
}
|
|
21662
21853
|
/**
|
|
21663
21854
|
* Sets the maximum time (in minutes) the traveler is willing to wait at
|
|
21664
21855
|
* the first boarding stop before the first transit vehicle departs.
|
|
@@ -21812,6 +22003,9 @@ class Route {
|
|
|
21812
22003
|
}
|
|
21813
22004
|
}
|
|
21814
22005
|
|
|
22006
|
+
/**
|
|
22007
|
+
* Details about the pickup and drop-off modalities at each stop in each trip of a route.
|
|
22008
|
+
*/
|
|
21815
22009
|
const pickUpDropOffTypeMap = [
|
|
21816
22010
|
'REGULAR',
|
|
21817
22011
|
'NOT_AVAILABLE',
|
|
@@ -21823,7 +22017,7 @@ const pickUpDropOffTypeMap = [
|
|
|
21823
22017
|
* into its corresponding string representation.
|
|
21824
22018
|
*
|
|
21825
22019
|
* @param numericalType - The numerical value representing the pick-up/drop-off type.
|
|
21826
|
-
* @returns The corresponding
|
|
22020
|
+
* @returns The corresponding PickUpDropOffTypeString as a string.
|
|
21827
22021
|
* @throws An error if the numerical type is invalid.
|
|
21828
22022
|
*/
|
|
21829
22023
|
const toPickupDropOffType = (rawType) => {
|
|
@@ -21979,6 +22173,13 @@ class Result {
|
|
|
21979
22173
|
}
|
|
21980
22174
|
return new Route(route.reverse());
|
|
21981
22175
|
}
|
|
22176
|
+
buildServiceRouteInfo(route) {
|
|
22177
|
+
const serviceRouteInfo = this.timetable.getServiceRouteInfo(route);
|
|
22178
|
+
return {
|
|
22179
|
+
type: routeTypeToString(serviceRouteInfo.type),
|
|
22180
|
+
name: serviceRouteInfo.name,
|
|
22181
|
+
};
|
|
22182
|
+
}
|
|
21982
22183
|
/**
|
|
21983
22184
|
* Builds a vehicle leg from a chain of vehicle edges.
|
|
21984
22185
|
*
|
|
@@ -22006,7 +22207,7 @@ class Result {
|
|
|
22006
22207
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22007
22208
|
to: this.stopsIndex.findStopById(lastRoute.stopId(lastEdge.hopOffStopIndex)),
|
|
22008
22209
|
// The route info comes from the first boarded route in case of continuous trips
|
|
22009
|
-
route: this.
|
|
22210
|
+
route: this.buildServiceRouteInfo(firstRoute),
|
|
22010
22211
|
departureTime: firstRoute.departureFrom(firstEdge.stopIndex, firstEdge.tripIndex),
|
|
22011
22212
|
arrivalTime: lastEdge.arrival,
|
|
22012
22213
|
pickUpType: toPickupDropOffType(firstRoute.pickUpTypeFrom(firstEdge.stopIndex, firstEdge.tripIndex)),
|
|
@@ -22026,7 +22227,7 @@ class Result {
|
|
|
22026
22227
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22027
22228
|
to: this.stopsIndex.findStopById(edge.to),
|
|
22028
22229
|
minTransferTime: edge.minTransferTime,
|
|
22029
|
-
type: edge.type,
|
|
22230
|
+
type: transferTypeToString(edge.type),
|
|
22030
22231
|
};
|
|
22031
22232
|
}
|
|
22032
22233
|
/**
|
|
@@ -22063,7 +22264,7 @@ class Result {
|
|
|
22063
22264
|
from: this.stopsIndex.findStopById(fromStopId),
|
|
22064
22265
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22065
22266
|
to: this.stopsIndex.findStopById(toStopId),
|
|
22066
|
-
type:
|
|
22267
|
+
type: transferTypeToString(TransferTypes.GUARANTEED),
|
|
22067
22268
|
};
|
|
22068
22269
|
}
|
|
22069
22270
|
/**
|
|
@@ -22145,7 +22346,7 @@ class AccessFinder {
|
|
|
22145
22346
|
});
|
|
22146
22347
|
}
|
|
22147
22348
|
for (const transfer of this.timetable.getTransfers(origin)) {
|
|
22148
|
-
if (transfer.type ===
|
|
22349
|
+
if (transfer.type === TransferTypes.REQUIRES_MINIMAL_TIME) {
|
|
22149
22350
|
const duration = (_a = transfer.minTransferTime) !== null && _a !== void 0 ? _a : fallbackMinTransferTime;
|
|
22150
22351
|
const existingAccess = accessPaths.get(transfer.destination);
|
|
22151
22352
|
// Keep the shortest walk to maximize the set of reachable trips.
|
|
@@ -22198,7 +22399,8 @@ class AccessFinder {
|
|
|
22198
22399
|
const dep = route.departureFrom(stopIndex, tripIndex);
|
|
22199
22400
|
if (dep > searchTo)
|
|
22200
22401
|
break;
|
|
22201
|
-
if (route.pickUpTypeFrom(stopIndex, tripIndex) !==
|
|
22402
|
+
if (route.pickUpTypeFrom(stopIndex, tripIndex) !==
|
|
22403
|
+
PickUpDropOffTypes.NOT_AVAILABLE) {
|
|
22202
22404
|
const t = dep - path.duration;
|
|
22203
22405
|
let paths = slotMap.get(t);
|
|
22204
22406
|
if (paths === undefined) {
|
|
@@ -22231,12 +22433,17 @@ const UNREACHED_TIME = 0xffff;
|
|
|
22231
22433
|
* Encapsulates all mutable state for a single RAPTOR routing query.
|
|
22232
22434
|
*/
|
|
22233
22435
|
class RoutingState {
|
|
22234
|
-
constructor(departureTime, destinations, accessPaths, nbStops, maxRounds = 0) {
|
|
22436
|
+
constructor(departureTime, destinations, accessPaths, nbStops, maxRounds = 0, maxDuration) {
|
|
22235
22437
|
/**
|
|
22236
22438
|
* Cached best arrival time at any destination stop, kept up-to-date by
|
|
22237
22439
|
* {@link updateArrival} so that destination pruning is always O(1).
|
|
22238
22440
|
*/
|
|
22239
22441
|
this._destinationBest = UNREACHED_TIME;
|
|
22442
|
+
/**
|
|
22443
|
+
* Maximum arrival time allowed for this run. Defaults to UNREACHED_TIME when
|
|
22444
|
+
* the query has no maxDuration limit.
|
|
22445
|
+
*/
|
|
22446
|
+
this.maxArrivalTime = UNREACHED_TIME;
|
|
22240
22447
|
/**
|
|
22241
22448
|
* Every stop that has received an arrival improvement during the current run,
|
|
22242
22449
|
* in the order the improvements occurred. Used by {@link resetFor} to clear
|
|
@@ -22244,6 +22451,9 @@ class RoutingState {
|
|
|
22244
22451
|
*/
|
|
22245
22452
|
this.reachedStops = [];
|
|
22246
22453
|
this.destinations = destinations;
|
|
22454
|
+
this.maxDuration = maxDuration;
|
|
22455
|
+
this.maxArrivalTime =
|
|
22456
|
+
maxDuration === undefined ? UNREACHED_TIME : departureTime + maxDuration;
|
|
22247
22457
|
this.destinationSet = new Set(destinations);
|
|
22248
22458
|
this.earliestArrivalTimes = new Uint16Array(nbStops).fill(UNREACHED_TIME);
|
|
22249
22459
|
this.earliestArrivalLegs = new Uint8Array(nbStops);
|
|
@@ -22265,6 +22475,8 @@ class RoutingState {
|
|
|
22265
22475
|
const seededOrigins = new Set();
|
|
22266
22476
|
for (const access of accessPaths) {
|
|
22267
22477
|
const arrival = depTime + access.duration;
|
|
22478
|
+
if (arrival > this.maxArrivalTime)
|
|
22479
|
+
continue;
|
|
22268
22480
|
const edge = access.duration === 0
|
|
22269
22481
|
? { stopId: access.fromStopId, arrival: depTime }
|
|
22270
22482
|
: {
|
|
@@ -22356,6 +22568,10 @@ class RoutingState {
|
|
|
22356
22568
|
}
|
|
22357
22569
|
this.reachedStops.length = 0;
|
|
22358
22570
|
this._destinationBest = UNREACHED_TIME;
|
|
22571
|
+
this.maxArrivalTime =
|
|
22572
|
+
this.maxDuration === undefined
|
|
22573
|
+
? UNREACHED_TIME
|
|
22574
|
+
: depTime + this.maxDuration;
|
|
22359
22575
|
this.seedAccessPaths(depTime, accessPaths);
|
|
22360
22576
|
}
|
|
22361
22577
|
/**
|
|
@@ -22483,7 +22699,7 @@ class PlainRouter {
|
|
|
22483
22699
|
const destinations = Array.from(query.to)
|
|
22484
22700
|
.flatMap((destination) => this.stopsIndex.equivalentStops(destination))
|
|
22485
22701
|
.map((destination) => destination.id);
|
|
22486
|
-
const routingState = new RoutingState(query.departureTime, destinations, accessLegs, this.timetable.nbStops(), query.options.maxTransfers + 1);
|
|
22702
|
+
const routingState = new RoutingState(query.departureTime, destinations, accessLegs, this.timetable.nbStops(), query.options.maxTransfers + 1, query.options.maxDuration);
|
|
22487
22703
|
this.raptor.run(query.options, routingState);
|
|
22488
22704
|
return new Result(new Set(destinations), routingState, this.stopsIndex, this.timetable);
|
|
22489
22705
|
}
|
|
@@ -22812,6 +23028,9 @@ class RangeRaptorState {
|
|
|
22812
23028
|
get destinationBest() {
|
|
22813
23029
|
return this._destinationBest;
|
|
22814
23030
|
}
|
|
23031
|
+
get maxArrivalTime() {
|
|
23032
|
+
return this.currentRun.maxArrivalTime;
|
|
23033
|
+
}
|
|
22815
23034
|
isDestination(stop) {
|
|
22816
23035
|
return this.currentRun.isDestination(stop);
|
|
22817
23036
|
}
|
|
@@ -22899,7 +23118,7 @@ class RangeRouter {
|
|
|
22899
23118
|
const trivialDestCovered = new Set();
|
|
22900
23119
|
let routingState = null;
|
|
22901
23120
|
if (query.rangeOptions.optimizeBeyondLatestDeparture) {
|
|
22902
|
-
routingState = new RoutingState(latest + 1, destinations, accessLegs, this.timetable.nbStops(), maxRounds);
|
|
23121
|
+
routingState = new RoutingState(latest + 1, destinations, accessLegs, this.timetable.nbStops(), maxRounds, query.options.maxDuration);
|
|
22903
23122
|
rangeState.setCurrentRun(routingState);
|
|
22904
23123
|
this.raptor.run(Object.assign(Object.assign({}, query.options), { maxInitialWaitingTime: undefined }), rangeState);
|
|
22905
23124
|
if (!noDestinations) {
|
|
@@ -22915,7 +23134,7 @@ class RangeRouter {
|
|
|
22915
23134
|
break;
|
|
22916
23135
|
}
|
|
22917
23136
|
if (routingState === null) {
|
|
22918
|
-
routingState = new RoutingState(depTime, destinations, legs, this.timetable.nbStops(), maxRounds);
|
|
23137
|
+
routingState = new RoutingState(depTime, destinations, legs, this.timetable.nbStops(), maxRounds, query.options.maxDuration);
|
|
22919
23138
|
}
|
|
22920
23139
|
else {
|
|
22921
23140
|
routingState.resetFor(depTime, legs);
|
|
@@ -23043,7 +23262,8 @@ class Raptor {
|
|
|
23043
23262
|
const currentStop = route.stops[currentStopIndex];
|
|
23044
23263
|
const arrivalTime = route.arrivalAtOffset(currentStopIndex, tripStopOffset);
|
|
23045
23264
|
const dropOffType = route.dropOffTypeAtOffset(currentStopIndex, tripStopOffset);
|
|
23046
|
-
if (dropOffType !== NOT_AVAILABLE &&
|
|
23265
|
+
if (dropOffType !== PickUpDropOffTypes.NOT_AVAILABLE &&
|
|
23266
|
+
arrivalTime <= state.maxArrivalTime &&
|
|
23047
23267
|
arrivalTime < state.improvementBound(round, currentStop) &&
|
|
23048
23268
|
arrivalTime < state.destinationBest) {
|
|
23049
23269
|
edgesAtCurrentRound[currentStop] = {
|
|
@@ -23090,7 +23310,8 @@ class Raptor {
|
|
|
23090
23310
|
if (activeTripIndex !== undefined) {
|
|
23091
23311
|
const arrivalTime = route.arrivalAtOffset(currentStopIndex, activeTripStopOffset);
|
|
23092
23312
|
const dropOffType = route.dropOffTypeAtOffset(currentStopIndex, activeTripStopOffset);
|
|
23093
|
-
if (dropOffType !== NOT_AVAILABLE &&
|
|
23313
|
+
if (dropOffType !== PickUpDropOffTypes.NOT_AVAILABLE &&
|
|
23314
|
+
arrivalTime <= state.maxArrivalTime &&
|
|
23094
23315
|
arrivalTime < state.improvementBound(round, currentStop) &&
|
|
23095
23316
|
arrivalTime < state.destinationBest) {
|
|
23096
23317
|
edgesAtCurrentRound[currentStop] = {
|
|
@@ -23124,15 +23345,16 @@ class Raptor {
|
|
|
23124
23345
|
: undefined;
|
|
23125
23346
|
const firstBoardableTrip = this.timetable.findFirstBoardableTrip(currentStopIndex, route, earliestTrip, earliestArrivalOnPreviousRound, activeTripIndex, fromTripStop, options.minTransferTime);
|
|
23126
23347
|
if (firstBoardableTrip !== undefined) {
|
|
23348
|
+
const departureTime = route.departureFrom(currentStopIndex, firstBoardableTrip);
|
|
23127
23349
|
// At round 1, enforce maxInitialWaitingTime: skip boarding if the
|
|
23128
23350
|
// traveler would have to wait longer than the allowed threshold at
|
|
23129
23351
|
// the first boarding stop.
|
|
23130
23352
|
const exceedsInitialWait = round === 1 &&
|
|
23131
23353
|
options.maxInitialWaitingTime !== undefined &&
|
|
23132
|
-
|
|
23133
|
-
earliestArrivalOnPreviousRound >
|
|
23354
|
+
departureTime - earliestArrivalOnPreviousRound >
|
|
23134
23355
|
options.maxInitialWaitingTime;
|
|
23135
|
-
|
|
23356
|
+
const exceedsMaxDuration = departureTime > state.maxArrivalTime;
|
|
23357
|
+
if (!exceedsInitialWait && !exceedsMaxDuration) {
|
|
23136
23358
|
activeTripIndex = firstBoardableTrip;
|
|
23137
23359
|
activeTripBoardStopIndex = currentStopIndex;
|
|
23138
23360
|
activeTripStopOffset = route.tripStopOffset(firstBoardableTrip);
|
|
@@ -23167,20 +23389,21 @@ class Raptor {
|
|
|
23167
23389
|
if (transfer.minTransferTime) {
|
|
23168
23390
|
transferTime = transfer.minTransferTime;
|
|
23169
23391
|
}
|
|
23170
|
-
else if (transfer.type ===
|
|
23392
|
+
else if (transfer.type === TransferTypes.IN_SEAT) {
|
|
23171
23393
|
transferTime = DURATION_ZERO;
|
|
23172
23394
|
}
|
|
23173
23395
|
else {
|
|
23174
23396
|
transferTime = options.minTransferTime;
|
|
23175
23397
|
}
|
|
23176
23398
|
const arrivalAfterTransfer = currentArrival.arrival + transferTime;
|
|
23177
|
-
if (arrivalAfterTransfer
|
|
23178
|
-
|
|
23399
|
+
if (arrivalAfterTransfer <= state.maxArrivalTime &&
|
|
23400
|
+
arrivalAfterTransfer <
|
|
23401
|
+
state.improvementBound(round, transfer.destination) &&
|
|
23179
23402
|
arrivalAfterTransfer < state.destinationBest) {
|
|
23180
23403
|
arrivalsAtCurrentRound[transfer.destination] = {
|
|
23181
23404
|
arrival: arrivalAfterTransfer,
|
|
23182
23405
|
from: stop,
|
|
23183
|
-
to: transfer.destination,
|
|
23406
|
+
to: transfer.destination, // TODO needed?
|
|
23184
23407
|
minTransferTime: transferTime || undefined,
|
|
23185
23408
|
type: transfer.type,
|
|
23186
23409
|
};
|
|
@@ -23294,7 +23517,8 @@ const loadQueriesFromJson = (filePath, stopsIndex) => {
|
|
|
23294
23517
|
.from(fromStop.id)
|
|
23295
23518
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23296
23519
|
.to(new Set(toStops.map((stop) => stop.id)))
|
|
23297
|
-
.departureTime(timeFromString(serializedQuery.departureTime))
|
|
23520
|
+
.departureTime(timeFromString(serializedQuery.departureTime))
|
|
23521
|
+
.maxDuration(6 * 60);
|
|
23298
23522
|
if (serializedQuery.maxTransfers !== undefined) {
|
|
23299
23523
|
queryBuilder.maxTransfers(serializedQuery.maxTransfers);
|
|
23300
23524
|
}
|
|
@@ -23333,7 +23557,8 @@ const loadRangeQueriesFromJson = (filePath, stopsIndex) => {
|
|
|
23333
23557
|
.to(new Set(toStops.map((stop) => stop.id)))
|
|
23334
23558
|
.departureTime(timeFromString(serializedQuery.departureTime))
|
|
23335
23559
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23336
|
-
.lastDepartureTime(timeFromString(serializedQuery.lastDepartureTime))
|
|
23560
|
+
.lastDepartureTime(timeFromString(serializedQuery.lastDepartureTime))
|
|
23561
|
+
.maxDuration(6 * 60);
|
|
23337
23562
|
if (serializedQuery.maxTransfers !== undefined) {
|
|
23338
23563
|
queryBuilder.maxTransfers(serializedQuery.maxTransfers);
|
|
23339
23564
|
}
|
|
@@ -23595,8 +23820,9 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
23595
23820
|
this.displayPrompt();
|
|
23596
23821
|
},
|
|
23597
23822
|
});
|
|
23823
|
+
const routeSyntax = '.route from <stop> to <stop> at <HH:mm> [before <HH:mm>] [with <N> transfers] [wait max <N> minutes]';
|
|
23598
23824
|
replServer.defineCommand('route', {
|
|
23599
|
-
help:
|
|
23825
|
+
help: `Find a route using ${routeSyntax}`,
|
|
23600
23826
|
action(routeQuery) {
|
|
23601
23827
|
this.clearBufferedCommand();
|
|
23602
23828
|
const parts = routeQuery.split(' ').filter(Boolean);
|
|
@@ -23605,30 +23831,40 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
23605
23831
|
const atIndex = parts.indexOf('at');
|
|
23606
23832
|
const beforeIndex = parts.indexOf('before');
|
|
23607
23833
|
const withIndex = parts.indexOf('with');
|
|
23834
|
+
const waitIndex = parts.indexOf('wait');
|
|
23835
|
+
const routeClauseIndexes = [beforeIndex, withIndex, waitIndex].filter((index) => index !== -1);
|
|
23608
23836
|
if (fromIndex === -1 || toIndex === -1 || atIndex === -1) {
|
|
23609
|
-
console.log(
|
|
23837
|
+
console.log(`Usage: ${routeSyntax}`);
|
|
23610
23838
|
this.displayPrompt();
|
|
23611
23839
|
return;
|
|
23612
23840
|
}
|
|
23613
23841
|
const fromId = parts.slice(fromIndex + 1, toIndex).join(' ');
|
|
23614
23842
|
const toId = parts.slice(toIndex + 1, atIndex).join(' ');
|
|
23615
|
-
// atTime ends at 'before', 'with', or the end of the input.
|
|
23616
|
-
const atTimeEnd =
|
|
23617
|
-
? beforeIndex
|
|
23618
|
-
: withIndex !== -1
|
|
23619
|
-
? withIndex
|
|
23620
|
-
: parts.length;
|
|
23843
|
+
// atTime ends at 'before', 'with', 'wait', or the end of the input.
|
|
23844
|
+
const atTimeEnd = Math.min(...routeClauseIndexes.filter((index) => index > atIndex), parts.length);
|
|
23621
23845
|
const atTime = parts.slice(atIndex + 1, atTimeEnd).join(' ');
|
|
23622
23846
|
// beforeTime is only present when the 'before' keyword appears.
|
|
23623
|
-
const beforeTimeEnd = withIndex !== -1
|
|
23847
|
+
const beforeTimeEnd = Math.min(...[withIndex, waitIndex].filter((index) => index !== -1 && index > beforeIndex), parts.length);
|
|
23624
23848
|
const beforeTime = beforeIndex !== -1
|
|
23625
23849
|
? parts.slice(beforeIndex + 1, beforeTimeEnd).join(' ')
|
|
23626
23850
|
: undefined;
|
|
23627
23851
|
const maxTransfers = withIndex !== -1 && parts[withIndex + 1] !== undefined
|
|
23628
23852
|
? parseInt(parts[withIndex + 1])
|
|
23629
23853
|
: 4;
|
|
23630
|
-
|
|
23631
|
-
|
|
23854
|
+
const maxInitialWaitingTime = waitIndex !== -1 &&
|
|
23855
|
+
parts[waitIndex + 1] === 'max' &&
|
|
23856
|
+
parts[waitIndex + 2] !== undefined
|
|
23857
|
+
? Number(parts[waitIndex + 2])
|
|
23858
|
+
: undefined;
|
|
23859
|
+
const waitUnit = parts[waitIndex + 3];
|
|
23860
|
+
const hasInvalidWaitClause = waitIndex !== -1 &&
|
|
23861
|
+
(parts[waitIndex + 1] !== 'max' ||
|
|
23862
|
+
maxInitialWaitingTime === undefined ||
|
|
23863
|
+
!Number.isFinite(maxInitialWaitingTime) ||
|
|
23864
|
+
maxInitialWaitingTime < 0 ||
|
|
23865
|
+
(waitUnit !== 'minute' && waitUnit !== 'minutes'));
|
|
23866
|
+
if (!fromId || !toId || !atTime || hasInvalidWaitClause) {
|
|
23867
|
+
console.log(`Usage: ${routeSyntax}`);
|
|
23632
23868
|
this.displayPrompt();
|
|
23633
23869
|
return;
|
|
23634
23870
|
}
|
|
@@ -23657,13 +23893,16 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
23657
23893
|
const router = new Router(timetable, stopsIndex);
|
|
23658
23894
|
if (beforeTime !== undefined) {
|
|
23659
23895
|
const lastDepartureTime = timeFromString(beforeTime);
|
|
23660
|
-
const
|
|
23896
|
+
const queryBuilder = new RangeQuery.Builder()
|
|
23661
23897
|
.from(fromStop.id)
|
|
23662
23898
|
.to(toStop.id)
|
|
23663
23899
|
.departureTime(departureTime)
|
|
23664
23900
|
.lastDepartureTime(lastDepartureTime)
|
|
23665
|
-
.maxTransfers(maxTransfers)
|
|
23666
|
-
|
|
23901
|
+
.maxTransfers(maxTransfers);
|
|
23902
|
+
if (maxInitialWaitingTime !== undefined) {
|
|
23903
|
+
queryBuilder.maxInitialWaitingTime(maxInitialWaitingTime);
|
|
23904
|
+
}
|
|
23905
|
+
const query = queryBuilder.build();
|
|
23667
23906
|
const result = router.rangeRoute(query);
|
|
23668
23907
|
if (result.size === 0) {
|
|
23669
23908
|
console.log(`No journeys found from ${fromStop.name} to ${toStop.name} ` +
|
|
@@ -23682,12 +23921,15 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
23682
23921
|
}
|
|
23683
23922
|
}
|
|
23684
23923
|
else {
|
|
23685
|
-
const
|
|
23924
|
+
const queryBuilder = new Query.Builder()
|
|
23686
23925
|
.from(fromStop.id)
|
|
23687
23926
|
.to(toStop.id)
|
|
23688
23927
|
.departureTime(departureTime)
|
|
23689
|
-
.maxTransfers(maxTransfers)
|
|
23690
|
-
|
|
23928
|
+
.maxTransfers(maxTransfers);
|
|
23929
|
+
if (maxInitialWaitingTime !== undefined) {
|
|
23930
|
+
queryBuilder.maxInitialWaitingTime(maxInitialWaitingTime);
|
|
23931
|
+
}
|
|
23932
|
+
const query = queryBuilder.build();
|
|
23691
23933
|
const result = router.route(query);
|
|
23692
23934
|
const arrivalTime = result.arrivalAt(toStop.id);
|
|
23693
23935
|
if (arrivalTime === undefined) {
|
|
@@ -23781,13 +24023,13 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
23781
24023
|
});
|
|
23782
24024
|
const formatPickupDropoffType = (type) => {
|
|
23783
24025
|
switch (type) {
|
|
23784
|
-
case REGULAR:
|
|
24026
|
+
case PickUpDropOffTypes.REGULAR:
|
|
23785
24027
|
return 'R';
|
|
23786
|
-
case NOT_AVAILABLE:
|
|
24028
|
+
case PickUpDropOffTypes.NOT_AVAILABLE:
|
|
23787
24029
|
return 'N';
|
|
23788
|
-
case MUST_PHONE_AGENCY:
|
|
24030
|
+
case PickUpDropOffTypes.MUST_PHONE_AGENCY:
|
|
23789
24031
|
return 'A';
|
|
23790
|
-
case MUST_COORDINATE_WITH_DRIVER:
|
|
24032
|
+
case PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER:
|
|
23791
24033
|
return 'D';
|
|
23792
24034
|
default:
|
|
23793
24035
|
return '?';
|
|
@@ -24013,6 +24255,7 @@ program
|
|
|
24013
24255
|
.option('-t, --timetableOutputPath <path>', 'Path to output timetable file', '/tmp/timetable')
|
|
24014
24256
|
.option('-s, --stopsOutputPath <path>', 'Path to output stops file', '/tmp/stops')
|
|
24015
24257
|
.option('-p, --profileName <name>', 'Profile name for GTFS config', 'extended')
|
|
24258
|
+
.option('--virtual-transfers-radius <meters>', 'Generate virtual walking transfers between stops within this radius (in meters). Disabled when omitted.')
|
|
24016
24259
|
.option('-v, --verbose', 'Verbose mode', false)
|
|
24017
24260
|
.action((gtfsPath, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24018
24261
|
if (options.verbose) {
|
|
@@ -24021,7 +24264,15 @@ program
|
|
|
24021
24264
|
else {
|
|
24022
24265
|
log.setDefaultLevel(log.levels.ERROR);
|
|
24023
24266
|
}
|
|
24024
|
-
const
|
|
24267
|
+
const radiusMeters = options.virtualTransfersRadius !== undefined
|
|
24268
|
+
? parseInt(options.virtualTransfersRadius, 10)
|
|
24269
|
+
: undefined;
|
|
24270
|
+
const transferGenerator = radiusMeters !== undefined && Number.isFinite(radiusMeters)
|
|
24271
|
+
? new StraightLineTransferGenerator({
|
|
24272
|
+
maxDistanceMeters: radiusMeters,
|
|
24273
|
+
})
|
|
24274
|
+
: undefined;
|
|
24275
|
+
const parser = new GtfsParser(gtfsPath, profiles[options.profileName], transferGenerator);
|
|
24025
24276
|
const stopsIndex = yield parser.parseStops();
|
|
24026
24277
|
fs.writeFileSync(options.stopsOutputPath, stopsIndex.serialize());
|
|
24027
24278
|
const timetable = yield parser.parseTimetable(new Date(options.date));
|