@knowvah/dot-engine 2.8.0 → 2.9.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-emit.d.ts +6 -11
- package/dist/common/htmltable-emit.d.ts.map +1 -1
- package/dist/common/nodeinit.d.ts.map +1 -1
- package/dist/common/poly-gencode.d.ts.map +1 -1
- package/dist/common/poly-init.d.ts +13 -2
- package/dist/common/poly-init.d.ts.map +1 -1
- package/dist/common/safefile.d.ts +23 -0
- package/dist/common/safefile.d.ts.map +1 -0
- package/dist/common/shapes.d.ts +6 -6
- package/dist/common/shapes.d.ts.map +1 -1
- package/dist/gvc/device.d.ts.map +1 -1
- package/dist/gvc/image-type.d.ts +41 -0
- package/dist/gvc/image-type.d.ts.map +1 -0
- package/dist/gvc/render-usershape.d.ts +68 -0
- package/dist/gvc/render-usershape.d.ts.map +1 -0
- package/dist/gvc/usershape.d.ts +23 -1
- package/dist/gvc/usershape.d.ts.map +1 -1
- package/dist/index.js +46393 -44890
- package/dist/index.js.map +4 -4
- package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts +118 -0
- package/dist/layout/neato/__fixtures__/quad-prog-vpsc.d.ts.map +1 -0
- package/dist/layout/neato/__fixtures__/stress-models.d.ts +39 -0
- package/dist/layout/neato/__fixtures__/stress-models.d.ts.map +1 -0
- package/dist/layout/neato/circuit.d.ts +10 -0
- package/dist/layout/neato/circuit.d.ts.map +1 -0
- package/dist/layout/neato/init.d.ts +3 -2
- package/dist/layout/neato/init.d.ts.map +1 -1
- package/dist/layout/neato/ipsep-opts.d.ts +19 -0
- package/dist/layout/neato/ipsep-opts.d.ts.map +1 -0
- package/dist/layout/neato/lu.d.ts +35 -0
- package/dist/layout/neato/lu.d.ts.map +1 -0
- package/dist/layout/neato/matinv.d.ts +8 -0
- package/dist/layout/neato/matinv.d.ts.map +1 -0
- package/dist/layout/neato/quad-prog-vpsc-overlap.d.ts +35 -0
- package/dist/layout/neato/quad-prog-vpsc-overlap.d.ts.map +1 -0
- package/dist/layout/neato/quad-prog-vpsc.d.ts +110 -0
- package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -0
- package/dist/layout/neato/start.d.ts +5 -4
- package/dist/layout/neato/start.d.ts.map +1 -1
- package/dist/layout/neato/stress-cola.d.ts +65 -0
- package/dist/layout/neato/stress-cola.d.ts.map +1 -0
- package/dist/layout/neato/stress-kernel.d.ts +0 -2
- package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
- package/dist/layout/neato/stress-models.d.ts +48 -0
- package/dist/layout/neato/stress-models.d.ts.map +1 -0
- package/dist/layout/neato/vpsc-adjust.d.ts +7 -8
- package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
- package/dist/render/color-resolve.d.ts +14 -0
- package/dist/render/color-resolve.d.ts.map +1 -1
- package/dist/render/dot/edge-draw.d.ts.map +1 -1
- package/dist/render/dot.d.ts +8 -1
- package/dist/render/dot.d.ts.map +1 -1
- package/dist/render/svg-arrow-ops.d.ts +21 -4
- package/dist/render/svg-arrow-ops.d.ts.map +1 -1
- package/dist/render/svg-edge-arrows.d.ts +3 -3
- package/dist/render/svg-edge-arrows.d.ts.map +1 -1
- package/dist/render/svg-helpers.d.ts +1 -1
- package/dist/render/svg-helpers.d.ts.map +1 -1
- package/dist/render/svg.d.ts.map +1 -1
- package/dist/render.js +8505 -7002
- package/dist/render.js.map +4 -4
- package/package.json +1 -1
- package/src/common/graph-init.ts +4 -2
- package/src/common/htmltable-emit.ts +11 -46
- package/src/common/nodeinit.ts +3 -1
- package/src/common/poly-gencode.ts +53 -3
- package/src/common/poly-init.ts +30 -17
- package/src/common/safefile.ts +74 -0
- package/src/common/shapes.ts +43 -22
- package/src/gvc/__fixtures__/p7/colors/98-point.gv +1 -0
- package/src/gvc/__fixtures__/p7/colors/98-point.json +54 -0
- package/src/gvc/__fixtures__/p7/colors/98-point.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/98-point.svg +17 -0
- package/src/gvc/__fixtures__/p7/colors/98-point.svg.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/98-point.xdot +13 -0
- package/src/gvc/__fixtures__/p7/colors/98-point.xdot.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.gv +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.json +150 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.svg +30 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.svg.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.xdot +22 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-color.xdot.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.gv +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.json +149 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.json.stderr +0 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.svg +30 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.xdot +21 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge-red-colon.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.gv +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.json +149 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.svg +30 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.svg.stderr +1 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.xdot +21 -0
- package/src/gvc/__fixtures__/p7/colors/99-edge.xdot.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/100-rotate.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/100-rotate.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/100-rotate.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.cmapx +2 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.cmapx.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.dot +8 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.dot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.json +68 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.json.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.plain +3 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.plain.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.svg +18 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.svg.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/101-bad.xdot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.cmapx +2 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.cmapx.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.dot +8 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.dot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.json +70 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.plain +3 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.plain.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/101-gif.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.cmapx +2 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.cmapx.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.dot +8 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.dot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.json +70 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.plain +3 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.plain.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/101-jpg.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-png.cmapx +2 -0
- package/src/gvc/__fixtures__/p7/images/101-png.cmapx.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-png.dot +8 -0
- package/src/gvc/__fixtures__/p7/images/101-png.dot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-png.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/101-png.json +70 -0
- package/src/gvc/__fixtures__/p7/images/101-png.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/101-png.plain +3 -0
- package/src/gvc/__fixtures__/p7/images/101-png.plain.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-png.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/101-png.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-png.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/101-png.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.cmapx +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.cmapx.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.dot +8 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.dot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.json +70 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.json.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.plain +3 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.plain.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/101-svg.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.cmapx +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.cmapx.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.dot +8 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.dot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.json +68 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.json.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.plain +3 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.plain.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.svg +18 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.svg.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/101-svgbare.xdot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-abs.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-abs.svg +18 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-abs.svg.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-abs.xdot +14 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-abs.xdot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-found.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-found.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-found.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-found.xdot +14 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-found.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-missing.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-missing.svg +18 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-missing.svg.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-missing.xdot +14 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-missing.xdot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.svg +18 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.svg.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.xdot +15 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-shapefile.xdot.stderr +2 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-two.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-two.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-two.svg.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-two.xdot +14 -0
- package/src/gvc/__fixtures__/p7/images/102-ip-two.xdot.stderr +0 -0
- package/src/gvc/__fixtures__/p7/images/97-custom.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/97-custom.svg +18 -0
- package/src/gvc/__fixtures__/p7/images/97-custom.svg.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/97-custom.xdot +13 -0
- package/src/gvc/__fixtures__/p7/images/97-custom.xdot.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/97-nosuch-image.gv +1 -0
- package/src/gvc/__fixtures__/p7/images/97-nosuch-image.svg +19 -0
- package/src/gvc/__fixtures__/p7/images/97-nosuch-image.svg.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/97-nosuch-image.xdot +14 -0
- package/src/gvc/__fixtures__/p7/images/97-nosuch-image.xdot.stderr +1 -0
- package/src/gvc/__fixtures__/p7/images/bad.png +1 -0
- package/src/gvc/__fixtures__/p7/images/d/r.png +0 -0
- package/src/gvc/__fixtures__/p7/images/d2/r.png +0 -0
- package/src/gvc/__fixtures__/p7/images/g.gif +0 -0
- package/src/gvc/__fixtures__/p7/images/graphs-val_val.gv +10 -0
- package/src/gvc/__fixtures__/p7/images/graphs-val_val.svg +25 -0
- package/src/gvc/__fixtures__/p7/images/graphs-val_val.svg.stderr +3 -0
- package/src/gvc/__fixtures__/p7/images/graphs-val_val.xdot +30 -0
- package/src/gvc/__fixtures__/p7/images/graphs-val_val.xdot.stderr +3 -0
- package/src/gvc/__fixtures__/p7/images/j.jpg +0 -0
- package/src/gvc/__fixtures__/p7/images/r.png +0 -0
- package/src/gvc/__fixtures__/p7/images/s.svg +2 -0
- package/src/gvc/__fixtures__/p7/images/sb.svg +1 -0
- package/src/gvc/__fixtures__/p7/images/t.png +0 -0
- package/src/gvc/__fixtures__/p7/regen.sh +23 -0
- package/src/gvc/device-cluster.ts +3 -2
- package/src/gvc/device.ts +12 -4
- package/src/gvc/image-type.ts +122 -0
- package/src/gvc/render-usershape.ts +260 -0
- package/src/gvc/usershape.ts +40 -1
- package/src/layout/neato/__fixtures__/ipsep/big-dired.gv +243 -0
- package/src/layout/neato/__fixtures__/ipsep/big-dired.trace +55 -0
- package/src/layout/neato/__fixtures__/ipsep/big-dired.xdot +1832 -0
- package/src/layout/neato/__fixtures__/ipsep/big-dired.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/cluster.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/cluster.trace +95 -0
- package/src/layout/neato/__fixtures__/ipsep/cluster.xdot +58 -0
- package/src/layout/neato/__fixtures__/ipsep/cluster.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.trace +40 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.xdot +72 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-levelsgap.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.trace +43 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.xdot +72 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier-sep.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier.trace +43 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier.xdot +71 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-hier.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-true.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-true.trace +51 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-true.xdot +71 -0
- package/src/layout/neato/__fixtures__/ipsep/dired-true.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.trace +41 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +77 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.trace +41 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +68 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.trace +42 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +110 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.trace +49 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +108 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.trace +43 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +83 -0
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.trace +49 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +48 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.trace +45 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +47 -0
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/len-dired.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/len-dired.trace +44 -0
- package/src/layout/neato/__fixtures__/ipsep/len-dired.xdot +66 -0
- package/src/layout/neato/__fixtures__/ipsep/len-dired.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/model-circuit.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/model-circuit.trace +46 -0
- package/src/layout/neato/__fixtures__/ipsep/model-circuit.xdot +83 -0
- package/src/layout/neato/__fixtures__/ipsep/model-circuit.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds-len.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds-len.trace +52 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds-len.xdot +72 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds-len.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds.trace +52 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds.xdot +83 -0
- package/src/layout/neato/__fixtures__/ipsep/model-mds.xdot.stderr +2 -0
- package/src/layout/neato/__fixtures__/ipsep/model-subset.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/model-subset.trace +49 -0
- package/src/layout/neato/__fixtures__/ipsep/model-subset.xdot +83 -0
- package/src/layout/neato/__fixtures__/ipsep/model-subset.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.trace +211 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.xdot +60 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-ipsep.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.trace +50 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.xdot +60 -0
- package/src/layout/neato/__fixtures__/ipsep/overlap-vpsc.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self-dired.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self-dired.trace +51 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self-dired.xdot +72 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self-dired.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self.gv +1 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self.trace +43 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self.xdot +84 -0
- package/src/layout/neato/__fixtures__/ipsep/start-self.xdot.stderr +0 -0
- package/src/layout/neato/__fixtures__/quad-prog-vpsc.ts +109 -0
- package/src/layout/neato/__fixtures__/stress-models.ts +64 -0
- package/src/layout/neato/circuit.ts +31 -0
- package/src/layout/neato/index.ts +2 -2
- package/src/layout/neato/init.ts +25 -34
- package/src/layout/neato/ipsep-opts.ts +158 -0
- package/src/layout/neato/lu.ts +189 -0
- package/src/layout/neato/matinv.ts +37 -0
- package/src/layout/neato/quad-prog-vpsc-overlap.ts +365 -0
- package/src/layout/neato/quad-prog-vpsc.ts +416 -0
- package/src/layout/neato/start.ts +9 -24
- package/src/layout/neato/stress-cola.ts +497 -0
- package/src/layout/neato/stress-kernel.ts +1 -17
- package/src/layout/neato/stress-models.ts +212 -0
- package/src/layout/neato/vpsc-adjust.ts +35 -66
- package/src/render/color-resolve.ts +25 -2
- package/src/render/dot/edge-draw.ts +7 -4
- package/src/render/dot.ts +14 -1
- package/src/render/svg-arrow-ops.ts +35 -19
- package/src/render/svg-edge-arrows.ts +7 -6
- package/src/render/svg-helpers.ts +19 -11
- package/src/render/svg.ts +15 -3
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* IPSep-CoLa stress majorization subject to separation constraints
|
|
5
|
+
* (mode=ipsep) — a float32-faithful port of
|
|
6
|
+
* `constrained_majorization_ipsep.c:stress_majorization_cola`.
|
|
7
|
+
*
|
|
8
|
+
* Kernels, as the 16.1 arm64 `-O3 -flto=thin` build runs them: both inlined
|
|
9
|
+
* `right_mult_with_vector_ff` copies are the kD copy's instructions
|
|
10
|
+
* (`rightMultWithVectorFFFused`); `conjugate_gradient_mkernel` is the one
|
|
11
|
+
* out-of-line fused body the kD kernel also calls
|
|
12
|
+
* (`conjugateGradientMkernelFused`); the squared distances are `square_vec`
|
|
13
|
+
* then `vectors_additionf`, two loops, so each product is rounded before its
|
|
14
|
+
* add (313-316, unlike stress.c's fused `+= tmp * tmp`).
|
|
15
|
+
*
|
|
16
|
+
* The complexity limits force the C body into helpers, each kept in C order
|
|
17
|
+
* and named with its C line range: {@link maxEdgeLength} (112-116),
|
|
18
|
+
* {@link modelDistances} (128-151), {@link diameterOf} (158-164),
|
|
19
|
+
* {@link colaScaleLayout} (166-191), {@link clusterLaplacian} (205-236),
|
|
20
|
+
* {@link laplacianDiagonal} (237-253), {@link floatCoords} (255-262),
|
|
21
|
+
* {@link optimize} (282-293, 434-444), {@link iterate} (295-433) with
|
|
22
|
+
* {@link pairDistances} / {@link buildLap1} (298-336), {@link computeStress}
|
|
23
|
+
* (338-357), {@link scaleUpNodes} (377-385), {@link solveHorizontal} /
|
|
24
|
+
* {@link solveVertical} (400-432), and {@link writeBack} (446-455).
|
|
25
|
+
*
|
|
26
|
+
* `Verbose` output and the timers are not ported (the port has no Verbose);
|
|
27
|
+
* {@link stressMajorizationColaTraced} reports each iteration's stress, the
|
|
28
|
+
* value C prints under `-v`, for tests. C's `Epsilon` global is the
|
|
29
|
+
* `epsilon` option.
|
|
30
|
+
*
|
|
31
|
+
* @see lib/neatogen/constrained_majorization_ipsep.c:stress_majorization_cola
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
import type { Node } from '../../model/node.js';
|
|
35
|
+
import { agerr, agwarningf } from '../../common/agerr.js';
|
|
36
|
+
import { conjugateGradientMkernelFused, rightMultWithVectorFFFused } from './conjgrad-mkernel.js';
|
|
37
|
+
import {
|
|
38
|
+
invertSqrtVec, invertVec, orthog1, sqrtVecF, squareVec, vectorsInnerProductF, vectorsMultAdditionF,
|
|
39
|
+
} from './matrix-ops.js';
|
|
40
|
+
import type { DirectedVtxData } from './opt-arrangement.js';
|
|
41
|
+
import {
|
|
42
|
+
constrainedMajorizationVpsc, deleteCMajEnvVPSC, initCMajVPSC, type CMajEnvVPSC, type IpsepOptions,
|
|
43
|
+
} from './quad-prog-vpsc.js';
|
|
44
|
+
import { generateNonoverlapConstraints, removeoverlaps } from './quad-prog-vpsc-overlap.js';
|
|
45
|
+
import { computeApspPacked, initLayout } from './stress-kernel.js';
|
|
46
|
+
import { circuitModel, computeApspArtificialWeightsPacked } from './stress-models.js';
|
|
47
|
+
// C defs.h MODEL_* values (init.ts), as constrained-majorization.ts takes them.
|
|
48
|
+
import { MODEL_CIRCUIT, MODEL_MDS, MODEL_SUBSET } from './init.js';
|
|
49
|
+
import { TOLERANCE_CG, mdsModel } from './stress.js';
|
|
50
|
+
|
|
51
|
+
const fr = Math.fround;
|
|
52
|
+
|
|
53
|
+
/** `#define localConstrMajorIterations` @see constrained_majorization_ipsep.c:59 */
|
|
54
|
+
const LOCAL_CONSTR_MAJOR_ITERATIONS = 1000;
|
|
55
|
+
/** C `FLT_MAX`. */
|
|
56
|
+
const FLT_MAX = 3.4028234663852886e38;
|
|
57
|
+
/** The `0.01f` floor of a cluster boundary weight. */
|
|
58
|
+
const CLUSTER_WEIGHT_FLOOR = fr(0.01);
|
|
59
|
+
/** Guard added to `old_stress` in the convergence ratio. */
|
|
60
|
+
const STRESS_GUARD = 1e-10;
|
|
61
|
+
/** Node sizes grow by this much per non-overlap stage ... */
|
|
62
|
+
const NSIZE_SCALE_STEP = 0.1;
|
|
63
|
+
/** ... until they pass this. */
|
|
64
|
+
const NSIZE_SCALE_LIMIT = 0.999;
|
|
65
|
+
/** Non-overlap constraints are generated once the scale exceeds this. */
|
|
66
|
+
const NSIZE_SCALE_ACTIVE = 0.001;
|
|
67
|
+
/** Horizontal constraints take the transitive closure from this scale. */
|
|
68
|
+
const TRANSITIVE_CLOSURE_SCALE = 0.5;
|
|
69
|
+
/** `opt->noverlap`: non-overlap constraints during layout. */
|
|
70
|
+
const NOVERLAP_CONSTRAINTS = 1;
|
|
71
|
+
/** `opt->noverlap`: remove overlaps after layout. */
|
|
72
|
+
const NOVERLAP_POSTPROCESS = 2;
|
|
73
|
+
|
|
74
|
+
/** `stress_majorization_cola`'s scalar arguments after `nodes` (C `Epsilon` included). */
|
|
75
|
+
export interface ColaOptions {
|
|
76
|
+
/** Dimensionality of the layout. */
|
|
77
|
+
dim: number;
|
|
78
|
+
/** Distance model: C `defs.h` `MODEL_*` (the `init.ts` constants). */
|
|
79
|
+
model: number;
|
|
80
|
+
/** Maximum iterations. */
|
|
81
|
+
maxi: number;
|
|
82
|
+
/** C's global `Epsilon` (graph `epsilon`, default `DFLT_TOLERANCE`). */
|
|
83
|
+
epsilon: number;
|
|
84
|
+
opt: IpsepOptions;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Receives each iteration's stress, the value C prints under `-v` (360-364). */
|
|
88
|
+
export type ColaStressObserver = (stress: number) => void;
|
|
89
|
+
|
|
90
|
+
/** Working storage of the optimisation; `n` includes the cluster boundary variables. */
|
|
91
|
+
interface ColaState {
|
|
92
|
+
n: number;
|
|
93
|
+
origN: number;
|
|
94
|
+
dim: number;
|
|
95
|
+
lap2: Float32Array;
|
|
96
|
+
lapLength: number;
|
|
97
|
+
lap1: Float32Array;
|
|
98
|
+
degrees: Float64Array;
|
|
99
|
+
coords: Float32Array[];
|
|
100
|
+
b: Float32Array[];
|
|
101
|
+
tmpCoords: Float32Array;
|
|
102
|
+
distAccumulator: Float32Array;
|
|
103
|
+
constantTerm: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The two constraint environments. */
|
|
107
|
+
interface ColaEnvs {
|
|
108
|
+
hor: CMajEnvVPSC;
|
|
109
|
+
vrt: CMajEnvVPSC;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The loop variables C keeps across iterations. */
|
|
113
|
+
interface LoopState {
|
|
114
|
+
iterations: number;
|
|
115
|
+
converged: boolean;
|
|
116
|
+
oldStress: number;
|
|
117
|
+
nsizeScale: number;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Largest edge weight (C `float`). @see constrained_majorization_ipsep.c:112-116 */
|
|
121
|
+
function maxEdgeLength(graph: readonly DirectedVtxData[], n: number): number {
|
|
122
|
+
let maxEdgeLen = 0;
|
|
123
|
+
for (let i = 0; i < n; i++) {
|
|
124
|
+
for (let j = 1; j < graph[i]!.nedges; j++) {
|
|
125
|
+
maxEdgeLen = fr(Math.max(graph[i]!.ewgts[j]!, maxEdgeLen));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return maxEdgeLen;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The packed distance matrix of the model; the circuit model warns and the
|
|
133
|
+
* shortest-path model stands in when it is undefined.
|
|
134
|
+
* @see constrained_majorization_ipsep.c:128-151
|
|
135
|
+
*/
|
|
136
|
+
function modelDistances(graph: DirectedVtxData[], n: number, model: number): Float32Array {
|
|
137
|
+
let Dij: Float32Array | null = null;
|
|
138
|
+
if (model === MODEL_SUBSET) {
|
|
139
|
+
/* weight graph to separate high-degree nodes */
|
|
140
|
+
/* and perform slower Dijkstra-based computation */
|
|
141
|
+
Dij = computeApspArtificialWeightsPacked(graph, n);
|
|
142
|
+
} else if (model === MODEL_CIRCUIT) {
|
|
143
|
+
Dij = circuitModel(graph, n);
|
|
144
|
+
if (!Dij) {
|
|
145
|
+
agwarningf('graph is disconnected. Hence, the circuit model');
|
|
146
|
+
agerr('prev', 'is undefined. Reverting to the shortest path model.');
|
|
147
|
+
}
|
|
148
|
+
} else if (model === MODEL_MDS) {
|
|
149
|
+
Dij = mdsModel(graph, n);
|
|
150
|
+
}
|
|
151
|
+
Dij ??= computeApspPacked(graph, n);
|
|
152
|
+
return Dij;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The graph diameter (C `DistType`, an `int`). C computes it and never reads
|
|
157
|
+
* it; kept so the port does the same work.
|
|
158
|
+
* @see constrained_majorization_ipsep.c:158-164
|
|
159
|
+
*/
|
|
160
|
+
function diameterOf(Dij: Float32Array, n: number): number {
|
|
161
|
+
let diameter = -1;
|
|
162
|
+
const length = n + (n * (n - 1)) / 2;
|
|
163
|
+
for (let i = 0; i < length; i++) {
|
|
164
|
+
if (Dij[i]! > diameter) diameter = Math.trunc(Dij[i]!);
|
|
165
|
+
}
|
|
166
|
+
return diameter;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Scale the layout down so its largest coordinate is 10 (no jiggling, which
|
|
171
|
+
* might conflict with constraints), centre each axis, then translate y so
|
|
172
|
+
* y[0] = 0.
|
|
173
|
+
* @see constrained_majorization_ipsep.c:166-191
|
|
174
|
+
*/
|
|
175
|
+
function colaScaleLayout(n: number, dim: number, dCoords: Float64Array[]): void {
|
|
176
|
+
let max = 1;
|
|
177
|
+
for (let i = 0; i < dim; i++) {
|
|
178
|
+
for (let j = 0; j < n; j++) max = Math.max(max, Math.abs(dCoords[i]![j]!));
|
|
179
|
+
}
|
|
180
|
+
for (let i = 0; i < dim; i++) {
|
|
181
|
+
for (let j = 0; j < n; j++) dCoords[i]![j] = dCoords[i]![j]! * (10 / max);
|
|
182
|
+
}
|
|
183
|
+
for (let i = 0; i < dim; i++) orthog1(n, dCoords[i]!);
|
|
184
|
+
/* for the y-coords, don't center them, but translate them so y[0]=0 */
|
|
185
|
+
const y0 = dCoords[1]![0]!;
|
|
186
|
+
for (let i = 0; i < n; i++) dCoords[1]![i] = dCoords[1]![i]! - y0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Extend the packed Laplacian by two boundary variables per cluster; odd
|
|
191
|
+
* rows' first off-diagonal entry is `1/maxEdgeLen²` (when above 0.01).
|
|
192
|
+
* @see constrained_majorization_ipsep.c:205-236
|
|
193
|
+
*/
|
|
194
|
+
function clusterLaplacian(lap2: Float32Array, n: number, nclusters: number, maxEdgeLen: number): Float32Array {
|
|
195
|
+
const nn = n + nclusters * 2;
|
|
196
|
+
const clap = new Float32Array(nn + (nn * (nn - 1)) / 2);
|
|
197
|
+
let c0 = 0;
|
|
198
|
+
let c1 = 0;
|
|
199
|
+
for (let i = 0; i < nn; i++) {
|
|
200
|
+
for (let j = 0; j < nn - i; j++) {
|
|
201
|
+
let v: number;
|
|
202
|
+
if (i < n && j < n - i) {
|
|
203
|
+
v = lap2[c0++]!;
|
|
204
|
+
} else if (j === 1 && i % 2 === 1) {
|
|
205
|
+
/* v=j==1?i%2:0; */
|
|
206
|
+
v = fr(maxEdgeLen * maxEdgeLen);
|
|
207
|
+
if (v > CLUSTER_WEIGHT_FLOOR) v = fr(1.0 / v);
|
|
208
|
+
} else {
|
|
209
|
+
v = 0;
|
|
210
|
+
}
|
|
211
|
+
clap[c1++] = v;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return clap;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Diagonal entries: the negated row sums. @see constrained_majorization_ipsep.c:237-253 */
|
|
218
|
+
function laplacianDiagonal(lap2: Float32Array, n: number, degrees: Float64Array): void {
|
|
219
|
+
let count = 0;
|
|
220
|
+
for (let i = 0; i < n - 1; i++) {
|
|
221
|
+
let degree = 0;
|
|
222
|
+
count++; /* skip main diag entry */
|
|
223
|
+
for (let j = 1; j < n - i; j++, count++) {
|
|
224
|
+
const val = lap2[count]!;
|
|
225
|
+
degree += val;
|
|
226
|
+
degrees[i + j] = degrees[i + j]! - val;
|
|
227
|
+
}
|
|
228
|
+
degrees[i] = degrees[i]! - degree;
|
|
229
|
+
}
|
|
230
|
+
for (let step = n, i = 0, c = 0; i < n; i++, c += step, step--) {
|
|
231
|
+
lap2[c] = degrees[i]!;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Float copies of the coordinates, zero for the cluster variables. @see constrained_majorization_ipsep.c:255-262 */
|
|
236
|
+
function floatCoords(dCoords: Float64Array[], dim: number, n: number, origN: number): Float32Array[] {
|
|
237
|
+
const coords: Float32Array[] = [];
|
|
238
|
+
for (let i = 0; i < dim; i++) {
|
|
239
|
+
const c = new Float32Array(n);
|
|
240
|
+
for (let j = 0; j < n; j++) c[j] = j < origN ? dCoords[i]![j]! : 0;
|
|
241
|
+
coords.push(c);
|
|
242
|
+
}
|
|
243
|
+
return coords;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Laplacian computation and the storage the optimisation needs.
|
|
248
|
+
* @see constrained_majorization_ipsep.c:199-280
|
|
249
|
+
*/
|
|
250
|
+
function colaState(Dij: Float32Array, origN: number, dCoords: Float64Array[], o: ColaOptions, maxEdgeLen: number): ColaState {
|
|
251
|
+
let lap2 = Dij;
|
|
252
|
+
let n = origN;
|
|
253
|
+
let lapLength = n + (n * (n - 1)) / 2;
|
|
254
|
+
squareVec(lapLength, lap2);
|
|
255
|
+
/* compute off-diagonal entries */
|
|
256
|
+
invertVec(lapLength, lap2);
|
|
257
|
+
const { nclusters } = o.opt.clusters;
|
|
258
|
+
if (nclusters > 0) {
|
|
259
|
+
lap2 = clusterLaplacian(lap2, n, nclusters, maxEdgeLen);
|
|
260
|
+
n += nclusters * 2;
|
|
261
|
+
lapLength = lap2.length;
|
|
262
|
+
}
|
|
263
|
+
/* compute diagonal entries */
|
|
264
|
+
const degrees = new Float64Array(n);
|
|
265
|
+
laplacianDiagonal(lap2, n, degrees);
|
|
266
|
+
return {
|
|
267
|
+
n, origN, dim: o.dim, lap2, lapLength, lap1: new Float32Array(0), degrees,
|
|
268
|
+
coords: floatCoords(dCoords, o.dim, n, origN),
|
|
269
|
+
/* compute constant term in stress sum which is \sum_{i<j} w_{ij}d_{ij}^2 */
|
|
270
|
+
constantTerm: fr((n * (n - 1)) / 2),
|
|
271
|
+
b: Array.from({ length: o.dim }, () => new Float32Array(n)),
|
|
272
|
+
tmpCoords: new Float32Array(n),
|
|
273
|
+
distAccumulator: new Float32Array(n),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* `1/|p_i - p_j|` for j = i+1..n-1 in `distAccumulator`, overflows zeroed.
|
|
279
|
+
* @see constrained_majorization_ipsep.c:303-323
|
|
280
|
+
*/
|
|
281
|
+
function pairDistances(st: ColaState, i: number, len: number): void {
|
|
282
|
+
const { distAccumulator: dist, tmpCoords: tmp } = st;
|
|
283
|
+
/* init 'dist_accumulator' with zeros */
|
|
284
|
+
dist.fill(0, 0, st.n);
|
|
285
|
+
/* put into 'dist_accumulator' all squared distances between 'i' and 'i'+1,...,'n'-1 */
|
|
286
|
+
for (let k = 0; k < st.dim; k++) {
|
|
287
|
+
const ck = st.coords[k]!;
|
|
288
|
+
tmp.fill(ck[i]!, 0, len);
|
|
289
|
+
vectorsMultAdditionF(len, tmp, -1, ck.subarray(i + 1));
|
|
290
|
+
squareVec(len, tmp);
|
|
291
|
+
for (let x = 0; x < len; x++) dist[x] = tmp[x]! + dist[x]!; // vectors_additionf
|
|
292
|
+
}
|
|
293
|
+
/* convert to 1/d_{ij} */
|
|
294
|
+
invertSqrtVec(len, dist);
|
|
295
|
+
/* detect overflows */
|
|
296
|
+
for (let j = 0; j < len; j++) {
|
|
297
|
+
if (dist[j]! >= FLT_MAX || dist[j]! < 0) dist[j] = 0;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** The Laplacian of `1/(d_ij*|p_i-p_j|)`. @see constrained_majorization_ipsep.c:298-336 */
|
|
302
|
+
function buildLap1(st: ColaState): void {
|
|
303
|
+
const { n, lap1, degrees } = st;
|
|
304
|
+
degrees.fill(0);
|
|
305
|
+
sqrtVecF(st.lapLength, st.lap2, lap1);
|
|
306
|
+
let count = 0;
|
|
307
|
+
for (let i = 0; i < n - 1; i++) {
|
|
308
|
+
const len = n - i - 1;
|
|
309
|
+
pairDistances(st, i, len);
|
|
310
|
+
count++; /* save place for the main diagonal entry */
|
|
311
|
+
let degree = 0;
|
|
312
|
+
for (let j = 0; j < len; j++, count++) {
|
|
313
|
+
// C `val = lap1[count] *= ...` is the stored float; a JS assignment yields the double.
|
|
314
|
+
const val = (lap1[count] = fr(lap1[count]! * st.distAccumulator[j]!));
|
|
315
|
+
degree += val;
|
|
316
|
+
degrees[i + j + 1] = degrees[i + j + 1]! - val;
|
|
317
|
+
}
|
|
318
|
+
degrees[i] = degrees[i]! - degree;
|
|
319
|
+
}
|
|
320
|
+
for (let step = n, i = 0, c = 0; i < n; i++, c += step, step--) {
|
|
321
|
+
lap1[c] = degrees[i]!;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* `b = lap1 * X`, then the stress (the Laplacians are negated, so subtract
|
|
327
|
+
* instead of add and vice versa).
|
|
328
|
+
* @see constrained_majorization_ipsep.c:338-357
|
|
329
|
+
*/
|
|
330
|
+
function computeStress(st: ColaState): number {
|
|
331
|
+
for (let k = 0; k < st.dim; k++) {
|
|
332
|
+
/* b[k] := lap1*coords[k] */
|
|
333
|
+
rightMultWithVectorFFFused(st.lap1, st.n, st.coords[k]!, st.b[k]!);
|
|
334
|
+
}
|
|
335
|
+
let newStress = 0;
|
|
336
|
+
for (let k = 0; k < st.dim; k++) newStress += vectorsInnerProductF(st.n, st.coords[k]!, st.b[k]!);
|
|
337
|
+
newStress *= 2;
|
|
338
|
+
newStress += st.constantTerm; /* only after mult by 2 */
|
|
339
|
+
for (let k = 0; k < st.dim; k++) {
|
|
340
|
+
rightMultWithVectorFFFused(st.lap2, st.n, st.coords[k]!, st.tmpCoords);
|
|
341
|
+
newStress -= vectorsInnerProductF(st.n, st.coords[k]!, st.tmpCoords);
|
|
342
|
+
}
|
|
343
|
+
return newStress;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* In determining non-overlap constraints, gradually scale up the size of
|
|
348
|
+
* nodes to avoid local minima: each stage restarts the iteration count.
|
|
349
|
+
* @see constrained_majorization_ipsep.c:374-385
|
|
350
|
+
*/
|
|
351
|
+
function scaleUpNodes(s: LoopState, maxi: number, opt: IpsepOptions): void {
|
|
352
|
+
if ((s.iterations >= maxi - 1 || s.converged) && opt.noverlap === NOVERLAP_CONSTRAINTS
|
|
353
|
+
&& s.nsizeScale < NSIZE_SCALE_LIMIT) {
|
|
354
|
+
s.nsizeScale += NSIZE_SCALE_STEP;
|
|
355
|
+
s.iterations = 0;
|
|
356
|
+
s.converged = false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Is a non-overlap pass due? (`noverlap == 1 && nsizeScale > 0.001`) */
|
|
361
|
+
const overlapDue = (opt: IpsepOptions, nsizeScale: number): boolean =>
|
|
362
|
+
opt.noverlap === NOVERLAP_CONSTRAINTS && nsizeScale > NSIZE_SCALE_ACTIVE;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* The new x: VPSC with constraints, else (considerably faster) conjugate
|
|
366
|
+
* gradient. Returns -1 where C jumps to `finish`.
|
|
367
|
+
* @see constrained_majorization_ipsep.c:400-418
|
|
368
|
+
*/
|
|
369
|
+
function solveHorizontal(st: ColaState, e: CMajEnvVPSC, nsizeScale: number, opt: IpsepOptions): number {
|
|
370
|
+
if (overlapDue(opt, nsizeScale)) {
|
|
371
|
+
generateNonoverlapConstraints(e, {
|
|
372
|
+
nsizeScale: fr(nsizeScale), coords: st.coords, k: 0,
|
|
373
|
+
transitiveClosure: nsizeScale >= TRANSITIVE_CLOSURE_SCALE, opt,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
if (e.m > 0) {
|
|
377
|
+
constrainedMajorizationVpsc(e, st.b[0]!, st.coords[0]!, LOCAL_CONSTR_MAJOR_ITERATIONS);
|
|
378
|
+
} else if (conjugateGradientMkernelFused(st.lap2, st.coords[0]!, st.b[0]!, st.n, {
|
|
379
|
+
tol: TOLERANCE_CG, maxIterations: st.n,
|
|
380
|
+
}) < 0) {
|
|
381
|
+
// conjugate_gradient_mkernel returns 0 or 1, so C never takes this jump.
|
|
382
|
+
/* v8 ignore next -- @preserve */
|
|
383
|
+
return -1;
|
|
384
|
+
}
|
|
385
|
+
return 0;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* The new y, as {@link solveHorizontal} (no transitive closure).
|
|
390
|
+
* @see constrained_majorization_ipsep.c:419-432
|
|
391
|
+
*/
|
|
392
|
+
function solveVertical(st: ColaState, e: CMajEnvVPSC, nsizeScale: number, opt: IpsepOptions): number {
|
|
393
|
+
if (overlapDue(opt, nsizeScale)) {
|
|
394
|
+
generateNonoverlapConstraints(e, { nsizeScale: fr(nsizeScale), coords: st.coords, k: 1, transitiveClosure: false, opt });
|
|
395
|
+
}
|
|
396
|
+
if (e.m > 0) {
|
|
397
|
+
// constrained_majorization_vpsc returns its iteration count, so C never takes this jump.
|
|
398
|
+
/* v8 ignore next -- @preserve */
|
|
399
|
+
if (constrainedMajorizationVpsc(e, st.b[1]!, st.coords[1]!, LOCAL_CONSTR_MAJOR_ITERATIONS) < 0) return -1;
|
|
400
|
+
} else {
|
|
401
|
+
conjugateGradientMkernelFused(st.lap2, st.coords[1]!, st.b[1]!, st.n, { tol: TOLERANCE_CG, maxIterations: st.n });
|
|
402
|
+
}
|
|
403
|
+
return 0;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* The majorization loop with cola's convergence test (a decrease below
|
|
408
|
+
* `Epsilon`, relative). Returns the iteration count, -1 on a `finish` jump.
|
|
409
|
+
* @see constrained_majorization_ipsep.c:295-433
|
|
410
|
+
*/
|
|
411
|
+
function iterate(st: ColaState, envs: ColaEnvs, o: ColaOptions, observe: ColaStressObserver | null): number {
|
|
412
|
+
const s: LoopState = { iterations: 0, converged: false, oldStress: Number.MAX_VALUE, nsizeScale: 0 };
|
|
413
|
+
for (; s.iterations < o.maxi && !s.converged; s.iterations++) {
|
|
414
|
+
buildLap1(st);
|
|
415
|
+
const newStress = computeStress(st);
|
|
416
|
+
observe?.(newStress);
|
|
417
|
+
s.converged = newStress < s.oldStress
|
|
418
|
+
&& Math.abs(newStress - s.oldStress) / Math.abs(s.oldStress + STRESS_GUARD) < o.epsilon;
|
|
419
|
+
/* in first iteration we allowed stress increase, which might result ny imposing constraints */
|
|
420
|
+
s.oldStress = newStress;
|
|
421
|
+
scaleUpNodes(s, o.maxi, o.opt);
|
|
422
|
+
if (solveHorizontal(st, envs.hor, s.nsizeScale, o.opt) < 0) return -1;
|
|
423
|
+
if (solveVertical(st, envs.vrt, s.nsizeScale, o.opt) < 0) return -1;
|
|
424
|
+
}
|
|
425
|
+
return s.iterations;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* The constraint environments, the loop, and the overlap post-process.
|
|
430
|
+
* `initCMajVPSC` failing jumps to `finish` (-1) as in C, skipping the deletes.
|
|
431
|
+
* @see constrained_majorization_ipsep.c:282-293, 434-444
|
|
432
|
+
*/
|
|
433
|
+
function optimize(st: ColaState, graph: DirectedVtxData[], o: ColaOptions, observe: ColaStressObserver | null): number {
|
|
434
|
+
const hor = initCMajVPSC(st.n, st.lap2, graph, o.opt, 0);
|
|
435
|
+
// diredges 0 never reaches compute_hierarchy, so this is never NULL.
|
|
436
|
+
/* v8 ignore next -- @preserve */
|
|
437
|
+
if (hor === null) return -1;
|
|
438
|
+
const vrt = initCMajVPSC(st.n, st.lap2, graph, o.opt, o.opt.diredges);
|
|
439
|
+
// initCMajVPSC's digcola NULL is unreachable (quad-prog-vpsc.ts).
|
|
440
|
+
/* v8 ignore next -- @preserve */
|
|
441
|
+
if (vrt === null) return -1;
|
|
442
|
+
st.lap1 = new Float32Array(st.lapLength);
|
|
443
|
+
const iterations = iterate(st, { hor, vrt }, o, observe);
|
|
444
|
+
/* v8 ignore next -- @preserve */
|
|
445
|
+
if (iterations < 0) return iterations;
|
|
446
|
+
deleteCMajEnvVPSC(hor);
|
|
447
|
+
deleteCMajEnvVPSC(vrt);
|
|
448
|
+
if (o.opt.noverlap === NOVERLAP_POSTPROCESS) {
|
|
449
|
+
removeoverlaps(st.origN, st.coords, o.opt);
|
|
450
|
+
}
|
|
451
|
+
return iterations;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** Copy the real nodes' coordinates back. @see constrained_majorization_ipsep.c:446-455 */
|
|
455
|
+
function writeBack(st: ColaState, dCoords: Float64Array[]): void {
|
|
456
|
+
for (let i = 0; i < st.dim; i++) {
|
|
457
|
+
for (let j = 0; j < st.origN; j++) dCoords[i]![j] = st.coords[i]![j]!;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* {@link stressMajorizationCola} reporting each iteration's stress to
|
|
463
|
+
* `observe`. Internal: for tests, not exported from the package.
|
|
464
|
+
* @see lib/neatogen/constrained_majorization_ipsep.c:stress_majorization_cola
|
|
465
|
+
*/
|
|
466
|
+
export function stressMajorizationColaTraced(
|
|
467
|
+
graph: DirectedVtxData[], n: number, dCoords: Float64Array[], nodes: Node[],
|
|
468
|
+
o: ColaOptions & { observe: ColaStressObserver | null },
|
|
469
|
+
): number {
|
|
470
|
+
// C ignores initLayout's pinned result: cola has no pinned-node branch.
|
|
471
|
+
initLayout(n, o.dim, dCoords, nodes);
|
|
472
|
+
if (n === 1) return 0;
|
|
473
|
+
const maxEdgeLen = maxEdgeLength(graph, n);
|
|
474
|
+
/* Compute the all-pairs-shortest-distances matrix */
|
|
475
|
+
if (o.maxi === 0) return 0;
|
|
476
|
+
const Dij = modelDistances(graph, n, o.model);
|
|
477
|
+
diameterOf(Dij, n);
|
|
478
|
+
colaScaleLayout(n, o.dim, dCoords);
|
|
479
|
+
const st = colaState(Dij, n, dCoords, o, maxEdgeLen);
|
|
480
|
+
const iterations = optimize(st, graph, o, o.observe);
|
|
481
|
+
writeBack(st, dCoords);
|
|
482
|
+
return iterations;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Stress majorization subject to separation constraints: directed-edge
|
|
487
|
+
* (`diredges` 1) or DiG-CoLa level (2) constraints, cluster containment, and
|
|
488
|
+
* node non-overlap during (`noverlap` 1) or after (2) layout. Mutates
|
|
489
|
+
* `dCoords`; returns C's value (iterations, -1 on error, 0 for n == 1 or
|
|
490
|
+
* maxi == 0). C has no `maxi < 0` return here: `neatoLayout` returns before.
|
|
491
|
+
* @see lib/neatogen/constrained_majorization_ipsep.c:stress_majorization_cola
|
|
492
|
+
*/
|
|
493
|
+
export function stressMajorizationCola(
|
|
494
|
+
graph: DirectedVtxData[], n: number, dCoords: Float64Array[], nodes: Node[], o: ColaOptions,
|
|
495
|
+
): number {
|
|
496
|
+
return stressMajorizationColaTraced(graph, n, dCoords, nodes, { ...o, observe: null });
|
|
497
|
+
}
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
invertSqrtVec,
|
|
28
28
|
invertVec,
|
|
29
29
|
orthog1,
|
|
30
|
-
rightMultWithVectorFF,
|
|
31
30
|
sqrtVecF,
|
|
32
31
|
squareVec,
|
|
33
32
|
vectorsInnerProductF,
|
|
@@ -122,19 +121,6 @@ const FUSED_OPS: KernelOps = {
|
|
|
122
121
|
squareAdd: (tmp, acc) => fmaf(tmp, tmp, acc),
|
|
123
122
|
rightMult: rightMultWithVectorFFFused, cg: conjugateGradientMkernelFused,
|
|
124
123
|
};
|
|
125
|
-
/**
|
|
126
|
-
* The kernels as `stress_majorization_cola` (mode=ipsep) runs them: its squared
|
|
127
|
-
* distances are `square_vec` then `vectors_additionf` (two loops, so the product
|
|
128
|
-
* is rounded before the add), its inlined `right_mult_with_vector_ff` copy is not
|
|
129
|
-
* read from the disassembly (kept unfused), and its conjugate gradient is the same
|
|
130
|
-
* out-of-line `conjugate_gradient_mkernel` the kD kernel calls.
|
|
131
|
-
* @see lib/neatogen/constrained_majorization_ipsep.c:stress_majorization_cola
|
|
132
|
-
*/
|
|
133
|
-
const COLA_OPS: KernelOps = {
|
|
134
|
-
squareAdd: (tmp, acc) => acc + fr(tmp * tmp),
|
|
135
|
-
rightMult: rightMultWithVectorFF, cg: conjugateGradientMkernelFused,
|
|
136
|
-
};
|
|
137
|
-
|
|
138
124
|
/** Laplacian off-diagonal prep + diagonal degrees. @see stress.c (Laplacian computation) */
|
|
139
125
|
function buildLap2(lap2: Float32Array, n: number, exp: number): void {
|
|
140
126
|
const lapLength = (n * (n + 1)) / 2;
|
|
@@ -260,8 +246,6 @@ export interface StressOpts {
|
|
|
260
246
|
/** MODEL_* — only the resulting Dij matters here; pass it in. */
|
|
261
247
|
maxi: number;
|
|
262
248
|
epsilon: number;
|
|
263
|
-
/** Run the kernels as `stress_majorization_cola` does (mode=ipsep). */
|
|
264
|
-
cola?: boolean;
|
|
265
249
|
}
|
|
266
250
|
|
|
267
251
|
/**
|
|
@@ -296,7 +280,7 @@ export function stressMajorizationKDMkernel(
|
|
|
296
280
|
b: Array.from({ length: dim }, () => new Float32Array(n)),
|
|
297
281
|
tmpCoords: new Float32Array(n),
|
|
298
282
|
constantTerm,
|
|
299
|
-
ops:
|
|
283
|
+
ops: FUSED_OPS,
|
|
300
284
|
};
|
|
301
285
|
|
|
302
286
|
let oldStress = Number.MAX_VALUE;
|