Skip to content

Commit 32a3a88

Browse files
committed
temp changes
1 parent 859343c commit 32a3a88

10 files changed

Lines changed: 196 additions & 150 deletions

File tree

packages/app/src/routes/app/(canvas)/+page.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@
3838
3939
onMount(async () => {
4040
const graph = await loadGraph(selectedGraph);
41-
const spanner = await loadSpanner(selectedGraph);
4241
4342
// console.time('greedy');
4443
// const greedySpanner = new GreedySpanner({ graph, device, maxDistortion });
4544
// const greedySpannerGraph = await greedySpanner.compute();
4645
// console.timeEnd('greedy');
4746
48-
console.time('theta');
49-
const thetaSpanner = new ThetaSpanner({ graph, device, k: 100 });
50-
const thetaSpannerGraph = await thetaSpanner.compute();
51-
console.timeEnd('theta');
47+
// console.time('theta');
48+
// const thetaSpanner = new ThetaSpanner({ graph, device, k: 100 });
49+
// const thetaSpannerGraph = await thetaSpanner.compute();
50+
// console.timeEnd('theta');
5251
5352
epb = new EdgePathBundlingGPUFloydWarshall({
53+
device,
5454
graph,
55-
maxDistortion,
55+
maxDistortion: 128,
5656
edgeWeightFactor,
57-
device,
57+
spannerAlgorithm: ThetaSpanner,
5858
});
5959
6060
runGPU();

packages/app/src/routes/app/(canvas)/spanner/+page.svelte

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { drawGraphAndBundledEdges } from '$lib/_canvas';
32
import { getCanvasState } from '$lib/state/canvas';
43
import { getWebGPUState } from '$lib/state/webGPU';
54
import ControlPanel from '$lib/components/ControlPanel.svelte';
@@ -26,21 +25,29 @@
2625
2726
canvas.onResize = () => runGPU();
2827
28+
$effect(() => {
29+
console.log(maxDistortion);
30+
if (!theta) return;
31+
32+
theta.maxDistortion = maxDistortion;
33+
runGPU();
34+
});
35+
2936
onMount(async () => {
3037
const graph = await loadGraph(selectedGraph);
3138
3239
greedy = new GreedySpanner({ graph, device, maxDistortion: 2 });
33-
theta = new ThetaSpanner({ graph, device, k: 1000 });
40+
theta = new ThetaSpanner({ graph, device, maxDistortion: 3 });
3441
3542
runGPU();
3643
});
3744
3845
async function runGPU() {
3946
if (!greedy || !theta) return;
4047
41-
console.time('greedy');
42-
const greedySpanner = await greedy.compute();
43-
console.timeEnd('greedy');
48+
// console.time('greedy');
49+
// const greedySpanner = await greedy.compute();
50+
// console.timeEnd('greedy');
4451
4552
console.time('theta');
4653
const thetaSpanner = await theta.compute();

packages/app/src/routes/app/metrics/+page.svelte

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
1-
import type { EdgePathBundling } from '..';
21
import type { Edge } from '../../AdjacencyList';
32
import { Graph } from '../../AdjacencyList';
43
import { FloydWarshall } from '../../shortest-path/floyd-warshall/FloydWarshall';
54
import type { Spanner } from '../../spanner';
6-
import { ThetaSpanner } from '../../spanner/theta/gpu';
7-
8-
export type EdgePathBundlingGPUFloydWarshallParams = {
9-
graph: Graph;
10-
maxDistortion?: number;
11-
edgeWeightFactor?: number;
12-
device: GPUDevice;
13-
};
5+
import type { EdgePathBundling, EdgePathBundlingParams } from '../index';
146

157
export class EdgePathBundlingGPUFloydWarshall implements EdgePathBundling {
168
#device: GPUDevice;
@@ -19,40 +11,45 @@ export class EdgePathBundlingGPUFloydWarshall implements EdgePathBundling {
1911
#maxDistortion: number;
2012
#edgeWeightFactor: number;
2113

22-
#spanner?: Spanner;
14+
#spanner: Spanner;
2315
#floydWarshall?: FloydWarshall;
2416

2517
constructor({
2618
device,
2719
graph,
28-
maxDistortion = 2,
29-
edgeWeightFactor = 1,
30-
}: EdgePathBundlingGPUFloydWarshallParams) {
20+
maxDistortion,
21+
edgeWeightFactor,
22+
spannerAlgorithm,
23+
}: EdgePathBundlingParams) {
3124
this.#device = device;
3225

3326
this.#graph = graph;
3427

3528
this.#maxDistortion = maxDistortion;
3629
this.#edgeWeightFactor = edgeWeightFactor;
30+
31+
this.#spanner = new spannerAlgorithm({
32+
device: this.#device,
33+
graph: this.#graph,
34+
maxDistortion: this.#maxDistortion,
35+
});
3736
}
3837

3938
async bundle() {
40-
if (!this.#spanner) {
41-
// this.#spanner = new GreedySpanner({
42-
// graph: this.#graph,
43-
// device: this.#device,
44-
// maxDistortion: this.#maxDistortion,
45-
// });
46-
47-
this.#spanner = new ThetaSpanner({
48-
graph: this.#graph,
49-
device: this.#device,
50-
k: 100,
51-
});
39+
if (!this.#spanner?.graph) {
40+
await this.#spanner.compute();
41+
}
5242

43+
if (this.#edgeWeightFactor !== this.#spanner.maxDistortion) {
44+
console.log('Max distortion changed. Recomputing Spanner');
45+
this.#spanner.maxDistortion = this.#edgeWeightFactor;
5346
await this.#spanner.compute();
5447
}
5548

49+
if (!this.#spanner.graph) {
50+
throw new Error('Spanner graph not found');
51+
}
52+
5653
if (!this.#floydWarshall) {
5754
this.#floydWarshall = new FloydWarshall({
5855
graph: this.#spanner.graph,
@@ -71,11 +68,13 @@ export class EdgePathBundlingGPUFloydWarshall implements EdgePathBundling {
7168

7269
const difference: Edge[] = [];
7370
this.#graph.edges.forEach((edge, key) => {
74-
if (!this.#spanner!.graph.edges.has(key)) {
71+
if (!this.#spanner.graph!.edges.has(key)) {
7572
difference.push(edge);
7673
}
7774
});
7875

76+
console.log('difference', difference.length);
77+
7978
const shortestPaths = await this.#floydWarshall.shortestPaths(difference);
8079

8180
const bundeledEdges: {
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import type { Edge } from '../AdjacencyList';
1+
import type { Edge, Graph } from '../AdjacencyList';
2+
import type { Spanner, SpannerParams } from '../spanner';
23

34
export type BundledEdge = {
45
edge: Edge;
56
controlPoints: { x: number; y: number }[];
67
};
78

9+
export type EdgePathBundlingParams = {
10+
device: GPUDevice;
11+
graph: Graph;
12+
spannerAlgorithm: new (params: SpannerParams) => Spanner;
13+
maxDistortion: number;
14+
edgeWeightFactor: number;
15+
};
16+
817
export abstract class EdgePathBundling {
918
abstract bundle(): Promise<BundledEdge[]> | BundledEdge[];
1019
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { Spanner } from '..';
21
import { Graph } from '../../AdjacencyList';
32
import { AdjacencyMatrix } from '../../AdjacencyMatrix';
43
import { BufferData } from '../../BufferData';
54
import { createGPUBuffer, writeGPUBuffer } from '../../GPUBuffer';
5+
import type { Spanner } from '../index';
66
import shader from './shader.wgsl?raw';
77

88
export type GreedySpannerParams = {

packages/core/src/spanner/greedy/shader.wgsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ fn compute(
3131
let edge = edges[uniforms.k];
3232

3333
if(distance_matrix_get(x, y) > edge.weight * uniforms.max_distortion) {
34+
var value = min(distance_matrix_get(x, y), distance_matrix_get(x, edge.start) + edge.weight + distance_matrix_get(edge.end, y));
35+
value = min(value, distance_matrix_get(x, edge.end) + edge.weight + distance_matrix_get(edge.start, y));
36+
37+
distance_matrix_set(x, y, value);
38+
} else {
3439
skipped += 1;
3540
return;
3641
}
37-
38-
var value = min(distance_matrix_get(x, y), distance_matrix_get(x, edge.start) + edge.weight + distance_matrix_get(edge.end, y));
39-
value = min(value, distance_matrix_get(x, edge.end) + edge.weight + distance_matrix_get(edge.start, y));
40-
41-
distance_matrix_set(x, y, value);
4242
}
4343

4444
// Matrix getters and setters

packages/core/src/spanner/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import type { Graph } from '../AdjacencyList';
22

3+
export type SpannerParams = {
4+
device: GPUDevice;
5+
graph: Graph;
6+
maxDistortion: number;
7+
};
8+
39
export abstract class Spanner {
410
abstract compute(): Promise<Graph> | Graph;
511

6-
abstract get graph(): Graph;
12+
abstract get graph(): Graph | undefined;
13+
14+
abstract set maxDistortion(value: number);
15+
abstract get maxDistortion(): number;
716
}

0 commit comments

Comments
 (0)