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
|
@@ -6,6 +6,7 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
|
6
6
|
import { Route } from '../../timetable/route.js';
|
|
7
7
|
import { timeFromHM } from '../../timetable/time.js';
|
|
8
8
|
import {
|
|
9
|
+
RouteTypes,
|
|
9
10
|
ServiceRoute,
|
|
10
11
|
StopAdjacency,
|
|
11
12
|
Timetable,
|
|
@@ -40,7 +41,7 @@ const routesAdjacency = [
|
|
|
40
41
|
}),
|
|
41
42
|
];
|
|
42
43
|
const serviceRoutes: ServiceRoute[] = [
|
|
43
|
-
{ type:
|
|
44
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
44
45
|
];
|
|
45
46
|
const stops: Stop[] = [
|
|
46
47
|
{
|
package/src/routing/access.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { StopId } from '../stops/stops.js';
|
|
2
2
|
import { StopsIndex } from '../stops/stopsIndex.js';
|
|
3
|
-
import {
|
|
3
|
+
import { PickUpDropOffTypes } from '../timetable/route.js';
|
|
4
4
|
import { Duration, Time } from '../timetable/time.js';
|
|
5
|
-
import { Timetable } from '../timetable/timetable.js';
|
|
5
|
+
import { Timetable, TransferTypes } from '../timetable/timetable.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* An access path from the query origin to an initial boarding stop.
|
|
@@ -58,7 +58,7 @@ export class AccessFinder {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
for (const transfer of this.timetable.getTransfers(origin)) {
|
|
61
|
-
if (transfer.type ===
|
|
61
|
+
if (transfer.type === TransferTypes.REQUIRES_MINIMAL_TIME) {
|
|
62
62
|
const duration = transfer.minTransferTime ?? fallbackMinTransferTime;
|
|
63
63
|
const existingAccess = accessPaths.get(transfer.destination);
|
|
64
64
|
// Keep the shortest walk to maximize the set of reachable trips.
|
|
@@ -117,7 +117,10 @@ export class AccessFinder {
|
|
|
117
117
|
while (tripIndex < nbTrips) {
|
|
118
118
|
const dep = route.departureFrom(stopIndex, tripIndex);
|
|
119
119
|
if (dep > searchTo) break;
|
|
120
|
-
if (
|
|
120
|
+
if (
|
|
121
|
+
route.pickUpTypeFrom(stopIndex, tripIndex) !==
|
|
122
|
+
PickUpDropOffTypes.NOT_AVAILABLE
|
|
123
|
+
) {
|
|
121
124
|
const t = dep - path.duration;
|
|
122
125
|
let paths = slotMap.get(t);
|
|
123
126
|
if (paths === undefined) {
|
package/src/routing/plotter.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StopId } from '../stops/stops.js';
|
|
2
2
|
import { durationToString, timeToString } from '../timetable/time.js';
|
|
3
|
+
import { routeTypeToString } from '../timetable/timetable.js';
|
|
3
4
|
import { Result } from './result.js';
|
|
4
5
|
import {
|
|
5
6
|
AccessEdge,
|
|
@@ -326,7 +327,7 @@ export class Plotter {
|
|
|
326
327
|
|
|
327
328
|
const serviceRouteInfo = this.result.timetable.getServiceRouteInfo(route);
|
|
328
329
|
const routeName = serviceRouteInfo.name;
|
|
329
|
-
const routeType = serviceRouteInfo.type;
|
|
330
|
+
const routeType = routeTypeToString(serviceRouteInfo.type);
|
|
330
331
|
|
|
331
332
|
const departureTime = timeToString(
|
|
332
333
|
route.departureFrom(edge.stopIndex, edge.tripIndex),
|
|
@@ -424,8 +425,12 @@ export class Plotter {
|
|
|
424
425
|
const toRouteName =
|
|
425
426
|
toServiceRouteInfo?.name ?? `Route ${String(toEdge.routeId)}`;
|
|
426
427
|
|
|
427
|
-
const fromRouteType = fromServiceRouteInfo
|
|
428
|
-
|
|
428
|
+
const fromRouteType = fromServiceRouteInfo
|
|
429
|
+
? routeTypeToString(fromServiceRouteInfo.type)
|
|
430
|
+
: 'UNKNOWN';
|
|
431
|
+
const toRouteType = toServiceRouteInfo
|
|
432
|
+
? routeTypeToString(toServiceRouteInfo.type)
|
|
433
|
+
: 'UNKNOWN';
|
|
429
434
|
|
|
430
435
|
const fromArrivalTime = timeToString(fromEdge.arrival);
|
|
431
436
|
const toDepartureTime = toRoute
|
package/src/routing/query.ts
CHANGED
|
@@ -6,6 +6,14 @@ export type QueryOptions = {
|
|
|
6
6
|
maxTransfers: number;
|
|
7
7
|
minTransferTime: Duration;
|
|
8
8
|
transportModes: Set<RouteType>;
|
|
9
|
+
/**
|
|
10
|
+
* Maximum total journey duration (in minutes) from the query departure time.
|
|
11
|
+
*
|
|
12
|
+
* When set, arrivals after `departureTime + maxDuration` are skipped. The
|
|
13
|
+
* duration includes initial access, waiting time, transit legs, and transfers.
|
|
14
|
+
* Undefined means no limit.
|
|
15
|
+
*/
|
|
16
|
+
maxDuration?: Duration;
|
|
9
17
|
/**
|
|
10
18
|
* Maximum time (in minutes) the traveler is willing to wait at the first
|
|
11
19
|
* boarding stop before the first transit vehicle departs.
|
|
@@ -98,6 +106,16 @@ export class Query {
|
|
|
98
106
|
return this;
|
|
99
107
|
}
|
|
100
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Sets the maximum total journey duration (in minutes) from the query
|
|
111
|
+
* departure time. The limit includes initial access, waiting time, transit
|
|
112
|
+
* legs, and transfers.
|
|
113
|
+
*/
|
|
114
|
+
maxDuration(maxDuration: Duration): this {
|
|
115
|
+
this.optionsValue.maxDuration = maxDuration;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
101
119
|
/**
|
|
102
120
|
* Sets the maximum time (in minutes) the traveler is willing to wait at
|
|
103
121
|
* the first boarding stop before the first transit vehicle departs.
|
|
@@ -92,6 +92,7 @@ export class RangeRouter {
|
|
|
92
92
|
accessLegs,
|
|
93
93
|
this.timetable.nbStops(),
|
|
94
94
|
maxRounds,
|
|
95
|
+
query.options.maxDuration,
|
|
95
96
|
);
|
|
96
97
|
rangeState.setCurrentRun(routingState);
|
|
97
98
|
this.raptor.run(
|
|
@@ -122,6 +123,7 @@ export class RangeRouter {
|
|
|
122
123
|
legs,
|
|
123
124
|
this.timetable.nbStops(),
|
|
124
125
|
maxRounds,
|
|
126
|
+
query.options.maxDuration,
|
|
125
127
|
);
|
|
126
128
|
} else {
|
|
127
129
|
routingState.resetFor(depTime, legs);
|
|
@@ -109,6 +109,10 @@ export class RangeRaptorState implements IRaptorState {
|
|
|
109
109
|
return this._destinationBest;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
get maxArrivalTime(): Time {
|
|
113
|
+
return this.currentRun.maxArrivalTime;
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
isDestination(stop: StopId): boolean {
|
|
113
117
|
return this.currentRun.isDestination(stop);
|
|
114
118
|
}
|
package/src/routing/raptor.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
2
|
import { StopId } from '../stops/stops.js';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
PickUpDropOffTypes,
|
|
5
5
|
Route,
|
|
6
6
|
StopRouteIndex,
|
|
7
7
|
TripRouteIndex,
|
|
8
8
|
} from '../timetable/route.js';
|
|
9
9
|
import { Duration, DURATION_ZERO, Time } from '../timetable/time.js';
|
|
10
|
-
import { Timetable, TripStop } from '../timetable/timetable.js';
|
|
10
|
+
import { Timetable, TransferTypes, TripStop } from '../timetable/timetable.js';
|
|
11
11
|
import { QueryOptions } from './query.js';
|
|
12
12
|
import { RoutingEdge, TransferEdge, VehicleEdge } from './state.js';
|
|
13
13
|
|
|
@@ -34,6 +34,9 @@ export interface IRaptorState {
|
|
|
34
34
|
*/
|
|
35
35
|
readonly destinationBest: Time;
|
|
36
36
|
|
|
37
|
+
/** Latest arrival time allowed by the current query/run. */
|
|
38
|
+
readonly maxArrivalTime: Time;
|
|
39
|
+
|
|
37
40
|
/** Returns `true` if `stop` is one of the query's destination stops. */
|
|
38
41
|
isDestination(stop: StopId): boolean;
|
|
39
42
|
|
|
@@ -211,7 +214,8 @@ export class Raptor {
|
|
|
211
214
|
);
|
|
212
215
|
|
|
213
216
|
if (
|
|
214
|
-
dropOffType !== NOT_AVAILABLE &&
|
|
217
|
+
dropOffType !== PickUpDropOffTypes.NOT_AVAILABLE &&
|
|
218
|
+
arrivalTime <= state.maxArrivalTime &&
|
|
215
219
|
arrivalTime < state.improvementBound(round, currentStop) &&
|
|
216
220
|
arrivalTime < state.destinationBest
|
|
217
221
|
) {
|
|
@@ -281,7 +285,8 @@ export class Raptor {
|
|
|
281
285
|
);
|
|
282
286
|
|
|
283
287
|
if (
|
|
284
|
-
dropOffType !== NOT_AVAILABLE &&
|
|
288
|
+
dropOffType !== PickUpDropOffTypes.NOT_AVAILABLE &&
|
|
289
|
+
arrivalTime <= state.maxArrivalTime &&
|
|
285
290
|
arrivalTime < state.improvementBound(round, currentStop) &&
|
|
286
291
|
arrivalTime < state.destinationBest
|
|
287
292
|
) {
|
|
@@ -334,17 +339,21 @@ export class Raptor {
|
|
|
334
339
|
);
|
|
335
340
|
|
|
336
341
|
if (firstBoardableTrip !== undefined) {
|
|
342
|
+
const departureTime = route.departureFrom(
|
|
343
|
+
currentStopIndex,
|
|
344
|
+
firstBoardableTrip,
|
|
345
|
+
);
|
|
337
346
|
// At round 1, enforce maxInitialWaitingTime: skip boarding if the
|
|
338
347
|
// traveler would have to wait longer than the allowed threshold at
|
|
339
348
|
// the first boarding stop.
|
|
340
349
|
const exceedsInitialWait =
|
|
341
350
|
round === 1 &&
|
|
342
351
|
options.maxInitialWaitingTime !== undefined &&
|
|
343
|
-
|
|
344
|
-
earliestArrivalOnPreviousRound >
|
|
352
|
+
departureTime - earliestArrivalOnPreviousRound >
|
|
345
353
|
options.maxInitialWaitingTime;
|
|
354
|
+
const exceedsMaxDuration = departureTime > state.maxArrivalTime;
|
|
346
355
|
|
|
347
|
-
if (!exceedsInitialWait) {
|
|
356
|
+
if (!exceedsInitialWait && !exceedsMaxDuration) {
|
|
348
357
|
activeTripIndex = firstBoardableTrip;
|
|
349
358
|
activeTripBoardStopIndex = currentStopIndex;
|
|
350
359
|
activeTripStopOffset = route.tripStopOffset(firstBoardableTrip);
|
|
@@ -383,7 +392,7 @@ export class Raptor {
|
|
|
383
392
|
let transferTime: Duration;
|
|
384
393
|
if (transfer.minTransferTime) {
|
|
385
394
|
transferTime = transfer.minTransferTime;
|
|
386
|
-
} else if (transfer.type ===
|
|
395
|
+
} else if (transfer.type === TransferTypes.IN_SEAT) {
|
|
387
396
|
transferTime = DURATION_ZERO;
|
|
388
397
|
} else {
|
|
389
398
|
transferTime = options.minTransferTime;
|
|
@@ -391,6 +400,7 @@ export class Raptor {
|
|
|
391
400
|
const arrivalAfterTransfer = currentArrival.arrival + transferTime;
|
|
392
401
|
|
|
393
402
|
if (
|
|
403
|
+
arrivalAfterTransfer <= state.maxArrivalTime &&
|
|
394
404
|
arrivalAfterTransfer <
|
|
395
405
|
state.improvementBound(round, transfer.destination) &&
|
|
396
406
|
arrivalAfterTransfer < state.destinationBest
|
|
@@ -398,7 +408,7 @@ export class Raptor {
|
|
|
398
408
|
arrivalsAtCurrentRound[transfer.destination] = {
|
|
399
409
|
arrival: arrivalAfterTransfer,
|
|
400
410
|
from: stop,
|
|
401
|
-
to: transfer.destination,
|
|
411
|
+
to: transfer.destination, // TODO needed?
|
|
402
412
|
minTransferTime: transferTime || undefined,
|
|
403
413
|
type: transfer.type,
|
|
404
414
|
} as TransferEdge;
|
package/src/routing/result.ts
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { Timetable } from '../router.js';
|
|
2
2
|
import { SourceStopId, StopId } from '../stops/stops.js';
|
|
3
3
|
import { StopsIndex } from '../stops/stopsIndex.js';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
PickUpDropOffTypeString,
|
|
6
|
+
RawPickUpDropOffType,
|
|
7
|
+
Route as TimetableRoute,
|
|
8
|
+
} from '../timetable/route.js';
|
|
5
9
|
import { Time } from '../timetable/time.js';
|
|
6
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
routeTypeToString,
|
|
12
|
+
TransferTypes,
|
|
13
|
+
transferTypeToString,
|
|
14
|
+
} from '../timetable/timetable.js';
|
|
15
|
+
import {
|
|
16
|
+
Access,
|
|
17
|
+
Leg,
|
|
18
|
+
Route,
|
|
19
|
+
ServiceRouteInfo,
|
|
20
|
+
Transfer,
|
|
21
|
+
VehicleLeg,
|
|
22
|
+
} from './route.js';
|
|
7
23
|
import { Arrival, RoutingState, TransferEdge, VehicleEdge } from './router.js';
|
|
8
24
|
import { AccessEdge } from './state.js';
|
|
9
25
|
|
|
10
26
|
/**
|
|
11
27
|
* Details about the pickup and drop-off modalities at each stop in each trip of a route.
|
|
12
28
|
*/
|
|
13
|
-
|
|
14
|
-
| 'REGULAR'
|
|
15
|
-
| 'NOT_AVAILABLE'
|
|
16
|
-
| 'MUST_PHONE_AGENCY'
|
|
17
|
-
| 'MUST_COORDINATE_WITH_DRIVER';
|
|
18
|
-
|
|
19
|
-
const pickUpDropOffTypeMap: PickUpDropOffType[] = [
|
|
29
|
+
const pickUpDropOffTypeMap: PickUpDropOffTypeString[] = [
|
|
20
30
|
'REGULAR',
|
|
21
31
|
'NOT_AVAILABLE',
|
|
22
32
|
'MUST_PHONE_AGENCY',
|
|
@@ -28,12 +38,12 @@ const pickUpDropOffTypeMap: PickUpDropOffType[] = [
|
|
|
28
38
|
* into its corresponding string representation.
|
|
29
39
|
*
|
|
30
40
|
* @param numericalType - The numerical value representing the pick-up/drop-off type.
|
|
31
|
-
* @returns The corresponding
|
|
41
|
+
* @returns The corresponding PickUpDropOffTypeString as a string.
|
|
32
42
|
* @throws An error if the numerical type is invalid.
|
|
33
43
|
*/
|
|
34
44
|
const toPickupDropOffType = (
|
|
35
45
|
rawType: RawPickUpDropOffType,
|
|
36
|
-
):
|
|
46
|
+
): PickUpDropOffTypeString => {
|
|
37
47
|
const type = pickUpDropOffTypeMap[rawType];
|
|
38
48
|
if (!type) {
|
|
39
49
|
throw new Error(`Invalid pickup/drop-off type ${rawType}`);
|
|
@@ -212,6 +222,14 @@ export class Result {
|
|
|
212
222
|
return new Route(route.reverse());
|
|
213
223
|
}
|
|
214
224
|
|
|
225
|
+
private buildServiceRouteInfo(route: TimetableRoute): ServiceRouteInfo {
|
|
226
|
+
const serviceRouteInfo = this.timetable.getServiceRouteInfo(route);
|
|
227
|
+
return {
|
|
228
|
+
type: routeTypeToString(serviceRouteInfo.type),
|
|
229
|
+
name: serviceRouteInfo.name,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
215
233
|
/**
|
|
216
234
|
* Builds a vehicle leg from a chain of vehicle edges.
|
|
217
235
|
*
|
|
@@ -243,7 +261,7 @@ export class Result {
|
|
|
243
261
|
lastRoute.stopId(lastEdge.hopOffStopIndex),
|
|
244
262
|
)!,
|
|
245
263
|
// The route info comes from the first boarded route in case of continuous trips
|
|
246
|
-
route: this.
|
|
264
|
+
route: this.buildServiceRouteInfo(firstRoute),
|
|
247
265
|
departureTime: firstRoute.departureFrom(
|
|
248
266
|
firstEdge.stopIndex,
|
|
249
267
|
firstEdge.tripIndex,
|
|
@@ -271,7 +289,7 @@ export class Result {
|
|
|
271
289
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
272
290
|
to: this.stopsIndex.findStopById(edge.to)!,
|
|
273
291
|
minTransferTime: edge.minTransferTime,
|
|
274
|
-
type: edge.type,
|
|
292
|
+
type: transferTypeToString(edge.type),
|
|
275
293
|
};
|
|
276
294
|
}
|
|
277
295
|
|
|
@@ -314,7 +332,7 @@ export class Result {
|
|
|
314
332
|
from: this.stopsIndex.findStopById(fromStopId)!,
|
|
315
333
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
316
334
|
to: this.stopsIndex.findStopById(toStopId)!,
|
|
317
|
-
type:
|
|
335
|
+
type: transferTypeToString(TransferTypes.GUARANTEED),
|
|
318
336
|
};
|
|
319
337
|
}
|
|
320
338
|
|
package/src/routing/route.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Stop } from '../stops/stops.js';
|
|
2
|
+
import type { PickUpDropOffTypeString } from '../timetable/route.js';
|
|
2
3
|
import {
|
|
3
4
|
Duration,
|
|
4
5
|
DURATION_ZERO,
|
|
@@ -7,13 +8,15 @@ import {
|
|
|
7
8
|
TIME_ORIGIN,
|
|
8
9
|
timeToString,
|
|
9
10
|
} from '../timetable/time.js';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
import type {
|
|
12
|
+
RouteTypeString,
|
|
13
|
+
TransferTypeString,
|
|
14
|
+
} from '../timetable/timetable.js';
|
|
15
|
+
|
|
16
|
+
export type ServiceRouteInfo = {
|
|
17
|
+
type: RouteTypeString;
|
|
18
|
+
name: string;
|
|
19
|
+
};
|
|
17
20
|
|
|
18
21
|
export type BaseLeg = {
|
|
19
22
|
from: Stop;
|
|
@@ -26,15 +29,15 @@ export type Access = BaseLeg & {
|
|
|
26
29
|
|
|
27
30
|
export type Transfer = BaseLeg & {
|
|
28
31
|
minTransferTime?: Duration;
|
|
29
|
-
type:
|
|
32
|
+
type: TransferTypeString;
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
export type VehicleLeg = BaseLeg & {
|
|
33
36
|
route: ServiceRouteInfo;
|
|
34
37
|
departureTime: Time;
|
|
35
38
|
arrivalTime: Time;
|
|
36
|
-
pickUpType:
|
|
37
|
-
dropOffType:
|
|
39
|
+
pickUpType: PickUpDropOffTypeString;
|
|
40
|
+
dropOffType: PickUpDropOffTypeString;
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
export type Leg = Transfer | Access | VehicleLeg;
|
package/src/routing/state.ts
CHANGED
|
@@ -61,7 +61,16 @@ export class RoutingState implements IRaptorState {
|
|
|
61
61
|
* Indexed as graph[round][stopId]. Entries are undefined for stops not
|
|
62
62
|
* reached in that particular round.
|
|
63
63
|
*/
|
|
64
|
+
// TODO do not expose
|
|
64
65
|
readonly graph: (RoutingEdge | undefined)[][];
|
|
66
|
+
// TODO Can use typed arrays to represent the graph
|
|
67
|
+
// Uint32 [(alightStopId -> ? =index/to), boardingStopId (stopIndex,from),
|
|
68
|
+
// RouteId/TransferId, TripId (if not transfer), (previous_round, previous_stop
|
|
69
|
+
// -> allows to reconstruct transfers incl. continuous]
|
|
70
|
+
// TODO should try to reuse them in range raptor and use only one init
|
|
71
|
+
|
|
72
|
+
// TODO take out arrival times from Graph
|
|
73
|
+
// private arrivalTimes: Uint16Array[];
|
|
65
74
|
|
|
66
75
|
/**
|
|
67
76
|
* Earliest arrival time at each stop (minutes from midnight), indexed by stop ID.
|
|
@@ -89,6 +98,18 @@ export class RoutingState implements IRaptorState {
|
|
|
89
98
|
*/
|
|
90
99
|
private _destinationBest: Time = UNREACHED_TIME;
|
|
91
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Maximum arrival time allowed for this run. Defaults to UNREACHED_TIME when
|
|
103
|
+
* the query has no maxDuration limit.
|
|
104
|
+
*/
|
|
105
|
+
maxArrivalTime: Time = UNREACHED_TIME;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Query-level maximum duration, retained so resetFor() can recompute the
|
|
109
|
+
* absolute max arrival time for each departure-time iteration.
|
|
110
|
+
*/
|
|
111
|
+
private readonly maxDuration?: Duration;
|
|
112
|
+
|
|
92
113
|
/**
|
|
93
114
|
* Every stop that has received an arrival improvement during the current run,
|
|
94
115
|
* in the order the improvements occurred. Used by {@link resetFor} to clear
|
|
@@ -102,8 +123,12 @@ export class RoutingState implements IRaptorState {
|
|
|
102
123
|
accessPaths: AccessPoint[],
|
|
103
124
|
nbStops: number,
|
|
104
125
|
maxRounds: number = 0,
|
|
126
|
+
maxDuration?: Duration,
|
|
105
127
|
) {
|
|
106
128
|
this.destinations = destinations;
|
|
129
|
+
this.maxDuration = maxDuration;
|
|
130
|
+
this.maxArrivalTime =
|
|
131
|
+
maxDuration === undefined ? UNREACHED_TIME : departureTime + maxDuration;
|
|
107
132
|
this.destinationSet = new Set(destinations);
|
|
108
133
|
this.earliestArrivalTimes = new Uint16Array(nbStops).fill(UNREACHED_TIME);
|
|
109
134
|
this.earliestArrivalLegs = new Uint8Array(nbStops);
|
|
@@ -126,6 +151,7 @@ export class RoutingState implements IRaptorState {
|
|
|
126
151
|
const seededOrigins = new Set<StopId>();
|
|
127
152
|
for (const access of accessPaths) {
|
|
128
153
|
const arrival = depTime + access.duration;
|
|
154
|
+
if (arrival > this.maxArrivalTime) continue;
|
|
129
155
|
const edge: OriginNode | AccessEdge =
|
|
130
156
|
access.duration === 0
|
|
131
157
|
? { stopId: access.fromStopId, arrival: depTime }
|
|
@@ -224,6 +250,10 @@ export class RoutingState implements IRaptorState {
|
|
|
224
250
|
}
|
|
225
251
|
this.reachedStops.length = 0;
|
|
226
252
|
this._destinationBest = UNREACHED_TIME;
|
|
253
|
+
this.maxArrivalTime =
|
|
254
|
+
this.maxDuration === undefined
|
|
255
|
+
? UNREACHED_TIME
|
|
256
|
+
: depTime + this.maxDuration;
|
|
227
257
|
this.seedAccessPaths(depTime, accessPaths);
|
|
228
258
|
}
|
|
229
259
|
|
|
@@ -11,22 +11,28 @@ import {
|
|
|
11
11
|
serializeStopsAdjacency,
|
|
12
12
|
serializeTripTransfers,
|
|
13
13
|
} from '../io.js';
|
|
14
|
-
import {
|
|
14
|
+
import { PickUpDropOffTypes, Route } from '../route.js';
|
|
15
15
|
import { timeFromHMS } from '../time.js';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
RouteTypes,
|
|
18
|
+
ServiceRoute,
|
|
19
|
+
StopAdjacency,
|
|
20
|
+
TransferTypes,
|
|
21
|
+
TripStop,
|
|
22
|
+
} from '../timetable.js';
|
|
17
23
|
import { encode } from '../tripStopId.js';
|
|
18
24
|
|
|
19
25
|
describe('Timetable IO', () => {
|
|
20
26
|
const stopsAdjacency: StopAdjacency[] = [
|
|
21
27
|
{
|
|
22
|
-
transfers: [{ destination: 2, type:
|
|
28
|
+
transfers: [{ destination: 2, type: TransferTypes.RECOMMENDED }],
|
|
23
29
|
routes: [0],
|
|
24
30
|
},
|
|
25
31
|
{
|
|
26
32
|
transfers: [
|
|
27
33
|
{
|
|
28
34
|
destination: 1,
|
|
29
|
-
type:
|
|
35
|
+
type: TransferTypes.GUARANTEED,
|
|
30
36
|
minTransferTime: 3,
|
|
31
37
|
},
|
|
32
38
|
],
|
|
@@ -37,21 +43,21 @@ describe('Timetable IO', () => {
|
|
|
37
43
|
new Route(
|
|
38
44
|
0,
|
|
39
45
|
new Uint16Array([timeFromHMS(16, 40, 0), timeFromHMS(16, 50, 0)]),
|
|
40
|
-
new Uint8Array([REGULAR, REGULAR]),
|
|
46
|
+
new Uint8Array([PickUpDropOffTypes.REGULAR, PickUpDropOffTypes.REGULAR]),
|
|
41
47
|
new Uint32Array([1, 2]),
|
|
42
48
|
0,
|
|
43
49
|
),
|
|
44
50
|
new Route(
|
|
45
51
|
1,
|
|
46
52
|
new Uint16Array([timeFromHMS(15, 20, 0), timeFromHMS(15, 30, 0)]),
|
|
47
|
-
new Uint8Array([REGULAR, REGULAR]),
|
|
53
|
+
new Uint8Array([PickUpDropOffTypes.REGULAR, PickUpDropOffTypes.REGULAR]),
|
|
48
54
|
new Uint32Array([2, 1]),
|
|
49
55
|
1,
|
|
50
56
|
),
|
|
51
57
|
];
|
|
52
58
|
const routes: ServiceRoute[] = [
|
|
53
|
-
{ type:
|
|
54
|
-
{ type:
|
|
59
|
+
{ type: RouteTypes.RAIL, name: 'Route 1', routes: [0] },
|
|
60
|
+
{ type: RouteTypes.RAIL, name: 'Route 2', routes: [1] },
|
|
55
61
|
];
|
|
56
62
|
const stopsAdjacencyProto = [
|
|
57
63
|
{
|
|
@@ -76,7 +82,10 @@ describe('Timetable IO', () => {
|
|
|
76
82
|
new Uint16Array([timeFromHMS(16, 40, 0), timeFromHMS(16, 50, 0)])
|
|
77
83
|
.buffer,
|
|
78
84
|
),
|
|
79
|
-
pickupDropOffTypes: new Uint8Array([
|
|
85
|
+
pickupDropOffTypes: new Uint8Array([
|
|
86
|
+
PickUpDropOffTypes.REGULAR,
|
|
87
|
+
PickUpDropOffTypes.REGULAR,
|
|
88
|
+
]),
|
|
80
89
|
stops: new Uint8Array(new Uint32Array([1, 2]).buffer),
|
|
81
90
|
serviceRouteId: 0,
|
|
82
91
|
},
|
|
@@ -85,7 +94,10 @@ describe('Timetable IO', () => {
|
|
|
85
94
|
new Uint16Array([timeFromHMS(15, 20, 0), timeFromHMS(15, 30, 0)])
|
|
86
95
|
.buffer,
|
|
87
96
|
),
|
|
88
|
-
pickupDropOffTypes: new Uint8Array([
|
|
97
|
+
pickupDropOffTypes: new Uint8Array([
|
|
98
|
+
PickUpDropOffTypes.REGULAR,
|
|
99
|
+
PickUpDropOffTypes.REGULAR,
|
|
100
|
+
]),
|
|
89
101
|
stops: new Uint8Array(new Uint32Array([2, 1]).buffer),
|
|
90
102
|
serviceRouteId: 1,
|
|
91
103
|
},
|
|
@@ -2,13 +2,7 @@ import assert from 'node:assert';
|
|
|
2
2
|
import { describe, it } from 'node:test';
|
|
3
3
|
|
|
4
4
|
import { encodePickUpDropOffTypes } from '../../gtfs/trips.js';
|
|
5
|
-
import {
|
|
6
|
-
MUST_COORDINATE_WITH_DRIVER,
|
|
7
|
-
MUST_PHONE_AGENCY,
|
|
8
|
-
NOT_AVAILABLE,
|
|
9
|
-
REGULAR,
|
|
10
|
-
Route,
|
|
11
|
-
} from '../route.js';
|
|
5
|
+
import { PickUpDropOffTypes, Route } from '../route.js';
|
|
12
6
|
import { TIME_ORIGIN, timeFromHMS } from '../time.js';
|
|
13
7
|
|
|
14
8
|
describe('Route', () => {
|
|
@@ -33,25 +27,25 @@ describe('Route', () => {
|
|
|
33
27
|
const pickupDropOffTypes = encodePickUpDropOffTypes(
|
|
34
28
|
[
|
|
35
29
|
// Trip 0
|
|
36
|
-
REGULAR,
|
|
37
|
-
NOT_AVAILABLE,
|
|
30
|
+
PickUpDropOffTypes.REGULAR,
|
|
31
|
+
PickUpDropOffTypes.NOT_AVAILABLE,
|
|
38
32
|
// Trip 1
|
|
39
|
-
REGULAR,
|
|
40
|
-
REGULAR,
|
|
33
|
+
PickUpDropOffTypes.REGULAR,
|
|
34
|
+
PickUpDropOffTypes.REGULAR,
|
|
41
35
|
// Trip 2
|
|
42
|
-
MUST_PHONE_AGENCY,
|
|
43
|
-
MUST_COORDINATE_WITH_DRIVER,
|
|
36
|
+
PickUpDropOffTypes.MUST_PHONE_AGENCY,
|
|
37
|
+
PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER,
|
|
44
38
|
],
|
|
45
39
|
[
|
|
46
40
|
// Trip 0
|
|
47
|
-
REGULAR,
|
|
48
|
-
REGULAR,
|
|
41
|
+
PickUpDropOffTypes.REGULAR,
|
|
42
|
+
PickUpDropOffTypes.REGULAR,
|
|
49
43
|
// Trip 1
|
|
50
|
-
REGULAR,
|
|
51
|
-
REGULAR,
|
|
44
|
+
PickUpDropOffTypes.REGULAR,
|
|
45
|
+
PickUpDropOffTypes.REGULAR,
|
|
52
46
|
// Trip 2
|
|
53
|
-
REGULAR,
|
|
54
|
-
REGULAR,
|
|
47
|
+
PickUpDropOffTypes.REGULAR,
|
|
48
|
+
PickUpDropOffTypes.REGULAR,
|
|
55
49
|
],
|
|
56
50
|
);
|
|
57
51
|
|
|
@@ -159,17 +153,17 @@ describe('Route', () => {
|
|
|
159
153
|
describe('pickUpTypeFrom', () => {
|
|
160
154
|
it('should return REGULAR pickup type for trip 0 at stop index 0', () => {
|
|
161
155
|
const pickUpType = route.pickUpTypeFrom(0, 0);
|
|
162
|
-
assert.strictEqual(pickUpType, REGULAR);
|
|
156
|
+
assert.strictEqual(pickUpType, PickUpDropOffTypes.REGULAR);
|
|
163
157
|
});
|
|
164
158
|
|
|
165
159
|
it('should return NOT_AVAILABLE pickup type for trip 0 at stop index 1', () => {
|
|
166
160
|
const pickUpType = route.pickUpTypeFrom(1, 0);
|
|
167
|
-
assert.strictEqual(pickUpType, NOT_AVAILABLE);
|
|
161
|
+
assert.strictEqual(pickUpType, PickUpDropOffTypes.NOT_AVAILABLE);
|
|
168
162
|
});
|
|
169
163
|
|
|
170
164
|
it('should return MUST_PHONE_AGENCY pickup type for trip 2 at stop index 0', () => {
|
|
171
165
|
const pickUpType = route.pickUpTypeFrom(0, 2);
|
|
172
|
-
assert.strictEqual(pickUpType, MUST_PHONE_AGENCY);
|
|
166
|
+
assert.strictEqual(pickUpType, PickUpDropOffTypes.MUST_PHONE_AGENCY);
|
|
173
167
|
});
|
|
174
168
|
|
|
175
169
|
it('should throw error for invalid stop index', () => {
|
|
@@ -190,12 +184,12 @@ describe('Route', () => {
|
|
|
190
184
|
describe('dropOffTypeAt', () => {
|
|
191
185
|
it('should return REGULAR drop off type for trip 0 at stop index 0', () => {
|
|
192
186
|
const dropOffType = route.dropOffTypeAt(0, 0);
|
|
193
|
-
assert.strictEqual(dropOffType, REGULAR);
|
|
187
|
+
assert.strictEqual(dropOffType, PickUpDropOffTypes.REGULAR);
|
|
194
188
|
});
|
|
195
189
|
|
|
196
190
|
it('should return REGULAR drop off type for trip 1 at stop index 1', () => {
|
|
197
191
|
const dropOffType = route.dropOffTypeAt(1, 1);
|
|
198
|
-
assert.strictEqual(dropOffType, REGULAR);
|
|
192
|
+
assert.strictEqual(dropOffType, PickUpDropOffTypes.REGULAR);
|
|
199
193
|
});
|
|
200
194
|
|
|
201
195
|
it('should throw error for invalid stop index', () => {
|