Skip to content

Commit ec99120

Browse files
committed
stuff
1 parent cafb75e commit ec99120

10 files changed

Lines changed: 154 additions & 33 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"test": "pnpm --filter \"core\" test"
1313
},
1414
"devDependencies": {
15-
"@prettier/plugin-oxc": "0.0.4",
1615
"prettier": "3.6.2",
1716
"prettier-plugin-organize-imports": "4.2.0",
1817
"prettier-plugin-svelte": "3.4.0",

packages/core/src/edge-path-bundling/floyd-warshall/gpu.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { Edge } from '../../AdjacencyList';
33
import { Graph } from '../../AdjacencyList';
44
import { FloydWarshall } from '../../shortest-path/floyd-warshall/FloydWarshall';
55
import type { Spanner } from '../../spanner';
6-
import { GreedySpanner } from '../../spanner/greedy/gpu';
76
import { ThetaSpanner } from '../../spanner/theta/gpu';
87

98
export type EdgePathBundlingGPUFloydWarshallParams = {
@@ -64,6 +63,12 @@ export class EdgePathBundlingGPUFloydWarshall implements EdgePathBundling {
6463
await this.#floydWarshall.compute();
6564
}
6665

66+
if (this.#edgeWeightFactor !== this.#floydWarshall.edgeWeightFactor) {
67+
console.log('Edge weight factor changed. Recomputing Floyd-Warshall');
68+
this.#floydWarshall.edgeWeightFactor = this.#edgeWeightFactor;
69+
await this.#floydWarshall.compute();
70+
}
71+
6772
const difference: Edge[] = [];
6873
this.#graph.edges.forEach((edge, key) => {
6974
if (!this.#spanner!.graph.edges.has(key)) {
@@ -103,4 +108,12 @@ export class EdgePathBundlingGPUFloydWarshall implements EdgePathBundling {
103108

104109
return bundeledEdges;
105110
}
111+
112+
set maxDistortion(maxDistortion: number) {
113+
this.#maxDistortion = maxDistortion;
114+
}
115+
116+
set edgeWeightFactor(edgeWeightFactor: number) {
117+
this.#edgeWeightFactor = edgeWeightFactor;
118+
}
106119
}

packages/core/src/shortest-path/floyd-warshall/FloydWarshall.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import type { Edge, Graph } from '../../AdjacencyList';
12
import { AdjacencyMatrix } from '../../AdjacencyMatrix';
23
import { BufferData } from '../../BufferData';
3-
import type { Edge, Graph } from '../../AdjacencyList';
4+
import { createGPUBuffer, writeGPUBuffer } from '../../GPUBuffer';
45
import type { Path } from '../../path';
56
import { mapAndReadBuffer } from '../../utils';
67
import shader from './shader.wgsl?raw';
7-
import { createGPUBuffer, writeGPUBuffer } from '../../GPUBuffer';
88

99
export type FloydWarshallParams = {
1010
graph: Graph;

packages/core/src/spanner/theta/gpu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Spanner } from '../index';
21
import { Graph } from '../../AdjacencyList';
32
import { BufferData } from '../../BufferData';
43
import { createGPUBuffer } from '../../GPUBuffer';
4+
import { Spanner } from '../index';
55
import shader from './shader.wgsl?raw';
66

77
export type ThetaSpannerParams = {

packages/core/test/shortestPath.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from 'vitest';
2-
import { Graph } from '../src/Graph.js';
32
import { Graph as GraphNew } from '../src/AdjacencyList.js';
3+
import { Graph } from '../src/Graph.js';
44
import { dijkstra } from '../src/shortest-path/dijkstra/cpu.js';
55
import { dijkstraGPU } from '../src/shortest-path/dijkstra/gpu.js';
66
import { FloydWarshall } from '../src/shortest-path/floyd-warshall/FloydWarshall.js';
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { EdgePathBundlingGPUFloydWarshall } from '@bachelor/core/edge-path-bundling/floyd-warshall/gpu';
2+
import { initWebGPU } from '@bachelor/core/webGpu';
3+
import { afterAll, describe, test } from 'vitest';
4+
import { average, ITERATIONS, loadDatasets, writeResult, type CSV, type CSVRow } from './utils';
5+
6+
const datasets = await loadDatasets();
7+
8+
const steps = [
9+
{ parameter: 'edgeWeightFactor', value: 1 },
10+
{ parameter: 'maxDistortion', value: 1 },
11+
{ parameter: 'edgeWeightFactor', value: 3 },
12+
{ parameter: 'maxDistortion', value: 3 },
13+
] as const;
14+
15+
describe('Interactivity', () => {
16+
test.each(datasets)('%s', { repeats: ITERATIONS - 1 }, async (dataset, graph, times) => {
17+
const { device } = await initWebGPU();
18+
19+
const epb = new EdgePathBundlingGPUFloydWarshall({
20+
device,
21+
graph,
22+
maxDistortion: 2,
23+
edgeWeightFactor: 2,
24+
});
25+
26+
const start = performance.now();
27+
await epb.bundle();
28+
const end = performance.now();
29+
30+
times.push(end - start);
31+
32+
for await (const { parameter, value } of steps) {
33+
const start = performance.now();
34+
epb[parameter] = value;
35+
await epb.bundle();
36+
const end = performance.now();
37+
38+
times.push(end - start);
39+
}
40+
});
41+
});
42+
43+
afterAll(async () => {
44+
const csv: CSV = [];
45+
46+
const header: CSVRow = ['dataset'];
47+
48+
header.push('average_initial');
49+
for (const { parameter, value } of steps) {
50+
header.push(`average_${parameter}_${value}`);
51+
}
52+
53+
for (let i = 0; i < ITERATIONS; i++) {
54+
header.push(`run_${i + 1}_initial`);
55+
56+
for (const { parameter, value } of steps) {
57+
header.push(`run_${i + 1}_${parameter}_${value}`);
58+
}
59+
}
60+
61+
csv.push(header);
62+
63+
datasets.forEach(([dataset, graph, times]) => {
64+
const row: CSVRow = [dataset];
65+
66+
// Calculate average for each step
67+
for (let i = 0; i <= steps.length; i++) {
68+
const values: number[] = [];
69+
70+
for (let j = i; j < times.length; j += steps.length + 1) {
71+
console.log({ i, j });
72+
values.push(times[j]!);
73+
}
74+
75+
row.push(average(values));
76+
}
77+
78+
times.forEach((time) => {
79+
row.push(time);
80+
});
81+
82+
csv.push(row);
83+
});
84+
85+
await writeResult('interactivity', csv);
86+
});
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
import { afterAll, describe, test } from 'vitest';
2-
import { Graph } from '@bachelor/core/AdjacencyList';
3-
import { loadGraph } from '@bachelor/core/datasets/load';
4-
import type { DatasetName } from '@bachelor/core/datasets/load';
5-
import { initWebGPU } from '@bachelor/core/webGpu';
61
import { EdgePathBundlingGPUFloydWarshall } from '@bachelor/core/edge-path-bundling/floyd-warshall/gpu';
7-
import { server } from '@vitest/browser/context';
8-
9-
const ITERATIONS = 5;
2+
import { initWebGPU } from '@bachelor/core/webGpu';
3+
import { afterAll, describe, test } from 'vitest';
4+
import type { CSV, CSVRow } from './utils';
5+
import { average, ITERATIONS, loadDatasets, writeResult } from './utils';
106

11-
const datasets: [dataset: DatasetName, graph: Graph, times: number[]][] = await Promise.all(
12-
(['airlines', 'migration', 'airtraffic'] satisfies DatasetName[]).map(async (dataset) => {
13-
const graph = await loadGraph(dataset);
14-
return [dataset, graph, []];
15-
})
16-
);
7+
const datasets = await loadDatasets();
178

189
describe('Runtime', () => {
1910
test.each(datasets)('%s', { repeats: ITERATIONS - 1 }, async (dataset, graph, times) => {
@@ -34,12 +25,10 @@ describe('Runtime', () => {
3425
});
3526
});
3627

37-
type CSVRowValue = string | number;
38-
3928
afterAll(async () => {
40-
const csv: CSVRowValue[][] = [];
29+
const csv: CSV = [];
4130

42-
const header: CSVRowValue[] = ['dataset'];
31+
const header: CSVRow = ['dataset'];
4332
for (let i = 0; i < ITERATIONS; i++) {
4433
header.push(`run_${i + 1}`);
4534
}
@@ -49,16 +38,15 @@ afterAll(async () => {
4938
csv.push(header);
5039

5140
datasets.forEach(([dataset, graph, times]) => {
52-
const row: CSVRowValue[] = [dataset];
41+
const row: CSVRow = [dataset];
5342

5443
times.forEach((time) => {
5544
row.push(time);
5645
});
5746

58-
row.push(times.reduce((acc, time) => acc + time, 0) / times.length);
47+
row.push(average(times));
5948

6049
csv.push(row);
6150
});
62-
63-
await server.commands.writeFile('./result.csv', csv.map((row) => row.join(',')).join('\n'));
51+
await writeResult('runtime', csv);
6452
});

packages/experiments/src/utils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { Graph } from '@bachelor/core/AdjacencyList';
2+
import { loadGraph, type DatasetName } from '@bachelor/core/datasets/load';
3+
import { server } from '@vitest/browser/context';
4+
5+
export const ITERATIONS = 2;
6+
7+
export async function loadDatasets() {
8+
const datasets: [dataset: DatasetName, graph: Graph, times: number[]][] = await Promise.all(
9+
(['airlines'] satisfies DatasetName[]).map(async (dataset) => {
10+
// (['airlines', 'migration', 'airtraffic'] satisfies DatasetName[]).map(async (dataset) => {
11+
const graph = await loadGraph(dataset);
12+
return [dataset, graph, []];
13+
})
14+
);
15+
16+
return datasets;
17+
}
18+
19+
export type CSVRowValue = string | number;
20+
export type CSVRow = CSVRowValue[];
21+
export type CSV = CSVRow[];
22+
23+
export async function writeCSV(name: string, csv: CSV) {
24+
await writeResult(`./results/${name}.csv`, csv);
25+
}
26+
27+
export async function writeResult(name: string, csv: CSV) {
28+
await server.commands.writeFile(
29+
`./results/${name}.csv`,
30+
csv.map((row) => row.join(';')).join('\n')
31+
);
32+
}
33+
34+
export function average(values: number[]) {
35+
return values.reduce((acc, value) => acc + value, 0) / values.length;
36+
}

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prettier.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const config = {
66
printWidth: 100,
77
trailingComma: 'es5',
88
plugins: [
9-
'@prettier/plugin-oxc',
109
'prettier-plugin-svelte',
1110
'prettier-plugin-organize-imports',
1211
'prettier-plugin-tailwindcss',

0 commit comments

Comments
 (0)