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
|
@@ -7,9 +7,11 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
|
7
7
|
import { Route } from '../../timetable/route.js';
|
|
8
8
|
import { timeFromHM } from '../../timetable/time.js';
|
|
9
9
|
import {
|
|
10
|
+
RouteTypes,
|
|
10
11
|
ServiceRoute,
|
|
11
12
|
StopAdjacency,
|
|
12
13
|
Timetable,
|
|
14
|
+
TransferTypes,
|
|
13
15
|
} from '../../timetable/timetable.js';
|
|
14
16
|
import { AccessFinder, AccessPoint } from '../access.js';
|
|
15
17
|
|
|
@@ -20,8 +22,12 @@ import { AccessFinder, AccessPoint } from '../access.js';
|
|
|
20
22
|
const stopsAdjacency: StopAdjacency[] = [
|
|
21
23
|
{
|
|
22
24
|
transfers: [
|
|
23
|
-
{
|
|
24
|
-
|
|
25
|
+
{
|
|
26
|
+
destination: 1,
|
|
27
|
+
type: TransferTypes.REQUIRES_MINIMAL_TIME,
|
|
28
|
+
minTransferTime: 5,
|
|
29
|
+
},
|
|
30
|
+
{ destination: 2, type: TransferTypes.GUARANTEED },
|
|
25
31
|
],
|
|
26
32
|
routes: [],
|
|
27
33
|
},
|
|
@@ -67,7 +73,7 @@ const routesAdjacency = [
|
|
|
67
73
|
];
|
|
68
74
|
|
|
69
75
|
const serviceRoutes: ServiceRoute[] = [
|
|
70
|
-
{ type:
|
|
76
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
71
77
|
];
|
|
72
78
|
|
|
73
79
|
const stops: Stop[] = [
|
|
@@ -125,7 +131,9 @@ describe('AccessFinder', () => {
|
|
|
125
131
|
// Temporarily use a timetable where the transfer has no minTransferTime.
|
|
126
132
|
const adj: StopAdjacency[] = [
|
|
127
133
|
{
|
|
128
|
-
transfers: [
|
|
134
|
+
transfers: [
|
|
135
|
+
{ destination: 1, type: TransferTypes.REQUIRES_MINIMAL_TIME },
|
|
136
|
+
],
|
|
129
137
|
routes: [],
|
|
130
138
|
},
|
|
131
139
|
{ routes: [0] },
|
|
@@ -157,7 +165,7 @@ describe('AccessFinder', () => {
|
|
|
157
165
|
transfers: [
|
|
158
166
|
{
|
|
159
167
|
destination: 1,
|
|
160
|
-
type:
|
|
168
|
+
type: TransferTypes.REQUIRES_MINIMAL_TIME,
|
|
161
169
|
minTransferTime: 8,
|
|
162
170
|
},
|
|
163
171
|
],
|
|
@@ -167,7 +175,7 @@ describe('AccessFinder', () => {
|
|
|
167
175
|
transfers: [
|
|
168
176
|
{
|
|
169
177
|
destination: 1,
|
|
170
|
-
type:
|
|
178
|
+
type: TransferTypes.REQUIRES_MINIMAL_TIME,
|
|
171
179
|
minTransferTime: 3,
|
|
172
180
|
},
|
|
173
181
|
],
|
|
@@ -6,9 +6,11 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
|
6
6
|
import { Route } from '../../timetable/route.js';
|
|
7
7
|
import { durationFromSeconds, timeFromHM } from '../../timetable/time.js';
|
|
8
8
|
import {
|
|
9
|
+
RouteTypes,
|
|
9
10
|
ServiceRoute,
|
|
10
11
|
StopAdjacency,
|
|
11
12
|
Timetable,
|
|
13
|
+
TransferTypes,
|
|
12
14
|
TripTransfers,
|
|
13
15
|
} from '../../timetable/timetable.js';
|
|
14
16
|
import { encode } from '../../timetable/tripStopId.js';
|
|
@@ -63,7 +65,7 @@ describe('PlainRouter', () => {
|
|
|
63
65
|
|
|
64
66
|
const routes: ServiceRoute[] = [
|
|
65
67
|
{
|
|
66
|
-
type:
|
|
68
|
+
type: RouteTypes.BUS,
|
|
67
69
|
name: 'Line 1',
|
|
68
70
|
routes: [0],
|
|
69
71
|
},
|
|
@@ -148,6 +150,28 @@ describe('PlainRouter', () => {
|
|
|
148
150
|
// Route 0 arrives at stop3 at 08:35
|
|
149
151
|
assert.strictEqual(timeToStop3?.arrival, timeFromHM(8, 35));
|
|
150
152
|
});
|
|
153
|
+
|
|
154
|
+
it('should not return journeys arriving after maxDuration', () => {
|
|
155
|
+
const tooShort = new Query.Builder()
|
|
156
|
+
.from(0)
|
|
157
|
+
.to(2)
|
|
158
|
+
.departureTime(timeFromHM(8, 0))
|
|
159
|
+
.maxDuration(34)
|
|
160
|
+
.build();
|
|
161
|
+
|
|
162
|
+
assert.strictEqual(router.route(tooShort).bestRoute(), undefined);
|
|
163
|
+
|
|
164
|
+
const justEnough = new Query.Builder()
|
|
165
|
+
.from(0)
|
|
166
|
+
.to(2)
|
|
167
|
+
.departureTime(timeFromHM(8, 0))
|
|
168
|
+
.maxDuration(35)
|
|
169
|
+
.build();
|
|
170
|
+
|
|
171
|
+
const route = router.route(justEnough).bestRoute();
|
|
172
|
+
assert(route);
|
|
173
|
+
assert.strictEqual(route.arrivalTime(), timeFromHM(8, 35));
|
|
174
|
+
});
|
|
151
175
|
});
|
|
152
176
|
|
|
153
177
|
describe('with a route change', () => {
|
|
@@ -224,12 +248,12 @@ describe('PlainRouter', () => {
|
|
|
224
248
|
|
|
225
249
|
const routes: ServiceRoute[] = [
|
|
226
250
|
{
|
|
227
|
-
type:
|
|
251
|
+
type: RouteTypes.BUS,
|
|
228
252
|
name: 'Line 1',
|
|
229
253
|
routes: [0],
|
|
230
254
|
},
|
|
231
255
|
{
|
|
232
|
-
type:
|
|
256
|
+
type: RouteTypes.RAIL,
|
|
233
257
|
name: 'Line 2',
|
|
234
258
|
routes: [1],
|
|
235
259
|
},
|
|
@@ -338,7 +362,7 @@ describe('PlainRouter', () => {
|
|
|
338
362
|
transfers: [
|
|
339
363
|
{
|
|
340
364
|
destination: 4,
|
|
341
|
-
type:
|
|
365
|
+
type: TransferTypes.REQUIRES_MINIMAL_TIME,
|
|
342
366
|
minTransferTime: durationFromSeconds(300), // 5 minutes walking
|
|
343
367
|
},
|
|
344
368
|
],
|
|
@@ -407,12 +431,12 @@ describe('PlainRouter', () => {
|
|
|
407
431
|
|
|
408
432
|
const routes: ServiceRoute[] = [
|
|
409
433
|
{
|
|
410
|
-
type:
|
|
434
|
+
type: RouteTypes.BUS,
|
|
411
435
|
name: 'Line 1',
|
|
412
436
|
routes: [0],
|
|
413
437
|
},
|
|
414
438
|
{
|
|
415
|
-
type:
|
|
439
|
+
type: RouteTypes.RAIL,
|
|
416
440
|
name: 'Line 2',
|
|
417
441
|
routes: [1],
|
|
418
442
|
},
|
|
@@ -611,17 +635,17 @@ describe('PlainRouter', () => {
|
|
|
611
635
|
|
|
612
636
|
const routes: ServiceRoute[] = [
|
|
613
637
|
{
|
|
614
|
-
type:
|
|
638
|
+
type: RouteTypes.BUS,
|
|
615
639
|
name: 'Line 1',
|
|
616
640
|
routes: [0],
|
|
617
641
|
},
|
|
618
642
|
{
|
|
619
|
-
type:
|
|
643
|
+
type: RouteTypes.RAIL,
|
|
620
644
|
name: 'Line 2',
|
|
621
645
|
routes: [1],
|
|
622
646
|
},
|
|
623
647
|
{
|
|
624
|
-
type:
|
|
648
|
+
type: RouteTypes.FERRY,
|
|
625
649
|
name: 'Line 3',
|
|
626
650
|
routes: [2],
|
|
627
651
|
},
|
|
@@ -773,12 +797,12 @@ describe('PlainRouter', () => {
|
|
|
773
797
|
|
|
774
798
|
const routes: ServiceRoute[] = [
|
|
775
799
|
{
|
|
776
|
-
type:
|
|
800
|
+
type: RouteTypes.BUS,
|
|
777
801
|
name: 'Line 1',
|
|
778
802
|
routes: [0],
|
|
779
803
|
},
|
|
780
804
|
{
|
|
781
|
-
type:
|
|
805
|
+
type: RouteTypes.BUS,
|
|
782
806
|
name: 'Line 2',
|
|
783
807
|
routes: [1],
|
|
784
808
|
},
|
|
@@ -937,12 +961,12 @@ describe('PlainRouter', () => {
|
|
|
937
961
|
|
|
938
962
|
const routes: ServiceRoute[] = [
|
|
939
963
|
{
|
|
940
|
-
type:
|
|
964
|
+
type: RouteTypes.BUS,
|
|
941
965
|
name: 'Line 1',
|
|
942
966
|
routes: [0],
|
|
943
967
|
},
|
|
944
968
|
{
|
|
945
|
-
type:
|
|
969
|
+
type: RouteTypes.BUS,
|
|
946
970
|
name: 'Line 2',
|
|
947
971
|
routes: [1],
|
|
948
972
|
},
|
|
@@ -1101,12 +1125,12 @@ describe('PlainRouter', () => {
|
|
|
1101
1125
|
|
|
1102
1126
|
const routes: ServiceRoute[] = [
|
|
1103
1127
|
{
|
|
1104
|
-
type:
|
|
1128
|
+
type: RouteTypes.BUS,
|
|
1105
1129
|
name: 'Line 1',
|
|
1106
1130
|
routes: [0],
|
|
1107
1131
|
},
|
|
1108
1132
|
{
|
|
1109
|
-
type:
|
|
1133
|
+
type: RouteTypes.BUS,
|
|
1110
1134
|
name: 'Line 2',
|
|
1111
1135
|
routes: [1],
|
|
1112
1136
|
},
|
|
@@ -1259,9 +1283,9 @@ describe('PlainRouter', () => {
|
|
|
1259
1283
|
];
|
|
1260
1284
|
|
|
1261
1285
|
const routes: ServiceRoute[] = [
|
|
1262
|
-
{ type:
|
|
1263
|
-
{ type:
|
|
1264
|
-
{ type:
|
|
1286
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
1287
|
+
{ type: RouteTypes.BUS, name: 'Line 2', routes: [1] },
|
|
1288
|
+
{ type: RouteTypes.BUS, name: 'Line 3', routes: [2] },
|
|
1265
1289
|
];
|
|
1266
1290
|
|
|
1267
1291
|
timetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
|
|
@@ -1418,8 +1442,8 @@ describe('PlainRouter', () => {
|
|
|
1418
1442
|
];
|
|
1419
1443
|
|
|
1420
1444
|
const routes: ServiceRoute[] = [
|
|
1421
|
-
{ type:
|
|
1422
|
-
{ type:
|
|
1445
|
+
{ type: RouteTypes.BUS, name: 'Bus Line', routes: [0] },
|
|
1446
|
+
{ type: RouteTypes.RAIL, name: 'Rail Line', routes: [1] },
|
|
1423
1447
|
];
|
|
1424
1448
|
|
|
1425
1449
|
timetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
|
|
@@ -1469,7 +1493,7 @@ describe('PlainRouter', () => {
|
|
|
1469
1493
|
.from(0)
|
|
1470
1494
|
.to(1)
|
|
1471
1495
|
.departureTime(timeFromHM(8, 0))
|
|
1472
|
-
.transportModes(new Set([
|
|
1496
|
+
.transportModes(new Set([RouteTypes.BUS] as const))
|
|
1473
1497
|
.build();
|
|
1474
1498
|
|
|
1475
1499
|
const result: Result = router.route(query);
|
|
@@ -1483,7 +1507,7 @@ describe('PlainRouter', () => {
|
|
|
1483
1507
|
.from(0)
|
|
1484
1508
|
.to(1)
|
|
1485
1509
|
.departureTime(timeFromHM(8, 0))
|
|
1486
|
-
.transportModes(new Set([
|
|
1510
|
+
.transportModes(new Set([RouteTypes.FERRY] as const)) // Neither route is a ferry
|
|
1487
1511
|
.build();
|
|
1488
1512
|
|
|
1489
1513
|
const result: Result = router.route(query);
|
|
@@ -1545,7 +1569,7 @@ describe('PlainRouter', () => {
|
|
|
1545
1569
|
];
|
|
1546
1570
|
|
|
1547
1571
|
const routes: ServiceRoute[] = [
|
|
1548
|
-
{ type:
|
|
1572
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
1549
1573
|
];
|
|
1550
1574
|
|
|
1551
1575
|
timetable = new Timetable(stopsAdjacency, routesAdjacency, routes);
|
|
@@ -6,7 +6,12 @@ import { Stop } from '../../stops/stops.js';
|
|
|
6
6
|
import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
7
7
|
import { Route } from '../../timetable/route.js';
|
|
8
8
|
import { timeFromHMS, timeFromString } from '../../timetable/time.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
RouteTypes,
|
|
11
|
+
ServiceRoute,
|
|
12
|
+
StopAdjacency,
|
|
13
|
+
TransferTypes,
|
|
14
|
+
} from '../../timetable/timetable.js';
|
|
10
15
|
import { Plotter } from '../plotter.js';
|
|
11
16
|
import { Query } from '../query.js';
|
|
12
17
|
import { Result } from '../result.js';
|
|
@@ -58,7 +63,7 @@ describe('Plotter', () => {
|
|
|
58
63
|
|
|
59
64
|
const routes: ServiceRoute[] = [
|
|
60
65
|
{
|
|
61
|
-
type:
|
|
66
|
+
type: RouteTypes.RAIL,
|
|
62
67
|
name: 'IC 1',
|
|
63
68
|
routes: [0],
|
|
64
69
|
},
|
|
@@ -192,7 +197,7 @@ describe('Plotter', () => {
|
|
|
192
197
|
from: 0,
|
|
193
198
|
to: 1,
|
|
194
199
|
arrival: timeFromHMS(8, 45, 0),
|
|
195
|
-
type:
|
|
200
|
+
type: TransferTypes.RECOMMENDED,
|
|
196
201
|
minTransferTime: 5,
|
|
197
202
|
},
|
|
198
203
|
],
|
|
@@ -6,7 +6,11 @@ import { Stop, StopId } from '../../stops/stops.js';
|
|
|
6
6
|
import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
7
7
|
import { Route } from '../../timetable/route.js';
|
|
8
8
|
import { timeFromHM } from '../../timetable/time.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
RouteTypes,
|
|
11
|
+
ServiceRoute,
|
|
12
|
+
StopAdjacency,
|
|
13
|
+
} from '../../timetable/timetable.js';
|
|
10
14
|
import { ParetoRun, RangeResult } from '../rangeResult.js';
|
|
11
15
|
import { Result } from '../result.js';
|
|
12
16
|
import { RoutingState, VehicleEdge } from '../router.js';
|
|
@@ -74,7 +78,7 @@ const routesAdjacency = [
|
|
|
74
78
|
}),
|
|
75
79
|
];
|
|
76
80
|
const serviceRoutes: ServiceRoute[] = [
|
|
77
|
-
{ type:
|
|
81
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
78
82
|
];
|
|
79
83
|
const timetable = new Timetable(stopsAdjacency, routesAdjacency, serviceRoutes);
|
|
80
84
|
|
|
@@ -6,9 +6,11 @@ import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
|
6
6
|
import { Route } from '../../timetable/route.js';
|
|
7
7
|
import { durationFromSeconds, timeFromHM } from '../../timetable/time.js';
|
|
8
8
|
import {
|
|
9
|
+
RouteTypes,
|
|
9
10
|
ServiceRoute,
|
|
10
11
|
StopAdjacency,
|
|
11
12
|
Timetable,
|
|
13
|
+
TransferTypes,
|
|
12
14
|
} from '../../timetable/timetable.js';
|
|
13
15
|
import { AccessFinder } from '../access.js';
|
|
14
16
|
import { RangeQuery } from '../query.js';
|
|
@@ -24,7 +26,9 @@ describe('RangeRouter', () => {
|
|
|
24
26
|
const stopsAdjacency: StopAdjacency[] = [
|
|
25
27
|
{
|
|
26
28
|
routes: [],
|
|
27
|
-
transfers: [
|
|
29
|
+
transfers: [
|
|
30
|
+
{ destination: 1, type: TransferTypes.REQUIRES_MINIMAL_TIME },
|
|
31
|
+
],
|
|
28
32
|
},
|
|
29
33
|
{ routes: [0] },
|
|
30
34
|
{ routes: [0] },
|
|
@@ -54,7 +58,7 @@ describe('RangeRouter', () => {
|
|
|
54
58
|
];
|
|
55
59
|
|
|
56
60
|
const serviceRoutes: ServiceRoute[] = [
|
|
57
|
-
{ type:
|
|
61
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
58
62
|
];
|
|
59
63
|
|
|
60
64
|
const timetable = new Timetable(
|
|
@@ -174,7 +178,7 @@ describe('RangeRouter', () => {
|
|
|
174
178
|
];
|
|
175
179
|
|
|
176
180
|
const serviceRoutes: ServiceRoute[] = [
|
|
177
|
-
{ type:
|
|
181
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
178
182
|
];
|
|
179
183
|
|
|
180
184
|
timetable = new Timetable(stopsAdjacency, routesAdjacency, serviceRoutes);
|
|
@@ -276,7 +280,7 @@ describe('RangeRouter', () => {
|
|
|
276
280
|
];
|
|
277
281
|
|
|
278
282
|
const serviceRoutes: ServiceRoute[] = [
|
|
279
|
-
{ type:
|
|
283
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
280
284
|
];
|
|
281
285
|
|
|
282
286
|
const dominatingTimetable = new Timetable(
|
|
@@ -347,6 +351,28 @@ describe('RangeRouter', () => {
|
|
|
347
351
|
assert.strictEqual(result.size, 0);
|
|
348
352
|
assert.strictEqual(result.bestRoute(), undefined);
|
|
349
353
|
});
|
|
354
|
+
|
|
355
|
+
it('filters runs whose arrivals exceed maxDuration for their departure slot', () => {
|
|
356
|
+
const tooShort = new RangeQuery.Builder()
|
|
357
|
+
.from(0)
|
|
358
|
+
.to(1)
|
|
359
|
+
.departureTime(timeFromHM(8, 0))
|
|
360
|
+
.lastDepartureTime(timeFromHM(8, 30))
|
|
361
|
+
.maxDuration(29)
|
|
362
|
+
.build();
|
|
363
|
+
|
|
364
|
+
assert.strictEqual(router.rangeRoute(tooShort).size, 0);
|
|
365
|
+
|
|
366
|
+
const justEnough = new RangeQuery.Builder()
|
|
367
|
+
.from(0)
|
|
368
|
+
.to(1)
|
|
369
|
+
.departureTime(timeFromHM(8, 0))
|
|
370
|
+
.lastDepartureTime(timeFromHM(8, 30))
|
|
371
|
+
.maxDuration(30)
|
|
372
|
+
.build();
|
|
373
|
+
|
|
374
|
+
assert.strictEqual(router.rangeRoute(justEnough).size, 2);
|
|
375
|
+
});
|
|
350
376
|
});
|
|
351
377
|
|
|
352
378
|
describe('same-stop query (origin equals destination)', () => {
|
|
@@ -401,7 +427,7 @@ describe('RangeRouter', () => {
|
|
|
401
427
|
];
|
|
402
428
|
|
|
403
429
|
const serviceRoutes: ServiceRoute[] = [
|
|
404
|
-
{ type:
|
|
430
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
405
431
|
];
|
|
406
432
|
|
|
407
433
|
const timetable = new Timetable(
|
|
@@ -522,7 +548,7 @@ describe('RangeRouter', () => {
|
|
|
522
548
|
];
|
|
523
549
|
|
|
524
550
|
const serviceRoutes: ServiceRoute[] = [
|
|
525
|
-
{ type:
|
|
551
|
+
{ type: RouteTypes.BUS, name: 'Line 1', routes: [0] },
|
|
526
552
|
];
|
|
527
553
|
|
|
528
554
|
const timetable = new Timetable(
|
|
@@ -6,9 +6,11 @@ import { Route } from '../../timetable/route.js';
|
|
|
6
6
|
import { timeFromHM } from '../../timetable/time.js';
|
|
7
7
|
import {
|
|
8
8
|
ALL_TRANSPORT_MODES,
|
|
9
|
+
RouteTypes,
|
|
9
10
|
ServiceRoute,
|
|
10
11
|
StopAdjacency,
|
|
11
12
|
Timetable,
|
|
13
|
+
TransferTypes,
|
|
12
14
|
TripTransfers,
|
|
13
15
|
} from '../../timetable/timetable.js';
|
|
14
16
|
import { encode } from '../../timetable/tripStopId.js';
|
|
@@ -73,8 +75,8 @@ const stopsAdjacency: StopAdjacency[] = [
|
|
|
73
75
|
];
|
|
74
76
|
|
|
75
77
|
const serviceRoutes: ServiceRoute[] = [
|
|
76
|
-
{ type:
|
|
77
|
-
{ type:
|
|
78
|
+
{ type: RouteTypes.BUS, name: 'Route 0', routes: [0] },
|
|
79
|
+
{ type: RouteTypes.BUS, name: 'Route 1', routes: [1] },
|
|
78
80
|
];
|
|
79
81
|
|
|
80
82
|
// ─── Extended fixture: slower direct route 0→2 ────────────────────────────────
|
|
@@ -108,9 +110,9 @@ const stopsAdjacencyWithDirectRoute: StopAdjacency[] = [
|
|
|
108
110
|
];
|
|
109
111
|
|
|
110
112
|
const serviceRoutesWithDirectRoute: ServiceRoute[] = [
|
|
111
|
-
{ type:
|
|
112
|
-
{ type:
|
|
113
|
-
{ type:
|
|
113
|
+
{ type: RouteTypes.BUS, name: 'Route 0', routes: [0] },
|
|
114
|
+
{ type: RouteTypes.BUS, name: 'Route 1', routes: [1] },
|
|
115
|
+
{ type: RouteTypes.BUS, name: 'Route 2', routes: [2] },
|
|
114
116
|
];
|
|
115
117
|
|
|
116
118
|
// ─── Extended fixture: walking transfer from stop 1 to stop 2 ─────────────────
|
|
@@ -121,7 +123,11 @@ const stopsAdjacencyWithTransfer: StopAdjacency[] = [
|
|
|
121
123
|
{
|
|
122
124
|
routes: [0],
|
|
123
125
|
transfers: [
|
|
124
|
-
{
|
|
126
|
+
{
|
|
127
|
+
destination: 2,
|
|
128
|
+
type: TransferTypes.REQUIRES_MINIMAL_TIME,
|
|
129
|
+
minTransferTime: 5,
|
|
130
|
+
},
|
|
125
131
|
],
|
|
126
132
|
},
|
|
127
133
|
{ routes: [] },
|
|
@@ -131,8 +137,8 @@ const stopsAdjacencyWithTransfer: StopAdjacency[] = [
|
|
|
131
137
|
// Route 0 is BUS, route 1 is RAIL — used to verify mode filtering.
|
|
132
138
|
|
|
133
139
|
const mixedModeServiceRoutes: ServiceRoute[] = [
|
|
134
|
-
{ type:
|
|
135
|
-
{ type:
|
|
140
|
+
{ type: RouteTypes.BUS, name: 'Route 0', routes: [0] },
|
|
141
|
+
{ type: RouteTypes.RAIL, name: 'Route 1', routes: [1] },
|
|
136
142
|
];
|
|
137
143
|
|
|
138
144
|
// ─── Extended fixture: in-seat trip continuation ──────────────────────────────
|
|
@@ -249,6 +255,148 @@ describe('Raptor', () => {
|
|
|
249
255
|
});
|
|
250
256
|
});
|
|
251
257
|
|
|
258
|
+
describe('maxDuration', () => {
|
|
259
|
+
it('filters vehicle arrivals after the maxDuration cutoff and allows the exact boundary', () => {
|
|
260
|
+
const timetable = new Timetable(
|
|
261
|
+
stopsAdjacency,
|
|
262
|
+
[route0, route1],
|
|
263
|
+
serviceRoutes,
|
|
264
|
+
);
|
|
265
|
+
const raptor = new Raptor(timetable);
|
|
266
|
+
const tooShortOptions: QueryOptions = {
|
|
267
|
+
maxTransfers: 5,
|
|
268
|
+
minTransferTime: 2,
|
|
269
|
+
transportModes: ALL_TRANSPORT_MODES,
|
|
270
|
+
maxDuration: 29,
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const tooShort = new RoutingState(
|
|
274
|
+
timeFromHM(8, 0),
|
|
275
|
+
[1],
|
|
276
|
+
[{ fromStopId: 0, toStopId: 0, duration: 0 }],
|
|
277
|
+
NB_STOPS,
|
|
278
|
+
tooShortOptions.maxTransfers + 1,
|
|
279
|
+
tooShortOptions.maxDuration,
|
|
280
|
+
);
|
|
281
|
+
raptor.run(tooShortOptions, tooShort);
|
|
282
|
+
assert.strictEqual(tooShort.getArrival(1), undefined);
|
|
283
|
+
|
|
284
|
+
const justEnoughOptions: QueryOptions = {
|
|
285
|
+
maxTransfers: 5,
|
|
286
|
+
minTransferTime: 2,
|
|
287
|
+
transportModes: ALL_TRANSPORT_MODES,
|
|
288
|
+
maxDuration: 30,
|
|
289
|
+
};
|
|
290
|
+
const justEnough = new RoutingState(
|
|
291
|
+
timeFromHM(8, 0),
|
|
292
|
+
[1],
|
|
293
|
+
[{ fromStopId: 0, toStopId: 0, duration: 0 }],
|
|
294
|
+
NB_STOPS,
|
|
295
|
+
justEnoughOptions.maxTransfers + 1,
|
|
296
|
+
justEnoughOptions.maxDuration,
|
|
297
|
+
);
|
|
298
|
+
raptor.run(justEnoughOptions, justEnough);
|
|
299
|
+
assert.strictEqual(justEnough.getArrival(1)?.arrival, timeFromHM(8, 30));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('keeps intermediate stops reachable while filtering later vehicle arrivals', () => {
|
|
303
|
+
const timetable = new Timetable(
|
|
304
|
+
stopsAdjacency,
|
|
305
|
+
[route0, route1],
|
|
306
|
+
serviceRoutes,
|
|
307
|
+
);
|
|
308
|
+
const options: QueryOptions = {
|
|
309
|
+
maxTransfers: 5,
|
|
310
|
+
minTransferTime: 2,
|
|
311
|
+
transportModes: ALL_TRANSPORT_MODES,
|
|
312
|
+
maxDuration: 45,
|
|
313
|
+
};
|
|
314
|
+
const state = new RoutingState(
|
|
315
|
+
timeFromHM(8, 0),
|
|
316
|
+
[2],
|
|
317
|
+
[{ fromStopId: 0, toStopId: 0, duration: 0 }],
|
|
318
|
+
NB_STOPS,
|
|
319
|
+
options.maxTransfers + 1,
|
|
320
|
+
options.maxDuration,
|
|
321
|
+
);
|
|
322
|
+
const raptor = new Raptor(timetable);
|
|
323
|
+
raptor.run(options, state);
|
|
324
|
+
assert.strictEqual(state.getArrival(1)?.arrival, timeFromHM(8, 30));
|
|
325
|
+
assert.strictEqual(state.getArrival(2), undefined);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it('filters timed walking transfers after the maxDuration cutoff', () => {
|
|
329
|
+
const timetable = new Timetable(
|
|
330
|
+
stopsAdjacencyWithTransfer,
|
|
331
|
+
[route0],
|
|
332
|
+
[serviceRoutes[0]!],
|
|
333
|
+
);
|
|
334
|
+
const raptor = new Raptor(timetable);
|
|
335
|
+
const tooShortOptions: QueryOptions = {
|
|
336
|
+
maxTransfers: 5,
|
|
337
|
+
minTransferTime: 2,
|
|
338
|
+
transportModes: ALL_TRANSPORT_MODES,
|
|
339
|
+
maxDuration: 34,
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const tooShort = new RoutingState(
|
|
343
|
+
timeFromHM(8, 0),
|
|
344
|
+
[2],
|
|
345
|
+
[{ fromStopId: 0, toStopId: 0, duration: 0 }],
|
|
346
|
+
NB_STOPS,
|
|
347
|
+
tooShortOptions.maxTransfers + 1,
|
|
348
|
+
tooShortOptions.maxDuration,
|
|
349
|
+
);
|
|
350
|
+
raptor.run(tooShortOptions, tooShort);
|
|
351
|
+
assert.strictEqual(tooShort.getArrival(1)?.arrival, timeFromHM(8, 30));
|
|
352
|
+
assert.strictEqual(tooShort.getArrival(2), undefined);
|
|
353
|
+
|
|
354
|
+
const justEnoughOptions: QueryOptions = {
|
|
355
|
+
maxTransfers: 5,
|
|
356
|
+
minTransferTime: 2,
|
|
357
|
+
transportModes: ALL_TRANSPORT_MODES,
|
|
358
|
+
maxDuration: 35,
|
|
359
|
+
};
|
|
360
|
+
const justEnough = new RoutingState(
|
|
361
|
+
timeFromHM(8, 0),
|
|
362
|
+
[2],
|
|
363
|
+
[{ fromStopId: 0, toStopId: 0, duration: 0 }],
|
|
364
|
+
NB_STOPS,
|
|
365
|
+
justEnoughOptions.maxTransfers + 1,
|
|
366
|
+
justEnoughOptions.maxDuration,
|
|
367
|
+
);
|
|
368
|
+
raptor.run(justEnoughOptions, justEnough);
|
|
369
|
+
assert.strictEqual(justEnough.getArrival(2)?.arrival, timeFromHM(8, 35));
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('filters in-seat continuation arrivals after the maxDuration cutoff', () => {
|
|
373
|
+
const timetable = new Timetable(
|
|
374
|
+
stopsAdjacency,
|
|
375
|
+
[route0, route1],
|
|
376
|
+
serviceRoutes,
|
|
377
|
+
tripContinuations,
|
|
378
|
+
);
|
|
379
|
+
const options: QueryOptions = {
|
|
380
|
+
maxTransfers: 5,
|
|
381
|
+
minTransferTime: 2,
|
|
382
|
+
transportModes: ALL_TRANSPORT_MODES,
|
|
383
|
+
maxDuration: 45,
|
|
384
|
+
};
|
|
385
|
+
const state = new RoutingState(
|
|
386
|
+
timeFromHM(8, 0),
|
|
387
|
+
[2],
|
|
388
|
+
[{ fromStopId: 0, toStopId: 0, duration: 0 }],
|
|
389
|
+
NB_STOPS,
|
|
390
|
+
options.maxTransfers + 1,
|
|
391
|
+
options.maxDuration,
|
|
392
|
+
);
|
|
393
|
+
const raptor = new Raptor(timetable);
|
|
394
|
+
raptor.run(options, state);
|
|
395
|
+
assert.strictEqual(state.getArrival(1)?.arrival, timeFromHM(8, 30));
|
|
396
|
+
assert.strictEqual(state.getArrival(2), undefined);
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
252
400
|
describe('early termination', () => {
|
|
253
401
|
it('exits when no trips are catchable', () => {
|
|
254
402
|
// Departing at 09:00 — all trips have already left (route 0 at 08:10,
|
|
@@ -326,7 +474,7 @@ describe('Raptor', () => {
|
|
|
326
474
|
const options: QueryOptions = {
|
|
327
475
|
maxTransfers: 5,
|
|
328
476
|
minTransferTime: 2,
|
|
329
|
-
transportModes: new Set([
|
|
477
|
+
transportModes: new Set([RouteTypes.RAIL]),
|
|
330
478
|
};
|
|
331
479
|
raptor.run(options, state);
|
|
332
480
|
assert.strictEqual(state.getArrival(1), undefined);
|
|
@@ -6,7 +6,12 @@ import { Stop } from '../../stops/stops.js';
|
|
|
6
6
|
import { StopsIndex } from '../../stops/stopsIndex.js';
|
|
7
7
|
import { Route } from '../../timetable/route.js';
|
|
8
8
|
import { timeFromHMS, timeFromString } from '../../timetable/time.js';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
RouteTypes,
|
|
11
|
+
ServiceRoute,
|
|
12
|
+
StopAdjacency,
|
|
13
|
+
TransferTypes,
|
|
14
|
+
} from '../../timetable/timetable.js';
|
|
10
15
|
import { Query } from '../query.js';
|
|
11
16
|
import { Result } from '../result.js';
|
|
12
17
|
import { RoutingState, TransferEdge, VehicleEdge } from '../router.js';
|
|
@@ -155,8 +160,8 @@ describe('Result', () => {
|
|
|
155
160
|
];
|
|
156
161
|
|
|
157
162
|
const routes: ServiceRoute[] = [
|
|
158
|
-
{ type:
|
|
159
|
-
{ type:
|
|
163
|
+
{ type: RouteTypes.RAIL, name: 'Line 1', routes: [0] },
|
|
164
|
+
{ type: RouteTypes.RAIL, name: 'Line 2', routes: [1] },
|
|
160
165
|
];
|
|
161
166
|
|
|
162
167
|
const mockStopsIndex = new StopsIndex([
|
|
@@ -569,7 +574,7 @@ describe('Result', () => {
|
|
|
569
574
|
arrival: timeFromHMS(8, 35, 0),
|
|
570
575
|
from: 1,
|
|
571
576
|
to: 2,
|
|
572
|
-
type:
|
|
577
|
+
type: TransferTypes.RECOMMENDED,
|
|
573
578
|
minTransferTime: 5,
|
|
574
579
|
};
|
|
575
580
|
const secondVehicleEdge: VehicleEdge = {
|
|
@@ -3,8 +3,7 @@ import { describe, it } from 'node:test';
|
|
|
3
3
|
|
|
4
4
|
import { Stop } from '../../stops/stops.js';
|
|
5
5
|
import { timeFromHMS } from '../../timetable/time.js';
|
|
6
|
-
import { ServiceRouteInfo,
|
|
7
|
-
import { Route, VehicleLeg } from '../route.js';
|
|
6
|
+
import { Route, ServiceRouteInfo, Transfer, VehicleLeg } from '../route.js';
|
|
8
7
|
|
|
9
8
|
describe('Route', () => {
|
|
10
9
|
const stopA: Stop = {
|
|
@@ -59,10 +58,10 @@ describe('Route', () => {
|
|
|
59
58
|
dropOffType: 'REGULAR',
|
|
60
59
|
};
|
|
61
60
|
|
|
62
|
-
const transferLeg = {
|
|
61
|
+
const transferLeg: Transfer = {
|
|
63
62
|
from: stopB,
|
|
64
63
|
to: stopC,
|
|
65
|
-
type: 'RECOMMENDED'
|
|
64
|
+
type: 'RECOMMENDED',
|
|
66
65
|
minTransferTime: 5,
|
|
67
66
|
};
|
|
68
67
|
|