minotor 11.5.2 → 12.0.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 +9 -3
- package/README.md +1 -1
- package/dist/cli.mjs +10 -34
- package/dist/cli.mjs.map +1 -1
- package/dist/parser.cjs.js.map +1 -1
- 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 +6 -5
- 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/route.d.ts +6 -9
- package/dist/timetable/route.d.ts +5 -4
- package/package.json +1 -1
- package/src/__e2e__/router.test.ts +55 -56
- package/src/cli/repl.ts +9 -5
- package/src/router.ts +21 -8
- package/src/routing/__tests__/plainRouter.test.ts +2 -2
- package/src/routing/__tests__/result.test.ts +1 -1
- package/src/routing/__tests__/route.test.ts +8 -7
- package/src/routing/__tests__/router.test.ts +21 -1
- package/src/routing/result.ts +11 -45
- package/src/routing/route.ts +11 -13
- package/src/timetable/route.ts +21 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { describe, it } from 'node:test';
|
|
3
3
|
|
|
4
|
+
import { PickUpDropOffTypes, RouteTypes, TransferTypes } from '../../router.js';
|
|
4
5
|
import { Stop } from '../../stops/stops.js';
|
|
5
6
|
import { timeFromHMS } from '../../timetable/time.js';
|
|
6
7
|
import { Route, ServiceRouteInfo, Transfer, VehicleLeg } from '../route.js';
|
|
@@ -39,12 +40,12 @@ describe('Route', () => {
|
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
const serviceRoute: ServiceRouteInfo = {
|
|
42
|
-
type:
|
|
43
|
+
type: RouteTypes.BUS,
|
|
43
44
|
name: 'Route 1',
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
const serviceRoute2: ServiceRouteInfo = {
|
|
47
|
-
type:
|
|
48
|
+
type: RouteTypes.RAIL,
|
|
48
49
|
name: 'Route 2',
|
|
49
50
|
};
|
|
50
51
|
|
|
@@ -54,14 +55,14 @@ describe('Route', () => {
|
|
|
54
55
|
route: serviceRoute,
|
|
55
56
|
departureTime: timeFromHMS(8, 0, 0),
|
|
56
57
|
arrivalTime: timeFromHMS(8, 30, 0),
|
|
57
|
-
pickUpType:
|
|
58
|
-
dropOffType:
|
|
58
|
+
pickUpType: PickUpDropOffTypes.REGULAR,
|
|
59
|
+
dropOffType: PickUpDropOffTypes.REGULAR,
|
|
59
60
|
};
|
|
60
61
|
|
|
61
62
|
const transferLeg: Transfer = {
|
|
62
63
|
from: stopB,
|
|
63
64
|
to: stopC,
|
|
64
|
-
type:
|
|
65
|
+
type: TransferTypes.RECOMMENDED,
|
|
65
66
|
minTransferTime: 5,
|
|
66
67
|
};
|
|
67
68
|
|
|
@@ -71,8 +72,8 @@ describe('Route', () => {
|
|
|
71
72
|
route: serviceRoute2,
|
|
72
73
|
departureTime: timeFromHMS(8, 40, 0),
|
|
73
74
|
arrivalTime: timeFromHMS(9, 0, 0),
|
|
74
|
-
pickUpType:
|
|
75
|
-
dropOffType:
|
|
75
|
+
pickUpType: PickUpDropOffTypes.REGULAR,
|
|
76
|
+
dropOffType: PickUpDropOffTypes.REGULAR,
|
|
76
77
|
};
|
|
77
78
|
|
|
78
79
|
it('should calculate the correct departure time', () => {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import assert from 'node:assert';
|
|
2
2
|
import { describe, it } from 'node:test';
|
|
3
3
|
|
|
4
|
+
import { PickUpDropOffTypes, RouteType, RouteTypes } from '../../router.js';
|
|
4
5
|
import { Stop } from '../../stops/stops.js';
|
|
5
6
|
import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
6
7
|
import { Route } from '../../timetable/route.js';
|
|
7
8
|
import { timeFromHM } from '../../timetable/time.js';
|
|
8
9
|
import {
|
|
9
|
-
RouteTypes,
|
|
10
10
|
ServiceRoute,
|
|
11
11
|
StopAdjacency,
|
|
12
12
|
Timetable,
|
|
@@ -27,11 +27,13 @@ const routesAdjacency = [
|
|
|
27
27
|
stops: [
|
|
28
28
|
{
|
|
29
29
|
id: 0,
|
|
30
|
+
pickUpType: PickUpDropOffTypes.MUST_PHONE_AGENCY,
|
|
30
31
|
arrivalTime: timeFromHM(8, 0),
|
|
31
32
|
departureTime: timeFromHM(8, 10),
|
|
32
33
|
},
|
|
33
34
|
{
|
|
34
35
|
id: 1,
|
|
36
|
+
dropOffType: PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER,
|
|
35
37
|
arrivalTime: timeFromHM(8, 30),
|
|
36
38
|
departureTime: timeFromHM(8, 30),
|
|
37
39
|
},
|
|
@@ -72,10 +74,19 @@ describe('Router', () => {
|
|
|
72
74
|
const query = new Query.Builder()
|
|
73
75
|
.from(0)
|
|
74
76
|
.to(1)
|
|
77
|
+
.transportModes(new Set<RouteType>([RouteTypes.BUS]))
|
|
75
78
|
.departureTime(timeFromHM(8, 0))
|
|
76
79
|
.build();
|
|
77
80
|
const result = router.route(query);
|
|
78
81
|
assert(result instanceof Result);
|
|
82
|
+
const leg = result.bestRoute()?.legs[0];
|
|
83
|
+
assert(leg && 'route' in leg);
|
|
84
|
+
assert.strictEqual(leg.route.type, RouteTypes.BUS);
|
|
85
|
+
assert.strictEqual(leg.pickUpType, PickUpDropOffTypes.MUST_PHONE_AGENCY);
|
|
86
|
+
assert.strictEqual(
|
|
87
|
+
leg.dropOffType,
|
|
88
|
+
PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER,
|
|
89
|
+
);
|
|
79
90
|
assert.strictEqual(result.arrivalAt(1)?.arrival, timeFromHM(8, 30));
|
|
80
91
|
});
|
|
81
92
|
|
|
@@ -83,11 +94,20 @@ describe('Router', () => {
|
|
|
83
94
|
const query = new RangeQuery.Builder()
|
|
84
95
|
.from(0)
|
|
85
96
|
.to(1)
|
|
97
|
+
.transportModes(new Set<RouteType>([RouteTypes.BUS]))
|
|
86
98
|
.departureTime(timeFromHM(8, 0))
|
|
87
99
|
.lastDepartureTime(timeFromHM(9, 0))
|
|
88
100
|
.build();
|
|
89
101
|
const result = router.rangeRoute(query);
|
|
90
102
|
assert(result instanceof RangeResult);
|
|
103
|
+
const leg = result.bestRoute()?.legs[0];
|
|
104
|
+
assert(leg && 'route' in leg);
|
|
105
|
+
assert.strictEqual(leg.route.type, RouteTypes.BUS);
|
|
106
|
+
assert.strictEqual(leg.pickUpType, PickUpDropOffTypes.MUST_PHONE_AGENCY);
|
|
107
|
+
assert.strictEqual(
|
|
108
|
+
leg.dropOffType,
|
|
109
|
+
PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER,
|
|
110
|
+
);
|
|
91
111
|
assert.strictEqual(result.size, 1);
|
|
92
112
|
assert.strictEqual(result.bestRoute()?.arrivalTime(), timeFromHM(8, 30));
|
|
93
113
|
});
|
package/src/routing/result.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
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 {
|
|
5
|
-
PickUpDropOffTypeString,
|
|
6
|
-
RawPickUpDropOffType,
|
|
7
|
-
Route as TimetableRoute,
|
|
8
|
-
} from '../timetable/route.js';
|
|
4
|
+
import { Route as TimetableRoute } from '../timetable/route.js';
|
|
9
5
|
import { Time } from '../timetable/time.js';
|
|
10
|
-
import {
|
|
11
|
-
routeTypeToString,
|
|
12
|
-
TransferTypes,
|
|
13
|
-
transferTypeToString,
|
|
14
|
-
} from '../timetable/timetable.js';
|
|
6
|
+
import { TransferTypes } from '../timetable/timetable.js';
|
|
15
7
|
import {
|
|
16
8
|
Access,
|
|
17
9
|
Leg,
|
|
@@ -23,34 +15,6 @@ import {
|
|
|
23
15
|
import { Arrival, RoutingState, TransferEdge, VehicleEdge } from './router.js';
|
|
24
16
|
import { AccessEdge } from './state.js';
|
|
25
17
|
|
|
26
|
-
/**
|
|
27
|
-
* Details about the pickup and drop-off modalities at each stop in each trip of a route.
|
|
28
|
-
*/
|
|
29
|
-
const pickUpDropOffTypeMap: PickUpDropOffTypeString[] = [
|
|
30
|
-
'REGULAR',
|
|
31
|
-
'NOT_AVAILABLE',
|
|
32
|
-
'MUST_PHONE_AGENCY',
|
|
33
|
-
'MUST_COORDINATE_WITH_DRIVER',
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Converts a numerical representation of a pick-up/drop-off type
|
|
38
|
-
* into its corresponding string representation.
|
|
39
|
-
*
|
|
40
|
-
* @param numericalType - The numerical value representing the pick-up/drop-off type.
|
|
41
|
-
* @returns The corresponding PickUpDropOffTypeString as a string.
|
|
42
|
-
* @throws An error if the numerical type is invalid.
|
|
43
|
-
*/
|
|
44
|
-
const toPickupDropOffType = (
|
|
45
|
-
rawType: RawPickUpDropOffType,
|
|
46
|
-
): PickUpDropOffTypeString => {
|
|
47
|
-
const type = pickUpDropOffTypeMap[rawType];
|
|
48
|
-
if (!type) {
|
|
49
|
-
throw new Error(`Invalid pickup/drop-off type ${rawType}`);
|
|
50
|
-
}
|
|
51
|
-
return type;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
18
|
export class Result {
|
|
55
19
|
private readonly destinations: ReadonlySet<StopId>;
|
|
56
20
|
public readonly routingState: RoutingState;
|
|
@@ -225,7 +189,7 @@ export class Result {
|
|
|
225
189
|
private buildServiceRouteInfo(route: TimetableRoute): ServiceRouteInfo {
|
|
226
190
|
const serviceRouteInfo = this.timetable.getServiceRouteInfo(route);
|
|
227
191
|
return {
|
|
228
|
-
type:
|
|
192
|
+
type: serviceRouteInfo.type,
|
|
229
193
|
name: serviceRouteInfo.name,
|
|
230
194
|
};
|
|
231
195
|
}
|
|
@@ -267,11 +231,13 @@ export class Result {
|
|
|
267
231
|
firstEdge.tripIndex,
|
|
268
232
|
),
|
|
269
233
|
arrivalTime: lastEdge.arrival,
|
|
270
|
-
pickUpType:
|
|
271
|
-
|
|
234
|
+
pickUpType: firstRoute.pickUpTypeFrom(
|
|
235
|
+
firstEdge.stopIndex,
|
|
236
|
+
firstEdge.tripIndex,
|
|
272
237
|
),
|
|
273
|
-
dropOffType:
|
|
274
|
-
|
|
238
|
+
dropOffType: lastRoute.dropOffTypeAt(
|
|
239
|
+
lastEdge.hopOffStopIndex,
|
|
240
|
+
lastEdge.tripIndex,
|
|
275
241
|
),
|
|
276
242
|
};
|
|
277
243
|
}
|
|
@@ -289,7 +255,7 @@ export class Result {
|
|
|
289
255
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
290
256
|
to: this.stopsIndex.findStopById(edge.to)!,
|
|
291
257
|
minTransferTime: edge.minTransferTime,
|
|
292
|
-
type:
|
|
258
|
+
type: edge.type,
|
|
293
259
|
};
|
|
294
260
|
}
|
|
295
261
|
|
|
@@ -332,7 +298,7 @@ export class Result {
|
|
|
332
298
|
from: this.stopsIndex.findStopById(fromStopId)!,
|
|
333
299
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
334
300
|
to: this.stopsIndex.findStopById(toStopId)!,
|
|
335
|
-
type:
|
|
301
|
+
type: TransferTypes.GUARANTEED,
|
|
336
302
|
};
|
|
337
303
|
}
|
|
338
304
|
|
package/src/routing/route.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Stop } from '../stops/stops.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { PickUpDropOffType } from '../timetable/route.js';
|
|
3
3
|
import {
|
|
4
4
|
Duration,
|
|
5
5
|
DURATION_ZERO,
|
|
@@ -7,15 +7,13 @@ import {
|
|
|
7
7
|
Time,
|
|
8
8
|
timeToString,
|
|
9
9
|
} from '../timetable/time.js';
|
|
10
|
-
import type {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import type { ServiceRouteInfo, TransferType } from '../timetable/timetable.js';
|
|
11
|
+
import {
|
|
12
|
+
routeTypeToString,
|
|
13
|
+
transferTypeToString,
|
|
13
14
|
} from '../timetable/timetable.js';
|
|
14
15
|
|
|
15
|
-
export type ServiceRouteInfo
|
|
16
|
-
type: RouteTypeString;
|
|
17
|
-
name: string;
|
|
18
|
-
};
|
|
16
|
+
export type { ServiceRouteInfo } from '../timetable/timetable.js';
|
|
19
17
|
|
|
20
18
|
export type BaseLeg = {
|
|
21
19
|
from: Stop;
|
|
@@ -28,15 +26,15 @@ export type Access = BaseLeg & {
|
|
|
28
26
|
|
|
29
27
|
export type Transfer = BaseLeg & {
|
|
30
28
|
minTransferTime?: Duration;
|
|
31
|
-
type:
|
|
29
|
+
type: TransferType;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
export type VehicleLeg = BaseLeg & {
|
|
35
33
|
route: ServiceRouteInfo;
|
|
36
34
|
departureTime: Time;
|
|
37
35
|
arrivalTime: Time;
|
|
38
|
-
pickUpType:
|
|
39
|
-
dropOffType:
|
|
36
|
+
pickUpType: PickUpDropOffType;
|
|
37
|
+
dropOffType: PickUpDropOffType;
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
export type Leg = Transfer | Access | VehicleLeg;
|
|
@@ -119,7 +117,7 @@ export class Route {
|
|
|
119
117
|
const toStop = `To: ${leg.to.name}${leg.to.platform ? ` (Pl. ${leg.to.platform})` : ''}`;
|
|
120
118
|
const transferDetails =
|
|
121
119
|
'type' in leg && !('route' in leg)
|
|
122
|
-
? `Transfer: ${leg.type}${leg.minTransferTime ? `, Minimum Transfer Time: ${durationToString(leg.minTransferTime)}` : ''}`
|
|
120
|
+
? `Transfer: ${transferTypeToString(leg.type)}${leg.minTransferTime ? `, Minimum Transfer Time: ${durationToString(leg.minTransferTime)}` : ''}`
|
|
123
121
|
: '';
|
|
124
122
|
const accessDetails =
|
|
125
123
|
'duration' in leg
|
|
@@ -127,7 +125,7 @@ export class Route {
|
|
|
127
125
|
: '';
|
|
128
126
|
const travelDetails =
|
|
129
127
|
'route' in leg && 'departureTime' in leg && 'arrivalTime' in leg
|
|
130
|
-
? `Route: ${leg.route.type} ${leg.route.name}, Departure: ${timeToString(leg.departureTime)}, Arrival: ${timeToString(leg.arrivalTime)}`
|
|
128
|
+
? `Route: ${routeTypeToString(leg.route.type)} ${leg.route.name}, Departure: ${timeToString(leg.departureTime)}, Arrival: ${timeToString(leg.arrivalTime)}`
|
|
131
129
|
: '';
|
|
132
130
|
|
|
133
131
|
return [
|
package/src/timetable/route.ts
CHANGED
|
@@ -23,7 +23,21 @@ export type PickUpDropOffType =
|
|
|
23
23
|
|
|
24
24
|
export type PickUpDropOffTypeString = keyof typeof PickUpDropOffTypes;
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
/** Returns the identifier name for a pickup/drop-off type. */
|
|
27
|
+
export const pickUpDropOffTypeToString = (
|
|
28
|
+
type: PickUpDropOffType,
|
|
29
|
+
): PickUpDropOffTypeString => {
|
|
30
|
+
switch (type) {
|
|
31
|
+
case PickUpDropOffTypes.REGULAR:
|
|
32
|
+
return 'REGULAR';
|
|
33
|
+
case PickUpDropOffTypes.NOT_AVAILABLE:
|
|
34
|
+
return 'NOT_AVAILABLE';
|
|
35
|
+
case PickUpDropOffTypes.MUST_PHONE_AGENCY:
|
|
36
|
+
return 'MUST_PHONE_AGENCY';
|
|
37
|
+
case PickUpDropOffTypes.MUST_COORDINATE_WITH_DRIVER:
|
|
38
|
+
return 'MUST_COORDINATE_WITH_DRIVER';
|
|
39
|
+
}
|
|
40
|
+
};
|
|
27
41
|
|
|
28
42
|
/*
|
|
29
43
|
* A trip route index corresponds to the index of a given trip in a route.
|
|
@@ -323,7 +337,7 @@ export class Route {
|
|
|
323
337
|
dropOffTypeAtOffset(
|
|
324
338
|
stopIndex: StopRouteIndex,
|
|
325
339
|
offset: number,
|
|
326
|
-
):
|
|
340
|
+
): PickUpDropOffType {
|
|
327
341
|
const globalIndex = offset + stopIndex;
|
|
328
342
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
329
343
|
const byte = this.pickupDropOffTypes[globalIndex >> 1]!;
|
|
@@ -331,7 +345,7 @@ export class Route {
|
|
|
331
345
|
// First pair → drop-off in lower 2 bits; second pair → drop-off in bits 4-5.
|
|
332
346
|
return (
|
|
333
347
|
globalIndex & 1 ? (byte >> 4) & 0x03 : byte & 0x03
|
|
334
|
-
) as
|
|
348
|
+
) as PickUpDropOffType;
|
|
335
349
|
}
|
|
336
350
|
|
|
337
351
|
/**
|
|
@@ -362,7 +376,7 @@ export class Route {
|
|
|
362
376
|
pickUpTypeFrom(
|
|
363
377
|
stopIndex: StopRouteIndex,
|
|
364
378
|
tripIndex: TripRouteIndex,
|
|
365
|
-
):
|
|
379
|
+
): PickUpDropOffType {
|
|
366
380
|
const globalIndex = tripIndex * this.stops.length + stopIndex;
|
|
367
381
|
const byteIndex = globalIndex >> 1;
|
|
368
382
|
const isSecondPair = (globalIndex & 1) === 1;
|
|
@@ -377,7 +391,7 @@ export class Route {
|
|
|
377
391
|
const pickUpValue = isSecondPair
|
|
378
392
|
? (byte >> 6) & 0x03 // Upper 2 bits for second pair
|
|
379
393
|
: (byte >> 2) & 0x03; // Bits 2-3 for first pair
|
|
380
|
-
return pickUpValue as
|
|
394
|
+
return pickUpValue as PickUpDropOffType;
|
|
381
395
|
}
|
|
382
396
|
|
|
383
397
|
/**
|
|
@@ -390,7 +404,7 @@ export class Route {
|
|
|
390
404
|
dropOffTypeAt(
|
|
391
405
|
stopIndex: StopRouteIndex,
|
|
392
406
|
tripIndex: TripRouteIndex,
|
|
393
|
-
):
|
|
407
|
+
): PickUpDropOffType {
|
|
394
408
|
const globalIndex = tripIndex * this.stops.length + stopIndex;
|
|
395
409
|
const byteIndex = globalIndex >> 1;
|
|
396
410
|
const isSecondPair = (globalIndex & 1) === 1;
|
|
@@ -405,7 +419,7 @@ export class Route {
|
|
|
405
419
|
const dropOffValue = isSecondPair
|
|
406
420
|
? (byte >> 4) & 0x03 // Bits 4-5 for second pair
|
|
407
421
|
: byte & 0x03; // Lower 2 bits for first pair
|
|
408
|
-
return dropOffValue as
|
|
422
|
+
return dropOffValue as PickUpDropOffType;
|
|
409
423
|
}
|
|
410
424
|
|
|
411
425
|
/**
|