@knowvah/dot-engine 2.9.0 → 2.10.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/dist/common/graph-init.d.ts.map +1 -1
- package/dist/common/htmltable.d.ts +1 -1
- package/dist/common/htmltable.d.ts.map +1 -1
- package/dist/common/poly-init.d.ts +8 -8
- package/dist/common/poly-init.d.ts.map +1 -1
- package/dist/common/safefile.d.ts +15 -0
- package/dist/common/safefile.d.ts.map +1 -1
- package/dist/gvc/image-resolver.d.ts +5 -0
- package/dist/gvc/image-resolver.d.ts.map +1 -1
- package/dist/gvc/usershape.d.ts +2 -0
- package/dist/gvc/usershape.d.ts.map +1 -1
- package/dist/index.js +914 -813
- package/dist/index.js.map +4 -4
- package/dist/layout/neato/__fixtures__/kk-models.d.ts +59 -0
- package/dist/layout/neato/__fixtures__/kk-models.d.ts.map +1 -0
- package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts +6 -0
- package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts.map +1 -1
- package/dist/layout/neato/circuit.d.ts +38 -0
- package/dist/layout/neato/circuit.d.ts.map +1 -1
- package/dist/layout/neato/constrained-majorization.d.ts.map +1 -1
- package/dist/layout/neato/index.d.ts +6 -3
- package/dist/layout/neato/index.d.ts.map +1 -1
- package/dist/layout/neato/init.d.ts.map +1 -1
- package/dist/layout/neato/kk-paths.d.ts +11 -1
- package/dist/layout/neato/kk-paths.d.ts.map +1 -1
- package/dist/layout/neato/kk-solve.d.ts.map +1 -1
- package/dist/layout/neato/kk.d.ts +5 -3
- package/dist/layout/neato/kk.d.ts.map +1 -1
- package/dist/layout/neato/kkutils.d.ts +45 -0
- package/dist/layout/neato/kkutils.d.ts.map +1 -1
- package/dist/layout/neato/start.d.ts +11 -10
- package/dist/layout/neato/start.d.ts.map +1 -1
- package/dist/layout/neato/stress-models.d.ts +25 -19
- package/dist/layout/neato/stress-models.d.ts.map +1 -1
- package/dist/render.js +914 -813
- package/dist/render.js.map +4 -4
- package/dist/vpsc/SweepLine.d.ts +21 -8
- package/dist/vpsc/SweepLine.d.ts.map +1 -1
- package/dist/vpsc/sweepTypes.d.ts +12 -2
- package/dist/vpsc/sweepTypes.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/graph-init.ts +5 -1
- package/src/common/htmltable.ts +6 -4
- package/src/common/poly-init.ts +35 -15
- package/src/common/safefile.ts +20 -2
- package/src/gvc/__fixtures__/p8/bad.png +1 -0
- package/src/gvc/__fixtures__/p8/d/r.png +0 -0
- package/src/gvc/__fixtures__/p8/html-img-bad.gv +1 -0
- package/src/gvc/__fixtures__/p8/html-img-bad.svg +19 -0
- package/src/gvc/__fixtures__/p8/html-img-bad.svg.stderr +3 -0
- package/src/gvc/__fixtures__/p8/html-img-bad.xdot +13 -0
- package/src/gvc/__fixtures__/p8/html-img-bad.xdot.stderr +3 -0
- package/src/gvc/__fixtures__/p8/ip-shapefile.gv +1 -0
- package/src/gvc/__fixtures__/p8/ip-shapefile.svg +19 -0
- package/src/gvc/__fixtures__/p8/ip-shapefile.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p8/ip-shapefile.xdot +15 -0
- package/src/gvc/__fixtures__/p8/ip-shapefile.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p8/regen.sh +13 -0
- package/src/gvc/image-resolver.ts +8 -0
- package/src/gvc/usershape.ts +5 -0
- package/src/layout/neato/__fixtures__/kk-models.ts +82 -0
- package/src/layout/neato/__fixtures__/models/hier-circuit.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +92 -0
- package/src/layout/neato/__fixtures__/models/hier-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-default.gv +14 -0
- package/src/layout/neato/__fixtures__/models/hier-default.xdot +91 -0
- package/src/layout/neato/__fixtures__/models/hier-default.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-disc-circuit.gv +9 -0
- package/src/layout/neato/__fixtures__/models/hier-disc-circuit.xdot +54 -0
- package/src/layout/neato/__fixtures__/models/hier-disc-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-len-circuit.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-len-circuit.xdot +97 -0
- package/src/layout/neato/__fixtures__/models/hier-len-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-len-mds.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-len-mds.xdot +97 -0
- package/src/layout/neato/__fixtures__/models/hier-len-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-len-subset.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-len-subset.xdot +97 -0
- package/src/layout/neato/__fixtures__/models/hier-len-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-long-mds.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-long-mds.xdot +95 -0
- package/src/layout/neato/__fixtures__/models/hier-long-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-mds-nolen.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +92 -0
- package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot.stderr +2 -0
- package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.gv +10 -0
- package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +54 -0
- package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot.stderr +3 -0
- package/src/layout/neato/__fixtures__/models/hier-shortpath.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +92 -0
- package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/hier-subset.gv +15 -0
- package/src/layout/neato/__fixtures__/models/hier-subset.xdot +92 -0
- package/src/layout/neato/__fixtures__/models/hier-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-circuit.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-circuit.xdot +81 -0
- package/src/layout/neato/__fixtures__/models/kk-circuit.xdot.stderr +4 -0
- package/src/layout/neato/__fixtures__/models/kk-default.gv +14 -0
- package/src/layout/neato/__fixtures__/models/kk-default.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/kk-default.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit-pack.gv +10 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit-pack.native-crash +1 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit-pack.xdot +0 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit-pack.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit.gv +9 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit.xdot +49 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-circuit.xdot.stderr +4 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-shortpath-pack.gv +10 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-shortpath-pack.xdot +50 -0
- package/src/layout/neato/__fixtures__/models/kk-disc-shortpath-pack.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-circuit-pack.gv +13 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-circuit-pack.native-crash +1 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-circuit-pack.xdot +0 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-circuit-pack.xdot.stderr +4 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-shortpath-pack.gv +13 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-shortpath-pack.xdot +66 -0
- package/src/layout/neato/__fixtures__/models/kk-disc4-shortpath-pack.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-circuit.gv +11 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-circuit.xdot +51 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-circuit.xdot.stderr +4 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-len-circuit.gv +11 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-len-circuit.xdot +57 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-len-circuit.xdot.stderr +4 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-len-mds.gv +11 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-len-mds.xdot +57 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-len-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-long-mds.gv +11 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-long-mds.xdot +57 -0
- package/src/layout/neato/__fixtures__/models/kk-iso-long-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-large.gv +203 -0
- package/src/layout/neato/__fixtures__/models/kk-large.pow.json +1088 -0
- package/src/layout/neato/__fixtures__/models/kk-large.xdot +1208 -0
- package/src/layout/neato/__fixtures__/models/kk-large.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-len-circuit.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-len-circuit.xdot +86 -0
- package/src/layout/neato/__fixtures__/models/kk-len-circuit.xdot.stderr +4 -0
- package/src/layout/neato/__fixtures__/models/kk-len-mds.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-len-mds.xdot +86 -0
- package/src/layout/neato/__fixtures__/models/kk-len-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-len-subset.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-len-subset.xdot +86 -0
- package/src/layout/neato/__fixtures__/models/kk-len-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-mds-nolen.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-mds-nolen.xdot +81 -0
- package/src/layout/neato/__fixtures__/models/kk-mds-nolen.xdot.stderr +2 -0
- package/src/layout/neato/__fixtures__/models/kk-shortpath.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-shortpath.xdot +81 -0
- package/src/layout/neato/__fixtures__/models/kk-shortpath.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/kk-subset.gv +15 -0
- package/src/layout/neato/__fixtures__/models/kk-subset.xdot +81 -0
- package/src/layout/neato/__fixtures__/models/kk-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/large-circuit.gv +203 -0
- package/src/layout/neato/__fixtures__/models/large-circuit.xdot +1208 -0
- package/src/layout/neato/__fixtures__/models/large-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-circuit.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-circuit.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-default.gv +13 -0
- package/src/layout/neato/__fixtures__/models/major-default.xdot +79 -0
- package/src/layout/neato/__fixtures__/models/major-default.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-disc-circuit.gv +8 -0
- package/src/layout/neato/__fixtures__/models/major-disc-circuit.xdot +48 -0
- package/src/layout/neato/__fixtures__/models/major-disc-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-len-circuit.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-len-circuit.xdot +85 -0
- package/src/layout/neato/__fixtures__/models/major-len-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-len-mds.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-len-mds.xdot +85 -0
- package/src/layout/neato/__fixtures__/models/major-len-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-len-subset.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-len-subset.xdot +85 -0
- package/src/layout/neato/__fixtures__/models/major-len-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-long-mds.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-long-mds.xdot +83 -0
- package/src/layout/neato/__fixtures__/models/major-long-mds.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-long-shortpath.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-long-shortpath.xdot +83 -0
- package/src/layout/neato/__fixtures__/models/major-long-shortpath.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-mds-edge-default.gv +15 -0
- package/src/layout/neato/__fixtures__/models/major-mds-edge-default.xdot +81 -0
- package/src/layout/neato/__fixtures__/models/major-mds-edge-default.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-mds-nolen-anon.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-mds-nolen-anon.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-mds-nolen-anon.xdot.stderr +2 -0
- package/src/layout/neato/__fixtures__/models/major-mds-nolen.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-mds-nolen.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-mds-nolen.xdot.stderr +2 -0
- package/src/layout/neato/__fixtures__/models/major-model-Subset.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-model-Subset.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-model-Subset.xdot.stderr +1 -0
- package/src/layout/neato/__fixtures__/models/major-model-foo-anon.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-model-foo-anon.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-model-foo-anon.xdot.stderr +1 -0
- package/src/layout/neato/__fixtures__/models/major-model-foo.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-model-foo.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-model-foo.xdot.stderr +1 -0
- package/src/layout/neato/__fixtures__/models/major-pin-disc-circuit.gv +9 -0
- package/src/layout/neato/__fixtures__/models/major-pin-disc-circuit.xdot +48 -0
- package/src/layout/neato/__fixtures__/models/major-pin-disc-circuit.xdot.stderr +2 -0
- package/src/layout/neato/__fixtures__/models/major-shortpath.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-shortpath.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-shortpath.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/major-subset.gv +14 -0
- package/src/layout/neato/__fixtures__/models/major-subset.xdot +80 -0
- package/src/layout/neato/__fixtures__/models/major-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/models/regen.sh +46 -0
- package/src/layout/neato/__fixtures__/quad-prog-vpsc.ts +7 -1
- package/src/layout/neato/circuit.ts +67 -2
- package/src/layout/neato/constrained-majorization.ts +5 -22
- package/src/layout/neato/index.ts +41 -14
- package/src/layout/neato/init.ts +9 -13
- package/src/layout/neato/kk-paths.ts +23 -1
- package/src/layout/neato/kk-solve.ts +5 -3
- package/src/layout/neato/kk.ts +53 -21
- package/src/layout/neato/kkutils.ts +108 -3
- package/src/layout/neato/start.ts +20 -65
- package/src/layout/neato/stress-models.ts +55 -59
- package/src/layout/pack/index.ts +2 -2
- package/src/vpsc/SweepLine.ts +39 -26
- package/src/vpsc/sweepTypes.ts +13 -2
|
@@ -1,66 +1,29 @@
|
|
|
1
1
|
// SPDX-License-Identifier: EPL-2.0
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* The subset and circuit distance models of stress majorization,
|
|
5
|
-
*
|
|
6
|
-
* kkutils.ts
|
|
4
|
+
* The subset and circuit distance models of stress majorization, and the choice
|
|
5
|
+
* of `Dij` among them. The kkutils.c neighbour-vector helpers they use live in
|
|
6
|
+
* kkutils.ts, re-exported here.
|
|
7
|
+
* `circuitModel` here is stress.c's (float `Dij` from `vtx_data`); `circuit.ts`'s
|
|
8
|
+
* `circuitModel` is circuit.c's `circuit_model` (`GD_dist` from a graph, KK path).
|
|
7
9
|
*
|
|
8
10
|
* `Dij` is C `float` (Float32Array); the circuit matrices are C `double`.
|
|
9
11
|
* C `NULL` ewgts is the port's empty array.
|
|
10
12
|
*
|
|
11
13
|
* @see lib/neatogen/stress.c
|
|
12
|
-
* @see lib/neatogen/kkutils.c
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
import type { VtxData } from './dijkstra.js';
|
|
17
|
+
import { agerr, agwarningf } from '../../common/agerr.js';
|
|
16
18
|
import { computeApspPacked, computeWeightedApspPacked } from './bfs.js';
|
|
17
19
|
import { solveCircuit } from './circuit.js';
|
|
20
|
+
import { MODEL_CIRCUIT, MODEL_MDS, MODEL_SUBSET } from './init.js';
|
|
21
|
+
import { artificialWeight, emptyNeighborsVec, fillNeighborsVecUnweighted } from './kkutils.js';
|
|
18
22
|
import { newArray } from './lu.js';
|
|
19
23
|
import { fmaxf } from './quad-prog-solve.js';
|
|
24
|
+
import { mdsModel } from './stress.js';
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
const SIZE_T_MODULUS = 2 ** 64;
|
|
23
|
-
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
// kkutils.c helpers
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Count the neighbours of `u` marked in `vVector`.
|
|
30
|
-
* @see lib/neatogen/kkutils.c:common_neighbors
|
|
31
|
-
*/
|
|
32
|
-
export function commonNeighbors(graph: readonly VtxData[], u: number, vVector: Int32Array): number {
|
|
33
|
-
// count number of common neighbors of 'v_vector' and 'u'
|
|
34
|
-
let numSharedNeighbors = 0;
|
|
35
|
-
for (let j = 1; j < graph[u]!.nedges; j++) {
|
|
36
|
-
const neighbor = graph[u]!.edges[j]!;
|
|
37
|
-
if (vVector[neighbor]! > 0) {
|
|
38
|
-
// a shared neighbor
|
|
39
|
-
numSharedNeighbors++;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return numSharedNeighbors;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Mark the neighbours of `vtx` (a node is NOT a neighbour of itself).
|
|
47
|
-
* @see lib/neatogen/kkutils.c:fill_neighbors_vec_unweighted
|
|
48
|
-
*/
|
|
49
|
-
export function fillNeighborsVecUnweighted(graph: readonly VtxData[], vtx: number, vtxVec: Int32Array): void {
|
|
50
|
-
for (let j = 1; j < graph[vtx]!.nedges; j++) {
|
|
51
|
-
vtxVec[graph[vtx]!.edges[j]!] = 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Clear the marks set by `fillNeighborsVecUnweighted`.
|
|
57
|
-
* @see lib/neatogen/kkutils.c:empty_neighbors_vec
|
|
58
|
-
*/
|
|
59
|
-
export function emptyNeighborsVec(graph: readonly VtxData[], vtx: number, vtxVec: Int32Array): void {
|
|
60
|
-
for (let j = 1; j < graph[vtx]!.nedges; j++) {
|
|
61
|
-
vtxVec[graph[vtx]!.edges[j]!] = 0;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
26
|
+
export { commonNeighbors, emptyNeighborsVec, fillNeighborsVecUnweighted } from './kkutils.js';
|
|
64
27
|
|
|
65
28
|
// ---------------------------------------------------------------------------
|
|
66
29
|
// circuitModel
|
|
@@ -124,18 +87,6 @@ function circuitDistances(GmInv: readonly Float64Array[], nG: number, Dij: Float
|
|
|
124
87
|
// compute_apsp_artificial_weights_packed
|
|
125
88
|
// ---------------------------------------------------------------------------
|
|
126
89
|
|
|
127
|
-
/**
|
|
128
|
-
* The artificial weight of edge (i, neighbor): `deg_i + deg_j - 2 * common`
|
|
129
|
-
* in C `size_t`, so a negative value (only possible with duplicate
|
|
130
|
-
* neighbours) wraps modulo 2^64 before the (float) cast.
|
|
131
|
-
* @see lib/neatogen/stress.c:compute_apsp_artificial_weights_packed (stress.c:735-736, 752-753)
|
|
132
|
-
*/
|
|
133
|
-
function artificialWeight(graph: readonly VtxData[], degI: number, neighbor: number, vtxVec: Int32Array): number {
|
|
134
|
-
const degJ = graph[neighbor]!.nedges - 1;
|
|
135
|
-
const w = degI + degJ - 2 * commonNeighbors(graph, neighbor, vtxVec);
|
|
136
|
-
return Math.fround(w < 0 ? w + SIZE_T_MODULUS : w);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
90
|
/**
|
|
140
91
|
* Weighted branch: each weight is fmaxf(artificial, the caller's ewgts[j]),
|
|
141
92
|
* read from graph[i].ewgts before graph[i].ewgts is reassigned.
|
|
@@ -210,3 +161,48 @@ export function computeApspArtificialWeightsPacked(graph: VtxData[], n: number):
|
|
|
210
161
|
}
|
|
211
162
|
return Dij;
|
|
212
163
|
}
|
|
164
|
+
|
|
165
|
+
// ---------------------------------------------------------------------------
|
|
166
|
+
// Dij selection
|
|
167
|
+
// ---------------------------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The model branches C writes twice, with the same shape: subset, circuit
|
|
171
|
+
* (warning when it fails), mds. `null` is C's `Dij` still NULL, where each
|
|
172
|
+
* caller picks its own shortest paths. `model` is the defs.h numbering of
|
|
173
|
+
* init.ts, not stress.ts's.
|
|
174
|
+
* @see lib/neatogen/stress.c:stress_majorization_kD_mkernel (stress.c:837-852)
|
|
175
|
+
* @see lib/neatogen/constrained_majorization.c:stress_majorization_with_hierarchy (173-186)
|
|
176
|
+
*/
|
|
177
|
+
export function modelDistances(graph: VtxData[], n: number, model: number): Float32Array | null {
|
|
178
|
+
let Dij: Float32Array | null = null;
|
|
179
|
+
if (model === MODEL_SUBSET) {
|
|
180
|
+
/* weight graph to separate high-degree nodes */
|
|
181
|
+
/* and perform slower Dijkstra-based computation */
|
|
182
|
+
Dij = computeApspArtificialWeightsPacked(graph, n);
|
|
183
|
+
} else if (model === MODEL_CIRCUIT) {
|
|
184
|
+
Dij = circuitModel(graph, n);
|
|
185
|
+
if (Dij === null) {
|
|
186
|
+
agwarningf('graph is disconnected. Hence, the circuit model');
|
|
187
|
+
agerr('prev', 'is undefined. Reverting to the shortest path model.');
|
|
188
|
+
}
|
|
189
|
+
} else if (model === MODEL_MDS) {
|
|
190
|
+
Dij = mdsModel(graph, n);
|
|
191
|
+
}
|
|
192
|
+
return Dij;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The all-pairs-shortest-distances block of `stress_majorization_kD_mkernel`:
|
|
197
|
+
* the model's matrix, else shortest paths, weighted iff `graph->ewgts`.
|
|
198
|
+
*
|
|
199
|
+
* Boundary deviation: C computes this inside the kernel, after its `maxi < 0`
|
|
200
|
+
* return. The port's fused kernel takes `Dij` as a parameter, so the caller runs
|
|
201
|
+
* this first and owns that check (part-8 AD-2).
|
|
202
|
+
* @see lib/neatogen/stress.c:stress_majorization_kD_mkernel (stress.c:833-859)
|
|
203
|
+
*/
|
|
204
|
+
export function stressModelDij(graph: VtxData[], n: number, model: number): Float32Array {
|
|
205
|
+
const Dij = modelDistances(graph, n, model);
|
|
206
|
+
if (Dij !== null) return Dij;
|
|
207
|
+
return graph[0]!.ewgts.length !== 0 ? computeWeightedApspPacked(graph, n) : computeApspPacked(graph, n);
|
|
208
|
+
}
|
package/src/layout/pack/index.ts
CHANGED
|
@@ -452,14 +452,14 @@ export function pccomps(g: Graph, pfx: string): { graphs: Graph[]; pinned: boole
|
|
|
452
452
|
pinned = true;
|
|
453
453
|
}
|
|
454
454
|
if (pinnedNodes.length > 0) {
|
|
455
|
-
result.push(buildSubgraph(g, pinnedNodes, `${pfx}
|
|
455
|
+
result.push(buildSubgraph(g, pinnedNodes, `${pfx}${idx++}`));
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
// Pass 2 — remaining components in node order.
|
|
459
459
|
for (const n of g.nodes.values()) {
|
|
460
460
|
if (visited.has(n.name)) continue;
|
|
461
461
|
const comp = dfsCollect(g, n, visited);
|
|
462
|
-
result.push(buildSubgraph(g, comp, `${pfx}
|
|
462
|
+
result.push(buildSubgraph(g, comp, `${pfx}${idx++}`));
|
|
463
463
|
}
|
|
464
464
|
return { graphs: result, pinned };
|
|
465
465
|
}
|
package/src/vpsc/SweepLine.ts
CHANGED
|
@@ -10,13 +10,17 @@
|
|
|
10
10
|
import { Variable } from "./Variable.js";
|
|
11
11
|
import { Constraint } from "./Constraint.js";
|
|
12
12
|
import { Rectangle } from "./Solver.js";
|
|
13
|
-
import { EvType, SweepNode, SweepEvent } from "./sweepTypes.js";
|
|
13
|
+
import { EvType, NodeSet, SweepNode, SweepEvent } from "./sweepTypes.js";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* `seq` is the `make_shared<Node>` order: the rectangle index of the pass.
|
|
17
|
+
* @see lib/vpsc/generate-constraints.cpp: Node::Node
|
|
18
|
+
*/
|
|
19
|
+
export function makeNode(v: Variable, r: Rectangle, pos: number, seq: number): SweepNode {
|
|
16
20
|
return {
|
|
17
|
-
v, r, pos,
|
|
21
|
+
v, r, pos, seq,
|
|
18
22
|
firstAbove: null, firstBelow: null,
|
|
19
|
-
leftNeighbours:
|
|
23
|
+
leftNeighbours: [], rightNeighbours: [],
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -32,13 +36,19 @@ export function compareEvents(ea: SweepEvent, eb: SweepEvent): number {
|
|
|
32
36
|
return 0;
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
/**
|
|
40
|
+
* C++ ends with `u < v` on `Node*`. Addresses cannot be reproduced and vary run
|
|
41
|
+
* to run, so a position tie goes by creation order (part-8 AD-8).
|
|
42
|
+
* @see lib/vpsc/generate-constraints.cpp: CmpNodePos::operator()
|
|
43
|
+
*/
|
|
35
44
|
export function nodePosLt(a: SweepNode, b: SweepNode): boolean {
|
|
36
45
|
if (a.pos < b.pos) return true;
|
|
37
46
|
if (b.pos < a.pos) return false;
|
|
38
|
-
return a < b;
|
|
47
|
+
return a.seq < b.seq;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
/** @see lib/vpsc/generate-constraints.cpp: NodeSet::insert (std::set, so no duplicates) */
|
|
51
|
+
export function scanlineInsert(sl: NodeSet, node: SweepNode): void {
|
|
42
52
|
let lo = 0;
|
|
43
53
|
let hi = sl.length;
|
|
44
54
|
while (lo < hi) {
|
|
@@ -46,46 +56,49 @@ export function scanlineInsert(sl: SweepNode[], node: SweepNode): void {
|
|
|
46
56
|
if (nodePosLt(sl[mid]!, node)) lo = mid + 1;
|
|
47
57
|
else hi = mid;
|
|
48
58
|
}
|
|
49
|
-
sl.splice(lo, 0, node);
|
|
59
|
+
if (sl[lo] !== node) sl.splice(lo, 0, node);
|
|
50
60
|
}
|
|
51
61
|
|
|
52
|
-
export function scanlineRemove(sl:
|
|
62
|
+
export function scanlineRemove(sl: NodeSet, node: SweepNode): void {
|
|
53
63
|
const i = sl.indexOf(node);
|
|
54
64
|
if (i !== -1) sl.splice(i, 1);
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
67
|
+
/** @see lib/vpsc/generate-constraints.cpp: getLeftNeighbours */
|
|
68
|
+
export function getLeftNeighbours(sl: NodeSet, v: SweepNode): NodeSet {
|
|
69
|
+
const result: NodeSet = [];
|
|
59
70
|
const idx = sl.indexOf(v);
|
|
60
71
|
for (let i = idx - 1; i >= 0; i--) {
|
|
61
72
|
const u = sl[i]!;
|
|
62
|
-
if (u.r.overlapX(v.r) <= 0) { result
|
|
63
|
-
if (u.r.overlapX(v.r) <= u.r.overlapY(v.r)) result
|
|
73
|
+
if (u.r.overlapX(v.r) <= 0) { scanlineInsert(result, u); return result; }
|
|
74
|
+
if (u.r.overlapX(v.r) <= u.r.overlapY(v.r)) scanlineInsert(result, u);
|
|
64
75
|
}
|
|
65
76
|
return result;
|
|
66
77
|
}
|
|
67
78
|
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
/** @see lib/vpsc/generate-constraints.cpp: getRightNeighbours */
|
|
80
|
+
export function getRightNeighbours(sl: NodeSet, v: SweepNode): NodeSet {
|
|
81
|
+
const result: NodeSet = [];
|
|
70
82
|
const idx = sl.indexOf(v);
|
|
71
83
|
for (let i = idx + 1; i < sl.length; i++) {
|
|
72
84
|
const u = sl[i]!;
|
|
73
|
-
if (u.r.overlapX(v.r) <= 0) { result
|
|
74
|
-
if (u.r.overlapX(v.r) <= u.r.overlapY(v.r)) result
|
|
85
|
+
if (u.r.overlapX(v.r) <= 0) { scanlineInsert(result, u); return result; }
|
|
86
|
+
if (u.r.overlapX(v.r) <= u.r.overlapY(v.r)) scanlineInsert(result, u);
|
|
75
87
|
}
|
|
76
88
|
return result;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
|
|
91
|
+
/** @see lib/vpsc/generate-constraints.cpp: Node::setNeighbours */
|
|
92
|
+
export function xOpenNeighbour(sl: NodeSet, v: SweepNode): void {
|
|
80
93
|
const left = getLeftNeighbours(sl, v);
|
|
81
94
|
const right = getRightNeighbours(sl, v);
|
|
82
95
|
v.leftNeighbours = left;
|
|
83
96
|
v.rightNeighbours = right;
|
|
84
|
-
for (const n of left) n.rightNeighbours
|
|
85
|
-
for (const n of right) n.leftNeighbours
|
|
97
|
+
for (const n of left) scanlineInsert(n.rightNeighbours, v);
|
|
98
|
+
for (const n of right) scanlineInsert(n.leftNeighbours, v);
|
|
86
99
|
}
|
|
87
100
|
|
|
88
|
-
export function openLinkChain(sl:
|
|
101
|
+
export function openLinkChain(sl: NodeSet, v: SweepNode): void {
|
|
89
102
|
const idx = sl.indexOf(v);
|
|
90
103
|
if (idx > 0) { const u = sl[idx - 1]!; v.firstAbove = u; u.firstBelow = v; }
|
|
91
104
|
if (idx < sl.length - 1) { const u = sl[idx + 1]!; v.firstBelow = u; u.firstAbove = v; }
|
|
@@ -94,14 +107,14 @@ export function openLinkChain(sl: SweepNode[], v: SweepNode): void {
|
|
|
94
107
|
export function xCloseLeft(v: SweepNode, cs: Constraint[]): void {
|
|
95
108
|
for (const u of v.leftNeighbours) {
|
|
96
109
|
cs.push(new Constraint(u.v, v.v, (v.r.width() + u.r.width()) / 2.0));
|
|
97
|
-
u.rightNeighbours
|
|
110
|
+
scanlineRemove(u.rightNeighbours, v);
|
|
98
111
|
}
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
export function xCloseRight(v: SweepNode, cs: Constraint[]): void {
|
|
102
115
|
for (const u of v.rightNeighbours) {
|
|
103
116
|
cs.push(new Constraint(v.v, u.v, (v.r.width() + u.r.width()) / 2.0));
|
|
104
|
-
u.leftNeighbours
|
|
117
|
+
scanlineRemove(u.leftNeighbours, v);
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
|
|
@@ -141,7 +154,7 @@ export function buildXEvents(rects: Rectangle[], vs: Variable[]): SweepEvent[] {
|
|
|
141
154
|
for (let i = 0; i < rects.length; i++) {
|
|
142
155
|
const r = rects[i]!;
|
|
143
156
|
vs[i]!.desiredPosition = r.getCentreX();
|
|
144
|
-
const node = makeNode(vs[i]!, r, r.getCentreX());
|
|
157
|
+
const node = makeNode(vs[i]!, r, r.getCentreX(), i);
|
|
145
158
|
events.push({ type: EvType.Open, node, pos: r.getMinY() });
|
|
146
159
|
events.push({ type: EvType.Close, node, pos: r.getMaxY() });
|
|
147
160
|
}
|
|
@@ -153,7 +166,7 @@ export function buildYEvents(rects: Rectangle[], vs: Variable[]): SweepEvent[] {
|
|
|
153
166
|
for (let i = 0; i < rects.length; i++) {
|
|
154
167
|
const r = rects[i]!;
|
|
155
168
|
vs[i]!.desiredPosition = r.getCentreY();
|
|
156
|
-
const node = makeNode(vs[i]!, r, r.getCentreY());
|
|
169
|
+
const node = makeNode(vs[i]!, r, r.getCentreY(), i);
|
|
157
170
|
events.push({ type: EvType.Open, node, pos: r.getMinX() });
|
|
158
171
|
events.push({ type: EvType.Close, node, pos: r.getMaxX() });
|
|
159
172
|
}
|
|
@@ -171,7 +184,7 @@ export function generateXConstraints(
|
|
|
171
184
|
): Constraint[] {
|
|
172
185
|
const events = buildXEvents(rects, vs);
|
|
173
186
|
events.sort(compareEvents);
|
|
174
|
-
const sl:
|
|
187
|
+
const sl: NodeSet = [];
|
|
175
188
|
const cs: Constraint[] = [];
|
|
176
189
|
for (const e of events) {
|
|
177
190
|
const v = e.node;
|
|
@@ -198,7 +211,7 @@ export function generateYConstraints(
|
|
|
198
211
|
): Constraint[] {
|
|
199
212
|
const events = buildYEvents(rects, vs);
|
|
200
213
|
events.sort(compareEvents);
|
|
201
|
-
const sl:
|
|
214
|
+
const sl: NodeSet = [];
|
|
202
215
|
const cs: Constraint[] = [];
|
|
203
216
|
for (const e of events) {
|
|
204
217
|
const v = e.node;
|
package/src/vpsc/sweepTypes.ts
CHANGED
|
@@ -14,14 +14,25 @@ import type { Rectangle } from "./Solver.js";
|
|
|
14
14
|
export const EvType = { Open: 0, Close: 1 } as const;
|
|
15
15
|
export type EvType = (typeof EvType)[keyof typeof EvType];
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* `std::set<Node*, CmpNodePos>`: an array kept in `nodePosLt` order.
|
|
19
|
+
* @see lib/vpsc/generate-constraints.cpp: NodeSet
|
|
20
|
+
*/
|
|
21
|
+
export type NodeSet = SweepNode[];
|
|
22
|
+
|
|
17
23
|
export interface SweepNode {
|
|
18
24
|
v: Variable;
|
|
19
25
|
r: Rectangle;
|
|
20
26
|
pos: number;
|
|
27
|
+
/**
|
|
28
|
+
* Creation order in this pass, standing in for the `Node*` address that
|
|
29
|
+
* `CmpNodePos` compares on a position tie (part-8 AD-8).
|
|
30
|
+
*/
|
|
31
|
+
seq: number;
|
|
21
32
|
firstAbove: SweepNode | null;
|
|
22
33
|
firstBelow: SweepNode | null;
|
|
23
|
-
leftNeighbours:
|
|
24
|
-
rightNeighbours:
|
|
34
|
+
leftNeighbours: NodeSet;
|
|
35
|
+
rightNeighbours: NodeSet;
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
export interface SweepEvent {
|