minotor 12.0.1 → 13.0.1
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 +7 -4
- package/dist/cli/perf.d.ts +4 -4
- package/dist/cli.mjs +1558 -1488
- package/dist/cli.mjs.map +1 -1
- package/dist/gtfs/__tests__/logging.test.d.ts +1 -0
- package/dist/gtfs/logging.d.ts +8 -0
- package/dist/parser.cjs.js +108 -98
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.d.ts +4 -2
- package/dist/parser.esm.js +108 -99
- 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 +2 -1
- 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/rangeResult.d.ts +34 -25
- package/dist/routing/result.d.ts +28 -9
- package/dist/routing/resultInternals.d.ts +4 -0
- package/dist/routing/routingResult.d.ts +29 -0
- package/package.json +1 -1
- package/src/cli/minotor.ts +4 -12
- package/src/cli/perf.ts +5 -5
- package/src/cli/repl.ts +1 -1
- package/src/gtfs/__tests__/logging.test.ts +100 -0
- package/src/gtfs/frequencies.ts +1 -2
- package/src/gtfs/logging.ts +15 -0
- package/src/gtfs/parser.ts +1 -2
- package/src/gtfs/routes.ts +1 -2
- package/src/gtfs/stops.ts +1 -2
- package/src/gtfs/transfers.ts +1 -2
- package/src/gtfs/trips.ts +1 -2
- package/src/parser.ts +4 -0
- package/src/router.ts +3 -0
- package/src/routing/__tests__/plotter.test.ts +0 -11
- package/src/routing/__tests__/rangeResult.test.ts +1470 -46
- package/src/routing/__tests__/rangeRouter.test.ts +14 -8
- package/src/routing/__tests__/result.test.ts +375 -76
- package/src/routing/plainRouter.ts +1 -6
- package/src/routing/plotter.ts +6 -5
- package/src/routing/rangeResult.ts +67 -52
- package/src/routing/rangeRouter.ts +3 -8
- package/src/routing/result.ts +95 -36
- package/src/routing/resultInternals.ts +5 -0
- package/src/routing/routingResult.ts +34 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { StopId } from '../stops/stops.js';
|
|
2
2
|
import { Duration, Time } from '../timetable/time.js';
|
|
3
3
|
import { Result } from './result.js';
|
|
4
|
+
import { resultDestinations } from './resultInternals.js';
|
|
4
5
|
import { Route } from './route.js';
|
|
6
|
+
import type { RoutingResult, StopArrival } from './routingResult.js';
|
|
5
7
|
import { Arrival } from './state.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -42,56 +44,49 @@ export type ArrivalWithDuration = Arrival & {
|
|
|
42
44
|
* strictly earlier *and* arrives strictly earlier than the previous one,
|
|
43
45
|
* forming the classic staircase Pareto frontier.
|
|
44
46
|
*
|
|
45
|
-
* **Full-network mode** (
|
|
47
|
+
* **Full-network mode** (no query destinations): when no destinations are
|
|
46
48
|
* supplied to the range query every departure slot in the window becomes its
|
|
47
49
|
* own run, because destination-based Pareto pruning cannot be applied.
|
|
48
|
-
* In this mode the destination-specific helpers ({@link
|
|
50
|
+
* In this mode the destination-specific helpers ({@link routes},
|
|
49
51
|
* {@link bestRoute}, {@link latestDepartureRoute}, {@link fastestRoute})
|
|
50
|
-
* return empty results; use {@link
|
|
51
|
-
* {@link
|
|
52
|
+
* return empty results; use {@link arrivals},
|
|
53
|
+
* {@link shortestDurations}, {@link arrivalAt}, or
|
|
52
54
|
* {@link shortestDurationTo} instead.
|
|
53
55
|
*
|
|
54
56
|
* Destination handling is delegated to {@link Result}, which expands
|
|
55
57
|
* equivalent stops when reconstructing routes or looking up arrivals.
|
|
56
58
|
*/
|
|
57
|
-
export class RangeResult {
|
|
59
|
+
export class RangeResult implements RoutingResult {
|
|
58
60
|
private readonly _runs: readonly ParetoRun[];
|
|
59
|
-
private readonly _destinations: ReadonlySet<StopId>;
|
|
60
61
|
|
|
61
|
-
constructor(runs: ParetoRun[]
|
|
62
|
+
constructor(runs: ParetoRun[]) {
|
|
62
63
|
this._runs = runs;
|
|
63
|
-
this._destinations = destinations;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** The resolved destination stop IDs for this result. */
|
|
67
|
-
get destinations(): ReadonlySet<StopId> {
|
|
68
|
-
return this._destinations;
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
private normalizeTargets(to?: StopId | Set<StopId>): Set<StopId> {
|
|
72
67
|
if (to instanceof Set) return new Set(to);
|
|
73
68
|
if (to !== undefined) return new Set([to]);
|
|
74
|
-
return new Set(this.
|
|
69
|
+
return new Set(this._runs[0]?.result[resultDestinations]());
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
/**
|
|
78
|
-
*
|
|
73
|
+
* Lazily yields all non-dominated routes to this result's default destination set,
|
|
79
74
|
* ordered from the earliest departure to the latest departure.
|
|
80
75
|
*
|
|
81
|
-
* Each route in the list departs strictly
|
|
82
|
-
*
|
|
76
|
+
* Each route in the list departs strictly later *and* arrives strictly
|
|
77
|
+
* later than its predecessor.
|
|
83
78
|
*
|
|
84
|
-
*
|
|
85
|
-
* mode). Use {@link
|
|
79
|
+
* Yields nothing when no destinations were provided (full-network
|
|
80
|
+
* mode). Use {@link arrivals} or {@link shortestDurations}
|
|
86
81
|
* to query individual stops in that case.
|
|
87
82
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
*routes(): Generator<Route> {
|
|
84
|
+
for (let index = this._runs.length - 1; index >= 0; index--) {
|
|
85
|
+
const run = this._runs[index];
|
|
86
|
+
if (run === undefined) continue;
|
|
87
|
+
const route = run.result.bestRoute();
|
|
88
|
+
if (route !== undefined) yield route;
|
|
93
89
|
}
|
|
94
|
-
return routes.reverse();
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
/**
|
|
@@ -107,10 +102,14 @@ export class RangeResult {
|
|
|
107
102
|
* (no destinations), otherwise `undefined` is returned.
|
|
108
103
|
*
|
|
109
104
|
* @param to Optional destination stop ID or set of stop IDs.
|
|
105
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
110
106
|
* @returns The reconstructed {@link Route} with the earliest arrival,
|
|
111
107
|
* or `undefined` if the target is unreachable in every run.
|
|
112
108
|
*/
|
|
113
|
-
bestRoute(
|
|
109
|
+
bestRoute(
|
|
110
|
+
to?: StopId | Set<StopId>,
|
|
111
|
+
maxTransfers?: number,
|
|
112
|
+
): Route | undefined {
|
|
114
113
|
const targetStops = this.normalizeTargets(to);
|
|
115
114
|
|
|
116
115
|
let bestRun: ParetoRun | undefined;
|
|
@@ -118,7 +117,7 @@ export class RangeResult {
|
|
|
118
117
|
|
|
119
118
|
for (const run of this._runs) {
|
|
120
119
|
for (const stopId of targetStops) {
|
|
121
|
-
const arrival = run.result.arrivalAt(stopId);
|
|
120
|
+
const arrival = run.result.arrivalAt(stopId, maxTransfers);
|
|
122
121
|
if (arrival === undefined) continue;
|
|
123
122
|
if (bestArrival === undefined || arrival.arrival < bestArrival) {
|
|
124
123
|
bestArrival = arrival.arrival;
|
|
@@ -127,7 +126,7 @@ export class RangeResult {
|
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
return bestRun?.result.bestRoute(targetStops);
|
|
129
|
+
return bestRun?.result.bestRoute(targetStops, maxTransfers);
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
/**
|
|
@@ -144,13 +143,17 @@ export class RangeResult {
|
|
|
144
143
|
* (no destinations), otherwise `undefined` is returned.
|
|
145
144
|
*
|
|
146
145
|
* @param to Optional destination stop ID or set of stop IDs.
|
|
146
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
147
147
|
* @returns The reconstructed {@link Route} with the latest departure,
|
|
148
148
|
* or `undefined` if the target is unreachable in every run.
|
|
149
149
|
*/
|
|
150
|
-
latestDepartureRoute(
|
|
150
|
+
latestDepartureRoute(
|
|
151
|
+
to?: StopId | Set<StopId>,
|
|
152
|
+
maxTransfers?: number,
|
|
153
|
+
): Route | undefined {
|
|
151
154
|
const targetStops = this.normalizeTargets(to);
|
|
152
155
|
for (const { result } of this._runs) {
|
|
153
|
-
const route = result.bestRoute(targetStops);
|
|
156
|
+
const route = result.bestRoute(targetStops, maxTransfers);
|
|
154
157
|
if (route !== undefined) return route;
|
|
155
158
|
}
|
|
156
159
|
return undefined;
|
|
@@ -170,10 +173,14 @@ export class RangeResult {
|
|
|
170
173
|
* (no destinations), otherwise `undefined` is returned.
|
|
171
174
|
*
|
|
172
175
|
* @param to Optional destination stop ID or set of stop IDs.
|
|
176
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
173
177
|
* @returns The reconstructed fastest {@link Route}, or `undefined` if the
|
|
174
178
|
* target is unreachable in every run.
|
|
175
179
|
*/
|
|
176
|
-
fastestRoute(
|
|
180
|
+
fastestRoute(
|
|
181
|
+
to?: StopId | Set<StopId>,
|
|
182
|
+
maxTransfers?: number,
|
|
183
|
+
): Route | undefined {
|
|
177
184
|
const targetStops = this.normalizeTargets(to);
|
|
178
185
|
|
|
179
186
|
let fastestRun: ParetoRun | undefined;
|
|
@@ -181,7 +188,7 @@ export class RangeResult {
|
|
|
181
188
|
|
|
182
189
|
for (const run of this._runs) {
|
|
183
190
|
for (const stopId of targetStops) {
|
|
184
|
-
const arrival = run.result.arrivalAt(stopId);
|
|
191
|
+
const arrival = run.result.arrivalAt(stopId, maxTransfers);
|
|
185
192
|
if (arrival === undefined) continue;
|
|
186
193
|
const duration = arrival.arrival - run.departureTime;
|
|
187
194
|
if (
|
|
@@ -196,7 +203,7 @@ export class RangeResult {
|
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
|
|
199
|
-
return fastestRun?.result.bestRoute(targetStops);
|
|
206
|
+
return fastestRun?.result.bestRoute(targetStops, maxTransfers);
|
|
200
207
|
}
|
|
201
208
|
|
|
202
209
|
/** Number of Pareto-optimal journeys found. */
|
|
@@ -214,9 +221,9 @@ export class RangeResult {
|
|
|
214
221
|
* Equivalent stops are handled by {@link Result.arrivalAt}.
|
|
215
222
|
*
|
|
216
223
|
* @param stop The target stop ID.
|
|
217
|
-
* @param maxTransfers Optional
|
|
224
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
218
225
|
*/
|
|
219
|
-
|
|
226
|
+
arrivalAt(stop: StopId, maxTransfers?: number): Arrival | undefined {
|
|
220
227
|
let best: Arrival | undefined;
|
|
221
228
|
for (const { result } of this._runs) {
|
|
222
229
|
const arrival = result.arrivalAt(stop, maxTransfers);
|
|
@@ -246,7 +253,7 @@ export class RangeResult {
|
|
|
246
253
|
* Returns `undefined` if `stop` is unreachable in every run.
|
|
247
254
|
*
|
|
248
255
|
* @param stop The target stop ID.
|
|
249
|
-
* @param maxTransfers Optional
|
|
256
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
250
257
|
*/
|
|
251
258
|
shortestDurationTo(
|
|
252
259
|
stop: StopId,
|
|
@@ -266,16 +273,19 @@ export class RangeResult {
|
|
|
266
273
|
|
|
267
274
|
/**
|
|
268
275
|
* Shortest travel duration to **every reachable stop** across all
|
|
269
|
-
* Pareto-optimal runs,
|
|
276
|
+
* Pareto-optimal runs, yielding the stop ID and arrival with duration.
|
|
277
|
+
* All runs are aggregated before the first value is yielded. Ties retain
|
|
278
|
+
* the first run's arrival and leg count.
|
|
279
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
270
280
|
*/
|
|
271
|
-
|
|
281
|
+
*shortestDurations(
|
|
282
|
+
maxTransfers?: number,
|
|
283
|
+
): Generator<StopArrival & { duration: Duration }> {
|
|
272
284
|
const durations = new Map<StopId, ArrivalWithDuration>();
|
|
273
285
|
for (const { departureTime, result } of this._runs) {
|
|
274
|
-
for (const {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
legNumber,
|
|
278
|
-
} of result.routingState.arrivals()) {
|
|
286
|
+
for (const { stop, arrival, legNumber } of result.arrivals(
|
|
287
|
+
maxTransfers,
|
|
288
|
+
)) {
|
|
279
289
|
const duration = arrival - departureTime;
|
|
280
290
|
const existing = durations.get(stop);
|
|
281
291
|
if (existing === undefined || duration < existing.duration) {
|
|
@@ -283,28 +293,33 @@ export class RangeResult {
|
|
|
283
293
|
}
|
|
284
294
|
}
|
|
285
295
|
}
|
|
286
|
-
|
|
296
|
+
for (const [stop, arrival] of durations) {
|
|
297
|
+
yield { stop, ...arrival };
|
|
298
|
+
}
|
|
287
299
|
}
|
|
288
300
|
|
|
289
301
|
/**
|
|
290
302
|
* Earliest achievable arrival at **every reachable stop** across all
|
|
291
|
-
* Pareto-optimal runs,
|
|
303
|
+
* Pareto-optimal runs, yielding the stop ID and arrival.
|
|
304
|
+
* All runs are aggregated before the first value is yielded. Ties retain
|
|
305
|
+
* the first run's arrival and leg count.
|
|
306
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
292
307
|
*/
|
|
293
|
-
|
|
308
|
+
*arrivals(maxTransfers?: number): Generator<StopArrival> {
|
|
294
309
|
const arrivals = new Map<StopId, Arrival>();
|
|
295
310
|
for (const { result } of this._runs) {
|
|
296
|
-
for (const {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
legNumber,
|
|
300
|
-
} of result.routingState.arrivals()) {
|
|
311
|
+
for (const { stop, arrival, legNumber } of result.arrivals(
|
|
312
|
+
maxTransfers,
|
|
313
|
+
)) {
|
|
301
314
|
const existing = arrivals.get(stop);
|
|
302
315
|
if (existing === undefined || arrival < existing.arrival) {
|
|
303
316
|
arrivals.set(stop, { arrival, legNumber });
|
|
304
317
|
}
|
|
305
318
|
}
|
|
306
319
|
}
|
|
307
|
-
|
|
320
|
+
for (const [stop, arrival] of arrivals) {
|
|
321
|
+
yield { stop, ...arrival };
|
|
322
|
+
}
|
|
308
323
|
}
|
|
309
324
|
|
|
310
325
|
/**
|
|
@@ -58,7 +58,7 @@ export class RangeRouter {
|
|
|
58
58
|
latest,
|
|
59
59
|
);
|
|
60
60
|
if (departureSlots.length === 0) {
|
|
61
|
-
return new RangeResult([]
|
|
61
|
+
return new RangeResult([]);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const maxRounds = query.options.maxTransfers + 1;
|
|
@@ -161,17 +161,12 @@ export class RangeRouter {
|
|
|
161
161
|
if (isParetoOptimal) {
|
|
162
162
|
paretoRuns.push({
|
|
163
163
|
departureTime: depTime,
|
|
164
|
-
result: new Result(
|
|
165
|
-
new Set(destinations),
|
|
166
|
-
routingState,
|
|
167
|
-
this.stopsIndex,
|
|
168
|
-
this.timetable,
|
|
169
|
-
),
|
|
164
|
+
result: new Result(routingState, this.stopsIndex, this.timetable),
|
|
170
165
|
});
|
|
171
166
|
routingState = null;
|
|
172
167
|
}
|
|
173
168
|
}
|
|
174
169
|
|
|
175
|
-
return new RangeResult(paretoRuns
|
|
170
|
+
return new RangeResult(paretoRuns);
|
|
176
171
|
}
|
|
177
172
|
}
|
package/src/routing/result.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { StopsIndex } from '../stops/stopsIndex.js';
|
|
|
4
4
|
import { Route as TimetableRoute } from '../timetable/route.js';
|
|
5
5
|
import { Time } from '../timetable/time.js';
|
|
6
6
|
import { TransferTypes } from '../timetable/timetable.js';
|
|
7
|
+
import { resultDestinations, resultGraph } from './resultInternals.js';
|
|
7
8
|
import {
|
|
8
9
|
Access,
|
|
9
10
|
Leg,
|
|
@@ -13,38 +14,103 @@ import {
|
|
|
13
14
|
VehicleLeg,
|
|
14
15
|
} from './route.js';
|
|
15
16
|
import { Arrival, RoutingState, TransferEdge, VehicleEdge } from './router.js';
|
|
17
|
+
import type { RoutingResult, StopArrival } from './routingResult.js';
|
|
16
18
|
import { AccessEdge } from './state.js';
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
/**
|
|
21
|
+
* A single-departure routing result.
|
|
22
|
+
*/
|
|
23
|
+
export class Result implements RoutingResult {
|
|
24
|
+
readonly #routingState: RoutingState;
|
|
21
25
|
public readonly stopsIndex: StopsIndex;
|
|
22
26
|
public readonly timetable: Timetable;
|
|
23
27
|
|
|
24
28
|
constructor(
|
|
25
|
-
destinations: ReadonlySet<StopId>,
|
|
26
29
|
routingState: RoutingState,
|
|
27
30
|
stopsIndex: StopsIndex,
|
|
28
31
|
timetable: Timetable,
|
|
29
32
|
) {
|
|
30
|
-
this
|
|
31
|
-
this.routingState = routingState;
|
|
33
|
+
this.#routingState = routingState;
|
|
32
34
|
this.stopsIndex = stopsIndex;
|
|
33
35
|
this.timetable = timetable;
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
/** @internal Default query destinations for range result selection. */
|
|
39
|
+
[resultDestinations](): readonly StopId[] {
|
|
40
|
+
return this.#routingState.destinations;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @internal Routing graph and destination metadata for the graph plotter. */
|
|
44
|
+
[resultGraph](): Pick<RoutingState, 'graph' | 'destinations'> {
|
|
45
|
+
return {
|
|
46
|
+
graph: this.#routingState.graph,
|
|
47
|
+
destinations: this.#routingState.destinations,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Iterates over reached stops, yielding each concrete stop ID, its earliest
|
|
53
|
+
* arrival time, and the number of legs taken to reach it. Unreached stops
|
|
54
|
+
* are omitted. Destination pruning may limit which stops were reached.
|
|
55
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
56
|
+
*/
|
|
57
|
+
*arrivals(maxTransfers?: number): Generator<StopArrival> {
|
|
58
|
+
for (const reached of this.#routingState.arrivals()) {
|
|
59
|
+
if (maxTransfers === undefined) {
|
|
60
|
+
yield reached;
|
|
61
|
+
} else {
|
|
62
|
+
const arrival = this.concreteArrivalAt(reached.stop, maxTransfers);
|
|
63
|
+
if (arrival !== undefined) yield { stop: reached.stop, ...arrival };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Looks up one concrete stop without expanding equivalent stops. */
|
|
69
|
+
private concreteArrivalAt(
|
|
70
|
+
stop: StopId,
|
|
71
|
+
maxTransfers?: number,
|
|
72
|
+
): Arrival | undefined {
|
|
73
|
+
const best = this.#routingState.getArrival(stop);
|
|
74
|
+
if (
|
|
75
|
+
maxTransfers === undefined ||
|
|
76
|
+
(best !== undefined && best.legNumber <= maxTransfers + 1)
|
|
77
|
+
) {
|
|
78
|
+
return best;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let earliest: Arrival | undefined;
|
|
82
|
+
const lastRound = Math.min(
|
|
83
|
+
maxTransfers + 1,
|
|
84
|
+
this.#routingState.graph.length - 1,
|
|
85
|
+
);
|
|
86
|
+
for (let round = lastRound; round >= 0; round--) {
|
|
87
|
+
const edge = this.#routingState.graph[round]?.[stop];
|
|
88
|
+
if (
|
|
89
|
+
edge !== undefined &&
|
|
90
|
+
(earliest === undefined || edge.arrival < earliest.arrival)
|
|
91
|
+
) {
|
|
92
|
+
earliest = { arrival: edge.arrival, legNumber: round };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return earliest;
|
|
96
|
+
}
|
|
97
|
+
|
|
36
98
|
/**
|
|
37
99
|
* Expands a target stop or stop set to all equivalent concrete stop IDs.
|
|
38
100
|
*
|
|
39
|
-
* When `to` is omitted, defaults to the resolved destinations
|
|
40
|
-
*
|
|
101
|
+
* When `to` is omitted, defaults to the resolved destinations in the
|
|
102
|
+
* query.
|
|
41
103
|
*
|
|
42
104
|
* Equivalent stops are expanded here so destination handling has a single
|
|
43
105
|
* source of truth shared by route reconstruction and arrival lookups.
|
|
44
106
|
*/
|
|
45
107
|
private expandDestinations(to?: StopId | Set<StopId>): Set<StopId> {
|
|
46
108
|
const targets: Iterable<StopId> =
|
|
47
|
-
to instanceof Set
|
|
109
|
+
to instanceof Set
|
|
110
|
+
? to
|
|
111
|
+
: to !== undefined
|
|
112
|
+
? [to]
|
|
113
|
+
: this.#routingState.destinations;
|
|
48
114
|
|
|
49
115
|
const expanded = new Set<StopId>();
|
|
50
116
|
for (const target of targets) {
|
|
@@ -61,10 +127,12 @@ export class Result {
|
|
|
61
127
|
* destination set)
|
|
62
128
|
*
|
|
63
129
|
* @param to The destination stop by SourceStopId.
|
|
130
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
64
131
|
* @returns a route to the destination stop if it exists.
|
|
65
132
|
*/
|
|
66
133
|
bestRouteToSourceStopId(
|
|
67
134
|
to: SourceStopId | Set<SourceStopId>,
|
|
135
|
+
maxTransfers?: number,
|
|
68
136
|
): Route | undefined {
|
|
69
137
|
if (to instanceof Set) {
|
|
70
138
|
const stopIds = new Set<StopId>();
|
|
@@ -72,10 +140,14 @@ export class Result {
|
|
|
72
140
|
const found = this.stopsIndex.findStopBySourceStopId(sourceId);
|
|
73
141
|
if (found !== undefined) stopIds.add(found.id);
|
|
74
142
|
}
|
|
75
|
-
return stopIds.size === 0
|
|
143
|
+
return stopIds.size === 0
|
|
144
|
+
? undefined
|
|
145
|
+
: this.bestRoute(stopIds, maxTransfers);
|
|
76
146
|
}
|
|
77
147
|
const stopId = this.stopsIndex.findStopBySourceStopId(to)?.id;
|
|
78
|
-
return stopId === undefined
|
|
148
|
+
return stopId === undefined
|
|
149
|
+
? undefined
|
|
150
|
+
: this.bestRoute(stopId, maxTransfers);
|
|
79
151
|
}
|
|
80
152
|
|
|
81
153
|
/**
|
|
@@ -85,9 +157,13 @@ export class Result {
|
|
|
85
157
|
*
|
|
86
158
|
* @param to The destination stop. Defaults to this result's resolved
|
|
87
159
|
* destinations.
|
|
160
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
88
161
|
* @returns a route to the destination stop if it exists.
|
|
89
162
|
*/
|
|
90
|
-
bestRoute(
|
|
163
|
+
bestRoute(
|
|
164
|
+
to?: StopId | Set<StopId>,
|
|
165
|
+
maxTransfers?: number,
|
|
166
|
+
): Route | undefined {
|
|
91
167
|
const destinationStops = this.expandDestinations(to);
|
|
92
168
|
|
|
93
169
|
// Find the fastest-reached destination across all equivalent stops.
|
|
@@ -95,7 +171,7 @@ export class Result {
|
|
|
95
171
|
let fastestArrivalTime: Time | undefined = undefined;
|
|
96
172
|
let fastestLegNumber: number | undefined = undefined;
|
|
97
173
|
for (const destination of destinationStops) {
|
|
98
|
-
const arrivalData = this.
|
|
174
|
+
const arrivalData = this.concreteArrivalAt(destination, maxTransfers);
|
|
99
175
|
if (
|
|
100
176
|
arrivalData !== undefined &&
|
|
101
177
|
(fastestArrivalTime === undefined ||
|
|
@@ -117,7 +193,7 @@ export class Result {
|
|
|
117
193
|
let previousVehicleEdge: VehicleEdge | undefined;
|
|
118
194
|
|
|
119
195
|
while (round >= 0) {
|
|
120
|
-
const edge = this
|
|
196
|
+
const edge = this.#routingState.graph[round]?.[currentStop];
|
|
121
197
|
if (!edge) {
|
|
122
198
|
if (round === 0) break;
|
|
123
199
|
throw new Error(
|
|
@@ -307,7 +383,7 @@ export class Result {
|
|
|
307
383
|
* than this result's destination set.
|
|
308
384
|
*
|
|
309
385
|
* @param stop The target stop for which to return the arrival time.
|
|
310
|
-
* @param maxTransfers
|
|
386
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
311
387
|
* @returns The arrival time if the target stop is reachable, otherwise undefined.
|
|
312
388
|
*/
|
|
313
389
|
arrivalAt(stop: StopId, maxTransfers?: number): Arrival | undefined {
|
|
@@ -315,27 +391,10 @@ export class Result {
|
|
|
315
391
|
let earliestArrival: Arrival | undefined = undefined;
|
|
316
392
|
|
|
317
393
|
for (const equivalentStop of equivalentStops) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
maxTransfers
|
|
321
|
-
|
|
322
|
-
maxTransfers + 1
|
|
323
|
-
) {
|
|
324
|
-
arrivalTime = this.routingState.getArrival(equivalentStop.id);
|
|
325
|
-
} else {
|
|
326
|
-
// We have no guarantee that the stop was visited in the last round,
|
|
327
|
-
// so we need to check all rounds if it's not found in the last one.
|
|
328
|
-
for (let i = maxTransfers + 1; i >= 0; i--) {
|
|
329
|
-
const arrivalEdge = this.routingState.graph[i]?.[equivalentStop.id];
|
|
330
|
-
if (arrivalEdge !== undefined) {
|
|
331
|
-
arrivalTime = {
|
|
332
|
-
arrival: arrivalEdge.arrival,
|
|
333
|
-
legNumber: i,
|
|
334
|
-
};
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
394
|
+
const arrivalTime = this.concreteArrivalAt(
|
|
395
|
+
equivalentStop.id,
|
|
396
|
+
maxTransfers,
|
|
397
|
+
);
|
|
339
398
|
if (arrivalTime !== undefined) {
|
|
340
399
|
if (
|
|
341
400
|
earliestArrival === undefined ||
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Internal plotter access; deliberately not exported from the package entry point. */
|
|
2
|
+
export const resultGraph = Symbol('resultGraph');
|
|
3
|
+
|
|
4
|
+
/** Internal access to query destinations for range result selection. */
|
|
5
|
+
export const resultDestinations = Symbol('resultDestinations');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { StopId } from '../stops/stops.js';
|
|
2
|
+
import type { Route } from './route.js';
|
|
3
|
+
import type { Arrival } from './state.js';
|
|
4
|
+
|
|
5
|
+
export type StopArrival = Arrival & { stop: StopId };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Common earliest-arrival operations for single-departure and range results.
|
|
9
|
+
*/
|
|
10
|
+
export interface RoutingResult {
|
|
11
|
+
/**
|
|
12
|
+
* Earliest arrival at a stop or an equivalent stop, optionally limited by
|
|
13
|
+
* transfer count. Returns undefined when no matching stop was reached.
|
|
14
|
+
*/
|
|
15
|
+
arrivalAt(stop: StopId, maxTransfers?: number): Arrival | undefined;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Iterates once over each reached concrete stop and its earliest arrival.
|
|
19
|
+
* Destination pruning may limit coverage. Each call returns a fresh iterator.
|
|
20
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
21
|
+
*/
|
|
22
|
+
arrivals(maxTransfers?: number): IterableIterator<StopArrival>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Reconstructs the earliest-arriving route to the given or default
|
|
26
|
+
* destinations. Returns undefined when none
|
|
27
|
+
* were reached or when no destinations were provided.
|
|
28
|
+
* @param maxTransfers Optional transfer limit within retained data.
|
|
29
|
+
*/
|
|
30
|
+
bestRoute(
|
|
31
|
+
to?: StopId | Set<StopId>,
|
|
32
|
+
maxTransfers?: number,
|
|
33
|
+
): Route | undefined;
|
|
34
|
+
}
|