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
@@ -12715,6 +12715,7 @@ function isSet(value) {
12715
12715
  }
12716
12716
 
12717
12717
  const TIME_ORIGIN = 0;
12718
+ const DURATION_ZERO = 0;
12718
12719
  /**
12719
12720
  * Creates a Time from hours, minutes, and seconds.
12720
12721
  * Rounds to the closest minute as times are represented in minutes from midnight.
@@ -12921,6 +12922,17 @@ class Route {
12921
12922
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12922
12923
  return this.stopTimes[(offset + stopIndex) * 2];
12923
12924
  }
12925
+ /**
12926
+ * Hot-path variant of {@link departureFrom} that accepts a precomputed base offset.
12927
+ *
12928
+ * @param stopIndex - The index of the stop in the route.
12929
+ * @param offset - Precomputed value from {@link tripStopOffset}.
12930
+ * @returns The departure time at the specified stop.
12931
+ */
12932
+ departureAtOffset(stopIndex, offset) {
12933
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12934
+ return this.stopTimes[(offset + stopIndex) * 2 + 1];
12935
+ }
12924
12936
  /**
12925
12937
  * Hot-path variant of {@link dropOffTypeAt} that accepts a precomputed base offset.
12926
12938
  *
@@ -12960,8 +12972,8 @@ class Route {
12960
12972
  */
12961
12973
  pickUpTypeFrom(stopIndex, tripIndex) {
12962
12974
  const globalIndex = tripIndex * this.stops.length + stopIndex;
12963
- const byteIndex = Math.floor(globalIndex / 2);
12964
- const isSecondPair = globalIndex % 2 === 1;
12975
+ const byteIndex = globalIndex >> 1;
12976
+ const isSecondPair = (globalIndex & 1) === 1;
12965
12977
  const byte = this.pickupDropOffTypes[byteIndex];
12966
12978
  if (byte === undefined) {
12967
12979
  throw new Error(`Pick up type not found for stop ${this.stopId(stopIndex)} (${stopIndex}) at trip index ${tripIndex} in route ${this.serviceRouteId}`);
@@ -12980,8 +12992,8 @@ class Route {
12980
12992
  */
12981
12993
  dropOffTypeAt(stopIndex, tripIndex) {
12982
12994
  const globalIndex = tripIndex * this.stops.length + stopIndex;
12983
- const byteIndex = Math.floor(globalIndex / 2);
12984
- const isSecondPair = globalIndex % 2 === 1;
12995
+ const byteIndex = globalIndex >> 1;
12996
+ const isSecondPair = (globalIndex & 1) === 1;
12985
12997
  const byte = this.pickupDropOffTypes[byteIndex];
12986
12998
  if (byte === undefined) {
12987
12999
  throw new Error(`Drop off type not found for stop ${this.stopId(stopIndex)} (${stopIndex}) at trip index ${tripIndex} in route ${this.serviceRouteId}`);
@@ -13581,6 +13593,47 @@ class Timetable {
13581
13593
  }
13582
13594
  return false;
13583
13595
  }
13596
+ /**
13597
+ * Finds the first trip on `route` at `stopIndex` that can be boarded, starting
13598
+ * from `earliestTrip` and respecting pickup availability, transfer guarantees,
13599
+ * and minimum transfer times.
13600
+ *
13601
+ * @param stopIndex Stop at which boarding is attempted.
13602
+ * @param route The route to search.
13603
+ * @param earliestTrip First trip index to consider.
13604
+ * @param after Earliest time after which boarding is allowed.
13605
+ * @param beforeTrip Exclusive upper bound on the trip index (omit to search all).
13606
+ * @param fromTripStop The alighted trip stop when transferring from another trip;
13607
+ * `undefined` when boarding from a walk or origin.
13608
+ * @param transferTime Minimum transfer time required between trips.
13609
+ * @returns The index of the first boardable trip, or `undefined` if none found.
13610
+ */
13611
+ findFirstBoardableTrip(stopIndex, route, earliestTrip, after = TIME_ORIGIN, beforeTrip, fromTripStop, transferTime = DURATION_ZERO) {
13612
+ const nbTrips = route.getNbTrips();
13613
+ for (let t = earliestTrip; t < (beforeTrip !== null && beforeTrip !== void 0 ? beforeTrip : nbTrips); t++) {
13614
+ const pickup = route.pickUpTypeFrom(stopIndex, t);
13615
+ if (pickup === NOT_AVAILABLE) {
13616
+ continue;
13617
+ }
13618
+ if (fromTripStop === undefined) {
13619
+ return t;
13620
+ }
13621
+ const isGuaranteed = this.isTripTransferGuaranteed(fromTripStop, {
13622
+ stopIndex,
13623
+ routeId: route.id,
13624
+ tripIndex: t,
13625
+ });
13626
+ if (isGuaranteed) {
13627
+ return t;
13628
+ }
13629
+ const departure = route.departureFrom(stopIndex, t);
13630
+ const requiredTime = after + transferTime;
13631
+ if (departure >= requiredTime) {
13632
+ return t;
13633
+ }
13634
+ }
13635
+ return undefined;
13636
+ }
13584
13637
  /**
13585
13638
  * Retrieves all guaranteed trip transfer options available at the specified stop for a given trip.
13586
13639
  *