@graphty/graph-samples 0.0.1 → 0.1.1
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/LICENSE +21 -0
- package/NOTICE +123 -0
- package/README.md +190 -1
- package/dist/chunks/build-DdCe60t3.js +47 -0
- package/dist/chunks/build-DdCe60t3.js.map +1 -0
- package/dist/chunks/meta-B6toBzaa.js +19 -0
- package/dist/chunks/meta-B6toBzaa.js.map +1 -0
- package/dist/chunks/meta-BM_YIhlA.js +28 -0
- package/dist/chunks/meta-BM_YIhlA.js.map +1 -0
- package/dist/chunks/meta-BMmtUpPx.js +30 -0
- package/dist/chunks/meta-BMmtUpPx.js.map +1 -0
- package/dist/chunks/meta-BXC7oi86.js +22 -0
- package/dist/chunks/meta-BXC7oi86.js.map +1 -0
- package/dist/chunks/meta-BaFPvhc1.js +19 -0
- package/dist/chunks/meta-BaFPvhc1.js.map +1 -0
- package/dist/chunks/meta-C58v1Oy0.js +28 -0
- package/dist/chunks/meta-C58v1Oy0.js.map +1 -0
- package/dist/chunks/meta-CQRXyexG.js +23 -0
- package/dist/chunks/meta-CQRXyexG.js.map +1 -0
- package/dist/chunks/meta-DrgM1eS0.js +23 -0
- package/dist/chunks/meta-DrgM1eS0.js.map +1 -0
- package/dist/chunks/meta-IhoaDXAV.js +19 -0
- package/dist/chunks/meta-IhoaDXAV.js.map +1 -0
- package/dist/chunks/meta-MQPbBUUB.js +29 -0
- package/dist/chunks/meta-MQPbBUUB.js.map +1 -0
- package/dist/chunks/meta-Qp4HNYAZ.js +24 -0
- package/dist/chunks/meta-Qp4HNYAZ.js.map +1 -0
- package/dist/chunks/meta-mns0uFIW.js +19 -0
- package/dist/chunks/meta-mns0uFIW.js.map +1 -0
- package/dist/datasets/celegans-neural.d.ts +1 -0
- package/dist/datasets/celegans-neural.js +7359 -0
- package/dist/datasets/celegans-neural.js.map +1 -0
- package/dist/datasets/contiguous-usa.d.ts +1 -0
- package/dist/datasets/contiguous-usa.js +501 -0
- package/dist/datasets/contiguous-usa.js.map +1 -0
- package/dist/datasets/davis-southern-women.d.ts +1 -0
- package/dist/datasets/davis-southern-women.js +235 -0
- package/dist/datasets/davis-southern-women.js.map +1 -0
- package/dist/datasets/dolphins.d.ts +1 -0
- package/dist/datasets/dolphins.js +406 -0
- package/dist/datasets/dolphins.js.map +1 -0
- package/dist/datasets/florentine-families.d.ts +1 -0
- package/dist/datasets/florentine-families.js +75 -0
- package/dist/datasets/florentine-families.js.map +1 -0
- package/dist/datasets/football.d.ts +1 -0
- package/dist/datasets/football.js +1508 -0
- package/dist/datasets/football.js.map +1 -0
- package/dist/datasets/karate.d.ts +1 -0
- package/dist/datasets/karate.js +295 -0
- package/dist/datasets/karate.js.map +1 -0
- package/dist/datasets/knuth-miles.d.ts +1 -0
- package/dist/datasets/knuth-miles.js +24933 -0
- package/dist/datasets/knuth-miles.js.map +1 -0
- package/dist/datasets/les-miserables.d.ts +1 -0
- package/dist/datasets/les-miserables.js +860 -0
- package/dist/datasets/les-miserables.js.map +1 -0
- package/dist/datasets/openflights.d.ts +1 -0
- package/dist/datasets/openflights.js +130277 -0
- package/dist/datasets/openflights.js.map +1 -0
- package/dist/datasets/political-blogs.d.ts +1 -0
- package/dist/datasets/political-blogs.js +42551 -0
- package/dist/datasets/political-blogs.js.map +1 -0
- package/dist/datasets/political-books.d.ts +1 -0
- package/dist/datasets/political-books.js +1124 -0
- package/dist/datasets/political-books.js.map +1 -0
- package/dist/generators.d.ts +1 -0
- package/dist/generators.js +4496 -0
- package/dist/generators.js.map +1 -0
- package/dist/graph-samples.d.ts +1 -0
- package/dist/graph-samples.js +142 -0
- package/dist/graph-samples.js.map +1 -0
- package/dist/src/datasets/build.d.ts +89 -0
- package/dist/src/datasets/build.d.ts.map +1 -0
- package/dist/src/datasets/build.js +53 -0
- package/dist/src/datasets/build.js.map +1 -0
- package/dist/src/datasets/catalog.d.ts +8 -0
- package/dist/src/datasets/catalog.d.ts.map +1 -0
- package/dist/src/datasets/catalog.js +34 -0
- package/dist/src/datasets/catalog.js.map +1 -0
- package/dist/src/datasets/celegans-neural/data.d.ts +3 -0
- package/dist/src/datasets/celegans-neural/data.d.ts.map +1 -0
- package/dist/src/datasets/celegans-neural/data.js +573 -0
- package/dist/src/datasets/celegans-neural/data.js.map +1 -0
- package/dist/src/datasets/celegans-neural/index.d.ts +11 -0
- package/dist/src/datasets/celegans-neural/index.d.ts.map +1 -0
- package/dist/src/datasets/celegans-neural/index.js +14 -0
- package/dist/src/datasets/celegans-neural/index.js.map +1 -0
- package/dist/src/datasets/celegans-neural/meta.d.ts +4 -0
- package/dist/src/datasets/celegans-neural/meta.d.ts.map +1 -0
- package/dist/src/datasets/celegans-neural/meta.js +21 -0
- package/dist/src/datasets/celegans-neural/meta.js.map +1 -0
- package/dist/src/datasets/contiguous-usa/data.d.ts +3 -0
- package/dist/src/datasets/contiguous-usa/data.d.ts.map +1 -0
- package/dist/src/datasets/contiguous-usa/data.js +162 -0
- package/dist/src/datasets/contiguous-usa/data.js.map +1 -0
- package/dist/src/datasets/contiguous-usa/index.d.ts +11 -0
- package/dist/src/datasets/contiguous-usa/index.d.ts.map +1 -0
- package/dist/src/datasets/contiguous-usa/index.js +14 -0
- package/dist/src/datasets/contiguous-usa/index.js.map +1 -0
- package/dist/src/datasets/contiguous-usa/meta.d.ts +4 -0
- package/dist/src/datasets/contiguous-usa/meta.d.ts.map +1 -0
- package/dist/src/datasets/contiguous-usa/meta.js +27 -0
- package/dist/src/datasets/contiguous-usa/meta.js.map +1 -0
- package/dist/src/datasets/davis-southern-women/data.d.ts +3 -0
- package/dist/src/datasets/davis-southern-women/data.d.ts.map +1 -0
- package/dist/src/datasets/davis-southern-women/data.js +57 -0
- package/dist/src/datasets/davis-southern-women/data.js.map +1 -0
- package/dist/src/datasets/davis-southern-women/index.d.ts +11 -0
- package/dist/src/datasets/davis-southern-women/index.d.ts.map +1 -0
- package/dist/src/datasets/davis-southern-women/index.js +14 -0
- package/dist/src/datasets/davis-southern-women/index.js.map +1 -0
- package/dist/src/datasets/davis-southern-women/meta.d.ts +4 -0
- package/dist/src/datasets/davis-southern-women/meta.d.ts.map +1 -0
- package/dist/src/datasets/davis-southern-women/meta.js +17 -0
- package/dist/src/datasets/davis-southern-women/meta.js.map +1 -0
- package/dist/src/datasets/dolphins/data.d.ts +3 -0
- package/dist/src/datasets/dolphins/data.d.ts.map +1 -0
- package/dist/src/datasets/dolphins/data.js +93 -0
- package/dist/src/datasets/dolphins/data.js.map +1 -0
- package/dist/src/datasets/dolphins/index.d.ts +11 -0
- package/dist/src/datasets/dolphins/index.d.ts.map +1 -0
- package/dist/src/datasets/dolphins/index.js +14 -0
- package/dist/src/datasets/dolphins/index.js.map +1 -0
- package/dist/src/datasets/dolphins/meta.d.ts +4 -0
- package/dist/src/datasets/dolphins/meta.d.ts.map +1 -0
- package/dist/src/datasets/dolphins/meta.js +17 -0
- package/dist/src/datasets/dolphins/meta.js.map +1 -0
- package/dist/src/datasets/florentine-families/data.d.ts +3 -0
- package/dist/src/datasets/florentine-families/data.d.ts.map +1 -0
- package/dist/src/datasets/florentine-families/data.js +31 -0
- package/dist/src/datasets/florentine-families/data.js.map +1 -0
- package/dist/src/datasets/florentine-families/index.d.ts +11 -0
- package/dist/src/datasets/florentine-families/index.d.ts.map +1 -0
- package/dist/src/datasets/florentine-families/index.js +14 -0
- package/dist/src/datasets/florentine-families/index.js.map +1 -0
- package/dist/src/datasets/florentine-families/meta.d.ts +4 -0
- package/dist/src/datasets/florentine-families/meta.d.ts.map +1 -0
- package/dist/src/datasets/florentine-families/meta.js +17 -0
- package/dist/src/datasets/florentine-families/meta.js.map +1 -0
- package/dist/src/datasets/football/data.d.ts +3 -0
- package/dist/src/datasets/football/data.d.ts.map +1 -0
- package/dist/src/datasets/football/data.js +210 -0
- package/dist/src/datasets/football/data.js.map +1 -0
- package/dist/src/datasets/football/index.d.ts +11 -0
- package/dist/src/datasets/football/index.d.ts.map +1 -0
- package/dist/src/datasets/football/index.js +14 -0
- package/dist/src/datasets/football/index.js.map +1 -0
- package/dist/src/datasets/football/meta.d.ts +4 -0
- package/dist/src/datasets/football/meta.d.ts.map +1 -0
- package/dist/src/datasets/football/meta.js +17 -0
- package/dist/src/datasets/football/meta.js.map +1 -0
- package/dist/src/datasets/hosted.d.ts +7 -0
- package/dist/src/datasets/hosted.d.ts.map +1 -0
- package/dist/src/datasets/hosted.js +80 -0
- package/dist/src/datasets/hosted.js.map +1 -0
- package/dist/src/datasets/karate/data.d.ts +3 -0
- package/dist/src/datasets/karate/data.d.ts.map +1 -0
- package/dist/src/datasets/karate/data.js +30 -0
- package/dist/src/datasets/karate/data.js.map +1 -0
- package/dist/src/datasets/karate/index.d.ts +11 -0
- package/dist/src/datasets/karate/index.d.ts.map +1 -0
- package/dist/src/datasets/karate/index.js +14 -0
- package/dist/src/datasets/karate/index.js.map +1 -0
- package/dist/src/datasets/karate/meta.d.ts +4 -0
- package/dist/src/datasets/karate/meta.d.ts.map +1 -0
- package/dist/src/datasets/karate/meta.js +22 -0
- package/dist/src/datasets/karate/meta.js.map +1 -0
- package/dist/src/datasets/knuth-miles/data.d.ts +3 -0
- package/dist/src/datasets/knuth-miles/data.d.ts.map +1 -0
- package/dist/src/datasets/knuth-miles/data.js +1203 -0
- package/dist/src/datasets/knuth-miles/data.js.map +1 -0
- package/dist/src/datasets/knuth-miles/index.d.ts +11 -0
- package/dist/src/datasets/knuth-miles/index.d.ts.map +1 -0
- package/dist/src/datasets/knuth-miles/index.js +14 -0
- package/dist/src/datasets/knuth-miles/index.js.map +1 -0
- package/dist/src/datasets/knuth-miles/meta.d.ts +4 -0
- package/dist/src/datasets/knuth-miles/meta.d.ts.map +1 -0
- package/dist/src/datasets/knuth-miles/meta.js +26 -0
- package/dist/src/datasets/knuth-miles/meta.js.map +1 -0
- package/dist/src/datasets/les-miserables/data.d.ts +3 -0
- package/dist/src/datasets/les-miserables/data.d.ts.map +1 -0
- package/dist/src/datasets/les-miserables/data.js +117 -0
- package/dist/src/datasets/les-miserables/data.js.map +1 -0
- package/dist/src/datasets/les-miserables/index.d.ts +11 -0
- package/dist/src/datasets/les-miserables/index.d.ts.map +1 -0
- package/dist/src/datasets/les-miserables/index.js +14 -0
- package/dist/src/datasets/les-miserables/index.js.map +1 -0
- package/dist/src/datasets/les-miserables/meta.d.ts +4 -0
- package/dist/src/datasets/les-miserables/meta.d.ts.map +1 -0
- package/dist/src/datasets/les-miserables/meta.js +21 -0
- package/dist/src/datasets/les-miserables/meta.js.map +1 -0
- package/dist/src/datasets/openflights/data.d.ts +3 -0
- package/dist/src/datasets/openflights/data.d.ts.map +1 -0
- package/dist/src/datasets/openflights/data.js +15457 -0
- package/dist/src/datasets/openflights/data.js.map +1 -0
- package/dist/src/datasets/openflights/index.d.ts +11 -0
- package/dist/src/datasets/openflights/index.d.ts.map +1 -0
- package/dist/src/datasets/openflights/index.js +14 -0
- package/dist/src/datasets/openflights/index.js.map +1 -0
- package/dist/src/datasets/openflights/meta.d.ts +4 -0
- package/dist/src/datasets/openflights/meta.d.ts.map +1 -0
- package/dist/src/datasets/openflights/meta.js +28 -0
- package/dist/src/datasets/openflights/meta.js.map +1 -0
- package/dist/src/datasets/political-blogs/data.d.ts +3 -0
- package/dist/src/datasets/political-blogs/data.d.ts.map +1 -0
- package/dist/src/datasets/political-blogs/data.js +4857 -0
- package/dist/src/datasets/political-blogs/data.js.map +1 -0
- package/dist/src/datasets/political-blogs/index.d.ts +11 -0
- package/dist/src/datasets/political-blogs/index.d.ts.map +1 -0
- package/dist/src/datasets/political-blogs/index.js +14 -0
- package/dist/src/datasets/political-blogs/index.js.map +1 -0
- package/dist/src/datasets/political-blogs/meta.d.ts +4 -0
- package/dist/src/datasets/political-blogs/meta.d.ts.map +1 -0
- package/dist/src/datasets/political-blogs/meta.js +26 -0
- package/dist/src/datasets/political-blogs/meta.js.map +1 -0
- package/dist/src/datasets/political-books/data.d.ts +3 -0
- package/dist/src/datasets/political-books/data.d.ts.map +1 -0
- package/dist/src/datasets/political-books/data.js +165 -0
- package/dist/src/datasets/political-books/data.js.map +1 -0
- package/dist/src/datasets/political-books/index.d.ts +11 -0
- package/dist/src/datasets/political-books/index.d.ts.map +1 -0
- package/dist/src/datasets/political-books/index.js +14 -0
- package/dist/src/datasets/political-books/index.js.map +1 -0
- package/dist/src/datasets/political-books/meta.d.ts +4 -0
- package/dist/src/datasets/political-books/meta.d.ts.map +1 -0
- package/dist/src/datasets/political-books/meta.js +20 -0
- package/dist/src/datasets/political-books/meta.js.map +1 -0
- package/dist/src/datasets/remote.d.ts +27 -0
- package/dist/src/datasets/remote.d.ts.map +1 -0
- package/dist/src/datasets/remote.js +30 -0
- package/dist/src/datasets/remote.js.map +1 -0
- package/dist/src/element.d.ts +20 -0
- package/dist/src/element.d.ts.map +1 -0
- package/dist/src/element.js +27 -0
- package/dist/src/element.js.map +1 -0
- package/dist/src/generators/bipartite.d.ts +51 -0
- package/dist/src/generators/bipartite.d.ts.map +1 -0
- package/dist/src/generators/bipartite.js +99 -0
- package/dist/src/generators/bipartite.js.map +1 -0
- package/dist/src/generators/block-model.d.ts +75 -0
- package/dist/src/generators/block-model.d.ts.map +1 -0
- package/dist/src/generators/block-model.js +116 -0
- package/dist/src/generators/block-model.js.map +1 -0
- package/dist/src/generators/classic.d.ts +208 -0
- package/dist/src/generators/classic.d.ts.map +1 -0
- package/dist/src/generators/classic.js +437 -0
- package/dist/src/generators/classic.js.map +1 -0
- package/dist/src/generators/degree-sequence.d.ts +273 -0
- package/dist/src/generators/degree-sequence.d.ts.map +1 -0
- package/dist/src/generators/degree-sequence.js +646 -0
- package/dist/src/generators/degree-sequence.js.map +1 -0
- package/dist/src/generators/directed.d.ts +141 -0
- package/dist/src/generators/directed.d.ts.map +1 -0
- package/dist/src/generators/directed.js +329 -0
- package/dist/src/generators/directed.js.map +1 -0
- package/dist/src/generators/erdos-renyi.d.ts +58 -0
- package/dist/src/generators/erdos-renyi.d.ts.map +1 -0
- package/dist/src/generators/erdos-renyi.js +154 -0
- package/dist/src/generators/erdos-renyi.js.map +1 -0
- package/dist/src/generators/flow.d.ts +153 -0
- package/dist/src/generators/flow.d.ts.map +1 -0
- package/dist/src/generators/flow.js +346 -0
- package/dist/src/generators/flow.js.map +1 -0
- package/dist/src/generators/geometric.d.ts +133 -0
- package/dist/src/generators/geometric.d.ts.map +1 -0
- package/dist/src/generators/geometric.js +495 -0
- package/dist/src/generators/geometric.js.map +1 -0
- package/dist/src/generators/growth.d.ts +187 -0
- package/dist/src/generators/growth.d.ts.map +1 -0
- package/dist/src/generators/growth.js +445 -0
- package/dist/src/generators/growth.js.map +1 -0
- package/dist/src/generators/hyperbolic.d.ts +84 -0
- package/dist/src/generators/hyperbolic.d.ts.map +1 -0
- package/dist/src/generators/hyperbolic.js +153 -0
- package/dist/src/generators/hyperbolic.js.map +1 -0
- package/dist/src/generators/index.d.ts +25 -0
- package/dist/src/generators/index.d.ts.map +1 -0
- package/dist/src/generators/index.js +24 -0
- package/dist/src/generators/index.js.map +1 -0
- package/dist/src/generators/lattices.d.ts +87 -0
- package/dist/src/generators/lattices.d.ts.map +1 -0
- package/dist/src/generators/lattices.js +237 -0
- package/dist/src/generators/lattices.js.map +1 -0
- package/dist/src/generators/lfr.d.ts +55 -0
- package/dist/src/generators/lfr.d.ts.map +1 -0
- package/dist/src/generators/lfr.js +178 -0
- package/dist/src/generators/lfr.js.map +1 -0
- package/dist/src/generators/named.d.ts +23 -0
- package/dist/src/generators/named.d.ts.map +1 -0
- package/dist/src/generators/named.js +191 -0
- package/dist/src/generators/named.js.map +1 -0
- package/dist/src/generators/preferential-attachment.d.ts +66 -0
- package/dist/src/generators/preferential-attachment.d.ts.map +1 -0
- package/dist/src/generators/preferential-attachment.js +157 -0
- package/dist/src/generators/preferential-attachment.js.map +1 -0
- package/dist/src/generators/trees-and-dags.d.ts +53 -0
- package/dist/src/generators/trees-and-dags.d.ts.map +1 -0
- package/dist/src/generators/trees-and-dags.js +108 -0
- package/dist/src/generators/trees-and-dags.js.map +1 -0
- package/dist/src/generators/util.d.ts +84 -0
- package/dist/src/generators/util.d.ts.map +1 -0
- package/dist/src/generators/util.js +138 -0
- package/dist/src/generators/util.js.map +1 -0
- package/dist/src/generators/variants.d.ts +85 -0
- package/dist/src/generators/variants.d.ts.map +1 -0
- package/dist/src/generators/variants.js +215 -0
- package/dist/src/generators/variants.js.map +1 -0
- package/dist/src/generators/weights.d.ts +65 -0
- package/dist/src/generators/weights.d.ts.map +1 -0
- package/dist/src/generators/weights.js +135 -0
- package/dist/src/generators/weights.js.map +1 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/random/exp.d.ts +23 -0
- package/dist/src/random/exp.d.ts.map +1 -0
- package/dist/src/random/exp.js +101 -0
- package/dist/src/random/exp.js.map +1 -0
- package/dist/src/random/log.d.ts +19 -0
- package/dist/src/random/log.d.ts.map +1 -0
- package/dist/src/random/log.js +83 -0
- package/dist/src/random/log.js.map +1 -0
- package/dist/src/random/stream.d.ts +93 -0
- package/dist/src/random/stream.d.ts.map +1 -0
- package/dist/src/random/stream.js +154 -0
- package/dist/src/random/stream.js.map +1 -0
- package/dist/src/random/threefry.d.ts +19 -0
- package/dist/src/random/threefry.d.ts.map +1 -0
- package/dist/src/random/threefry.js +43 -0
- package/dist/src/random/threefry.js.map +1 -0
- package/dist/src/random/trig.d.ts +16 -0
- package/dist/src/random/trig.d.ts.map +1 -0
- package/dist/src/random/trig.js +78 -0
- package/dist/src/random/trig.js.map +1 -0
- package/dist/src/types.d.ts +28 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +102 -5
- package/src/datasets/build.ts +140 -0
- package/src/datasets/catalog.ts +35 -0
- package/src/datasets/celegans-neural/data.ts +575 -0
- package/src/datasets/celegans-neural/index.ts +17 -0
- package/src/datasets/celegans-neural/meta.ts +25 -0
- package/src/datasets/contiguous-usa/data.ts +164 -0
- package/src/datasets/contiguous-usa/index.ts +17 -0
- package/src/datasets/contiguous-usa/meta.ts +31 -0
- package/src/datasets/davis-southern-women/data.ts +59 -0
- package/src/datasets/davis-southern-women/index.ts +17 -0
- package/src/datasets/davis-southern-women/meta.ts +20 -0
- package/src/datasets/dolphins/data.ts +95 -0
- package/src/datasets/dolphins/index.ts +17 -0
- package/src/datasets/dolphins/meta.ts +21 -0
- package/src/datasets/florentine-families/data.ts +33 -0
- package/src/datasets/florentine-families/index.ts +17 -0
- package/src/datasets/florentine-families/meta.ts +20 -0
- package/src/datasets/football/data.ts +212 -0
- package/src/datasets/football/index.ts +17 -0
- package/src/datasets/football/meta.ts +20 -0
- package/src/datasets/hosted.ts +90 -0
- package/src/datasets/karate/data.ts +32 -0
- package/src/datasets/karate/index.ts +17 -0
- package/src/datasets/karate/meta.ts +25 -0
- package/src/datasets/knuth-miles/data.ts +1205 -0
- package/src/datasets/knuth-miles/index.ts +17 -0
- package/src/datasets/knuth-miles/meta.ts +29 -0
- package/src/datasets/les-miserables/data.ts +119 -0
- package/src/datasets/les-miserables/index.ts +17 -0
- package/src/datasets/les-miserables/meta.ts +24 -0
- package/src/datasets/openflights/data.ts +15459 -0
- package/src/datasets/openflights/index.ts +17 -0
- package/src/datasets/openflights/meta.ts +31 -0
- package/src/datasets/political-blogs/data.ts +4859 -0
- package/src/datasets/political-blogs/index.ts +17 -0
- package/src/datasets/political-blogs/meta.ts +30 -0
- package/src/datasets/political-books/data.ts +167 -0
- package/src/datasets/political-books/index.ts +17 -0
- package/src/datasets/political-books/meta.ts +23 -0
- package/src/datasets/remote.ts +42 -0
- package/src/element.ts +41 -0
- package/src/generators/bipartite.ts +127 -0
- package/src/generators/block-model.ts +160 -0
- package/src/generators/classic.ts +461 -0
- package/src/generators/degree-sequence.ts +807 -0
- package/src/generators/directed.ts +418 -0
- package/src/generators/erdos-renyi.ts +188 -0
- package/src/generators/flow.ts +443 -0
- package/src/generators/geometric.ts +591 -0
- package/src/generators/growth.ts +532 -0
- package/src/generators/hyperbolic.ts +193 -0
- package/src/generators/index.ts +133 -0
- package/src/generators/lattices.ts +290 -0
- package/src/generators/lfr.ts +227 -0
- package/src/generators/named.ts +198 -0
- package/src/generators/preferential-attachment.ts +188 -0
- package/src/generators/trees-and-dags.ts +139 -0
- package/src/generators/util.ts +167 -0
- package/src/generators/variants.ts +253 -0
- package/src/generators/weights.ts +177 -0
- package/src/index.ts +12 -0
- package/src/random/exp.ts +104 -0
- package/src/random/log.ts +86 -0
- package/src/random/stream.ts +169 -0
- package/src/random/threefry.ts +45 -0
- package/src/random/trig.ts +83 -0
- package/src/types.ts +28 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Random hyperbolic graphs (D. Krioukov, F. Papadopoulos, M. Kitsak, A. Vahdat and M. Boguna,
|
|
3
|
+
* "Hyperbolic geometry of complex networks", Phys. Rev. E 82, 036106, 2010,
|
|
4
|
+
* doi:10.1103/PhysRevE.82.036106): power-law degrees, high clustering and a native 2D embedding.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { detExp } from "../random/exp.js";
|
|
8
|
+
import { detLog } from "../random/log.js";
|
|
9
|
+
import { RandomStream, resolveSeed } from "../random/stream.js";
|
|
10
|
+
import { detCosSinTurn } from "../random/trig.js";
|
|
11
|
+
import { type SampleGraph } from "../types.js";
|
|
12
|
+
import { checkInt, EdgeBuffer, toGraph } from "./util.js";
|
|
13
|
+
import { applyWeights, type WeightOptions } from "./weights.js";
|
|
14
|
+
|
|
15
|
+
/** The largest node count of the O(n^2) pair loop. */
|
|
16
|
+
const MAX_NODES = 20000;
|
|
17
|
+
|
|
18
|
+
/** Options of {@link hyperbolicGraph}. */
|
|
19
|
+
export interface HyperbolicOptions extends WeightOptions {
|
|
20
|
+
/** The node count, in [0, 20000]. */
|
|
21
|
+
n: number;
|
|
22
|
+
/** The target mean degree, a finite number > 0 (approximate: see {@link hyperbolicGraph}). */
|
|
23
|
+
averageDegree: number;
|
|
24
|
+
/** The power-law exponent gamma of the degree distribution, a finite number > 2. */
|
|
25
|
+
exponent: number;
|
|
26
|
+
/** The temperature T in [0, 1); 0 (default) is the threshold model, higher T lowers clustering. */
|
|
27
|
+
temperature?: number | undefined;
|
|
28
|
+
/** The seed, an integer in [0, 2^53); default 0. */
|
|
29
|
+
seed?: number | undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The checked options, the disk radius and the points. */
|
|
33
|
+
interface HyperbolicPlan {
|
|
34
|
+
readonly n: number;
|
|
35
|
+
readonly seed: number;
|
|
36
|
+
readonly temperature: number;
|
|
37
|
+
/** The disk radius R. */
|
|
38
|
+
readonly R: number;
|
|
39
|
+
readonly coshR: number;
|
|
40
|
+
readonly cosT: Float64Array<ArrayBuffer>;
|
|
41
|
+
readonly sinT: Float64Array<ArrayBuffer>;
|
|
42
|
+
readonly coshr: Float64Array<ArrayBuffer>;
|
|
43
|
+
readonly sinhr: Float64Array<ArrayBuffer>;
|
|
44
|
+
readonly x: Float64Array<ArrayBuffer>;
|
|
45
|
+
readonly y: Float64Array<ArrayBuffer>;
|
|
46
|
+
readonly radius: Float64Array<ArrayBuffer>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* cosh(x) from detExp.
|
|
51
|
+
* @param x - the argument
|
|
52
|
+
* @returns cosh x
|
|
53
|
+
*/
|
|
54
|
+
function cosh(x: number): number {
|
|
55
|
+
return (detExp(x) + detExp(-x)) / 2;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* acosh(y) for y >= 1 from detLog.
|
|
60
|
+
* @param y - the argument
|
|
61
|
+
* @returns acosh y
|
|
62
|
+
*/
|
|
63
|
+
function acosh(y: number): number {
|
|
64
|
+
return detLog(y + Math.sqrt((y - 1) * (y + 1)));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check the options, compute the disk radius and draw the points.
|
|
69
|
+
* @param options - the options
|
|
70
|
+
* @returns the plan
|
|
71
|
+
*/
|
|
72
|
+
export function planHyperbolic(options: HyperbolicOptions): HyperbolicPlan {
|
|
73
|
+
const { n, averageDegree, exponent } = options;
|
|
74
|
+
const temperature = options.temperature ?? 0;
|
|
75
|
+
checkInt("n", n, 0, MAX_NODES);
|
|
76
|
+
if (!(Number.isFinite(averageDegree) && averageDegree > 0)) {
|
|
77
|
+
throw new RangeError(`averageDegree must be a finite number > 0, got ${String(averageDegree)}`);
|
|
78
|
+
}
|
|
79
|
+
if (!(Number.isFinite(exponent) && exponent > 2)) {
|
|
80
|
+
throw new RangeError(`exponent must be a finite number > 2, got ${String(exponent)}`);
|
|
81
|
+
}
|
|
82
|
+
if (!(temperature >= 0 && temperature < 1)) {
|
|
83
|
+
throw new RangeError(`temperature must be in [0, 1), got ${String(temperature)}`);
|
|
84
|
+
}
|
|
85
|
+
const seed = resolveSeed(options.seed);
|
|
86
|
+
|
|
87
|
+
const alpha = (exponent - 1) / 2;
|
|
88
|
+
const xi = alpha / (alpha - 0.5);
|
|
89
|
+
let correction = 1;
|
|
90
|
+
if (temperature > 0) {
|
|
91
|
+
const cs = new Float64Array(2);
|
|
92
|
+
detCosSinTurn(temperature / 2, cs);
|
|
93
|
+
correction = (Math.PI * temperature) / cs[1];
|
|
94
|
+
}
|
|
95
|
+
const scale = ((2 * xi * xi * n) / (Math.PI * averageDegree)) * correction;
|
|
96
|
+
if (n >= 2 && !(scale > 1)) {
|
|
97
|
+
throw new RangeError(`averageDegree ${averageDegree} is too large for n = ${n}: the disk radius would be <= 0`);
|
|
98
|
+
}
|
|
99
|
+
const R = n >= 2 ? 2 * detLog(scale) : 0;
|
|
100
|
+
const coshAlphaR = cosh(alpha * R);
|
|
101
|
+
if (!Number.isFinite(coshAlphaR)) {
|
|
102
|
+
throw new RangeError(`exponent ${exponent} is too large: cosh(alpha R) overflows`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const cosT = new Float64Array(n);
|
|
106
|
+
const sinT = new Float64Array(n);
|
|
107
|
+
const coshr = new Float64Array(n);
|
|
108
|
+
const sinhr = new Float64Array(n);
|
|
109
|
+
const x = new Float64Array(n);
|
|
110
|
+
const y = new Float64Array(n);
|
|
111
|
+
const radius = new Float64Array(n);
|
|
112
|
+
const cs = new Float64Array(2);
|
|
113
|
+
const stream = new RandomStream(seed, "hyperbolic-points", 0);
|
|
114
|
+
for (let i = 0; i < n; i++) {
|
|
115
|
+
stream.reset(i);
|
|
116
|
+
detCosSinTurn(stream.nextFloat(), cs);
|
|
117
|
+
const r = acosh(1 + (coshAlphaR - 1) * stream.nextFloat()) / alpha;
|
|
118
|
+
const er = detExp(r);
|
|
119
|
+
cosT[i] = cs[0];
|
|
120
|
+
sinT[i] = cs[1];
|
|
121
|
+
coshr[i] = (er + 1 / er) / 2;
|
|
122
|
+
sinhr[i] = (er - 1 / er) / 2;
|
|
123
|
+
radius[i] = r;
|
|
124
|
+
x[i] = r * cs[0];
|
|
125
|
+
y[i] = r * cs[1];
|
|
126
|
+
}
|
|
127
|
+
return { n, seed, temperature, R, coshR: cosh(R), cosT, sinT, coshr, sinhr, x, y, radius };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Rows [start, end) of the hyperbolic graph: row u holds the pairs (u, v), v = u + 1 .. n - 1 in
|
|
132
|
+
* ascending v, with cosh d = cosh r_u cosh r_v - sinh r_u sinh r_v cos(theta_u - theta_v) (the
|
|
133
|
+
* cosine of the angle difference expanded from the stored cosines and sines). At T = 0 the pair is
|
|
134
|
+
* an edge iff cosh d < cosh R (no draws). At T > 0 row u draws one nextFloat() t per pair from
|
|
135
|
+
* stream (seed, "hyperbolic", u) and the pair is an edge iff t < 1 / (1 + exp((d - R) / (2 T))),
|
|
136
|
+
* decided as acosh(cosh d) < R + 2 T ln((1 - t) / t) with no exp. Any split of [0, n) into
|
|
137
|
+
* consecutive ranges gives the whole graph.
|
|
138
|
+
* @param plan - the checked options and points
|
|
139
|
+
* @param start - the first row
|
|
140
|
+
* @param end - one past the last row
|
|
141
|
+
* @param out - receives the edges
|
|
142
|
+
*/
|
|
143
|
+
export function hyperbolicRows(plan: HyperbolicPlan, start: number, end: number, out: EdgeBuffer): void {
|
|
144
|
+
const { n, R, coshR, temperature, cosT, sinT, coshr, sinhr } = plan;
|
|
145
|
+
const stream = new RandomStream(plan.seed, "hyperbolic", 0);
|
|
146
|
+
for (let u = start; u < end; u++) {
|
|
147
|
+
stream.reset(u);
|
|
148
|
+
for (let v = u + 1; v < n; v++) {
|
|
149
|
+
const coshD = coshr[u] * coshr[v] - sinhr[u] * sinhr[v] * (cosT[u] * cosT[v] + sinT[u] * sinT[v]);
|
|
150
|
+
if (temperature === 0) {
|
|
151
|
+
if (coshD < coshR) {
|
|
152
|
+
out.push(u, v);
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const t = stream.nextFloat();
|
|
157
|
+
if (acosh(Math.max(1, coshD)) < R + 2 * temperature * detLog((1 - t) / t)) {
|
|
158
|
+
out.push(u, v);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* A random hyperbolic graph (Krioukov et al. 2010): n points in a hyperbolic disk of radius R,
|
|
166
|
+
* angles uniform and radii with density proportional to sinh(alpha r), alpha = (gamma - 1) / 2,
|
|
167
|
+
* so the degrees follow a power law with exponent gamma. At temperature 0 two nodes are joined iff
|
|
168
|
+
* their hyperbolic distance is below R; at T > 0 with probability 1 / (1 + exp((d - R) / (2 T))).
|
|
169
|
+
*
|
|
170
|
+
* R comes from the paper's approximation of the mean degree, R = 2 ln(2 xi^2 n / (pi k)) with
|
|
171
|
+
* xi = alpha / (alpha - 1/2), times (pi T / sin(pi T)) inside the logarithm for T > 0. It is an
|
|
172
|
+
* approximation, so the measured mean degree only lands near `averageDegree`: measured at n = 3000
|
|
173
|
+
* and 10000, within about 10% for exponent >= 2.5 and T <= 0.7, but about 0.6x at exponent 2.2 and
|
|
174
|
+
* about 0.5x at T = 0.9 (the approximation degrades as gamma approaches 2 and T approaches 1).
|
|
175
|
+
*
|
|
176
|
+
* Node i draws its angle theta = 2 pi u and then its radius r = acosh(1 + (cosh(alpha R) - 1) u') /
|
|
177
|
+
* alpha (inverse CDF) from stream (seed, "hyperbolic-points", i); the pairs are decided by
|
|
178
|
+
* {@link hyperbolicRows}. Edges are the pairs (u, v), u < v, ascending u then v. Node columns (all
|
|
179
|
+
* Float64Array): `x`, `y` (the native polar embedding r cos theta, r sin theta) and `radius` (r).
|
|
180
|
+
*
|
|
181
|
+
* Cost: O(n^2) pairs (and one draw per pair at T > 0), so n is capped at 20000.
|
|
182
|
+
* ponytail: naive pair loop, n <= 20000; the band algorithm of M. von Looz, H. Meyerhenke and
|
|
183
|
+
* R. Prutkin, "Generating random hyperbolic graphs in subquadratic time", ISAAC 2015,
|
|
184
|
+
* doi:10.1007/978-3-662-48971-0_40, is the upgrade path.
|
|
185
|
+
* @param options - n, averageDegree, exponent, temperature and seed
|
|
186
|
+
* @returns the undirected graph
|
|
187
|
+
*/
|
|
188
|
+
export function hyperbolicGraph(options: HyperbolicOptions): SampleGraph {
|
|
189
|
+
const plan = planHyperbolic(options);
|
|
190
|
+
const out = new EdgeBuffer(Math.ceil(plan.n * options.averageDegree * 0.75) + 16);
|
|
191
|
+
hyperbolicRows(plan, 0, plan.n, out);
|
|
192
|
+
return applyWeights(toGraph(plan.n, out, false, { x: plan.x, y: plan.y, radius: plan.radius }), options);
|
|
193
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@graphty/graph-samples/generators`: every graph generator. Each returns a {@link SampleGraph}
|
|
3
|
+
* (typed arrays that `fromEdgeArrays` of @graphty/graph-format loads directly). The random ones
|
|
4
|
+
* take an optional `seed` (default 0) and produce the same graph for the same options on every platform and
|
|
5
|
+
* every version of this package.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { type SampleGraph } from "../types.js";
|
|
9
|
+
export { randomBipartiteGraph, type RandomBipartiteOptions } from "./bipartite.js";
|
|
10
|
+
export {
|
|
11
|
+
plantedPartitionGraph,
|
|
12
|
+
type PlantedPartitionOptions,
|
|
13
|
+
stochasticBlockModelGraph,
|
|
14
|
+
type StochasticBlockModelOptions,
|
|
15
|
+
} from "./block-model.js";
|
|
16
|
+
export {
|
|
17
|
+
balancedTreeGraph,
|
|
18
|
+
barbellGraph,
|
|
19
|
+
cavemanGraph,
|
|
20
|
+
circularLadderGraph,
|
|
21
|
+
completeBipartiteGraph,
|
|
22
|
+
completeGraph,
|
|
23
|
+
completeMultipartiteGraph,
|
|
24
|
+
connectedCavemanGraph,
|
|
25
|
+
cycleGraph,
|
|
26
|
+
emptyGraph,
|
|
27
|
+
hypercubeGraph,
|
|
28
|
+
ladderGraph,
|
|
29
|
+
lollipopGraph,
|
|
30
|
+
mobiusLadderGraph,
|
|
31
|
+
pathGraph,
|
|
32
|
+
petersenGraph,
|
|
33
|
+
ringOfCliquesGraph,
|
|
34
|
+
starGraph,
|
|
35
|
+
wheelGraph,
|
|
36
|
+
} from "./classic.js";
|
|
37
|
+
export {
|
|
38
|
+
bipartiteConfigurationModelGraph,
|
|
39
|
+
type BipartiteConfigurationModelOptions,
|
|
40
|
+
chungLuGraph,
|
|
41
|
+
type ChungLuOptions,
|
|
42
|
+
configurationModelGraph,
|
|
43
|
+
type ConfigurationModelOptions,
|
|
44
|
+
degreeCorrectedSbmGraph,
|
|
45
|
+
type DegreeCorrectedSbmOptions,
|
|
46
|
+
directedConfigurationModelGraph,
|
|
47
|
+
type DirectedConfigurationModelOptions,
|
|
48
|
+
type EdgePolicy,
|
|
49
|
+
powerLawDegreeSequence,
|
|
50
|
+
type PowerLawDegreeSequenceOptions,
|
|
51
|
+
randomRegularGraph,
|
|
52
|
+
type RandomRegularOptions,
|
|
53
|
+
} from "./degree-sequence.js";
|
|
54
|
+
export {
|
|
55
|
+
kroneckerGraph,
|
|
56
|
+
type KroneckerOptions,
|
|
57
|
+
priceGraph,
|
|
58
|
+
type PriceOptions,
|
|
59
|
+
randomOrderDagGraph,
|
|
60
|
+
type RandomOrderDagOptions,
|
|
61
|
+
rmatGraph,
|
|
62
|
+
type RmatOptions,
|
|
63
|
+
} from "./directed.js";
|
|
64
|
+
export {
|
|
65
|
+
erdosRenyiGnmGraph,
|
|
66
|
+
type ErdosRenyiGnmOptions,
|
|
67
|
+
erdosRenyiGraph,
|
|
68
|
+
type ErdosRenyiOptions,
|
|
69
|
+
} from "./erdos-renyi.js";
|
|
70
|
+
export {
|
|
71
|
+
akGraph,
|
|
72
|
+
type AkOptions,
|
|
73
|
+
type FlowNetwork,
|
|
74
|
+
genrmfGraph,
|
|
75
|
+
type GenrmfOptions,
|
|
76
|
+
gridFlowNetwork,
|
|
77
|
+
type GridFlowOptions,
|
|
78
|
+
layeredFlowNetwork,
|
|
79
|
+
type LayeredFlowOptions,
|
|
80
|
+
} from "./flow.js";
|
|
81
|
+
export {
|
|
82
|
+
knnGraph,
|
|
83
|
+
type KnnOptions,
|
|
84
|
+
randomGeometricGraph,
|
|
85
|
+
type RandomGeometricOptions,
|
|
86
|
+
waxmanGraph,
|
|
87
|
+
type WaxmanOptions,
|
|
88
|
+
} from "./geometric.js";
|
|
89
|
+
export {
|
|
90
|
+
bianconiBarabasiGraph,
|
|
91
|
+
type BianconiBarabasiOptions,
|
|
92
|
+
duplicationDivergenceGraph,
|
|
93
|
+
type DuplicationDivergenceOptions,
|
|
94
|
+
forestFireGraph,
|
|
95
|
+
type ForestFireOptions,
|
|
96
|
+
newmanWattsGraph,
|
|
97
|
+
type NewmanWattsOptions,
|
|
98
|
+
randomApollonianGraph,
|
|
99
|
+
type RandomApollonianOptions,
|
|
100
|
+
randomRecursiveTreeGraph,
|
|
101
|
+
type RandomRecursiveTreeOptions,
|
|
102
|
+
wilsonMazeGraph,
|
|
103
|
+
type WilsonMazeOptions,
|
|
104
|
+
} from "./growth.js";
|
|
105
|
+
export { hyperbolicGraph, type HyperbolicOptions } from "./hyperbolic.js";
|
|
106
|
+
export {
|
|
107
|
+
grid3dGraph,
|
|
108
|
+
type Grid3dOptions,
|
|
109
|
+
gridGraph,
|
|
110
|
+
type GridOptions,
|
|
111
|
+
hexagonalLatticeGraph,
|
|
112
|
+
type PlanarLatticeOptions,
|
|
113
|
+
triangularLatticeGraph,
|
|
114
|
+
} from "./lattices.js";
|
|
115
|
+
export { lfrGraph, type LfrOptions } from "./lfr.js";
|
|
116
|
+
export { NAMED_GRAPH_NAMES, namedGraph, type NamedGraphName } from "./named.js";
|
|
117
|
+
export {
|
|
118
|
+
barabasiAlbertGraph,
|
|
119
|
+
type BarabasiAlbertOptions,
|
|
120
|
+
wattsStrogatzGraph,
|
|
121
|
+
type WattsStrogatzOptions,
|
|
122
|
+
} from "./preferential-attachment.js";
|
|
123
|
+
export { randomDagGraph, type RandomDagOptions, randomTreeGraph, type RandomTreeOptions } from "./trees-and-dags.js";
|
|
124
|
+
export {
|
|
125
|
+
addPathologicalEdges,
|
|
126
|
+
EDGE_CASE_NAMES,
|
|
127
|
+
edgeCaseGraph,
|
|
128
|
+
type EdgeCaseName,
|
|
129
|
+
type PathologicalEdgeOptions,
|
|
130
|
+
randomMultigraph,
|
|
131
|
+
type RandomMultigraphOptions,
|
|
132
|
+
} from "./variants.js";
|
|
133
|
+
export { type ColumnCombine, type WeightOptions, type WeightSpec, withWeights } from "./weights.js";
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lattices: the square and cubic grids (with torus wrap-around, diagonal neighbours, forward-only
|
|
3
|
+
* arcs, random obstacles and position columns), the triangular lattice and the hexagonal
|
|
4
|
+
* (honeycomb) lattice. All deterministic except the obstacles, which draw from stream
|
|
5
|
+
* (seed, "grid-obstacles", node).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { RandomStream, resolveSeed } from "../random/stream.js";
|
|
9
|
+
import { type SampleGraph } from "../types.js";
|
|
10
|
+
import { checkEdgeCount, checkInt, checkProbability, EdgeBuffer, toGraph } from "./util.js";
|
|
11
|
+
import { applyWeights, type WeightOptions } from "./weights.js";
|
|
12
|
+
|
|
13
|
+
/** Options of {@link grid3dGraph}. */
|
|
14
|
+
export interface Grid3dOptions extends WeightOptions {
|
|
15
|
+
/** The number of rows, >= 1. */
|
|
16
|
+
rows: number;
|
|
17
|
+
/** The number of columns, >= 1. */
|
|
18
|
+
cols: number;
|
|
19
|
+
/** The number of layers, >= 1. */
|
|
20
|
+
layers: number;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap around (a torus): the last node of each row, column and layer is joined to the first.
|
|
23
|
+
* A dimension shorter than 3 does not wrap, so the graph stays simple.
|
|
24
|
+
*/
|
|
25
|
+
periodic?: boolean | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Join diagonal neighbours too: the king's graph (8 neighbours) in 2D, the 26-neighbour lattice
|
|
28
|
+
* in 3D.
|
|
29
|
+
*/
|
|
30
|
+
diagonals?: boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Emit each edge once as an arc from the lower index to the higher: a DAG whose only source is
|
|
33
|
+
* node 0 and only sink node n - 1. Not with `periodic`.
|
|
34
|
+
*/
|
|
35
|
+
directed?: boolean | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Block each node independently with this probability, in [0, 1): a blocked node keeps its
|
|
38
|
+
* index (and position) but has no edges, and the u8 node column `blocked` marks it (1).
|
|
39
|
+
*/
|
|
40
|
+
obstacles?: number | undefined;
|
|
41
|
+
/** Emit Float64 node columns `x` (column), `y` (row) and, when layers > 1, `z` (layer). */
|
|
42
|
+
positions?: boolean | undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Options of {@link gridGraph}: {@link Grid3dOptions} without layers. */
|
|
46
|
+
export type GridOptions = Omit<Grid3dOptions, "layers">;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The neighbour offsets (dc, dr, dl) a node links forward to, in edge order: +column, +row,
|
|
50
|
+
* +layer, then (with diagonals) every other offset in {-1, 0, 1}^3 that is lexicographically
|
|
51
|
+
* positive in (dl, dr, dc), ordered by dl, then dr, then dc.
|
|
52
|
+
* @param diagonals - whether to include the diagonal offsets
|
|
53
|
+
* @returns the offsets
|
|
54
|
+
*/
|
|
55
|
+
function forwardOffsets(diagonals: boolean): number[][] {
|
|
56
|
+
const offsets = [
|
|
57
|
+
[1, 0, 0],
|
|
58
|
+
[0, 1, 0],
|
|
59
|
+
[0, 0, 1],
|
|
60
|
+
];
|
|
61
|
+
if (diagonals) {
|
|
62
|
+
for (let dl = 0; dl <= 1; dl++) {
|
|
63
|
+
for (let dr = -1; dr <= 1; dr++) {
|
|
64
|
+
for (let dc = -1; dc <= 1; dc++) {
|
|
65
|
+
const positive = dl > 0 || (dl === 0 && (dr > 0 || (dr === 0 && dc > 0)));
|
|
66
|
+
const axis = Math.abs(dc) + Math.abs(dr) + Math.abs(dl) === 1;
|
|
67
|
+
if (positive && !axis) {
|
|
68
|
+
offsets.push([dc, dr, dl]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return offsets;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The rows x cols x layers grid. Node (l, r, c) is index (l * rows + r) * cols + c. For each node
|
|
79
|
+
* in index order, the edge to each forward neighbour in the order of the offsets: +column, +row,
|
|
80
|
+
* +layer, then the diagonals. Without options this is the 6-neighbour lattice of phase 1, edge for
|
|
81
|
+
* edge. Obstacles draw one float per node from stream (seed, "grid-obstacles", node) -- node < p
|
|
82
|
+
* blocks it -- so the obstacle map does not depend on the other options.
|
|
83
|
+
* @param options - sizes and the lattice options
|
|
84
|
+
* @returns the graph
|
|
85
|
+
*/
|
|
86
|
+
export function grid3dGraph(options: Grid3dOptions): SampleGraph {
|
|
87
|
+
const { rows, cols, layers } = options;
|
|
88
|
+
checkInt("rows", rows, 1);
|
|
89
|
+
checkInt("cols", cols, 1);
|
|
90
|
+
checkInt("layers", layers, 1);
|
|
91
|
+
const n = rows * cols * layers;
|
|
92
|
+
checkInt("rows * cols * layers", n, 1);
|
|
93
|
+
const periodic = options.periodic === true;
|
|
94
|
+
const directed = options.directed === true;
|
|
95
|
+
if (periodic && directed) {
|
|
96
|
+
throw new RangeError("directed grids cannot be periodic: the wrap-around arcs would close cycles");
|
|
97
|
+
}
|
|
98
|
+
const offsets = forwardOffsets(options.diagonals === true);
|
|
99
|
+
checkEdgeCount(n * offsets.length);
|
|
100
|
+
let blocked: Uint8Array<ArrayBuffer> | null = null;
|
|
101
|
+
if (options.obstacles !== undefined) {
|
|
102
|
+
const p = options.obstacles;
|
|
103
|
+
checkProbability("obstacles", p);
|
|
104
|
+
if (p >= 1) {
|
|
105
|
+
throw new RangeError("obstacles must be below 1");
|
|
106
|
+
}
|
|
107
|
+
blocked = new Uint8Array(n);
|
|
108
|
+
const stream = new RandomStream(resolveSeed(options.seed), "grid-obstacles", 0);
|
|
109
|
+
for (let i = 0; i < n; i++) {
|
|
110
|
+
stream.reset(i);
|
|
111
|
+
blocked[i] = stream.nextFloat() < p ? 1 : 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const sizes = [cols, rows, layers];
|
|
115
|
+
const wraps = sizes.map((size) => periodic && size >= 3);
|
|
116
|
+
const plane = rows * cols;
|
|
117
|
+
const out = new EdgeBuffer(n * Math.min(offsets.length, 3));
|
|
118
|
+
const at = [0, 0, 0];
|
|
119
|
+
for (let l = 0; l < layers; l++) {
|
|
120
|
+
for (let r = 0; r < rows; r++) {
|
|
121
|
+
for (let c = 0; c < cols; c++) {
|
|
122
|
+
const i = l * plane + r * cols + c;
|
|
123
|
+
if (blocked?.[i] === 1) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const here = [c, r, l];
|
|
127
|
+
for (const offset of offsets) {
|
|
128
|
+
let inside = true;
|
|
129
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
130
|
+
let x = here[axis] + offset[axis];
|
|
131
|
+
if (x < 0 || x >= sizes[axis]) {
|
|
132
|
+
if (!wraps[axis]) {
|
|
133
|
+
inside = false;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
x = (x + sizes[axis]) % sizes[axis];
|
|
137
|
+
}
|
|
138
|
+
at[axis] = x;
|
|
139
|
+
}
|
|
140
|
+
if (!inside) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const j = at[2] * plane + at[1] * cols + at[0];
|
|
144
|
+
if (blocked?.[j] === 1) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
out.push(directed && j < i ? j : i, directed && j < i ? i : j);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const columns: Record<string, Uint8Array<ArrayBuffer> | Float64Array<ArrayBuffer>> = {};
|
|
153
|
+
if (blocked !== null) {
|
|
154
|
+
columns.blocked = blocked;
|
|
155
|
+
}
|
|
156
|
+
if (options.positions === true) {
|
|
157
|
+
const x = new Float64Array(n);
|
|
158
|
+
const y = new Float64Array(n);
|
|
159
|
+
const z = layers > 1 ? new Float64Array(n) : null;
|
|
160
|
+
for (let i = 0; i < n; i++) {
|
|
161
|
+
x[i] = i % cols;
|
|
162
|
+
y[i] = Math.floor(i / cols) % rows;
|
|
163
|
+
if (z !== null) {
|
|
164
|
+
z[i] = Math.floor(i / plane);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
columns.x = x;
|
|
168
|
+
columns.y = y;
|
|
169
|
+
if (z !== null) {
|
|
170
|
+
columns.z = z;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
const graph = toGraph(n, out, directed, Object.keys(columns).length > 0 ? columns : undefined);
|
|
174
|
+
return applyWeights(graph, options);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The rows x cols grid: {@link grid3dGraph} with one layer. Node (r, c) is index r * cols + c; for
|
|
179
|
+
* each node in index order, the edge to its right neighbour, then the one below, then (with
|
|
180
|
+
* diagonals) below-left and below-right.
|
|
181
|
+
* @param options - sizes and the lattice options
|
|
182
|
+
* @returns the graph
|
|
183
|
+
*/
|
|
184
|
+
export function gridGraph(options: GridOptions): SampleGraph {
|
|
185
|
+
return grid3dGraph({ ...options, layers: 1 });
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Options of {@link triangularLatticeGraph} and {@link hexagonalLatticeGraph}. */
|
|
189
|
+
export interface PlanarLatticeOptions extends WeightOptions {
|
|
190
|
+
/** The number of rows, >= 1. */
|
|
191
|
+
rows: number;
|
|
192
|
+
/** The number of columns, >= 1. */
|
|
193
|
+
cols: number;
|
|
194
|
+
/** Emit Float64 node columns `x` and `y` placing every edge at unit length. */
|
|
195
|
+
positions?: boolean | undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const HALF_SQRT3 = 0.8660254037844386;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Check the sizes of a planar lattice.
|
|
202
|
+
* @param options - the options
|
|
203
|
+
* @returns the node count
|
|
204
|
+
*/
|
|
205
|
+
function planarSize(options: PlanarLatticeOptions): number {
|
|
206
|
+
checkInt("rows", options.rows, 1);
|
|
207
|
+
checkInt("cols", options.cols, 1);
|
|
208
|
+
const n = options.rows * options.cols;
|
|
209
|
+
checkInt("rows * cols", n, 1);
|
|
210
|
+
checkEdgeCount(3 * n);
|
|
211
|
+
return n;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The triangular lattice as a triangulated rows x cols grid: node (r, c) is index r * cols + c and
|
|
216
|
+
* links to (r, c + 1), (r + 1, c) and (r + 1, c - 1), in that order, for each node in index order.
|
|
217
|
+
* Interior nodes have degree 6. Positions shear the grid into a parallelogram of equilateral
|
|
218
|
+
* triangles: x = c + r / 2, y = r sqrt(3) / 2.
|
|
219
|
+
* @param options - rows, cols, positions
|
|
220
|
+
* @returns the undirected graph
|
|
221
|
+
*/
|
|
222
|
+
export function triangularLatticeGraph(options: PlanarLatticeOptions): SampleGraph {
|
|
223
|
+
const n = planarSize(options);
|
|
224
|
+
const { rows, cols } = options;
|
|
225
|
+
const out = new EdgeBuffer(3 * n);
|
|
226
|
+
for (let r = 0; r < rows; r++) {
|
|
227
|
+
for (let c = 0; c < cols; c++) {
|
|
228
|
+
const i = r * cols + c;
|
|
229
|
+
if (c + 1 < cols) {
|
|
230
|
+
out.push(i, i + 1);
|
|
231
|
+
}
|
|
232
|
+
if (r + 1 < rows) {
|
|
233
|
+
out.push(i, i + cols);
|
|
234
|
+
if (c > 0) {
|
|
235
|
+
out.push(i, i + cols - 1);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
let columns: SampleGraph["nodeColumns"];
|
|
241
|
+
if (options.positions === true) {
|
|
242
|
+
const x = new Float64Array(n);
|
|
243
|
+
const y = new Float64Array(n);
|
|
244
|
+
for (let i = 0; i < n; i++) {
|
|
245
|
+
const r = Math.floor(i / cols);
|
|
246
|
+
x[i] = (i % cols) + r / 2;
|
|
247
|
+
y[i] = r * HALF_SQRT3;
|
|
248
|
+
}
|
|
249
|
+
columns = { x, y };
|
|
250
|
+
}
|
|
251
|
+
return applyWeights(toGraph(n, out, false, columns), options);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The hexagonal (honeycomb) lattice in its brick-wall form: node (r, c) is index r * cols + c and
|
|
256
|
+
* links to (r, c + 1) always and to (r + 1, c) when r + c is even, in that order, for each node in
|
|
257
|
+
* index order. Interior nodes have degree 3; every face is a hexagon. Positions give unit edges:
|
|
258
|
+
* x = c sqrt(3) / 2, y = 1.5 r + (r + c even ? 0.5 : 0).
|
|
259
|
+
* @param options - rows, cols, positions
|
|
260
|
+
* @returns the undirected graph
|
|
261
|
+
*/
|
|
262
|
+
export function hexagonalLatticeGraph(options: PlanarLatticeOptions): SampleGraph {
|
|
263
|
+
const n = planarSize(options);
|
|
264
|
+
const { rows, cols } = options;
|
|
265
|
+
const out = new EdgeBuffer(2 * n);
|
|
266
|
+
for (let r = 0; r < rows; r++) {
|
|
267
|
+
for (let c = 0; c < cols; c++) {
|
|
268
|
+
const i = r * cols + c;
|
|
269
|
+
if (c + 1 < cols) {
|
|
270
|
+
out.push(i, i + 1);
|
|
271
|
+
}
|
|
272
|
+
if (r + 1 < rows && (r + c) % 2 === 0) {
|
|
273
|
+
out.push(i, i + cols);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
let columns: SampleGraph["nodeColumns"];
|
|
278
|
+
if (options.positions === true) {
|
|
279
|
+
const x = new Float64Array(n);
|
|
280
|
+
const y = new Float64Array(n);
|
|
281
|
+
for (let i = 0; i < n; i++) {
|
|
282
|
+
const r = Math.floor(i / cols);
|
|
283
|
+
const c = i % cols;
|
|
284
|
+
x[i] = c * HALF_SQRT3;
|
|
285
|
+
y[i] = 1.5 * r + ((r + c) % 2 === 0 ? 0.5 : 0);
|
|
286
|
+
}
|
|
287
|
+
columns = { x, y };
|
|
288
|
+
}
|
|
289
|
+
return applyWeights(toGraph(n, out, false, columns), options);
|
|
290
|
+
}
|