@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.
Files changed (407) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +123 -0
  3. package/README.md +190 -1
  4. package/dist/chunks/build-DdCe60t3.js +47 -0
  5. package/dist/chunks/build-DdCe60t3.js.map +1 -0
  6. package/dist/chunks/meta-B6toBzaa.js +19 -0
  7. package/dist/chunks/meta-B6toBzaa.js.map +1 -0
  8. package/dist/chunks/meta-BM_YIhlA.js +28 -0
  9. package/dist/chunks/meta-BM_YIhlA.js.map +1 -0
  10. package/dist/chunks/meta-BMmtUpPx.js +30 -0
  11. package/dist/chunks/meta-BMmtUpPx.js.map +1 -0
  12. package/dist/chunks/meta-BXC7oi86.js +22 -0
  13. package/dist/chunks/meta-BXC7oi86.js.map +1 -0
  14. package/dist/chunks/meta-BaFPvhc1.js +19 -0
  15. package/dist/chunks/meta-BaFPvhc1.js.map +1 -0
  16. package/dist/chunks/meta-C58v1Oy0.js +28 -0
  17. package/dist/chunks/meta-C58v1Oy0.js.map +1 -0
  18. package/dist/chunks/meta-CQRXyexG.js +23 -0
  19. package/dist/chunks/meta-CQRXyexG.js.map +1 -0
  20. package/dist/chunks/meta-DrgM1eS0.js +23 -0
  21. package/dist/chunks/meta-DrgM1eS0.js.map +1 -0
  22. package/dist/chunks/meta-IhoaDXAV.js +19 -0
  23. package/dist/chunks/meta-IhoaDXAV.js.map +1 -0
  24. package/dist/chunks/meta-MQPbBUUB.js +29 -0
  25. package/dist/chunks/meta-MQPbBUUB.js.map +1 -0
  26. package/dist/chunks/meta-Qp4HNYAZ.js +24 -0
  27. package/dist/chunks/meta-Qp4HNYAZ.js.map +1 -0
  28. package/dist/chunks/meta-mns0uFIW.js +19 -0
  29. package/dist/chunks/meta-mns0uFIW.js.map +1 -0
  30. package/dist/datasets/celegans-neural.d.ts +1 -0
  31. package/dist/datasets/celegans-neural.js +7359 -0
  32. package/dist/datasets/celegans-neural.js.map +1 -0
  33. package/dist/datasets/contiguous-usa.d.ts +1 -0
  34. package/dist/datasets/contiguous-usa.js +501 -0
  35. package/dist/datasets/contiguous-usa.js.map +1 -0
  36. package/dist/datasets/davis-southern-women.d.ts +1 -0
  37. package/dist/datasets/davis-southern-women.js +235 -0
  38. package/dist/datasets/davis-southern-women.js.map +1 -0
  39. package/dist/datasets/dolphins.d.ts +1 -0
  40. package/dist/datasets/dolphins.js +406 -0
  41. package/dist/datasets/dolphins.js.map +1 -0
  42. package/dist/datasets/florentine-families.d.ts +1 -0
  43. package/dist/datasets/florentine-families.js +75 -0
  44. package/dist/datasets/florentine-families.js.map +1 -0
  45. package/dist/datasets/football.d.ts +1 -0
  46. package/dist/datasets/football.js +1508 -0
  47. package/dist/datasets/football.js.map +1 -0
  48. package/dist/datasets/karate.d.ts +1 -0
  49. package/dist/datasets/karate.js +295 -0
  50. package/dist/datasets/karate.js.map +1 -0
  51. package/dist/datasets/knuth-miles.d.ts +1 -0
  52. package/dist/datasets/knuth-miles.js +24933 -0
  53. package/dist/datasets/knuth-miles.js.map +1 -0
  54. package/dist/datasets/les-miserables.d.ts +1 -0
  55. package/dist/datasets/les-miserables.js +860 -0
  56. package/dist/datasets/les-miserables.js.map +1 -0
  57. package/dist/datasets/openflights.d.ts +1 -0
  58. package/dist/datasets/openflights.js +130277 -0
  59. package/dist/datasets/openflights.js.map +1 -0
  60. package/dist/datasets/political-blogs.d.ts +1 -0
  61. package/dist/datasets/political-blogs.js +42551 -0
  62. package/dist/datasets/political-blogs.js.map +1 -0
  63. package/dist/datasets/political-books.d.ts +1 -0
  64. package/dist/datasets/political-books.js +1124 -0
  65. package/dist/datasets/political-books.js.map +1 -0
  66. package/dist/generators.d.ts +1 -0
  67. package/dist/generators.js +4496 -0
  68. package/dist/generators.js.map +1 -0
  69. package/dist/graph-samples.d.ts +1 -0
  70. package/dist/graph-samples.js +142 -0
  71. package/dist/graph-samples.js.map +1 -0
  72. package/dist/src/datasets/build.d.ts +89 -0
  73. package/dist/src/datasets/build.d.ts.map +1 -0
  74. package/dist/src/datasets/build.js +53 -0
  75. package/dist/src/datasets/build.js.map +1 -0
  76. package/dist/src/datasets/catalog.d.ts +8 -0
  77. package/dist/src/datasets/catalog.d.ts.map +1 -0
  78. package/dist/src/datasets/catalog.js +34 -0
  79. package/dist/src/datasets/catalog.js.map +1 -0
  80. package/dist/src/datasets/celegans-neural/data.d.ts +3 -0
  81. package/dist/src/datasets/celegans-neural/data.d.ts.map +1 -0
  82. package/dist/src/datasets/celegans-neural/data.js +573 -0
  83. package/dist/src/datasets/celegans-neural/data.js.map +1 -0
  84. package/dist/src/datasets/celegans-neural/index.d.ts +11 -0
  85. package/dist/src/datasets/celegans-neural/index.d.ts.map +1 -0
  86. package/dist/src/datasets/celegans-neural/index.js +14 -0
  87. package/dist/src/datasets/celegans-neural/index.js.map +1 -0
  88. package/dist/src/datasets/celegans-neural/meta.d.ts +4 -0
  89. package/dist/src/datasets/celegans-neural/meta.d.ts.map +1 -0
  90. package/dist/src/datasets/celegans-neural/meta.js +21 -0
  91. package/dist/src/datasets/celegans-neural/meta.js.map +1 -0
  92. package/dist/src/datasets/contiguous-usa/data.d.ts +3 -0
  93. package/dist/src/datasets/contiguous-usa/data.d.ts.map +1 -0
  94. package/dist/src/datasets/contiguous-usa/data.js +162 -0
  95. package/dist/src/datasets/contiguous-usa/data.js.map +1 -0
  96. package/dist/src/datasets/contiguous-usa/index.d.ts +11 -0
  97. package/dist/src/datasets/contiguous-usa/index.d.ts.map +1 -0
  98. package/dist/src/datasets/contiguous-usa/index.js +14 -0
  99. package/dist/src/datasets/contiguous-usa/index.js.map +1 -0
  100. package/dist/src/datasets/contiguous-usa/meta.d.ts +4 -0
  101. package/dist/src/datasets/contiguous-usa/meta.d.ts.map +1 -0
  102. package/dist/src/datasets/contiguous-usa/meta.js +27 -0
  103. package/dist/src/datasets/contiguous-usa/meta.js.map +1 -0
  104. package/dist/src/datasets/davis-southern-women/data.d.ts +3 -0
  105. package/dist/src/datasets/davis-southern-women/data.d.ts.map +1 -0
  106. package/dist/src/datasets/davis-southern-women/data.js +57 -0
  107. package/dist/src/datasets/davis-southern-women/data.js.map +1 -0
  108. package/dist/src/datasets/davis-southern-women/index.d.ts +11 -0
  109. package/dist/src/datasets/davis-southern-women/index.d.ts.map +1 -0
  110. package/dist/src/datasets/davis-southern-women/index.js +14 -0
  111. package/dist/src/datasets/davis-southern-women/index.js.map +1 -0
  112. package/dist/src/datasets/davis-southern-women/meta.d.ts +4 -0
  113. package/dist/src/datasets/davis-southern-women/meta.d.ts.map +1 -0
  114. package/dist/src/datasets/davis-southern-women/meta.js +17 -0
  115. package/dist/src/datasets/davis-southern-women/meta.js.map +1 -0
  116. package/dist/src/datasets/dolphins/data.d.ts +3 -0
  117. package/dist/src/datasets/dolphins/data.d.ts.map +1 -0
  118. package/dist/src/datasets/dolphins/data.js +93 -0
  119. package/dist/src/datasets/dolphins/data.js.map +1 -0
  120. package/dist/src/datasets/dolphins/index.d.ts +11 -0
  121. package/dist/src/datasets/dolphins/index.d.ts.map +1 -0
  122. package/dist/src/datasets/dolphins/index.js +14 -0
  123. package/dist/src/datasets/dolphins/index.js.map +1 -0
  124. package/dist/src/datasets/dolphins/meta.d.ts +4 -0
  125. package/dist/src/datasets/dolphins/meta.d.ts.map +1 -0
  126. package/dist/src/datasets/dolphins/meta.js +17 -0
  127. package/dist/src/datasets/dolphins/meta.js.map +1 -0
  128. package/dist/src/datasets/florentine-families/data.d.ts +3 -0
  129. package/dist/src/datasets/florentine-families/data.d.ts.map +1 -0
  130. package/dist/src/datasets/florentine-families/data.js +31 -0
  131. package/dist/src/datasets/florentine-families/data.js.map +1 -0
  132. package/dist/src/datasets/florentine-families/index.d.ts +11 -0
  133. package/dist/src/datasets/florentine-families/index.d.ts.map +1 -0
  134. package/dist/src/datasets/florentine-families/index.js +14 -0
  135. package/dist/src/datasets/florentine-families/index.js.map +1 -0
  136. package/dist/src/datasets/florentine-families/meta.d.ts +4 -0
  137. package/dist/src/datasets/florentine-families/meta.d.ts.map +1 -0
  138. package/dist/src/datasets/florentine-families/meta.js +17 -0
  139. package/dist/src/datasets/florentine-families/meta.js.map +1 -0
  140. package/dist/src/datasets/football/data.d.ts +3 -0
  141. package/dist/src/datasets/football/data.d.ts.map +1 -0
  142. package/dist/src/datasets/football/data.js +210 -0
  143. package/dist/src/datasets/football/data.js.map +1 -0
  144. package/dist/src/datasets/football/index.d.ts +11 -0
  145. package/dist/src/datasets/football/index.d.ts.map +1 -0
  146. package/dist/src/datasets/football/index.js +14 -0
  147. package/dist/src/datasets/football/index.js.map +1 -0
  148. package/dist/src/datasets/football/meta.d.ts +4 -0
  149. package/dist/src/datasets/football/meta.d.ts.map +1 -0
  150. package/dist/src/datasets/football/meta.js +17 -0
  151. package/dist/src/datasets/football/meta.js.map +1 -0
  152. package/dist/src/datasets/hosted.d.ts +7 -0
  153. package/dist/src/datasets/hosted.d.ts.map +1 -0
  154. package/dist/src/datasets/hosted.js +80 -0
  155. package/dist/src/datasets/hosted.js.map +1 -0
  156. package/dist/src/datasets/karate/data.d.ts +3 -0
  157. package/dist/src/datasets/karate/data.d.ts.map +1 -0
  158. package/dist/src/datasets/karate/data.js +30 -0
  159. package/dist/src/datasets/karate/data.js.map +1 -0
  160. package/dist/src/datasets/karate/index.d.ts +11 -0
  161. package/dist/src/datasets/karate/index.d.ts.map +1 -0
  162. package/dist/src/datasets/karate/index.js +14 -0
  163. package/dist/src/datasets/karate/index.js.map +1 -0
  164. package/dist/src/datasets/karate/meta.d.ts +4 -0
  165. package/dist/src/datasets/karate/meta.d.ts.map +1 -0
  166. package/dist/src/datasets/karate/meta.js +22 -0
  167. package/dist/src/datasets/karate/meta.js.map +1 -0
  168. package/dist/src/datasets/knuth-miles/data.d.ts +3 -0
  169. package/dist/src/datasets/knuth-miles/data.d.ts.map +1 -0
  170. package/dist/src/datasets/knuth-miles/data.js +1203 -0
  171. package/dist/src/datasets/knuth-miles/data.js.map +1 -0
  172. package/dist/src/datasets/knuth-miles/index.d.ts +11 -0
  173. package/dist/src/datasets/knuth-miles/index.d.ts.map +1 -0
  174. package/dist/src/datasets/knuth-miles/index.js +14 -0
  175. package/dist/src/datasets/knuth-miles/index.js.map +1 -0
  176. package/dist/src/datasets/knuth-miles/meta.d.ts +4 -0
  177. package/dist/src/datasets/knuth-miles/meta.d.ts.map +1 -0
  178. package/dist/src/datasets/knuth-miles/meta.js +26 -0
  179. package/dist/src/datasets/knuth-miles/meta.js.map +1 -0
  180. package/dist/src/datasets/les-miserables/data.d.ts +3 -0
  181. package/dist/src/datasets/les-miserables/data.d.ts.map +1 -0
  182. package/dist/src/datasets/les-miserables/data.js +117 -0
  183. package/dist/src/datasets/les-miserables/data.js.map +1 -0
  184. package/dist/src/datasets/les-miserables/index.d.ts +11 -0
  185. package/dist/src/datasets/les-miserables/index.d.ts.map +1 -0
  186. package/dist/src/datasets/les-miserables/index.js +14 -0
  187. package/dist/src/datasets/les-miserables/index.js.map +1 -0
  188. package/dist/src/datasets/les-miserables/meta.d.ts +4 -0
  189. package/dist/src/datasets/les-miserables/meta.d.ts.map +1 -0
  190. package/dist/src/datasets/les-miserables/meta.js +21 -0
  191. package/dist/src/datasets/les-miserables/meta.js.map +1 -0
  192. package/dist/src/datasets/openflights/data.d.ts +3 -0
  193. package/dist/src/datasets/openflights/data.d.ts.map +1 -0
  194. package/dist/src/datasets/openflights/data.js +15457 -0
  195. package/dist/src/datasets/openflights/data.js.map +1 -0
  196. package/dist/src/datasets/openflights/index.d.ts +11 -0
  197. package/dist/src/datasets/openflights/index.d.ts.map +1 -0
  198. package/dist/src/datasets/openflights/index.js +14 -0
  199. package/dist/src/datasets/openflights/index.js.map +1 -0
  200. package/dist/src/datasets/openflights/meta.d.ts +4 -0
  201. package/dist/src/datasets/openflights/meta.d.ts.map +1 -0
  202. package/dist/src/datasets/openflights/meta.js +28 -0
  203. package/dist/src/datasets/openflights/meta.js.map +1 -0
  204. package/dist/src/datasets/political-blogs/data.d.ts +3 -0
  205. package/dist/src/datasets/political-blogs/data.d.ts.map +1 -0
  206. package/dist/src/datasets/political-blogs/data.js +4857 -0
  207. package/dist/src/datasets/political-blogs/data.js.map +1 -0
  208. package/dist/src/datasets/political-blogs/index.d.ts +11 -0
  209. package/dist/src/datasets/political-blogs/index.d.ts.map +1 -0
  210. package/dist/src/datasets/political-blogs/index.js +14 -0
  211. package/dist/src/datasets/political-blogs/index.js.map +1 -0
  212. package/dist/src/datasets/political-blogs/meta.d.ts +4 -0
  213. package/dist/src/datasets/political-blogs/meta.d.ts.map +1 -0
  214. package/dist/src/datasets/political-blogs/meta.js +26 -0
  215. package/dist/src/datasets/political-blogs/meta.js.map +1 -0
  216. package/dist/src/datasets/political-books/data.d.ts +3 -0
  217. package/dist/src/datasets/political-books/data.d.ts.map +1 -0
  218. package/dist/src/datasets/political-books/data.js +165 -0
  219. package/dist/src/datasets/political-books/data.js.map +1 -0
  220. package/dist/src/datasets/political-books/index.d.ts +11 -0
  221. package/dist/src/datasets/political-books/index.d.ts.map +1 -0
  222. package/dist/src/datasets/political-books/index.js +14 -0
  223. package/dist/src/datasets/political-books/index.js.map +1 -0
  224. package/dist/src/datasets/political-books/meta.d.ts +4 -0
  225. package/dist/src/datasets/political-books/meta.d.ts.map +1 -0
  226. package/dist/src/datasets/political-books/meta.js +20 -0
  227. package/dist/src/datasets/political-books/meta.js.map +1 -0
  228. package/dist/src/datasets/remote.d.ts +27 -0
  229. package/dist/src/datasets/remote.d.ts.map +1 -0
  230. package/dist/src/datasets/remote.js +30 -0
  231. package/dist/src/datasets/remote.js.map +1 -0
  232. package/dist/src/element.d.ts +20 -0
  233. package/dist/src/element.d.ts.map +1 -0
  234. package/dist/src/element.js +27 -0
  235. package/dist/src/element.js.map +1 -0
  236. package/dist/src/generators/bipartite.d.ts +51 -0
  237. package/dist/src/generators/bipartite.d.ts.map +1 -0
  238. package/dist/src/generators/bipartite.js +99 -0
  239. package/dist/src/generators/bipartite.js.map +1 -0
  240. package/dist/src/generators/block-model.d.ts +75 -0
  241. package/dist/src/generators/block-model.d.ts.map +1 -0
  242. package/dist/src/generators/block-model.js +116 -0
  243. package/dist/src/generators/block-model.js.map +1 -0
  244. package/dist/src/generators/classic.d.ts +208 -0
  245. package/dist/src/generators/classic.d.ts.map +1 -0
  246. package/dist/src/generators/classic.js +437 -0
  247. package/dist/src/generators/classic.js.map +1 -0
  248. package/dist/src/generators/degree-sequence.d.ts +273 -0
  249. package/dist/src/generators/degree-sequence.d.ts.map +1 -0
  250. package/dist/src/generators/degree-sequence.js +646 -0
  251. package/dist/src/generators/degree-sequence.js.map +1 -0
  252. package/dist/src/generators/directed.d.ts +141 -0
  253. package/dist/src/generators/directed.d.ts.map +1 -0
  254. package/dist/src/generators/directed.js +329 -0
  255. package/dist/src/generators/directed.js.map +1 -0
  256. package/dist/src/generators/erdos-renyi.d.ts +58 -0
  257. package/dist/src/generators/erdos-renyi.d.ts.map +1 -0
  258. package/dist/src/generators/erdos-renyi.js +154 -0
  259. package/dist/src/generators/erdos-renyi.js.map +1 -0
  260. package/dist/src/generators/flow.d.ts +153 -0
  261. package/dist/src/generators/flow.d.ts.map +1 -0
  262. package/dist/src/generators/flow.js +346 -0
  263. package/dist/src/generators/flow.js.map +1 -0
  264. package/dist/src/generators/geometric.d.ts +133 -0
  265. package/dist/src/generators/geometric.d.ts.map +1 -0
  266. package/dist/src/generators/geometric.js +495 -0
  267. package/dist/src/generators/geometric.js.map +1 -0
  268. package/dist/src/generators/growth.d.ts +187 -0
  269. package/dist/src/generators/growth.d.ts.map +1 -0
  270. package/dist/src/generators/growth.js +445 -0
  271. package/dist/src/generators/growth.js.map +1 -0
  272. package/dist/src/generators/hyperbolic.d.ts +84 -0
  273. package/dist/src/generators/hyperbolic.d.ts.map +1 -0
  274. package/dist/src/generators/hyperbolic.js +153 -0
  275. package/dist/src/generators/hyperbolic.js.map +1 -0
  276. package/dist/src/generators/index.d.ts +25 -0
  277. package/dist/src/generators/index.d.ts.map +1 -0
  278. package/dist/src/generators/index.js +24 -0
  279. package/dist/src/generators/index.js.map +1 -0
  280. package/dist/src/generators/lattices.d.ts +87 -0
  281. package/dist/src/generators/lattices.d.ts.map +1 -0
  282. package/dist/src/generators/lattices.js +237 -0
  283. package/dist/src/generators/lattices.js.map +1 -0
  284. package/dist/src/generators/lfr.d.ts +55 -0
  285. package/dist/src/generators/lfr.d.ts.map +1 -0
  286. package/dist/src/generators/lfr.js +178 -0
  287. package/dist/src/generators/lfr.js.map +1 -0
  288. package/dist/src/generators/named.d.ts +23 -0
  289. package/dist/src/generators/named.d.ts.map +1 -0
  290. package/dist/src/generators/named.js +191 -0
  291. package/dist/src/generators/named.js.map +1 -0
  292. package/dist/src/generators/preferential-attachment.d.ts +66 -0
  293. package/dist/src/generators/preferential-attachment.d.ts.map +1 -0
  294. package/dist/src/generators/preferential-attachment.js +157 -0
  295. package/dist/src/generators/preferential-attachment.js.map +1 -0
  296. package/dist/src/generators/trees-and-dags.d.ts +53 -0
  297. package/dist/src/generators/trees-and-dags.d.ts.map +1 -0
  298. package/dist/src/generators/trees-and-dags.js +108 -0
  299. package/dist/src/generators/trees-and-dags.js.map +1 -0
  300. package/dist/src/generators/util.d.ts +84 -0
  301. package/dist/src/generators/util.d.ts.map +1 -0
  302. package/dist/src/generators/util.js +138 -0
  303. package/dist/src/generators/util.js.map +1 -0
  304. package/dist/src/generators/variants.d.ts +85 -0
  305. package/dist/src/generators/variants.d.ts.map +1 -0
  306. package/dist/src/generators/variants.js +215 -0
  307. package/dist/src/generators/variants.js.map +1 -0
  308. package/dist/src/generators/weights.d.ts +65 -0
  309. package/dist/src/generators/weights.d.ts.map +1 -0
  310. package/dist/src/generators/weights.js +135 -0
  311. package/dist/src/generators/weights.js.map +1 -0
  312. package/dist/src/index.d.ts +12 -0
  313. package/dist/src/index.d.ts.map +1 -0
  314. package/dist/src/index.js +10 -0
  315. package/dist/src/index.js.map +1 -0
  316. package/dist/src/random/exp.d.ts +23 -0
  317. package/dist/src/random/exp.d.ts.map +1 -0
  318. package/dist/src/random/exp.js +101 -0
  319. package/dist/src/random/exp.js.map +1 -0
  320. package/dist/src/random/log.d.ts +19 -0
  321. package/dist/src/random/log.d.ts.map +1 -0
  322. package/dist/src/random/log.js +83 -0
  323. package/dist/src/random/log.js.map +1 -0
  324. package/dist/src/random/stream.d.ts +93 -0
  325. package/dist/src/random/stream.d.ts.map +1 -0
  326. package/dist/src/random/stream.js +154 -0
  327. package/dist/src/random/stream.js.map +1 -0
  328. package/dist/src/random/threefry.d.ts +19 -0
  329. package/dist/src/random/threefry.d.ts.map +1 -0
  330. package/dist/src/random/threefry.js +43 -0
  331. package/dist/src/random/threefry.js.map +1 -0
  332. package/dist/src/random/trig.d.ts +16 -0
  333. package/dist/src/random/trig.d.ts.map +1 -0
  334. package/dist/src/random/trig.js +78 -0
  335. package/dist/src/random/trig.js.map +1 -0
  336. package/dist/src/types.d.ts +28 -0
  337. package/dist/src/types.d.ts.map +1 -0
  338. package/dist/src/types.js +2 -0
  339. package/dist/src/types.js.map +1 -0
  340. package/package.json +102 -5
  341. package/src/datasets/build.ts +140 -0
  342. package/src/datasets/catalog.ts +35 -0
  343. package/src/datasets/celegans-neural/data.ts +575 -0
  344. package/src/datasets/celegans-neural/index.ts +17 -0
  345. package/src/datasets/celegans-neural/meta.ts +25 -0
  346. package/src/datasets/contiguous-usa/data.ts +164 -0
  347. package/src/datasets/contiguous-usa/index.ts +17 -0
  348. package/src/datasets/contiguous-usa/meta.ts +31 -0
  349. package/src/datasets/davis-southern-women/data.ts +59 -0
  350. package/src/datasets/davis-southern-women/index.ts +17 -0
  351. package/src/datasets/davis-southern-women/meta.ts +20 -0
  352. package/src/datasets/dolphins/data.ts +95 -0
  353. package/src/datasets/dolphins/index.ts +17 -0
  354. package/src/datasets/dolphins/meta.ts +21 -0
  355. package/src/datasets/florentine-families/data.ts +33 -0
  356. package/src/datasets/florentine-families/index.ts +17 -0
  357. package/src/datasets/florentine-families/meta.ts +20 -0
  358. package/src/datasets/football/data.ts +212 -0
  359. package/src/datasets/football/index.ts +17 -0
  360. package/src/datasets/football/meta.ts +20 -0
  361. package/src/datasets/hosted.ts +90 -0
  362. package/src/datasets/karate/data.ts +32 -0
  363. package/src/datasets/karate/index.ts +17 -0
  364. package/src/datasets/karate/meta.ts +25 -0
  365. package/src/datasets/knuth-miles/data.ts +1205 -0
  366. package/src/datasets/knuth-miles/index.ts +17 -0
  367. package/src/datasets/knuth-miles/meta.ts +29 -0
  368. package/src/datasets/les-miserables/data.ts +119 -0
  369. package/src/datasets/les-miserables/index.ts +17 -0
  370. package/src/datasets/les-miserables/meta.ts +24 -0
  371. package/src/datasets/openflights/data.ts +15459 -0
  372. package/src/datasets/openflights/index.ts +17 -0
  373. package/src/datasets/openflights/meta.ts +31 -0
  374. package/src/datasets/political-blogs/data.ts +4859 -0
  375. package/src/datasets/political-blogs/index.ts +17 -0
  376. package/src/datasets/political-blogs/meta.ts +30 -0
  377. package/src/datasets/political-books/data.ts +167 -0
  378. package/src/datasets/political-books/index.ts +17 -0
  379. package/src/datasets/political-books/meta.ts +23 -0
  380. package/src/datasets/remote.ts +42 -0
  381. package/src/element.ts +41 -0
  382. package/src/generators/bipartite.ts +127 -0
  383. package/src/generators/block-model.ts +160 -0
  384. package/src/generators/classic.ts +461 -0
  385. package/src/generators/degree-sequence.ts +807 -0
  386. package/src/generators/directed.ts +418 -0
  387. package/src/generators/erdos-renyi.ts +188 -0
  388. package/src/generators/flow.ts +443 -0
  389. package/src/generators/geometric.ts +591 -0
  390. package/src/generators/growth.ts +532 -0
  391. package/src/generators/hyperbolic.ts +193 -0
  392. package/src/generators/index.ts +133 -0
  393. package/src/generators/lattices.ts +290 -0
  394. package/src/generators/lfr.ts +227 -0
  395. package/src/generators/named.ts +198 -0
  396. package/src/generators/preferential-attachment.ts +188 -0
  397. package/src/generators/trees-and-dags.ts +139 -0
  398. package/src/generators/util.ts +167 -0
  399. package/src/generators/variants.ts +253 -0
  400. package/src/generators/weights.ts +177 -0
  401. package/src/index.ts +12 -0
  402. package/src/random/exp.ts +104 -0
  403. package/src/random/log.ts +86 -0
  404. package/src/random/stream.ts +169 -0
  405. package/src/random/threefry.ts +45 -0
  406. package/src/random/trig.ts +83 -0
  407. package/src/types.ts +28 -0
@@ -0,0 +1,532 @@
1
+ /**
2
+ * Sequential growth models: the random recursive tree, forest fire, duplication-divergence,
3
+ * Newman-Watts, Bianconi-Barabasi fitness, the random Apollonian network and Wilson's uniform
4
+ * spanning tree of a grid (a perfect maze). Each draws from one stream (seed, domain, 0): the
5
+ * processes are sequential, so there is no row-parallel form.
6
+ */
7
+
8
+ import { detLog } from "../random/log.js";
9
+ import { RandomStream, resolveSeed } from "../random/stream.js";
10
+ import { type SampleGraph } from "../types.js";
11
+ import { checkEdgeCount, checkInt, checkProbability, EdgeBuffer, toGraph } from "./util.js";
12
+ import { applyWeights, type WeightOptions } from "./weights.js";
13
+
14
+ /** Options of {@link randomRecursiveTreeGraph}. */
15
+ export interface RandomRecursiveTreeOptions extends WeightOptions {
16
+ /** The node count, >= 1. */
17
+ n: number;
18
+ /** The seed, an integer in [0, 2^53); default 0. */
19
+ seed?: number | undefined;
20
+ }
21
+
22
+ /**
23
+ * The random recursive tree (R. T. Smythe and H. M. Mahmoud, "A survey of recursive trees",
24
+ * Theory Probab. Math. Statist. 51, 1-27, 1995): node t = 1 .. n - 1 attaches to a uniform earlier
25
+ * node, drawn as nextBelow(t) from the stream (seed, "recursive-tree", 0). Edge t - 1 is
26
+ * (parent, t), in t order. O(n). Depth about ln n, root degree about ln n.
27
+ * @param options - n and seed
28
+ * @returns the undirected tree
29
+ */
30
+ export function randomRecursiveTreeGraph(options: RandomRecursiveTreeOptions): SampleGraph {
31
+ const { n } = options;
32
+ checkInt("n", n, 1);
33
+ const stream = new RandomStream(resolveSeed(options.seed), "recursive-tree", 0);
34
+ const src = new Uint32Array(n - 1);
35
+ const dst = new Uint32Array(n - 1);
36
+ for (let t = 1; t < n; t++) {
37
+ src[t - 1] = stream.nextBelow(t);
38
+ dst[t - 1] = t;
39
+ }
40
+ return applyWeights({ directed: false, nodeCount: n, src, dst }, options);
41
+ }
42
+
43
+ /** Options of {@link forestFireGraph}. */
44
+ export interface ForestFireOptions extends WeightOptions {
45
+ /** The node count, >= 1. */
46
+ n: number;
47
+ /** The forward burning probability p, in [0, 1). */
48
+ forward: number;
49
+ /** The backward burning ratio r >= 0; the backward burning probability r p must be below 1. */
50
+ backward: number;
51
+ /** The most nodes one new node may burn (and link to), >= 1; default 1000. */
52
+ maxBurn?: number | undefined;
53
+ /** The seed, an integer in [0, 2^53); default 0. */
54
+ seed?: number | undefined;
55
+ }
56
+
57
+ /**
58
+ * Pick `count` of `candidates` uniformly without replacement (a partial Fisher-Yates shuffle in
59
+ * place): the picks are candidates[0 .. count).
60
+ * @param stream - the stream
61
+ * @param candidates - the candidates, reordered in place
62
+ * @param count - how many to pick, <= candidates.length
63
+ */
64
+ function pickPrefix(stream: RandomStream, candidates: number[], count: number): void {
65
+ for (let i = 0; i < count; i++) {
66
+ const j = i + stream.nextBelow(candidates.length - i);
67
+ const t = candidates[i];
68
+ candidates[i] = candidates[j];
69
+ candidates[j] = t;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * The forest fire model (J. Leskovec, J. Kleinberg and C. Faloutsos, "Graphs over time:
75
+ * densification laws, shrinking diameters and possible explanations", KDD 2005,
76
+ * doi:10.1145/1081870.1081893). Directed; heavy-tailed degrees, densification, community locality.
77
+ *
78
+ * Node 0 starts alone. Each new node v = 1 .. n - 1 draws an ambassador w = nextBelow(v) and burns
79
+ * breadth-first from it: for each burning node x in burn order, draw x_out = floor(ln(1 - u) / ln p)
80
+ * (geometric, P(x_out >= k) = p^k, mean p / (1 - p)) and then x_in the same way with r p; then pick
81
+ * x_out of x's out-neighbours and then x_in of its in-neighbours uniformly among those not yet
82
+ * burned (adjacency order, partial Fisher-Yates; all of them when there are fewer), and burn them.
83
+ * Burning stops at `maxBurn` nodes. v then links to every burned node: arcs (v, t) in burn order.
84
+ * Edges are listed by v. All draws come from the stream (seed, "forest-fire", 0).
85
+ *
86
+ * Cost: O(sum over burning nodes of their degree), since each burning node's lists are scanned;
87
+ * the edge count explodes for p above about 0.37, which `maxBurn` bounds at n maxBurn arcs.
88
+ * @param options - n, forward, backward, maxBurn and seed
89
+ * @returns the directed graph
90
+ */
91
+ export function forestFireGraph(options: ForestFireOptions): SampleGraph {
92
+ const { n, forward: p, backward: r } = options;
93
+ const maxBurn = options.maxBurn ?? 1000;
94
+ checkInt("n", n, 1);
95
+ if (!(p >= 0 && p < 1)) {
96
+ throw new RangeError(`forward must be a probability in [0, 1), got ${String(p)}`);
97
+ }
98
+ if (!(r >= 0 && r * p < 1)) {
99
+ throw new RangeError(`backward must be >= 0 with backward * forward < 1, got ${String(r)}`);
100
+ }
101
+ checkInt("maxBurn", maxBurn, 1);
102
+ const stream = new RandomStream(resolveSeed(options.seed), "forest-fire", 0);
103
+ const pb = r * p;
104
+ const logForward = detLog(p);
105
+ const logBackward = detLog(pb);
106
+ // ponytail: number[][] adjacency, fine to a few million arcs; a growable CSR beyond
107
+ const out: number[][] = Array.from({ length: n }, () => []);
108
+ const inn: number[][] = Array.from({ length: n }, () => []);
109
+ const stamp = new Uint32Array(n);
110
+ const edges = new EdgeBuffer(4 * n);
111
+ const burned: number[] = [];
112
+ const burn = (v: number, list: number[], count: number): void => {
113
+ const candidates = list.filter((t) => stamp[t] !== v);
114
+ const take = Math.min(count, candidates.length, maxBurn - burned.length);
115
+ pickPrefix(stream, candidates, take);
116
+ for (let i = 0; i < take; i++) {
117
+ stamp[candidates[i]] = v;
118
+ burned.push(candidates[i]);
119
+ }
120
+ };
121
+ for (let v = 1; v < n; v++) {
122
+ burned.length = 0;
123
+ const w = stream.nextBelow(v);
124
+ stamp[w] = v;
125
+ burned.push(w);
126
+ for (let head = 0; head < burned.length && burned.length < maxBurn; head++) {
127
+ const x = burned[head];
128
+ const xOut = p === 0 ? 0 : stream.nextSkip(logForward);
129
+ const xIn = pb === 0 ? 0 : stream.nextSkip(logBackward);
130
+ burn(v, out[x], xOut);
131
+ burn(v, inn[x], xIn);
132
+ }
133
+ for (const t of burned) {
134
+ edges.push(v, t);
135
+ out[v].push(t);
136
+ inn[t].push(v);
137
+ }
138
+ }
139
+ return applyWeights(toGraph(n, edges, true), options);
140
+ }
141
+
142
+ /** Options of {@link duplicationDivergenceGraph}. */
143
+ export interface DuplicationDivergenceOptions extends WeightOptions {
144
+ /** The node count, >= 2. */
145
+ n: number;
146
+ /** The probability that a duplicate keeps each of the original's edges, in (0, 1]. */
147
+ retention: number;
148
+ /** The seed, an integer in [0, 2^53); default 0. */
149
+ seed?: number | undefined;
150
+ }
151
+
152
+ /**
153
+ * The duplication-divergence model (I. Ispolatov, P. L. Krapivsky and A. Yuryev,
154
+ * "Duplication-divergence model of protein interaction network", Phys. Rev. E 71, 061911, 2005,
155
+ * doi:10.1103/PhysRevE.71.061911), as networkx's `duplication_divergence_graph`: protein-network
156
+ * like, with many nodes sharing neighbours.
157
+ *
158
+ * Start with the edge (0, 1). While there are fewer than n nodes, draw a node x = nextBelow(i) for
159
+ * the next index i, then one float per neighbour of x (in the order they were joined to x): below
160
+ * `retention`, the edge (i, neighbour). If i got at least one edge it is kept, otherwise the attempt
161
+ * is discarded. All draws come from the stream (seed, "duplication-divergence", 0). Edges are
162
+ * listed by new node. Simple and connected.
163
+ *
164
+ * Cost: O(sum of the copied nodes' degrees). Each attempt succeeds with probability at least
165
+ * `retention`; after 1000 n attempts in total it throws a RangeError rather than loop on.
166
+ * @param options - n, retention and seed
167
+ * @returns the undirected graph
168
+ */
169
+ export function duplicationDivergenceGraph(options: DuplicationDivergenceOptions): SampleGraph {
170
+ const { n, retention } = options;
171
+ checkInt("n", n, 2);
172
+ if (!(retention > 0 && retention <= 1)) {
173
+ throw new RangeError(`retention must be a probability in (0, 1], got ${String(retention)}`);
174
+ }
175
+ const stream = new RandomStream(resolveSeed(options.seed), "duplication-divergence", 0);
176
+ // ponytail: number[][] adjacency, fine to a few million edges; a growable CSR beyond
177
+ const adj: number[][] = Array.from({ length: n }, () => []);
178
+ const edges = new EdgeBuffer(4 * n);
179
+ edges.push(0, 1);
180
+ adj[0].push(1);
181
+ adj[1].push(0);
182
+ const maxAttempts = 1000 * n;
183
+ let attempts = 0;
184
+ for (let i = 2; i < n; ) {
185
+ if (++attempts > maxAttempts) {
186
+ throw new RangeError(
187
+ `duplicationDivergenceGraph gave up after ${maxAttempts} attempts at ${i} of ${n} nodes: retention ${retention} is too small`,
188
+ );
189
+ }
190
+ const copied = adj[stream.nextBelow(i)];
191
+ for (const t of copied) {
192
+ if (stream.nextFloat() < retention) {
193
+ edges.push(i, t);
194
+ adj[i].push(t);
195
+ }
196
+ }
197
+ for (const t of adj[i]) {
198
+ adj[t].push(i);
199
+ }
200
+ if (adj[i].length > 0) {
201
+ i++;
202
+ }
203
+ }
204
+ return applyWeights(toGraph(n, edges, false), options);
205
+ }
206
+
207
+ /** Options of {@link newmanWattsGraph}. */
208
+ export interface NewmanWattsOptions extends WeightOptions {
209
+ /** The node count, > k. */
210
+ n: number;
211
+ /** Each node's ring neighbours, even, >= 2. */
212
+ k: number;
213
+ /** The probability of a shortcut per ring edge, in [0, 1]. */
214
+ p: number;
215
+ /** The seed, an integer in [0, 2^53); default 0. */
216
+ seed?: number | undefined;
217
+ }
218
+
219
+ /**
220
+ * The Newman-Watts small world (M. E. J. Newman and D. J. Watts, "Renormalization group analysis
221
+ * of the small-world network model", Phys. Lett. A 263, 341-346, 1999,
222
+ * doi:10.1016/S0375-9601(99)00757-4): Watts-Strogatz with shortcuts added instead of rewired, so
223
+ * the graph stays connected.
224
+ *
225
+ * The ring lattice of `wattsStrogatzGraph` comes first: edge slot u k/2 + (j - 1) is
226
+ * (u, (u + j) mod n). Then for each slot in order, with source u: draw a float; if it is below p and
227
+ * u is not joined to every other node, redraw w = nextBelow(n) until w is neither u nor a
228
+ * neighbour of u, and append the shortcut (u, w). All draws come from the stream (seed,
229
+ * "newman-watts", 0). O(n k) expected.
230
+ * @param options - n, k, p and seed
231
+ * @returns the undirected graph
232
+ */
233
+ export function newmanWattsGraph(options: NewmanWattsOptions): SampleGraph {
234
+ const { n, k, p } = options;
235
+ checkInt("k", k, 2);
236
+ if (k % 2 !== 0) {
237
+ throw new RangeError(`k must be even, got ${k}`);
238
+ }
239
+ checkInt("n", n, k + 1);
240
+ checkProbability("p", p);
241
+ const half = k / 2;
242
+ const ring = n * half;
243
+ checkEdgeCount(2 * ring);
244
+ const edges = new EdgeBuffer(ring + Math.ceil(ring * p + 6 * Math.sqrt(ring) + 16));
245
+ const degree = new Uint32Array(n).fill(k);
246
+ // ponytail: a Set of u * n + v keys, like wattsStrogatzGraph; a hashed typed table beyond millions
247
+ const present = new Set<number>();
248
+ const key = (a: number, b: number): number => (a < b ? a * n + b : b * n + a);
249
+ for (let u = 0; u < n; u++) {
250
+ for (let j = 1; j <= half; j++) {
251
+ const v = (u + j) % n;
252
+ edges.push(u, v);
253
+ present.add(key(u, v));
254
+ }
255
+ }
256
+ const stream = new RandomStream(resolveSeed(options.seed), "newman-watts", 0);
257
+ for (let slot = 0; slot < ring; slot++) {
258
+ const u = edges.src[slot];
259
+ if (stream.nextFloat() >= p || degree[u] >= n - 1) {
260
+ continue;
261
+ }
262
+ let w = stream.nextBelow(n);
263
+ while (w === u || present.has(key(u, w))) {
264
+ w = stream.nextBelow(n);
265
+ }
266
+ edges.push(u, w);
267
+ present.add(key(u, w));
268
+ degree[u]++;
269
+ degree[w]++;
270
+ }
271
+ return applyWeights(toGraph(n, edges, false), options);
272
+ }
273
+
274
+ /** Options of {@link bianconiBarabasiGraph}. */
275
+ export interface BianconiBarabasiOptions extends WeightOptions {
276
+ /** The node count, > m. */
277
+ n: number;
278
+ /** The number of edges each new node brings, >= 1. */
279
+ m: number;
280
+ /**
281
+ * Each node's fitness, n finite positive values; default uniform in (0, 1], node i's drawn as
282
+ * 1 - nextFloat() from the stream (seed, "fitness", i).
283
+ */
284
+ fitness?: ArrayLike<number> | undefined;
285
+ /** The seed, an integer in [0, 2^53); default 0. */
286
+ seed?: number | undefined;
287
+ }
288
+
289
+ /**
290
+ * The Bianconi-Barabasi fitness model (G. Bianconi and A.-L. Barabasi, "Competition and
291
+ * multiscaling in evolving networks", Europhys. Lett. 54, 436-442, 2001,
292
+ * doi:10.1209/epl/i2001-00260-6): preferential attachment weighted by fitness, so a fit latecomer
293
+ * can overtake older hubs ("fit get richer").
294
+ *
295
+ * Start from the clique on nodes 0 .. m, edges (a, b) for a < b in lexicographic order. Each new
296
+ * node s = m + 1 .. n - 1 picks m distinct existing nodes, one at a time, with probability
297
+ * proportional to fitness_i * degree_i among those not yet picked: x = nextFloat() * total, then a
298
+ * descent of a Fenwick tree over the Float64 weights. Edges (s, t) follow in pick order. Draws
299
+ * come from the stream (seed, "bianconi-barabasi", 0). O(n m log n). Emits the Float64 node column
300
+ * `fitness`.
301
+ * @param options - n, m, fitness and seed
302
+ * @returns the undirected graph
303
+ */
304
+ export function bianconiBarabasiGraph(options: BianconiBarabasiOptions): SampleGraph {
305
+ const { n, m } = options;
306
+ checkInt("m", m, 1);
307
+ checkInt("n", n, m + 1);
308
+ const seed = resolveSeed(options.seed);
309
+ checkEdgeCount((m * (m + 1)) / 2 + (n - m - 1) * m);
310
+ const fitness = new Float64Array(n);
311
+ if (options.fitness === undefined) {
312
+ const draw = new RandomStream(seed, "fitness", 0);
313
+ for (let i = 0; i < n; i++) {
314
+ draw.reset(i);
315
+ fitness[i] = 1 - draw.nextFloat();
316
+ }
317
+ } else {
318
+ if (options.fitness.length !== n) {
319
+ throw new RangeError(`fitness must have n = ${n} values, got ${options.fitness.length}`);
320
+ }
321
+ for (let i = 0; i < n; i++) {
322
+ const f = options.fitness[i];
323
+ if (!(f > 0 && Number.isFinite(f))) {
324
+ throw new RangeError(`fitness[${i}] must be finite and positive, got ${String(f)}`);
325
+ }
326
+ fitness[i] = f;
327
+ }
328
+ }
329
+ const edges = new EdgeBuffer((m * (m + 1)) / 2 + (n - m - 1) * m);
330
+ const degree = new Uint32Array(n);
331
+ for (let a = 0; a <= m; a++) {
332
+ for (let b = a + 1; b <= m; b++) {
333
+ edges.push(a, b);
334
+ }
335
+ degree[a] = m;
336
+ }
337
+ // Fenwick tree over weight[i] = fitness[i] * degree[i] (1-based internally)
338
+ const weight = new Float64Array(n);
339
+ const tree = new Float64Array(n + 1);
340
+ const add = (i: number, delta: number): void => {
341
+ weight[i] += delta;
342
+ for (let j = i + 1; j <= n; j += j & -j) {
343
+ tree[j] += delta;
344
+ }
345
+ };
346
+ let top = 1;
347
+ while (top * 2 <= n) {
348
+ top *= 2;
349
+ }
350
+ const find = (x: number, limit: number): number => {
351
+ let pos = 0;
352
+ let rest = x;
353
+ for (let step = top; step >= 1; step = Math.floor(step / 2)) {
354
+ if (pos + step <= n && tree[pos + step] <= rest) {
355
+ pos += step;
356
+ rest -= tree[pos];
357
+ }
358
+ }
359
+ // rounding guard: land on a node with weight, below the newcomer
360
+ pos = Math.min(pos, limit - 1);
361
+ while (weight[pos] === 0) {
362
+ pos--;
363
+ }
364
+ return pos;
365
+ };
366
+ let total = 0;
367
+ for (let i = 0; i <= m; i++) {
368
+ add(i, fitness[i] * m);
369
+ total += fitness[i] * m;
370
+ }
371
+ const stream = new RandomStream(seed, "bianconi-barabasi", 0);
372
+ const picked = new Uint32Array(m);
373
+ for (let s = m + 1; s < n; s++) {
374
+ let remaining = total;
375
+ for (let i = 0; i < m; i++) {
376
+ const t = find(stream.nextFloat() * remaining, s);
377
+ picked[i] = t;
378
+ remaining -= weight[t];
379
+ add(t, -weight[t]);
380
+ }
381
+ for (let i = 0; i < m; i++) {
382
+ const t = picked[i];
383
+ edges.push(s, t);
384
+ degree[t]++;
385
+ add(t, fitness[t] * degree[t]);
386
+ }
387
+ degree[s] = m;
388
+ add(s, fitness[s] * m);
389
+ total = 0;
390
+ // recompute the total from the tree's roots so it never drifts from the tree
391
+ for (let j = n; j > 0; j -= j & -j) {
392
+ total += tree[j];
393
+ }
394
+ }
395
+ return applyWeights(toGraph(n, edges, false, { fitness }), options);
396
+ }
397
+
398
+ /** Options of {@link randomApollonianGraph}. */
399
+ export interface RandomApollonianOptions extends WeightOptions {
400
+ /** The node count, >= 3. */
401
+ n: number;
402
+ /** The seed, an integer in [0, 2^53); default 0. */
403
+ seed?: number | undefined;
404
+ }
405
+
406
+ /**
407
+ * The random Apollonian network (T. Zhou, G. Yan and B.-H. Wang, "Maximal planar networks with
408
+ * large clustering coefficient and power-law degree distribution", Phys. Rev. E 71, 046141, 2005,
409
+ * doi:10.1103/PhysRevE.71.046141; the deterministic one is J. S. Andrade et al., Phys. Rev. Lett. 94,
410
+ * 018702, 2005): maximal planar, power-law degrees, high clustering.
411
+ *
412
+ * Start from the triangle 0, 1, 2 (edges (0, 1), (0, 2), (1, 2)) whose inner face is face 0; the
413
+ * outer face is never split. Each new node v = 3 .. n - 1 picks face f = nextBelow(faceCount) =
414
+ * (a, b, c), adds the edges (v, a), (v, b), (v, c), and splits f: face f becomes (a, b, v), and
415
+ * (b, c, v) and (a, c, v) are appended. Draws come from the stream (seed, "apollonian", 0).
416
+ * 3n - 6 edges. O(n).
417
+ * @param options - n and seed
418
+ * @returns the undirected graph
419
+ */
420
+ export function randomApollonianGraph(options: RandomApollonianOptions): SampleGraph {
421
+ const { n } = options;
422
+ checkInt("n", n, 3);
423
+ const m = 3 * n - 6;
424
+ checkEdgeCount(m);
425
+ const stream = new RandomStream(resolveSeed(options.seed), "apollonian", 0);
426
+ const faces = 2 * n - 5;
427
+ const fa = new Uint32Array(faces);
428
+ const fb = new Uint32Array(faces);
429
+ const fc = new Uint32Array(faces);
430
+ fa[0] = 0;
431
+ fb[0] = 1;
432
+ fc[0] = 2;
433
+ let faceCount = 1;
434
+ const src = new Uint32Array(m);
435
+ const dst = new Uint32Array(m);
436
+ src.set([0, 0, 1]);
437
+ dst.set([1, 2, 2]);
438
+ let e = 3;
439
+ for (let v = 3; v < n; v++) {
440
+ const f = stream.nextBelow(faceCount);
441
+ const a = fa[f];
442
+ const b = fb[f];
443
+ const c = fc[f];
444
+ src.fill(v, e, e + 3);
445
+ dst[e++] = a;
446
+ dst[e++] = b;
447
+ dst[e++] = c;
448
+ fc[f] = v;
449
+ fa[faceCount] = b;
450
+ fb[faceCount] = c;
451
+ fc[faceCount++] = v;
452
+ fa[faceCount] = a;
453
+ fb[faceCount] = c;
454
+ fc[faceCount++] = v;
455
+ }
456
+ return applyWeights({ directed: false, nodeCount: n, src, dst }, options);
457
+ }
458
+
459
+ /** Options of {@link wilsonMazeGraph}. */
460
+ export interface WilsonMazeOptions extends WeightOptions {
461
+ /** The number of rows, >= 1. */
462
+ rows: number;
463
+ /** The number of columns, >= 1. */
464
+ cols: number;
465
+ /** The seed, an integer in [0, 2^53); default 0. */
466
+ seed?: number | undefined;
467
+ }
468
+
469
+ /**
470
+ * A uniform spanning tree of the rows x cols grid, a perfect maze, by Wilson's algorithm
471
+ * (D. B. Wilson, "Generating random spanning trees more quickly than the cover time", STOC 1996,
472
+ * doi:10.1145/237814.237880): loop-erased random walks.
473
+ *
474
+ * Node (r, c) is index r cols + c. The root is node 0. For each start node in index order that is
475
+ * not yet in the tree, walk until the tree is hit, each step to a uniform grid neighbour
476
+ * (candidates in the order left, right, up, down; nextBelow(count)), remembering only the last exit
477
+ * from each node (which erases the loops); then add the path: edges (u, next(u)) from the start to
478
+ * the tree, in that order. Draws come from the stream (seed, "wilson", 0). rows cols - 1 edges.
479
+ * Float64 node columns `x` = column and `y` = row. Expected cost is the mean hitting time of the
480
+ * root, about O(n log n) on a grid.
481
+ * @param options - rows, cols and seed
482
+ * @returns the undirected tree
483
+ */
484
+ export function wilsonMazeGraph(options: WilsonMazeOptions): SampleGraph {
485
+ const { rows, cols } = options;
486
+ checkInt("rows", rows, 1);
487
+ checkInt("cols", cols, 1);
488
+ const n = rows * cols;
489
+ checkInt("rows * cols", n, 1);
490
+ const stream = new RandomStream(resolveSeed(options.seed), "wilson", 0);
491
+ const inTree = new Uint8Array(n);
492
+ const next = new Uint32Array(n);
493
+ const src = new Uint32Array(n - 1);
494
+ const dst = new Uint32Array(n - 1);
495
+ const options4 = new Uint32Array(4);
496
+ inTree[0] = 1;
497
+ let e = 0;
498
+ for (let start = 1; start < n; start++) {
499
+ let u = start;
500
+ while (inTree[u] === 0) {
501
+ const r = Math.floor(u / cols);
502
+ const c = u - r * cols;
503
+ let count = 0;
504
+ if (c > 0) {
505
+ options4[count++] = u - 1;
506
+ }
507
+ if (c + 1 < cols) {
508
+ options4[count++] = u + 1;
509
+ }
510
+ if (r > 0) {
511
+ options4[count++] = u - cols;
512
+ }
513
+ if (r + 1 < rows) {
514
+ options4[count++] = u + cols;
515
+ }
516
+ next[u] = options4[stream.nextBelow(count)];
517
+ u = next[u];
518
+ }
519
+ for (u = start; inTree[u] === 0; u = next[u]) {
520
+ inTree[u] = 1;
521
+ src[e] = u;
522
+ dst[e++] = next[u];
523
+ }
524
+ }
525
+ const x = new Float64Array(n);
526
+ const y = new Float64Array(n);
527
+ for (let i = 0; i < n; i++) {
528
+ y[i] = Math.floor(i / cols);
529
+ x[i] = i - y[i] * cols;
530
+ }
531
+ return applyWeights({ directed: false, nodeCount: n, src, dst, nodeColumns: { x, y } }, options);
532
+ }