minotor 11.1.2 → 11.2.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.
Files changed (71) hide show
  1. package/.cspell.json +7 -1
  2. package/CHANGELOG.md +3 -3
  3. package/README.md +111 -86
  4. package/dist/cli/perf.d.ts +57 -18
  5. package/dist/cli.mjs +1371 -342
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/parser.cjs.js +57 -4
  8. package/dist/parser.cjs.js.map +1 -1
  9. package/dist/parser.esm.js +57 -4
  10. package/dist/parser.esm.js.map +1 -1
  11. package/dist/router.cjs.js +1 -1
  12. package/dist/router.cjs.js.map +1 -1
  13. package/dist/router.d.ts +5 -5
  14. package/dist/router.esm.js +1 -1
  15. package/dist/router.esm.js.map +1 -1
  16. package/dist/router.umd.js +1 -1
  17. package/dist/router.umd.js.map +1 -1
  18. package/dist/routing/__tests__/access.test.d.ts +1 -0
  19. package/dist/routing/__tests__/plainRouter.test.d.ts +1 -0
  20. package/dist/routing/__tests__/rangeResult.test.d.ts +1 -0
  21. package/dist/routing/__tests__/rangeRouter.test.d.ts +1 -0
  22. package/dist/routing/__tests__/rangeState.test.d.ts +1 -0
  23. package/dist/routing/__tests__/raptor.test.d.ts +1 -0
  24. package/dist/routing/__tests__/state.test.d.ts +1 -0
  25. package/dist/routing/access.d.ts +55 -0
  26. package/dist/routing/plainRouter.d.ts +21 -0
  27. package/dist/routing/plotter.d.ts +9 -0
  28. package/dist/routing/query.d.ts +132 -13
  29. package/dist/routing/rangeResult.d.ts +155 -0
  30. package/dist/routing/rangeRouter.d.ts +24 -0
  31. package/dist/routing/rangeState.d.ts +83 -0
  32. package/dist/routing/raptor.d.ts +96 -0
  33. package/dist/routing/result.d.ts +27 -7
  34. package/dist/routing/route.d.ts +5 -21
  35. package/dist/routing/router.d.ts +20 -91
  36. package/dist/routing/state.d.ts +92 -17
  37. package/dist/timetable/route.d.ts +8 -0
  38. package/dist/timetable/timetable.d.ts +17 -1
  39. package/package.json +1 -1
  40. package/src/__e2e__/benchmark.json +18 -0
  41. package/src/__e2e__/router.test.ts +461 -127
  42. package/src/cli/minotor.ts +39 -3
  43. package/src/cli/perf.ts +324 -60
  44. package/src/cli/repl.ts +96 -41
  45. package/src/router.ts +11 -3
  46. package/src/routing/__tests__/access.test.ts +294 -0
  47. package/src/routing/__tests__/plainRouter.test.ts +1633 -0
  48. package/src/routing/__tests__/plotter.test.ts +8 -8
  49. package/src/routing/__tests__/rangeResult.test.ts +273 -0
  50. package/src/routing/__tests__/rangeRouter.test.ts +472 -0
  51. package/src/routing/__tests__/rangeState.test.ts +246 -0
  52. package/src/routing/__tests__/raptor.test.ts +366 -0
  53. package/src/routing/__tests__/result.test.ts +27 -27
  54. package/src/routing/__tests__/route.test.ts +28 -0
  55. package/src/routing/__tests__/router.test.ts +75 -1587
  56. package/src/routing/__tests__/state.test.ts +78 -0
  57. package/src/routing/access.ts +144 -0
  58. package/src/routing/plainRouter.ts +60 -0
  59. package/src/routing/plotter.ts +53 -6
  60. package/src/routing/query.ts +116 -13
  61. package/src/routing/rangeResult.ts +292 -0
  62. package/src/routing/rangeRouter.ts +167 -0
  63. package/src/routing/rangeState.ts +150 -0
  64. package/src/routing/raptor.ts +416 -0
  65. package/src/routing/result.ts +68 -26
  66. package/src/routing/route.ts +15 -53
  67. package/src/routing/router.ts +40 -480
  68. package/src/routing/state.ts +191 -32
  69. package/src/timetable/__tests__/timetable.test.ts +373 -0
  70. package/src/timetable/route.ts +16 -4
  71. package/src/timetable/timetable.ts +54 -1
@@ -294,6 +294,18 @@ export class Route {
294
294
  return this.stopTimes[(offset + stopIndex) * 2]!;
295
295
  }
296
296
 
297
+ /**
298
+ * Hot-path variant of {@link departureFrom} that accepts a precomputed base offset.
299
+ *
300
+ * @param stopIndex - The index of the stop in the route.
301
+ * @param offset - Precomputed value from {@link tripStopOffset}.
302
+ * @returns The departure time at the specified stop.
303
+ */
304
+ departureAtOffset(stopIndex: StopRouteIndex, offset: number): Time {
305
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
306
+ return this.stopTimes[(offset + stopIndex) * 2 + 1]!;
307
+ }
308
+
297
309
  /**
298
310
  * Hot-path variant of {@link dropOffTypeAt} that accepts a precomputed base offset.
299
311
  *
@@ -345,8 +357,8 @@ export class Route {
345
357
  tripIndex: TripRouteIndex,
346
358
  ): RawPickUpDropOffType {
347
359
  const globalIndex = tripIndex * this.stops.length + stopIndex;
348
- const byteIndex = Math.floor(globalIndex / 2);
349
- const isSecondPair = globalIndex % 2 === 1;
360
+ const byteIndex = globalIndex >> 1;
361
+ const isSecondPair = (globalIndex & 1) === 1;
350
362
 
351
363
  const byte = this.pickupDropOffTypes[byteIndex];
352
364
  if (byte === undefined) {
@@ -373,8 +385,8 @@ export class Route {
373
385
  tripIndex: TripRouteIndex,
374
386
  ): RawPickUpDropOffType {
375
387
  const globalIndex = tripIndex * this.stops.length + stopIndex;
376
- const byteIndex = Math.floor(globalIndex / 2);
377
- const isSecondPair = globalIndex % 2 === 1;
388
+ const byteIndex = globalIndex >> 1;
389
+ const isSecondPair = (globalIndex & 1) === 1;
378
390
 
379
391
  const byte = this.pickupDropOffTypes[byteIndex];
380
392
  if (byte === undefined) {
@@ -13,8 +13,9 @@ import {
13
13
  serializeTripTransfers,
14
14
  } from './io.js';
15
15
  import { Timetable as ProtoTimetable } from './proto/v1/timetable.js';
16
+ import { NOT_AVAILABLE } from './route.js';
16
17
  import { Route, RouteId, StopRouteIndex, TripRouteIndex } from './route.js';
17
- import { Duration } from './time.js';
18
+ import { Duration, DURATION_ZERO, Time, TIME_ORIGIN } from './time.js';
18
19
  import { encode, TripStopId } from './tripStopId.js';
19
20
 
20
21
  export type TransferType =
@@ -341,6 +342,58 @@ export class Timetable {
341
342
  return false;
342
343
  }
343
344
 
345
+ /**
346
+ * Finds the first trip on `route` at `stopIndex` that can be boarded, starting
347
+ * from `earliestTrip` and respecting pickup availability, transfer guarantees,
348
+ * and minimum transfer times.
349
+ *
350
+ * @param stopIndex Stop at which boarding is attempted.
351
+ * @param route The route to search.
352
+ * @param earliestTrip First trip index to consider.
353
+ * @param after Earliest time after which boarding is allowed.
354
+ * @param beforeTrip Exclusive upper bound on the trip index (omit to search all).
355
+ * @param fromTripStop The alighted trip stop when transferring from another trip;
356
+ * `undefined` when boarding from a walk or origin.
357
+ * @param transferTime Minimum transfer time required between trips.
358
+ * @returns The index of the first boardable trip, or `undefined` if none found.
359
+ */
360
+ findFirstBoardableTrip(
361
+ stopIndex: StopRouteIndex,
362
+ route: Route,
363
+ earliestTrip: TripRouteIndex,
364
+ after: Time = TIME_ORIGIN,
365
+ beforeTrip?: TripRouteIndex,
366
+ fromTripStop?: TripStop,
367
+ transferTime: Duration = DURATION_ZERO,
368
+ ): TripRouteIndex | undefined {
369
+ const nbTrips = route.getNbTrips();
370
+
371
+ for (let t = earliestTrip; t < (beforeTrip ?? nbTrips); t++) {
372
+ const pickup = route.pickUpTypeFrom(stopIndex, t);
373
+ if (pickup === NOT_AVAILABLE) {
374
+ continue;
375
+ }
376
+ if (fromTripStop === undefined) {
377
+ return t;
378
+ }
379
+
380
+ const isGuaranteed = this.isTripTransferGuaranteed(fromTripStop, {
381
+ stopIndex,
382
+ routeId: route.id,
383
+ tripIndex: t,
384
+ });
385
+ if (isGuaranteed) {
386
+ return t;
387
+ }
388
+ const departure = route.departureFrom(stopIndex, t);
389
+ const requiredTime = after + transferTime;
390
+ if (departure >= requiredTime) {
391
+ return t;
392
+ }
393
+ }
394
+ return undefined;
395
+ }
396
+
344
397
  /**
345
398
  * Retrieves all guaranteed trip transfer options available at the specified stop for a given trip.
346
399
  *