@osmix/router 0.0.11 → 0.1.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 +78 -0
- package/LICENSE +21 -0
- package/README.md +138 -53
- package/dist/algorithms/bidirectional.d.ts +6 -9
- package/dist/algorithms/bidirectional.d.ts.map +1 -1
- package/dist/algorithms/bidirectional.js +84 -104
- package/dist/algorithms/bidirectional.js.map +1 -1
- package/dist/algorithms/index.d.ts +2 -2
- package/dist/algorithms/index.d.ts.map +1 -1
- package/dist/algorithms/index.js +1 -1
- package/dist/algorithms/index.js.map +1 -1
- package/dist/algorithms/shortest-path.d.ts +2 -1
- package/dist/algorithms/shortest-path.d.ts.map +1 -1
- package/dist/algorithms/shortest-path.js +9 -7
- package/dist/algorithms/shortest-path.js.map +1 -1
- package/dist/binary-heap.d.ts +5 -0
- package/dist/binary-heap.d.ts.map +1 -1
- package/dist/binary-heap.js +11 -4
- package/dist/binary-heap.js.map +1 -1
- package/dist/graph.d.ts +35 -7
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +161 -119
- package/dist/graph.js.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/router.d.ts +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +6 -3
- package/dist/router.js.map +1 -1
- package/dist/topology-stats.d.ts +37 -0
- package/dist/topology-stats.d.ts.map +1 -0
- package/dist/topology-stats.js +62 -0
- package/dist/topology-stats.js.map +1 -0
- package/dist/types.d.ts +15 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -7
- package/dist/utils.js.map +1 -1
- package/package.json +32 -29
- package/src/algorithms/bidirectional.ts +124 -136
- package/src/algorithms/index.ts +10 -10
- package/src/algorithms/shortest-path.ts +96 -92
- package/src/binary-heap.ts +133 -129
- package/src/graph.ts +389 -355
- package/src/index.ts +14 -9
- package/src/router.ts +221 -233
- package/src/topology-stats.ts +84 -0
- package/src/types.ts +102 -87
- package/src/utils.ts +67 -74
- package/test/algorithms.test.ts +396 -353
- package/test/binary-heap.test.ts +27 -0
- package/test/limits.test.ts +82 -0
- package/test/no-shared-array-buffer.test.ts +37 -0
- package/test/router.bench.ts +171 -188
- package/test/router.test.ts +685 -726
- package/test/spatial-capability.test.ts +23 -0
- package/test/topology-stats.test.ts +82 -0
- package/tsconfig.build.json +6 -3
- package/tsconfig.json +7 -7
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { BinaryHeap } from "../src/binary-heap.ts";
|
|
4
|
+
|
|
5
|
+
describe("BinaryHeap", () => {
|
|
6
|
+
it("preserves priority order when a replacement must move down multiple levels", () => {
|
|
7
|
+
const heap = new BinaryHeap();
|
|
8
|
+
for (let priority = 1; priority <= 7; priority++) {
|
|
9
|
+
heap.push(priority, priority);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const popped: number[] = [];
|
|
13
|
+
while (heap.size > 0) popped.push(heap.pop()!);
|
|
14
|
+
|
|
15
|
+
expect(popped).toEqual([1, 2, 3, 4, 5, 6, 7]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("preserves ordering after decreasing an existing item's priority", () => {
|
|
19
|
+
const heap = new BinaryHeap();
|
|
20
|
+
heap.push(1, 10);
|
|
21
|
+
heap.push(2, 20);
|
|
22
|
+
heap.push(3, 30);
|
|
23
|
+
heap.push(3, 5);
|
|
24
|
+
|
|
25
|
+
expect([heap.pop(), heap.pop(), heap.pop()]).toEqual([3, 1, 2]);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Osm } from "@osmix/core";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { buildGraph, Router } from "../src/index.ts";
|
|
5
|
+
|
|
6
|
+
function finish(osm: Osm): Osm {
|
|
7
|
+
osm.buildIndexes();
|
|
8
|
+
osm.buildSpatialIndexes();
|
|
9
|
+
return osm;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
describe("graph build with missing nodes", () => {
|
|
13
|
+
it("skips segments that touch a node outside the dataset", () => {
|
|
14
|
+
const osm = new Osm({ id: "dangling" });
|
|
15
|
+
osm.nodes.addNode({ id: 1, lon: 0, lat: 0 });
|
|
16
|
+
osm.nodes.addNode({ id: 2, lon: 0.001, lat: 0 });
|
|
17
|
+
osm.nodes.addNode({ id: 3, lon: 0.002, lat: 0 });
|
|
18
|
+
// Node 99 is not in the dataset, as after a bbox extract.
|
|
19
|
+
osm.ways.addWay({ id: 10, refs: [99, 1, 2, 3], tags: { highway: "residential" } });
|
|
20
|
+
finish(osm);
|
|
21
|
+
|
|
22
|
+
const graph = buildGraph(osm);
|
|
23
|
+
// Two two-way segments remain: 1-2 and 2-3.
|
|
24
|
+
expect(graph.edges).toBe(4);
|
|
25
|
+
const targets = new Uint32Array(graph.transferables().edgeTargets);
|
|
26
|
+
for (const target of targets) expect(target).toBeLessThan(graph.size);
|
|
27
|
+
|
|
28
|
+
const router = new Router(osm, graph);
|
|
29
|
+
const path = router.route(0, 2);
|
|
30
|
+
expect(path?.map((p) => p.nodeIndex)).toEqual([0, 1, 2]);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("bidirectional routing on one-way streets", () => {
|
|
35
|
+
it("never travels against a one-way", () => {
|
|
36
|
+
const osm = new Osm({ id: "one-way" });
|
|
37
|
+
osm.nodes.addNode({ id: 1, lon: 0, lat: 0 });
|
|
38
|
+
osm.nodes.addNode({ id: 2, lon: 0.001, lat: 0 });
|
|
39
|
+
osm.nodes.addNode({ id: 3, lon: 0.002, lat: 0 });
|
|
40
|
+
osm.nodes.addNode({ id: 4, lon: 0.001, lat: 0.01 });
|
|
41
|
+
osm.ways.addWay({ id: 10, refs: [1, 2, 3], tags: { highway: "residential", oneway: "yes" } });
|
|
42
|
+
osm.ways.addWay({ id: 11, refs: [3, 4, 1], tags: { highway: "residential" } });
|
|
43
|
+
finish(osm);
|
|
44
|
+
|
|
45
|
+
const graph = buildGraph(osm);
|
|
46
|
+
const router = new Router(osm, graph, { algorithm: "bidirectional" });
|
|
47
|
+
const node = (id: number) => osm.nodes.ids.getIndexFromId(id);
|
|
48
|
+
|
|
49
|
+
const back = router.route(node(3), node(1));
|
|
50
|
+
expect(back?.map((p) => osm.nodes.ids.at(p.nodeIndex))).toEqual([3, 4, 1]);
|
|
51
|
+
const dijkstra = router.route(node(3), node(1), { algorithm: "dijkstra" });
|
|
52
|
+
expect(back?.at(-1)?.cost).toBeCloseTo(dijkstra!.at(-1)!.cost);
|
|
53
|
+
|
|
54
|
+
const incoming = graph
|
|
55
|
+
.getIncomingEdges(node(2))
|
|
56
|
+
.map((e) => osm.nodes.ids.at(e.targetNodeIndex));
|
|
57
|
+
expect(incoming).toEqual([1]);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("A* time heuristic", () => {
|
|
62
|
+
it("stays optimal when a maxspeed is above 130 km/h", () => {
|
|
63
|
+
// A slow direct road (100 km/h, ~11 km) and a much longer detour at 1,000 km/h.
|
|
64
|
+
// The detour is faster. A heuristic fixed at 130 km/h overestimates on it.
|
|
65
|
+
const osm = new Osm({ id: "fast-road" });
|
|
66
|
+
osm.nodes.addNode({ id: 1, lon: 0, lat: 0 });
|
|
67
|
+
osm.nodes.addNode({ id: 2, lon: 0.1, lat: 0 });
|
|
68
|
+
osm.nodes.addNode({ id: 3, lon: 0.05, lat: 0.3 });
|
|
69
|
+
osm.ways.addWay({ id: 10, refs: [1, 2], tags: { highway: "primary", maxspeed: "100" } });
|
|
70
|
+
osm.ways.addWay({ id: 11, refs: [1, 3, 2], tags: { highway: "motorway", maxspeed: "1000" } });
|
|
71
|
+
finish(osm);
|
|
72
|
+
|
|
73
|
+
const graph = buildGraph(osm);
|
|
74
|
+
expect(graph.maxSpeedMps).toBeCloseTo(1000 / 3.6, 2);
|
|
75
|
+
|
|
76
|
+
const router = new Router(osm, graph, { metric: "time" });
|
|
77
|
+
const astar = router.route(0, 1, { algorithm: "astar" });
|
|
78
|
+
const dijkstra = router.route(0, 1, { algorithm: "dijkstra" });
|
|
79
|
+
expect(astar?.map((p) => p.nodeIndex)).toEqual([0, 2, 1]);
|
|
80
|
+
expect(astar?.at(-1)?.cost).toBeCloseTo(dijkstra!.at(-1)!.cost);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
describe("router transfers without SharedArrayBuffer", () => {
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
vi.unstubAllGlobals();
|
|
6
|
+
vi.resetModules();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it("returns every ArrayBuffer in the transfer list", async () => {
|
|
10
|
+
vi.stubGlobal("SharedArrayBuffer", undefined);
|
|
11
|
+
vi.resetModules();
|
|
12
|
+
|
|
13
|
+
const { getTransferableBuffers } = await import("../src/graph.ts");
|
|
14
|
+
const createBuffer = () => new ArrayBuffer(4);
|
|
15
|
+
const transferables = {
|
|
16
|
+
nodeCount: 0,
|
|
17
|
+
edgeCount: 0,
|
|
18
|
+
edgeOffsets: createBuffer(),
|
|
19
|
+
edgeTargets: createBuffer(),
|
|
20
|
+
edgeWayIndexes: createBuffer(),
|
|
21
|
+
edgeDistances: createBuffer(),
|
|
22
|
+
edgeTimes: createBuffer(),
|
|
23
|
+
routableBits: createBuffer(),
|
|
24
|
+
intersectionBits: createBuffer(),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
expect(getTransferableBuffers(transferables)).toEqual([
|
|
28
|
+
transferables.edgeOffsets,
|
|
29
|
+
transferables.edgeTargets,
|
|
30
|
+
transferables.edgeWayIndexes,
|
|
31
|
+
transferables.edgeDistances,
|
|
32
|
+
transferables.edgeTimes,
|
|
33
|
+
transferables.routableBits,
|
|
34
|
+
transferables.intersectionBits,
|
|
35
|
+
]);
|
|
36
|
+
});
|
|
37
|
+
});
|
package/test/router.bench.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { Osm } from "@osmix/core"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
1
|
+
import { Osm } from "@osmix/core";
|
|
2
|
+
import { fromPbf } from "@osmix/load";
|
|
3
|
+
import { getFixtureFile, PBFs } from "@osmix/test-utils/fixtures";
|
|
4
|
+
import { bench, group, run } from "mitata";
|
|
5
|
+
|
|
6
|
+
import { buildGraph } from "../src/index.ts";
|
|
7
|
+
import { Router } from "../src/router.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Router Benchmark Suite using mitata
|
|
10
11
|
*
|
|
11
|
-
* Run with:
|
|
12
|
+
* Run with: pnpm --filter @osmix/router run bench
|
|
12
13
|
*
|
|
13
14
|
* These benchmarks compare the performance of different routing algorithms
|
|
14
15
|
* using both real-world OSM data (Monaco) and synthetic grid networks.
|
|
@@ -28,230 +29,212 @@ import { Router } from "../src/router"
|
|
|
28
29
|
* @param spacing - Spacing between nodes in degrees (~100m per 0.001)
|
|
29
30
|
*/
|
|
30
31
|
function createSyntheticGrid(size: number, spacing: number): Osm {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
32
|
+
const osm = new Osm({ id: "synthetic-grid" });
|
|
33
|
+
|
|
34
|
+
// Create nodes in a grid pattern
|
|
35
|
+
for (let row = 0; row < size; row++) {
|
|
36
|
+
for (let col = 0; col < size; col++) {
|
|
37
|
+
const nodeId = row * size + col + 1;
|
|
38
|
+
osm.nodes.addNode({
|
|
39
|
+
id: nodeId,
|
|
40
|
+
lat: row * spacing,
|
|
41
|
+
lon: col * spacing,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
osm.nodes.buildIndex();
|
|
47
|
+
osm.nodes.buildSpatialIndex();
|
|
48
|
+
|
|
49
|
+
// Create horizontal ways (connecting nodes in each row)
|
|
50
|
+
let wayId = 1;
|
|
51
|
+
for (let row = 0; row < size; row++) {
|
|
52
|
+
const refs: number[] = [];
|
|
53
|
+
for (let col = 0; col < size; col++) {
|
|
54
|
+
refs.push(row * size + col + 1);
|
|
55
|
+
}
|
|
56
|
+
osm.ways.addWay({
|
|
57
|
+
id: wayId++,
|
|
58
|
+
refs,
|
|
59
|
+
tags: { highway: "residential" },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Create vertical ways (connecting nodes in each column)
|
|
64
|
+
for (let col = 0; col < size; col++) {
|
|
65
|
+
const refs: number[] = [];
|
|
66
|
+
for (let row = 0; row < size; row++) {
|
|
67
|
+
refs.push(row * size + col + 1);
|
|
68
|
+
}
|
|
69
|
+
osm.ways.addWay({
|
|
70
|
+
id: wayId++,
|
|
71
|
+
refs,
|
|
72
|
+
tags: { highway: "residential" },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
osm.ways.buildIndex();
|
|
77
|
+
osm.ways.buildSpatialIndex();
|
|
78
|
+
osm.buildIndexes();
|
|
79
|
+
|
|
80
|
+
return osm;
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
// ---------------------------------------------------------------------------
|
|
83
84
|
// Setup
|
|
84
85
|
// ---------------------------------------------------------------------------
|
|
85
86
|
|
|
86
|
-
console.log("Setting up benchmark data...")
|
|
87
|
+
console.log("Setting up benchmark data...");
|
|
87
88
|
|
|
88
89
|
// Load Monaco PBF
|
|
89
|
-
const monacoPbf = PBFs["monaco"]
|
|
90
|
-
const pbfData = await getFixtureFile(monacoPbf.url)
|
|
91
|
-
const monacoOsm = await fromPbf(pbfData, {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const monacoGraph = buildGraph(monacoOsm)
|
|
95
|
-
const monacoRouter = new Router(monacoOsm, monacoGraph)
|
|
90
|
+
const monacoPbf = PBFs["monaco"]!;
|
|
91
|
+
const pbfData = await getFixtureFile(monacoPbf.url);
|
|
92
|
+
const monacoOsm = await fromPbf(pbfData, { loadProfile: "full" });
|
|
93
|
+
const monacoGraph = buildGraph(monacoOsm);
|
|
94
|
+
const monacoRouter = new Router(monacoOsm, monacoGraph);
|
|
96
95
|
|
|
97
96
|
// Create synthetic grid
|
|
98
|
-
const GRID_SIZE = 50
|
|
99
|
-
const GRID_SPACING = 0.001
|
|
100
|
-
const gridOsm = createSyntheticGrid(GRID_SIZE, GRID_SPACING)
|
|
101
|
-
const gridGraph = buildGraph(gridOsm)
|
|
102
|
-
const gridRouter = new Router(gridOsm, gridGraph)
|
|
97
|
+
const GRID_SIZE = 50;
|
|
98
|
+
const GRID_SPACING = 0.001;
|
|
99
|
+
const gridOsm = createSyntheticGrid(GRID_SIZE, GRID_SPACING);
|
|
100
|
+
const gridGraph = buildGraph(gridOsm);
|
|
101
|
+
const gridRouter = new Router(gridOsm, gridGraph);
|
|
103
102
|
|
|
104
103
|
// Pre-snap coordinates to node indexes for benchmarking
|
|
105
104
|
const monacoShortFrom = monacoGraph.findNearestRoutableNode(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)!.nodeIndex
|
|
105
|
+
monacoOsm,
|
|
106
|
+
[7.42, 43.735],
|
|
107
|
+
500,
|
|
108
|
+
)!.nodeIndex;
|
|
110
109
|
const monacoShortTo = monacoGraph.findNearestRoutableNode(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
)!.nodeIndex
|
|
110
|
+
monacoOsm,
|
|
111
|
+
[7.425, 43.738],
|
|
112
|
+
500,
|
|
113
|
+
)!.nodeIndex;
|
|
115
114
|
const monacoLongFrom = monacoGraph.findNearestRoutableNode(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)!.nodeIndex
|
|
120
|
-
const monacoLongTo = monacoGraph.findNearestRoutableNode(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
)!.nodeIndex
|
|
125
|
-
|
|
126
|
-
const gridShortFrom = gridGraph.findNearestRoutableNode(
|
|
127
|
-
gridOsm,
|
|
128
|
-
[0.01, 0.01],
|
|
129
|
-
200,
|
|
130
|
-
)!.nodeIndex
|
|
131
|
-
const gridShortTo = gridGraph.findNearestRoutableNode(
|
|
132
|
-
gridOsm,
|
|
133
|
-
[0.015, 0.015],
|
|
134
|
-
200,
|
|
135
|
-
)!.nodeIndex
|
|
136
|
-
const gridLongFrom = gridGraph.findNearestRoutableNode(
|
|
137
|
-
gridOsm,
|
|
138
|
-
[0, 0],
|
|
139
|
-
200,
|
|
140
|
-
)!.nodeIndex
|
|
115
|
+
monacoOsm,
|
|
116
|
+
[7.41, 43.725],
|
|
117
|
+
500,
|
|
118
|
+
)!.nodeIndex;
|
|
119
|
+
const monacoLongTo = monacoGraph.findNearestRoutableNode(monacoOsm, [7.44, 43.745], 500)!.nodeIndex;
|
|
120
|
+
|
|
121
|
+
const gridShortFrom = gridGraph.findNearestRoutableNode(gridOsm, [0.01, 0.01], 200)!.nodeIndex;
|
|
122
|
+
const gridShortTo = gridGraph.findNearestRoutableNode(gridOsm, [0.015, 0.015], 200)!.nodeIndex;
|
|
123
|
+
const gridLongFrom = gridGraph.findNearestRoutableNode(gridOsm, [0, 0], 200)!.nodeIndex;
|
|
141
124
|
const gridLongTo = gridGraph.findNearestRoutableNode(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
)!.nodeIndex
|
|
125
|
+
gridOsm,
|
|
126
|
+
[(GRID_SIZE - 1) * GRID_SPACING, (GRID_SIZE - 1) * GRID_SPACING],
|
|
127
|
+
200,
|
|
128
|
+
)!.nodeIndex;
|
|
146
129
|
|
|
147
|
-
console.log("Setup complete. Running benchmarks...\n")
|
|
130
|
+
console.log("Setup complete. Running benchmarks...\n");
|
|
148
131
|
|
|
149
132
|
// ---------------------------------------------------------------------------
|
|
150
133
|
// Monaco PBF Benchmarks
|
|
151
134
|
// ---------------------------------------------------------------------------
|
|
152
135
|
|
|
153
136
|
group("Monaco - Short Distance (~500m)", () => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
})
|
|
137
|
+
bench("Dijkstra", () => {
|
|
138
|
+
monacoRouter.route(monacoShortFrom, monacoShortTo, {
|
|
139
|
+
algorithm: "dijkstra",
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
bench("A*", () => {
|
|
144
|
+
monacoRouter.route(monacoShortFrom, monacoShortTo, {
|
|
145
|
+
algorithm: "astar",
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
bench("Bidirectional", () => {
|
|
150
|
+
monacoRouter.route(monacoShortFrom, monacoShortTo, {
|
|
151
|
+
algorithm: "bidirectional",
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
172
155
|
|
|
173
156
|
group("Monaco - Long Distance (~2km)", () => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
})
|
|
157
|
+
bench("Dijkstra", () => {
|
|
158
|
+
monacoRouter.route(monacoLongFrom, monacoLongTo, {
|
|
159
|
+
algorithm: "dijkstra",
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
bench("A*", () => {
|
|
164
|
+
monacoRouter.route(monacoLongFrom, monacoLongTo, {
|
|
165
|
+
algorithm: "astar",
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
bench("Bidirectional", () => {
|
|
170
|
+
monacoRouter.route(monacoLongFrom, monacoLongTo, {
|
|
171
|
+
algorithm: "bidirectional",
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
192
175
|
|
|
193
176
|
// ---------------------------------------------------------------------------
|
|
194
177
|
// Synthetic Grid Benchmarks
|
|
195
178
|
// ---------------------------------------------------------------------------
|
|
196
179
|
|
|
197
180
|
group("Grid 50x50 - Short Path", () => {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
})
|
|
181
|
+
bench("Dijkstra", () => {
|
|
182
|
+
gridRouter.route(gridShortFrom, gridShortTo, {
|
|
183
|
+
algorithm: "dijkstra",
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
bench("A*", () => {
|
|
188
|
+
gridRouter.route(gridShortFrom, gridShortTo, {
|
|
189
|
+
algorithm: "astar",
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
bench("Bidirectional", () => {
|
|
194
|
+
gridRouter.route(gridShortFrom, gridShortTo, {
|
|
195
|
+
algorithm: "bidirectional",
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
});
|
|
216
199
|
|
|
217
200
|
group("Grid 50x50 - Long Path (corner to corner)", () => {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
})
|
|
201
|
+
bench("Dijkstra", () => {
|
|
202
|
+
gridRouter.route(gridLongFrom, gridLongTo, {
|
|
203
|
+
algorithm: "dijkstra",
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
bench("A*", () => {
|
|
208
|
+
gridRouter.route(gridLongFrom, gridLongTo, {
|
|
209
|
+
algorithm: "astar",
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
bench("Bidirectional", () => {
|
|
214
|
+
gridRouter.route(gridLongFrom, gridLongTo, {
|
|
215
|
+
algorithm: "bidirectional",
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
236
219
|
|
|
237
220
|
// ---------------------------------------------------------------------------
|
|
238
221
|
// Router Initialization Benchmarks
|
|
239
222
|
// ---------------------------------------------------------------------------
|
|
240
223
|
|
|
241
224
|
group("Router Initialization", () => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
225
|
+
bench("Monaco OSM (14k nodes, 3k ways)", () => {
|
|
226
|
+
new Router(monacoOsm, buildGraph(monacoOsm));
|
|
227
|
+
});
|
|
245
228
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
})
|
|
229
|
+
bench("Grid 50x50 (2.5k nodes)", () => {
|
|
230
|
+
new Router(gridOsm, buildGraph(gridOsm));
|
|
231
|
+
});
|
|
232
|
+
});
|
|
250
233
|
|
|
251
234
|
// ---------------------------------------------------------------------------
|
|
252
235
|
// Run benchmarks
|
|
253
236
|
// ---------------------------------------------------------------------------
|
|
254
237
|
|
|
255
238
|
await run({
|
|
256
|
-
|
|
257
|
-
})
|
|
239
|
+
colors: true,
|
|
240
|
+
});
|