1- import type { EdgePathBundling } from '..' ;
21import type { Edge } from '../../AdjacencyList' ;
32import { Graph } from '../../AdjacencyList' ;
43import { FloydWarshall } from '../../shortest-path/floyd-warshall/FloydWarshall' ;
54import 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
157export 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 : {
0 commit comments