okstra 0.108.0 → 0.110.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (648) hide show
  1. package/README.kr.md +1 -1
  2. package/README.md +1 -1
  3. package/docs/kr/architecture.md +3 -3
  4. package/docs/kr/cli.md +2 -2
  5. package/docs/project-structure-overview.md +3 -3
  6. package/package.json +1 -1
  7. package/runtime/BUILD.json +2 -2
  8. package/runtime/prompts/profiles/_common-contract.md +1 -1
  9. package/runtime/python/okstra_ctl/graphify_cmd.py +225 -0
  10. package/runtime/python/okstra_ctl/resolve_task_key.py +15 -9
  11. package/runtime/python/okstra_ctl/worktree.py +14 -13
  12. package/runtime/python/okstra_project/__init__.py +2 -0
  13. package/runtime/python/okstra_project/state.py +36 -0
  14. package/runtime/python/okstra_vendor/__init__.py +41 -0
  15. package/runtime/python/okstra_vendor/graphify/.vendored-version +1 -0
  16. package/runtime/python/okstra_vendor/graphify/__init__.py +28 -0
  17. package/runtime/python/okstra_vendor/graphify/__main__.py +1371 -0
  18. package/runtime/python/okstra_vendor/graphify/analyze.py +540 -0
  19. package/runtime/python/okstra_vendor/graphify/benchmark.py +129 -0
  20. package/runtime/python/okstra_vendor/graphify/build.py +107 -0
  21. package/runtime/python/okstra_vendor/graphify/cache.py +169 -0
  22. package/runtime/python/okstra_vendor/graphify/cluster.py +137 -0
  23. package/runtime/python/okstra_vendor/graphify/detect.py +510 -0
  24. package/runtime/python/okstra_vendor/graphify/export.py +1014 -0
  25. package/runtime/python/okstra_vendor/graphify/extract.py +3277 -0
  26. package/runtime/python/okstra_vendor/graphify/hooks.py +220 -0
  27. package/runtime/python/okstra_vendor/graphify/ingest.py +297 -0
  28. package/runtime/python/okstra_vendor/graphify/manifest.py +4 -0
  29. package/runtime/python/okstra_vendor/graphify/report.py +175 -0
  30. package/runtime/python/okstra_vendor/graphify/security.py +203 -0
  31. package/runtime/python/okstra_vendor/graphify/serve.py +373 -0
  32. package/runtime/python/okstra_vendor/graphify/skill-aider.md +1184 -0
  33. package/runtime/python/okstra_vendor/graphify/skill-claw.md +1184 -0
  34. package/runtime/python/okstra_vendor/graphify/skill-codex.md +1242 -0
  35. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +1268 -0
  36. package/runtime/python/okstra_vendor/graphify/skill-droid.md +1239 -0
  37. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +1183 -0
  38. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +1238 -0
  39. package/runtime/python/okstra_vendor/graphify/skill-trae.md +1208 -0
  40. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +253 -0
  41. package/runtime/python/okstra_vendor/graphify/skill-windows.md +1245 -0
  42. package/runtime/python/okstra_vendor/graphify/skill.md +1319 -0
  43. package/runtime/python/okstra_vendor/graphify/transcribe.py +182 -0
  44. package/runtime/python/okstra_vendor/graphify/validate.py +72 -0
  45. package/runtime/python/okstra_vendor/graphify/watch.py +188 -0
  46. package/runtime/python/okstra_vendor/graphify/wiki.py +214 -0
  47. package/runtime/python/okstra_vendor/networkx/__init__.py +62 -0
  48. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +134 -0
  49. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +26 -0
  50. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +259 -0
  51. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +71 -0
  52. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +412 -0
  53. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +396 -0
  54. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +150 -0
  55. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +149 -0
  56. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +369 -0
  57. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +44 -0
  58. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +143 -0
  59. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +53 -0
  60. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +265 -0
  61. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  62. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +41 -0
  63. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +112 -0
  64. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +199 -0
  65. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +146 -0
  66. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +59 -0
  67. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +78 -0
  68. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +303 -0
  69. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +8 -0
  70. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +94 -0
  71. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +31 -0
  72. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +306 -0
  73. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +1014 -0
  74. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +274 -0
  75. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +68 -0
  76. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +1508 -0
  77. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +255 -0
  78. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +83 -0
  79. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +5 -0
  80. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +122 -0
  81. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +302 -0
  82. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +255 -0
  83. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +160 -0
  84. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +127 -0
  85. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  86. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +81 -0
  87. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +143 -0
  88. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +122 -0
  89. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +174 -0
  90. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +107 -0
  91. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +87 -0
  92. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +164 -0
  93. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +88 -0
  94. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +322 -0
  95. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +290 -0
  96. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +289 -0
  97. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +57 -0
  98. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +360 -0
  99. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +105 -0
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +603 -0
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +316 -0
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +590 -0
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +232 -0
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +526 -0
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +112 -0
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +69 -0
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +125 -0
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +192 -0
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +84 -0
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +33 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +240 -0
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +334 -0
  114. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +407 -0
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +218 -0
  116. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +327 -0
  117. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +138 -0
  118. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +409 -0
  119. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +35 -0
  120. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +80 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +168 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +205 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +164 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +20 -0
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +591 -0
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +236 -0
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +282 -0
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +364 -0
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +227 -0
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +96 -0
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +150 -0
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +107 -0
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +357 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +130 -0
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +787 -0
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +88 -0
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +331 -0
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +150 -0
  139. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +200 -0
  140. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +128 -0
  141. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +209 -0
  142. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +141 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +361 -0
  144. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  145. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +923 -0
  146. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +354 -0
  147. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +274 -0
  148. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +259 -0
  149. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +147 -0
  150. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +43 -0
  151. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +144 -0
  152. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +73 -0
  153. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +186 -0
  154. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +277 -0
  155. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +122 -0
  156. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +345 -0
  157. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +220 -0
  158. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +344 -0
  159. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +87 -0
  160. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +140 -0
  161. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +82 -0
  162. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +110 -0
  163. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +302 -0
  164. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +64 -0
  165. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +181 -0
  166. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +95 -0
  167. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +172 -0
  168. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +443 -0
  169. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +818 -0
  170. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +732 -0
  171. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +4 -0
  172. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +505 -0
  173. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +565 -0
  174. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  175. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +863 -0
  176. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +163 -0
  177. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +28 -0
  178. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +153 -0
  179. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +354 -0
  180. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +171 -0
  181. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +30 -0
  182. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +216 -0
  183. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +79 -0
  184. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +338 -0
  185. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +162 -0
  186. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +220 -0
  187. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +384 -0
  188. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +227 -0
  189. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +452 -0
  190. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +347 -0
  191. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  192. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +147 -0
  193. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +157 -0
  194. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +85 -0
  195. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +106 -0
  196. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +91 -0
  197. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +241 -0
  198. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +138 -0
  199. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +76 -0
  200. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +264 -0
  201. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +152 -0
  202. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +340 -0
  203. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +139 -0
  204. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +26 -0
  205. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +6 -0
  206. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +115 -0
  207. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +394 -0
  208. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +282 -0
  209. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +71 -0
  210. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +359 -0
  211. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  212. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +70 -0
  213. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +248 -0
  214. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +138 -0
  215. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +55 -0
  216. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +193 -0
  217. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +96 -0
  218. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +196 -0
  219. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +11 -0
  220. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +811 -0
  221. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +616 -0
  222. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +408 -0
  223. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +1270 -0
  224. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +592 -0
  225. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +220 -0
  226. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +235 -0
  227. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +152 -0
  228. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  229. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +421 -0
  230. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +309 -0
  231. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +249 -0
  232. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +502 -0
  233. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +488 -0
  234. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +323 -0
  235. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +280 -0
  236. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +102 -0
  237. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +88 -0
  238. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +588 -0
  239. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +142 -0
  240. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +416 -0
  241. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +1234 -0
  242. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +677 -0
  243. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +1392 -0
  244. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +1095 -0
  245. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +272 -0
  246. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +142 -0
  247. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +268 -0
  248. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +167 -0
  249. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +470 -0
  250. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +11 -0
  251. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +370 -0
  252. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +407 -0
  253. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +238 -0
  254. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +241 -0
  255. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +178 -0
  256. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +611 -0
  257. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +356 -0
  258. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +662 -0
  259. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +425 -0
  260. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +300 -0
  261. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  262. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  263. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  264. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  265. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +128 -0
  266. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +573 -0
  267. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +155 -0
  268. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +475 -0
  269. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +481 -0
  270. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  271. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +194 -0
  272. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +435 -0
  273. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +483 -0
  274. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +57 -0
  275. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +196 -0
  276. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +107 -0
  277. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +7 -0
  278. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +1306 -0
  279. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +336 -0
  280. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +1262 -0
  281. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +352 -0
  282. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +308 -0
  283. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  284. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  285. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  286. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  287. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  288. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +719 -0
  289. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +103 -0
  290. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +490 -0
  291. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +64 -0
  292. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +212 -0
  293. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +202 -0
  294. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +1655 -0
  295. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +3118 -0
  296. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +196 -0
  297. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +264 -0
  298. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +1102 -0
  299. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +192 -0
  300. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +2 -0
  301. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +337 -0
  302. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +498 -0
  303. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  304. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +77 -0
  305. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +213 -0
  306. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +687 -0
  307. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +280 -0
  308. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +1148 -0
  309. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +27 -0
  310. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +738 -0
  311. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +544 -0
  312. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +78 -0
  313. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +59 -0
  314. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +219 -0
  315. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +155 -0
  316. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +4 -0
  317. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +324 -0
  318. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +468 -0
  319. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +633 -0
  320. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  321. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +328 -0
  322. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +451 -0
  323. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +491 -0
  324. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +55 -0
  325. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +77 -0
  326. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +73 -0
  327. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +464 -0
  328. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +1463 -0
  329. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +306 -0
  330. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +98 -0
  331. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +167 -0
  332. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +138 -0
  333. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +5 -0
  334. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +239 -0
  335. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +264 -0
  336. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +716 -0
  337. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  338. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +254 -0
  339. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +212 -0
  340. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +88 -0
  341. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +511 -0
  342. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +149 -0
  343. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +983 -0
  344. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +625 -0
  345. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +2542 -0
  346. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +2107 -0
  347. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +966 -0
  348. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +404 -0
  349. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +30 -0
  350. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +296 -0
  351. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +374 -0
  352. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +564 -0
  353. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +406 -0
  354. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  355. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +23 -0
  356. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +154 -0
  357. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +144 -0
  358. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +109 -0
  359. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +136 -0
  360. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +129 -0
  361. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +300 -0
  362. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +678 -0
  363. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +80 -0
  364. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +266 -0
  365. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +85 -0
  366. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +171 -0
  367. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +984 -0
  368. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +340 -0
  369. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +835 -0
  370. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +831 -0
  371. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +85 -0
  372. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +299 -0
  373. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +115 -0
  374. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +58 -0
  375. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +314 -0
  376. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +872 -0
  377. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +163 -0
  378. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +46 -0
  379. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +24 -0
  380. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +26 -0
  381. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +615 -0
  382. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +459 -0
  383. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +556 -0
  384. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +179 -0
  385. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +62 -0
  386. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +15 -0
  387. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +140 -0
  388. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +60 -0
  389. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +27 -0
  390. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +274 -0
  391. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +556 -0
  392. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +57 -0
  393. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +37 -0
  394. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +88 -0
  395. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +149 -0
  396. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +1158 -0
  397. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +803 -0
  398. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +76 -0
  399. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +8 -0
  400. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +138 -0
  401. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +191 -0
  402. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +642 -0
  403. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +179 -0
  404. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +270 -0
  405. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +431 -0
  406. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +161 -0
  407. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +248 -0
  408. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +41 -0
  409. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +103 -0
  410. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +54 -0
  411. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +157 -0
  412. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +981 -0
  413. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +142 -0
  414. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +406 -0
  415. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +5 -0
  416. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +90 -0
  417. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +576 -0
  418. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +529 -0
  419. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +185 -0
  420. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +182 -0
  421. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  422. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +25 -0
  423. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +203 -0
  424. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +307 -0
  425. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +147 -0
  426. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +131 -0
  427. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +7 -0
  428. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +1042 -0
  429. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +413 -0
  430. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +88 -0
  431. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +219 -0
  432. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +1281 -0
  433. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +106 -0
  434. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +273 -0
  435. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  436. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +624 -0
  437. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +114 -0
  438. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +79 -0
  439. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +99 -0
  440. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +934 -0
  441. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +53 -0
  442. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +174 -0
  443. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +500 -0
  444. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +76 -0
  445. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +86 -0
  446. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +77 -0
  447. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +278 -0
  448. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +13 -0
  449. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +435 -0
  450. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +1363 -0
  451. package/runtime/python/okstra_vendor/networkx/classes/filters.py +95 -0
  452. package/runtime/python/okstra_vendor/networkx/classes/function.py +1549 -0
  453. package/runtime/python/okstra_vendor/networkx/classes/graph.py +2082 -0
  454. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +269 -0
  455. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +977 -0
  456. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +1294 -0
  457. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +1447 -0
  458. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  459. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +192 -0
  460. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +476 -0
  461. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +362 -0
  462. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +331 -0
  463. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +110 -0
  464. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +177 -0
  465. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +1045 -0
  466. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +950 -0
  467. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +12 -0
  468. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +349 -0
  469. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +459 -0
  470. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +528 -0
  471. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +1421 -0
  472. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +131 -0
  473. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +371 -0
  474. package/runtime/python/okstra_vendor/networkx/conftest.py +261 -0
  475. package/runtime/python/okstra_vendor/networkx/convert.py +502 -0
  476. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +1314 -0
  477. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +7 -0
  478. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +2036 -0
  479. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +470 -0
  480. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +570 -0
  481. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +361 -0
  482. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +2978 -0
  483. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  484. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  485. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  486. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  487. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  488. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  489. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  490. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +237 -0
  491. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +229 -0
  492. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +285 -0
  493. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +631 -0
  494. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +146 -0
  495. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +1582 -0
  496. package/runtime/python/okstra_vendor/networkx/exception.py +131 -0
  497. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +34 -0
  498. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  499. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +227 -0
  500. package/runtime/python/okstra_vendor/networkx/generators/classic.py +1091 -0
  501. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +68 -0
  502. package/runtime/python/okstra_vendor/networkx/generators/community.py +1070 -0
  503. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +886 -0
  504. package/runtime/python/okstra_vendor/networkx/generators/directed.py +572 -0
  505. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +174 -0
  506. package/runtime/python/okstra_vendor/networkx/generators/ego.py +66 -0
  507. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +499 -0
  508. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +1037 -0
  509. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +163 -0
  510. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +443 -0
  511. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +125 -0
  512. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +70 -0
  513. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +664 -0
  514. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +405 -0
  515. package/runtime/python/okstra_vendor/networkx/generators/line.py +501 -0
  516. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +110 -0
  517. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +259 -0
  518. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +117 -0
  519. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +1416 -0
  520. package/runtime/python/okstra_vendor/networkx/generators/small.py +1070 -0
  521. package/runtime/python/okstra_vendor/networkx/generators/social.py +554 -0
  522. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +120 -0
  523. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +54 -0
  524. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +131 -0
  525. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  526. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +75 -0
  527. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +642 -0
  528. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +20 -0
  529. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +362 -0
  530. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +224 -0
  531. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +189 -0
  532. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +103 -0
  533. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +39 -0
  534. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +182 -0
  535. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +488 -0
  536. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +133 -0
  537. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +221 -0
  538. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +28 -0
  539. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +144 -0
  540. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +125 -0
  541. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +264 -0
  542. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +316 -0
  543. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +30 -0
  544. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +82 -0
  545. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +33 -0
  546. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +495 -0
  547. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +220 -0
  548. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +49 -0
  549. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +72 -0
  550. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +92 -0
  551. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +64 -0
  552. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +195 -0
  553. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +15 -0
  554. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +74 -0
  555. package/runtime/python/okstra_vendor/networkx/generators/trees.py +1070 -0
  556. package/runtime/python/okstra_vendor/networkx/generators/triads.py +94 -0
  557. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +188 -0
  558. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +13 -0
  559. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +650 -0
  560. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +466 -0
  561. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +77 -0
  562. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +168 -0
  563. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +512 -0
  564. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +166 -0
  565. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +186 -0
  566. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  567. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +400 -0
  568. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +108 -0
  569. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +40 -0
  570. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +275 -0
  571. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +334 -0
  572. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +86 -0
  573. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +70 -0
  574. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +17 -0
  575. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +330 -0
  576. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +489 -0
  577. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +1084 -0
  578. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +879 -0
  579. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +427 -0
  580. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +1053 -0
  581. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +19 -0
  582. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +156 -0
  583. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +190 -0
  584. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +261 -0
  585. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  586. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +78 -0
  587. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +78 -0
  588. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +109 -0
  589. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +48 -0
  590. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +137 -0
  591. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +108 -0
  592. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +393 -0
  593. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +113 -0
  594. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +286 -0
  595. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +379 -0
  596. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  597. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +354 -0
  598. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +318 -0
  599. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +612 -0
  600. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +744 -0
  601. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +181 -0
  602. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +1531 -0
  603. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +30 -0
  604. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +63 -0
  605. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +128 -0
  606. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +166 -0
  607. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +1742 -0
  608. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +851 -0
  609. package/runtime/python/okstra_vendor/networkx/relabel.py +285 -0
  610. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  611. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +248 -0
  612. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +321 -0
  613. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +531 -0
  614. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +349 -0
  615. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +281 -0
  616. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +40 -0
  617. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +11 -0
  618. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +96 -0
  619. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +349 -0
  620. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +8 -0
  621. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +8 -0
  622. package/runtime/python/okstra_vendor/networkx/utils/backends.py +2171 -0
  623. package/runtime/python/okstra_vendor/networkx/utils/configs.py +396 -0
  624. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +1233 -0
  625. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +338 -0
  626. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +297 -0
  627. package/runtime/python/okstra_vendor/networkx/utils/misc.py +703 -0
  628. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +198 -0
  629. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +159 -0
  630. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  631. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +11 -0
  632. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +225 -0
  633. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +263 -0
  634. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +510 -0
  635. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +131 -0
  636. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +268 -0
  637. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +393 -0
  638. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +53 -0
  639. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +63 -0
  640. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +55 -0
  641. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +106 -0
  642. package/runtime/skills/okstra-graphify/SKILL.md +161 -0
  643. package/runtime/skills/okstra-inspect/SKILL.md +17 -9
  644. package/runtime/templates/reports/settings.template.json +4 -0
  645. package/src/cli-registry.mjs +7 -0
  646. package/src/commands/graphify.mjs +32 -0
  647. package/src/commands/lifecycle/doctor.mjs +9 -0
  648. package/src/lib/skill-catalog.mjs +1 -0
@@ -0,0 +1,1416 @@
1
+ """
2
+ Generators for random graphs.
3
+
4
+ """
5
+
6
+ import itertools
7
+ import math
8
+ from collections import defaultdict
9
+
10
+ import networkx as nx
11
+ from networkx.utils import py_random_state
12
+
13
+ from ..utils.misc import check_create_using
14
+ from .classic import complete_graph, empty_graph, path_graph, star_graph
15
+ from .degree_seq import degree_sequence_tree
16
+
17
+ __all__ = [
18
+ "fast_gnp_random_graph",
19
+ "gnp_random_graph",
20
+ "dense_gnm_random_graph",
21
+ "gnm_random_graph",
22
+ "erdos_renyi_graph",
23
+ "binomial_graph",
24
+ "newman_watts_strogatz_graph",
25
+ "watts_strogatz_graph",
26
+ "connected_watts_strogatz_graph",
27
+ "random_regular_graph",
28
+ "barabasi_albert_graph",
29
+ "dual_barabasi_albert_graph",
30
+ "extended_barabasi_albert_graph",
31
+ "powerlaw_cluster_graph",
32
+ "random_lobster",
33
+ "random_lobster_graph",
34
+ "random_shell_graph",
35
+ "random_powerlaw_tree",
36
+ "random_powerlaw_tree_sequence",
37
+ "random_kernel_graph",
38
+ ]
39
+
40
+
41
+ @py_random_state(2)
42
+ @nx._dispatchable(graphs=None, returns_graph=True)
43
+ def fast_gnp_random_graph(n, p, seed=None, directed=False, *, create_using=None):
44
+ """Returns a $G_{n,p}$ random graph, also known as an Erdős-Rényi graph or
45
+ a binomial graph.
46
+
47
+ Parameters
48
+ ----------
49
+ n : int
50
+ The number of nodes.
51
+ p : float
52
+ Probability for edge creation.
53
+ seed : integer, random_state, or None (default)
54
+ Indicator of random number generation state.
55
+ See :ref:`Randomness<randomness>`.
56
+ directed : bool, optional (default=False)
57
+ If True, this function returns a directed graph.
58
+ create_using : Graph constructor, optional (default=nx.Graph or nx.DiGraph)
59
+ Graph type to create. If graph instance, then cleared before populated.
60
+ Multigraph types are not supported and raise a ``NetworkXError``.
61
+ By default NetworkX Graph or DiGraph are used depending on `directed`.
62
+
63
+ Notes
64
+ -----
65
+ The $G_{n,p}$ graph algorithm chooses each of the $[n (n - 1)] / 2$
66
+ (undirected) or $n (n - 1)$ (directed) possible edges with probability $p$.
67
+
68
+ This algorithm [1]_ runs in $O(n + m)$ time, where `m` is the expected number of
69
+ edges, which equals $p n (n - 1) / 2$. This should be faster than
70
+ :func:`gnp_random_graph` when $p$ is small and the expected number of edges
71
+ is small (that is, the graph is sparse).
72
+
73
+ See Also
74
+ --------
75
+ gnp_random_graph
76
+
77
+ References
78
+ ----------
79
+ .. [1] Vladimir Batagelj and Ulrik Brandes,
80
+ "Efficient generation of large random networks",
81
+ Phys. Rev. E, 71, 036113, 2005.
82
+ """
83
+ default = nx.DiGraph if directed else nx.Graph
84
+ create_using = check_create_using(
85
+ create_using, directed=directed, multigraph=False, default=default
86
+ )
87
+ if p <= 0 or p >= 1:
88
+ return nx.gnp_random_graph(
89
+ n, p, seed=seed, directed=directed, create_using=create_using
90
+ )
91
+
92
+ G = empty_graph(n, create_using=create_using)
93
+
94
+ lp = math.log(1.0 - p)
95
+
96
+ if directed:
97
+ v = 1
98
+ w = -1
99
+ while v < n:
100
+ lr = math.log(1.0 - seed.random())
101
+ w = w + 1 + int(lr / lp)
102
+ while w >= v and v < n:
103
+ w = w - v
104
+ v = v + 1
105
+ if v < n:
106
+ G.add_edge(w, v)
107
+
108
+ # Nodes in graph are from 0,n-1 (start with v as the second node index).
109
+ v = 1
110
+ w = -1
111
+ while v < n:
112
+ lr = math.log(1.0 - seed.random())
113
+ w = w + 1 + int(lr / lp)
114
+ while w >= v and v < n:
115
+ w = w - v
116
+ v = v + 1
117
+ if v < n:
118
+ G.add_edge(v, w)
119
+ return G
120
+
121
+
122
+ @py_random_state(2)
123
+ @nx._dispatchable(graphs=None, returns_graph=True)
124
+ def gnp_random_graph(n, p, seed=None, directed=False, *, create_using=None):
125
+ """Returns a $G_{n,p}$ random graph, also known as an Erdős-Rényi graph
126
+ or a binomial graph.
127
+
128
+ The $G_{n,p}$ model chooses each of the possible edges with probability $p$.
129
+
130
+ Parameters
131
+ ----------
132
+ n : int
133
+ The number of nodes.
134
+ p : float
135
+ Probability for edge creation.
136
+ seed : integer, random_state, or None (default)
137
+ Indicator of random number generation state.
138
+ See :ref:`Randomness<randomness>`.
139
+ directed : bool, optional (default=False)
140
+ If True, this function returns a directed graph.
141
+ create_using : Graph constructor, optional (default=nx.Graph or nx.DiGraph)
142
+ Graph type to create. If graph instance, then cleared before populated.
143
+ Multigraph types are not supported and raise a ``NetworkXError``.
144
+ By default NetworkX Graph or DiGraph are used depending on `directed`.
145
+
146
+ See Also
147
+ --------
148
+ fast_gnp_random_graph
149
+
150
+ Notes
151
+ -----
152
+ This algorithm [2]_ runs in $O(n^2)$ time. For sparse graphs (that is, for
153
+ small values of $p$), :func:`fast_gnp_random_graph` is a faster algorithm.
154
+
155
+ :func:`binomial_graph` and :func:`erdos_renyi_graph` are
156
+ aliases for :func:`gnp_random_graph`.
157
+
158
+ >>> nx.binomial_graph is nx.gnp_random_graph
159
+ True
160
+ >>> nx.erdos_renyi_graph is nx.gnp_random_graph
161
+ True
162
+
163
+ References
164
+ ----------
165
+ .. [1] P. Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
166
+ .. [2] E. N. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
167
+ """
168
+ default = nx.DiGraph if directed else nx.Graph
169
+ create_using = check_create_using(
170
+ create_using, directed=directed, multigraph=False, default=default
171
+ )
172
+ if p >= 1:
173
+ return complete_graph(n, create_using=create_using)
174
+
175
+ G = nx.empty_graph(n, create_using=create_using)
176
+ if p <= 0:
177
+ return G
178
+
179
+ edgetool = itertools.permutations if directed else itertools.combinations
180
+ for e in edgetool(range(n), 2):
181
+ if seed.random() < p:
182
+ G.add_edge(*e)
183
+ return G
184
+
185
+
186
+ # add some aliases to common names
187
+ binomial_graph = gnp_random_graph
188
+ erdos_renyi_graph = gnp_random_graph
189
+
190
+
191
+ @py_random_state(2)
192
+ @nx._dispatchable(graphs=None, returns_graph=True)
193
+ def dense_gnm_random_graph(n, m, seed=None, *, create_using=None):
194
+ """Returns a $G_{n,m}$ random graph.
195
+
196
+ In the $G_{n,m}$ model, a graph is chosen uniformly at random from the set
197
+ of all graphs with $n$ nodes and $m$ edges.
198
+
199
+ This algorithm should be faster than :func:`gnm_random_graph` for dense
200
+ graphs.
201
+
202
+ Parameters
203
+ ----------
204
+ n : int
205
+ The number of nodes.
206
+ m : int
207
+ The number of edges.
208
+ seed : integer, random_state, or None (default)
209
+ Indicator of random number generation state.
210
+ See :ref:`Randomness<randomness>`.
211
+ create_using : Graph constructor, optional (default=nx.Graph)
212
+ Graph type to create. If graph instance, then cleared before populated.
213
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
214
+
215
+ See Also
216
+ --------
217
+ gnm_random_graph
218
+
219
+ Notes
220
+ -----
221
+ Algorithm by Keith M. Briggs Mar 31, 2006.
222
+ Inspired by Knuth's Algorithm S (Selection sampling technique),
223
+ in section 3.4.2 of [1]_.
224
+
225
+ References
226
+ ----------
227
+ .. [1] Donald E. Knuth, The Art of Computer Programming,
228
+ Volume 2/Seminumerical algorithms, Third Edition, Addison-Wesley, 1997.
229
+ """
230
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
231
+ mmax = n * (n - 1) // 2
232
+ if m >= mmax:
233
+ return complete_graph(n, create_using)
234
+ G = empty_graph(n, create_using)
235
+
236
+ if n == 1:
237
+ return G
238
+
239
+ u = 0
240
+ v = 1
241
+ t = 0
242
+ k = 0
243
+ while True:
244
+ if seed.randrange(mmax - t) < m - k:
245
+ G.add_edge(u, v)
246
+ k += 1
247
+ if k == m:
248
+ return G
249
+ t += 1
250
+ v += 1
251
+ if v == n: # go to next row of adjacency matrix
252
+ u += 1
253
+ v = u + 1
254
+
255
+
256
+ @py_random_state(2)
257
+ @nx._dispatchable(graphs=None, returns_graph=True)
258
+ def gnm_random_graph(n, m, seed=None, directed=False, *, create_using=None):
259
+ """Returns a $G_{n,m}$ random graph.
260
+
261
+ In the $G_{n,m}$ model, a graph is chosen uniformly at random from the set
262
+ of all graphs with $n$ nodes and $m$ edges.
263
+
264
+ This algorithm should be faster than :func:`dense_gnm_random_graph` for
265
+ sparse graphs.
266
+
267
+ Parameters
268
+ ----------
269
+ n : int
270
+ The number of nodes.
271
+ m : int
272
+ The number of edges.
273
+ seed : integer, random_state, or None (default)
274
+ Indicator of random number generation state.
275
+ See :ref:`Randomness<randomness>`.
276
+ directed : bool, optional (default=False)
277
+ If True return a directed graph
278
+ create_using : Graph constructor, optional (default=nx.Graph or nx.DiGraph)
279
+ Graph type to create. If graph instance, then cleared before populated.
280
+ Multigraph types are not supported and raise a ``NetworkXError``.
281
+ By default NetworkX Graph or DiGraph are used depending on `directed`.
282
+
283
+ See also
284
+ --------
285
+ dense_gnm_random_graph
286
+
287
+ """
288
+ default = nx.DiGraph if directed else nx.Graph
289
+ create_using = check_create_using(
290
+ create_using, directed=directed, multigraph=False, default=default
291
+ )
292
+ if n == 1:
293
+ return nx.empty_graph(n, create_using=create_using)
294
+ max_edges = n * (n - 1) if directed else n * (n - 1) / 2.0
295
+ if m >= max_edges:
296
+ return complete_graph(n, create_using=create_using)
297
+
298
+ G = nx.empty_graph(n, create_using=create_using)
299
+ nlist = list(G)
300
+ edge_count = 0
301
+ while edge_count < m:
302
+ # generate random edge,u,v
303
+ u = seed.choice(nlist)
304
+ v = seed.choice(nlist)
305
+ if u == v or G.has_edge(u, v):
306
+ continue
307
+ else:
308
+ G.add_edge(u, v)
309
+ edge_count = edge_count + 1
310
+ return G
311
+
312
+
313
+ @py_random_state(3)
314
+ @nx._dispatchable(graphs=None, returns_graph=True)
315
+ def newman_watts_strogatz_graph(n, k, p, seed=None, *, create_using=None):
316
+ """Returns a Newman–Watts–Strogatz small-world graph.
317
+
318
+ Parameters
319
+ ----------
320
+ n : int
321
+ The number of nodes.
322
+ k : int
323
+ Each node is joined with its `k` nearest neighbors in a ring
324
+ topology.
325
+ p : float
326
+ The probability of adding a new edge for each edge.
327
+ seed : integer, random_state, or None (default)
328
+ Indicator of random number generation state.
329
+ See :ref:`Randomness<randomness>`.
330
+ create_using : Graph constructor, optional (default=nx.Graph)
331
+ Graph type to create. If graph instance, then cleared before populated.
332
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
333
+
334
+ Notes
335
+ -----
336
+ First create a ring over $n$ nodes [1]_. Then each node in the ring is
337
+ connected with its $k$ nearest neighbors (or $k - 1$ neighbors if $k$
338
+ is odd). Then shortcuts are created by adding new edges as follows: for
339
+ each edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest
340
+ neighbors" with probability $p$ add a new edge $(u, w)$ with
341
+ randomly-chosen existing node $w$. In contrast with
342
+ :func:`watts_strogatz_graph`, no edges are removed.
343
+
344
+ See Also
345
+ --------
346
+ watts_strogatz_graph
347
+
348
+ References
349
+ ----------
350
+ .. [1] M. E. J. Newman and D. J. Watts,
351
+ Renormalization group analysis of the small-world network model,
352
+ Physics Letters A, 263, 341, 1999.
353
+ https://doi.org/10.1016/S0375-9601(99)00757-4
354
+ """
355
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
356
+ if k > n:
357
+ raise nx.NetworkXError("k>=n, choose smaller k or larger n")
358
+
359
+ # If k == n the graph return is a complete graph
360
+ if k == n:
361
+ return nx.complete_graph(n, create_using)
362
+
363
+ G = empty_graph(n, create_using)
364
+ nlist = list(G.nodes())
365
+ fromv = nlist
366
+ # connect the k/2 neighbors
367
+ for j in range(1, k // 2 + 1):
368
+ tov = fromv[j:] + fromv[0:j] # the first j are now last
369
+ for i in range(len(fromv)):
370
+ G.add_edge(fromv[i], tov[i])
371
+ # for each edge u-v, with probability p, randomly select existing
372
+ # node w and add new edge u-w
373
+ e = list(G.edges())
374
+ for u, v in e:
375
+ if seed.random() < p:
376
+ w = seed.choice(nlist)
377
+ # no self-loops and reject if edge u-w exists
378
+ # is that the correct NWS model?
379
+ while w == u or G.has_edge(u, w):
380
+ w = seed.choice(nlist)
381
+ if G.degree(u) >= n - 1:
382
+ break # skip this rewiring
383
+ else:
384
+ G.add_edge(u, w)
385
+ return G
386
+
387
+
388
+ @py_random_state(3)
389
+ @nx._dispatchable(graphs=None, returns_graph=True)
390
+ def watts_strogatz_graph(n, k, p, seed=None, *, create_using=None):
391
+ """Returns a Watts–Strogatz small-world graph.
392
+
393
+ Parameters
394
+ ----------
395
+ n : int
396
+ The number of nodes
397
+ k : int
398
+ Each node is joined with its `k` nearest neighbors in a ring
399
+ topology.
400
+ p : float
401
+ The probability of rewiring each edge
402
+ seed : integer, random_state, or None (default)
403
+ Indicator of random number generation state.
404
+ See :ref:`Randomness<randomness>`.
405
+ create_using : Graph constructor, optional (default=nx.Graph)
406
+ Graph type to create. If graph instance, then cleared before populated.
407
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
408
+
409
+ See Also
410
+ --------
411
+ newman_watts_strogatz_graph
412
+ connected_watts_strogatz_graph
413
+
414
+ Notes
415
+ -----
416
+ First create a ring over $n$ nodes [1]_. Then each node in the ring is joined
417
+ to its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd).
418
+ Then shortcuts are created by replacing some edges as follows: for each
419
+ edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors"
420
+ with probability $p$ replace it with a new edge $(u, w)$ with uniformly
421
+ random choice of existing node $w$.
422
+
423
+ In contrast with :func:`newman_watts_strogatz_graph`, the random rewiring
424
+ does not increase the number of edges. The rewired graph is not guaranteed
425
+ to be connected as in :func:`connected_watts_strogatz_graph`.
426
+
427
+ References
428
+ ----------
429
+ .. [1] Duncan J. Watts and Steven H. Strogatz,
430
+ Collective dynamics of small-world networks,
431
+ Nature, 393, pp. 440--442, 1998.
432
+ """
433
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
434
+ if k > n:
435
+ raise nx.NetworkXError("k>n, choose smaller k or larger n")
436
+
437
+ # If k == n, the graph is complete not Watts-Strogatz
438
+ if k == n:
439
+ G = nx.complete_graph(n, create_using)
440
+ return G
441
+
442
+ G = nx.empty_graph(n, create_using=create_using)
443
+ nodes = list(range(n)) # nodes are labeled 0 to n-1
444
+ # connect each node to k/2 neighbors
445
+ for j in range(1, k // 2 + 1):
446
+ targets = nodes[j:] + nodes[0:j] # first j nodes are now last in list
447
+ G.add_edges_from(zip(nodes, targets))
448
+ # rewire edges from each node
449
+ # loop over all nodes in order (label) and neighbors in order (distance)
450
+ # no self loops or multiple edges allowed
451
+ for j in range(1, k // 2 + 1): # outer loop is neighbors
452
+ targets = nodes[j:] + nodes[0:j] # first j nodes are now last in list
453
+ # inner loop in node order
454
+ for u, v in zip(nodes, targets):
455
+ if seed.random() < p:
456
+ w = seed.choice(nodes)
457
+ # Enforce no self-loops or multiple edges
458
+ while w == u or G.has_edge(u, w):
459
+ w = seed.choice(nodes)
460
+ if G.degree(u) >= n - 1:
461
+ break # skip this rewiring
462
+ else:
463
+ G.remove_edge(u, v)
464
+ G.add_edge(u, w)
465
+ return G
466
+
467
+
468
+ @py_random_state(4)
469
+ @nx._dispatchable(graphs=None, returns_graph=True)
470
+ def connected_watts_strogatz_graph(n, k, p, tries=100, seed=None, *, create_using=None):
471
+ """Returns a connected Watts–Strogatz small-world graph.
472
+
473
+ Attempts to generate a connected graph by repeated generation of
474
+ Watts–Strogatz small-world graphs. An exception is raised if the maximum
475
+ number of tries is exceeded.
476
+
477
+ Parameters
478
+ ----------
479
+ n : int
480
+ The number of nodes
481
+ k : int
482
+ Each node is joined with its `k` nearest neighbors in a ring
483
+ topology.
484
+ p : float
485
+ The probability of rewiring each edge
486
+ tries : int
487
+ Number of attempts to generate a connected graph.
488
+ seed : integer, random_state, or None (default)
489
+ Indicator of random number generation state.
490
+ See :ref:`Randomness<randomness>`.
491
+ create_using : Graph constructor, optional (default=nx.Graph)
492
+ Graph type to create. If graph instance, then cleared before populated.
493
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
494
+
495
+ Notes
496
+ -----
497
+ First create a ring over $n$ nodes [1]_. Then each node in the ring is joined
498
+ to its $k$ nearest neighbors (or $k - 1$ neighbors if $k$ is odd).
499
+ Then shortcuts are created by replacing some edges as follows: for each
500
+ edge $(u, v)$ in the underlying "$n$-ring with $k$ nearest neighbors"
501
+ with probability $p$ replace it with a new edge $(u, w)$ with uniformly
502
+ random choice of existing node $w$.
503
+ The entire process is repeated until a connected graph results.
504
+
505
+ See Also
506
+ --------
507
+ newman_watts_strogatz_graph
508
+ watts_strogatz_graph
509
+
510
+ References
511
+ ----------
512
+ .. [1] Duncan J. Watts and Steven H. Strogatz,
513
+ Collective dynamics of small-world networks,
514
+ Nature, 393, pp. 440--442, 1998.
515
+ """
516
+ for i in range(tries):
517
+ # seed is an RNG so should change sequence each call
518
+ G = watts_strogatz_graph(n, k, p, seed, create_using=create_using)
519
+ if nx.is_connected(G):
520
+ return G
521
+ raise nx.NetworkXError("Maximum number of tries exceeded")
522
+
523
+
524
+ @py_random_state(2)
525
+ @nx._dispatchable(graphs=None, returns_graph=True)
526
+ def random_regular_graph(d, n, seed=None, *, create_using=None):
527
+ r"""Returns a random $d$-regular graph on $n$ nodes.
528
+
529
+ A regular graph is a graph where each node has the same number of neighbors.
530
+
531
+ The resulting graph has no self-loops or parallel edges.
532
+
533
+ Parameters
534
+ ----------
535
+ d : int
536
+ The degree of each node.
537
+ n : integer
538
+ The number of nodes. The value of $n \times d$ must be even.
539
+ seed : integer, random_state, or None (default)
540
+ Indicator of random number generation state.
541
+ See :ref:`Randomness<randomness>`.
542
+ create_using : Graph constructor, optional (default=nx.Graph)
543
+ Graph type to create. If graph instance, then cleared before populated.
544
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
545
+
546
+ Notes
547
+ -----
548
+ The nodes are numbered from $0$ to $n - 1$.
549
+
550
+ Kim and Vu's paper [2]_ shows that this algorithm samples in an
551
+ asymptotically uniform way from the space of random graphs when
552
+ $d = O(n^{1 / 3 - \epsilon})$.
553
+
554
+ Raises
555
+ ------
556
+
557
+ NetworkXError
558
+ If $n \times d$ is odd or $d$ is greater than or equal to $n$.
559
+
560
+ References
561
+ ----------
562
+ .. [1] A. Steger and N. Wormald,
563
+ Generating random regular graphs quickly,
564
+ Probability and Computing 8 (1999), 377-396, 1999.
565
+ https://doi.org/10.1017/S0963548399003867
566
+
567
+ .. [2] Jeong Han Kim and Van H. Vu,
568
+ Generating random regular graphs,
569
+ Proceedings of the thirty-fifth ACM symposium on Theory of computing,
570
+ San Diego, CA, USA, pp 213--222, 2003.
571
+ http://portal.acm.org/citation.cfm?id=780542.780576
572
+ """
573
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
574
+ if (n * d) % 2 != 0:
575
+ raise nx.NetworkXError("n * d must be even")
576
+
577
+ if not 0 <= d < n:
578
+ raise nx.NetworkXError("the 0 <= d < n inequality must be satisfied")
579
+
580
+ G = nx.empty_graph(n, create_using=create_using)
581
+
582
+ if d == 0:
583
+ return G
584
+
585
+ def _suitable(edges, potential_edges):
586
+ # Helper subroutine to check if there are suitable edges remaining
587
+ # If False, the generation of the graph has failed
588
+ if not potential_edges:
589
+ return True
590
+ for s1 in potential_edges:
591
+ for s2 in potential_edges:
592
+ # Two iterators on the same dictionary are guaranteed
593
+ # to visit it in the same order if there are no
594
+ # intervening modifications.
595
+ if s1 == s2:
596
+ # Only need to consider s1-s2 pair one time
597
+ break
598
+ if s1 > s2:
599
+ s1, s2 = s2, s1
600
+ if (s1, s2) not in edges:
601
+ return True
602
+ return False
603
+
604
+ def _try_creation():
605
+ # Attempt to create an edge set
606
+
607
+ edges = set()
608
+ stubs = list(range(n)) * d
609
+
610
+ while stubs:
611
+ potential_edges = defaultdict(lambda: 0)
612
+ seed.shuffle(stubs)
613
+ stubiter = iter(stubs)
614
+ for s1, s2 in zip(stubiter, stubiter):
615
+ if s1 > s2:
616
+ s1, s2 = s2, s1
617
+ if s1 != s2 and ((s1, s2) not in edges):
618
+ edges.add((s1, s2))
619
+ else:
620
+ potential_edges[s1] += 1
621
+ potential_edges[s2] += 1
622
+
623
+ if not _suitable(edges, potential_edges):
624
+ return None # failed to find suitable edge set
625
+
626
+ stubs = [
627
+ node
628
+ for node, potential in potential_edges.items()
629
+ for _ in range(potential)
630
+ ]
631
+ return edges
632
+
633
+ # Even though a suitable edge set exists,
634
+ # the generation of such a set is not guaranteed.
635
+ # Try repeatedly to find one.
636
+ edges = _try_creation()
637
+ while edges is None:
638
+ edges = _try_creation()
639
+ G.add_edges_from(edges)
640
+
641
+ return G
642
+
643
+
644
+ def _random_subset(seq, m, rng):
645
+ """Return m unique elements from seq.
646
+
647
+ This differs from random.sample which can return repeated
648
+ elements if seq holds repeated elements.
649
+
650
+ Note: rng is a random.Random or numpy.random.RandomState instance.
651
+ """
652
+ targets = set()
653
+ while len(targets) < m:
654
+ x = rng.choice(seq)
655
+ targets.add(x)
656
+ return targets
657
+
658
+
659
+ @py_random_state(2)
660
+ @nx._dispatchable(graphs=None, returns_graph=True)
661
+ def barabasi_albert_graph(n, m, seed=None, initial_graph=None, *, create_using=None):
662
+ """Returns a random graph using Barabási–Albert preferential attachment
663
+
664
+ A graph of $n$ nodes is grown by attaching new nodes each with $m$
665
+ edges that are preferentially attached to existing nodes with high degree.
666
+
667
+ Parameters
668
+ ----------
669
+ n : int
670
+ Number of nodes
671
+ m : int
672
+ Number of edges to attach from a new node to existing nodes
673
+ seed : integer, random_state, or None (default)
674
+ Indicator of random number generation state.
675
+ See :ref:`Randomness<randomness>`.
676
+ initial_graph : Graph or None (default)
677
+ Initial network for Barabási–Albert algorithm.
678
+ It should be a connected graph for most use cases.
679
+ A copy of `initial_graph` is used.
680
+ If None, starts from a star graph on (m+1) nodes.
681
+ create_using : Graph constructor, optional (default=nx.Graph)
682
+ Graph type to create. If graph instance, then cleared before populated.
683
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
684
+
685
+ Returns
686
+ -------
687
+ G : Graph
688
+
689
+ Raises
690
+ ------
691
+ NetworkXError
692
+ If `m` does not satisfy ``1 <= m < n``, or
693
+ the initial graph number of nodes m0 does not satisfy ``m <= m0 <= n``.
694
+
695
+ References
696
+ ----------
697
+ .. [1] A. L. Barabási and R. Albert "Emergence of scaling in
698
+ random networks", Science 286, pp 509-512, 1999.
699
+ """
700
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
701
+ if m < 1 or m >= n:
702
+ raise nx.NetworkXError(
703
+ f"Barabási–Albert network must have m >= 1 and m < n, m = {m}, n = {n}"
704
+ )
705
+
706
+ if initial_graph is None:
707
+ # Default initial graph : star graph on (m + 1) nodes
708
+ G = star_graph(m, create_using)
709
+ else:
710
+ if len(initial_graph) < m or len(initial_graph) > n:
711
+ raise nx.NetworkXError(
712
+ f"Barabási–Albert initial graph needs between m={m} and n={n} nodes"
713
+ )
714
+ G = initial_graph.copy()
715
+
716
+ # List of existing nodes, with nodes repeated once for each adjacent edge
717
+ repeated_nodes = [n for n, d in G.degree() for _ in range(d)]
718
+ # Start adding the other n - m0 nodes.
719
+ source = len(G)
720
+ while source < n:
721
+ # Now choose m unique nodes from the existing nodes
722
+ # Pick uniformly from repeated_nodes (preferential attachment)
723
+ targets = _random_subset(repeated_nodes, m, seed)
724
+ # Add edges to m nodes from the source.
725
+ G.add_edges_from(zip([source] * m, targets))
726
+ # Add one node to the list for each new edge just created.
727
+ repeated_nodes.extend(targets)
728
+ # And the new node "source" has m edges to add to the list.
729
+ repeated_nodes.extend([source] * m)
730
+
731
+ source += 1
732
+ return G
733
+
734
+
735
+ @py_random_state(4)
736
+ @nx._dispatchable(graphs=None, returns_graph=True)
737
+ def dual_barabasi_albert_graph(
738
+ n, m1, m2, p, seed=None, initial_graph=None, *, create_using=None
739
+ ):
740
+ """Returns a random graph using dual Barabási–Albert preferential attachment
741
+
742
+ A graph of $n$ nodes is grown by attaching new nodes each with either $m_1$
743
+ edges (with probability $p$) or $m_2$ edges (with probability $1-p$) that
744
+ are preferentially attached to existing nodes with high degree.
745
+
746
+ Parameters
747
+ ----------
748
+ n : int
749
+ Number of nodes
750
+ m1 : int
751
+ Number of edges to link each new node to existing nodes with probability $p$
752
+ m2 : int
753
+ Number of edges to link each new node to existing nodes with probability $1-p$
754
+ p : float
755
+ The probability of attaching $m_1$ edges (as opposed to $m_2$ edges)
756
+ seed : integer, random_state, or None (default)
757
+ Indicator of random number generation state.
758
+ See :ref:`Randomness<randomness>`.
759
+ initial_graph : Graph or None (default)
760
+ Initial network for Barabási–Albert algorithm.
761
+ A copy of `initial_graph` is used.
762
+ It should be connected for most use cases.
763
+ If None, starts from an star graph on max(m1, m2) + 1 nodes.
764
+ create_using : Graph constructor, optional (default=nx.Graph)
765
+ Graph type to create. If graph instance, then cleared before populated.
766
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
767
+
768
+ Returns
769
+ -------
770
+ G : Graph
771
+
772
+ Raises
773
+ ------
774
+ NetworkXError
775
+ If `m1` and `m2` do not satisfy ``1 <= m1,m2 < n``, or
776
+ `p` does not satisfy ``0 <= p <= 1``, or
777
+ the initial graph number of nodes m0 does not satisfy m1, m2 <= m0 <= n.
778
+
779
+ References
780
+ ----------
781
+ .. [1] N. Moshiri "The dual-Barabasi-Albert model", arXiv:1810.10538.
782
+ """
783
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
784
+ if m1 < 1 or m1 >= n:
785
+ raise nx.NetworkXError(
786
+ f"Dual Barabási–Albert must have m1 >= 1 and m1 < n, m1 = {m1}, n = {n}"
787
+ )
788
+ if m2 < 1 or m2 >= n:
789
+ raise nx.NetworkXError(
790
+ f"Dual Barabási–Albert must have m2 >= 1 and m2 < n, m2 = {m2}, n = {n}"
791
+ )
792
+ if p < 0 or p > 1:
793
+ raise nx.NetworkXError(
794
+ f"Dual Barabási–Albert network must have 0 <= p <= 1, p = {p}"
795
+ )
796
+
797
+ # For simplicity, if p == 0 or 1, just return BA
798
+ if p == 1:
799
+ return barabasi_albert_graph(n, m1, seed, create_using=create_using)
800
+ elif p == 0:
801
+ return barabasi_albert_graph(n, m2, seed, create_using=create_using)
802
+
803
+ if initial_graph is None:
804
+ # Default initial graph : star graph on max(m1, m2) nodes
805
+ G = star_graph(max(m1, m2), create_using)
806
+ else:
807
+ if len(initial_graph) < max(m1, m2) or len(initial_graph) > n:
808
+ raise nx.NetworkXError(
809
+ f"Barabási–Albert initial graph must have between "
810
+ f"max(m1, m2) = {max(m1, m2)} and n = {n} nodes"
811
+ )
812
+ G = initial_graph.copy()
813
+
814
+ # Target nodes for new edges
815
+ targets = list(G)
816
+ # List of existing nodes, with nodes repeated once for each adjacent edge
817
+ repeated_nodes = [n for n, d in G.degree() for _ in range(d)]
818
+ # Start adding the remaining nodes.
819
+ source = len(G)
820
+ while source < n:
821
+ # Pick which m to use (m1 or m2)
822
+ if seed.random() < p:
823
+ m = m1
824
+ else:
825
+ m = m2
826
+ # Now choose m unique nodes from the existing nodes
827
+ # Pick uniformly from repeated_nodes (preferential attachment)
828
+ targets = _random_subset(repeated_nodes, m, seed)
829
+ # Add edges to m nodes from the source.
830
+ G.add_edges_from(zip([source] * m, targets))
831
+ # Add one node to the list for each new edge just created.
832
+ repeated_nodes.extend(targets)
833
+ # And the new node "source" has m edges to add to the list.
834
+ repeated_nodes.extend([source] * m)
835
+
836
+ source += 1
837
+ return G
838
+
839
+
840
+ @py_random_state(4)
841
+ @nx._dispatchable(graphs=None, returns_graph=True)
842
+ def extended_barabasi_albert_graph(n, m, p, q, seed=None, *, create_using=None):
843
+ """Returns an extended Barabási–Albert model graph.
844
+
845
+ An extended Barabási–Albert model graph is a random graph constructed
846
+ using preferential attachment. The extended model allows new edges,
847
+ rewired edges or new nodes. Based on the probabilities $p$ and $q$
848
+ with $p + q < 1$, the growing behavior of the graph is determined as:
849
+
850
+ 1) With $p$ probability, $m$ new edges are added to the graph,
851
+ starting from randomly chosen existing nodes and attached preferentially at the
852
+ other end.
853
+
854
+ 2) With $q$ probability, $m$ existing edges are rewired
855
+ by randomly choosing an edge and rewiring one end to a preferentially chosen node.
856
+
857
+ 3) With $(1 - p - q)$ probability, $m$ new nodes are added to the graph
858
+ with edges attached preferentially.
859
+
860
+ When $p = q = 0$, the model behaves just like the Barabási–Alber model.
861
+
862
+ Parameters
863
+ ----------
864
+ n : int
865
+ Number of nodes
866
+ m : int
867
+ Number of edges with which a new node attaches to existing nodes
868
+ p : float
869
+ Probability value for adding an edge between existing nodes. p + q < 1
870
+ q : float
871
+ Probability value of rewiring of existing edges. p + q < 1
872
+ seed : integer, random_state, or None (default)
873
+ Indicator of random number generation state.
874
+ See :ref:`Randomness<randomness>`.
875
+ create_using : Graph constructor, optional (default=nx.Graph)
876
+ Graph type to create. If graph instance, then cleared before populated.
877
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
878
+
879
+ Returns
880
+ -------
881
+ G : Graph
882
+
883
+ Raises
884
+ ------
885
+ NetworkXError
886
+ If `m` does not satisfy ``1 <= m < n`` or ``1 >= p + q``
887
+
888
+ References
889
+ ----------
890
+ .. [1] Albert, R., & Barabási, A. L. (2000)
891
+ Topology of evolving networks: local events and universality
892
+ Physical review letters, 85(24), 5234.
893
+ """
894
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
895
+ if m < 1 or m >= n:
896
+ msg = f"Extended Barabasi-Albert network needs m>=1 and m<n, m={m}, n={n}"
897
+ raise nx.NetworkXError(msg)
898
+ if p + q >= 1:
899
+ msg = f"Extended Barabasi-Albert network needs p + q <= 1, p={p}, q={q}"
900
+ raise nx.NetworkXError(msg)
901
+
902
+ # Add m initial nodes (m0 in barabasi-speak)
903
+ G = empty_graph(m, create_using)
904
+
905
+ # List of nodes to represent the preferential attachment random selection.
906
+ # At the creation of the graph, all nodes are added to the list
907
+ # so that even nodes that are not connected have a chance to get selected,
908
+ # for rewiring and adding of edges.
909
+ # With each new edge, nodes at the ends of the edge are added to the list.
910
+ attachment_preference = []
911
+ attachment_preference.extend(range(m))
912
+
913
+ # Start adding the other n-m nodes. The first node is m.
914
+ new_node = m
915
+ while new_node < n:
916
+ a_probability = seed.random()
917
+
918
+ # Total number of edges of a Clique of all the nodes
919
+ clique_degree = len(G) - 1
920
+ clique_size = (len(G) * clique_degree) / 2
921
+
922
+ # Adding m new edges, if there is room to add them
923
+ if a_probability < p and G.size() <= clique_size - m:
924
+ # Select the nodes where an edge can be added
925
+ eligible_nodes = [nd for nd, deg in G.degree() if deg < clique_degree]
926
+ for i in range(m):
927
+ # Choosing a random source node from eligible_nodes
928
+ src_node = seed.choice(eligible_nodes)
929
+
930
+ # Picking a possible node that is not 'src_node' or
931
+ # neighbor with 'src_node', with preferential attachment
932
+ prohibited_nodes = list(G[src_node])
933
+ prohibited_nodes.append(src_node)
934
+ # This will raise an exception if the sequence is empty
935
+ dest_node = seed.choice(
936
+ [nd for nd in attachment_preference if nd not in prohibited_nodes]
937
+ )
938
+ # Adding the new edge
939
+ G.add_edge(src_node, dest_node)
940
+
941
+ # Appending both nodes to add to their preferential attachment
942
+ attachment_preference.append(src_node)
943
+ attachment_preference.append(dest_node)
944
+
945
+ # Adjusting the eligible nodes. Degree may be saturated.
946
+ if G.degree(src_node) == clique_degree:
947
+ eligible_nodes.remove(src_node)
948
+ if G.degree(dest_node) == clique_degree and dest_node in eligible_nodes:
949
+ eligible_nodes.remove(dest_node)
950
+
951
+ # Rewiring m edges, if there are enough edges
952
+ elif p <= a_probability < (p + q) and m <= G.size() < clique_size:
953
+ # Selecting nodes that have at least 1 edge but that are not
954
+ # fully connected to ALL other nodes (center of star).
955
+ # These nodes are the pivot nodes of the edges to rewire
956
+ eligible_nodes = [nd for nd, deg in G.degree() if 0 < deg < clique_degree]
957
+ for i in range(m):
958
+ # Choosing a random source node
959
+ node = seed.choice(eligible_nodes)
960
+
961
+ # The available nodes do have a neighbor at least.
962
+ nbr_nodes = list(G[node])
963
+
964
+ # Choosing the other end that will get detached
965
+ src_node = seed.choice(nbr_nodes)
966
+
967
+ # Picking a target node that is not 'node' or
968
+ # neighbor with 'node', with preferential attachment
969
+ nbr_nodes.append(node)
970
+ dest_node = seed.choice(
971
+ [nd for nd in attachment_preference if nd not in nbr_nodes]
972
+ )
973
+ # Rewire
974
+ G.remove_edge(node, src_node)
975
+ G.add_edge(node, dest_node)
976
+
977
+ # Adjusting the preferential attachment list
978
+ attachment_preference.remove(src_node)
979
+ attachment_preference.append(dest_node)
980
+
981
+ # Adjusting the eligible nodes.
982
+ # nodes may be saturated or isolated.
983
+ if G.degree(src_node) == 0 and src_node in eligible_nodes:
984
+ eligible_nodes.remove(src_node)
985
+ if dest_node in eligible_nodes:
986
+ if G.degree(dest_node) == clique_degree:
987
+ eligible_nodes.remove(dest_node)
988
+ else:
989
+ if G.degree(dest_node) == 1:
990
+ eligible_nodes.append(dest_node)
991
+
992
+ # Adding new node with m edges
993
+ else:
994
+ # Select the edges' nodes by preferential attachment
995
+ targets = _random_subset(attachment_preference, m, seed)
996
+ G.add_edges_from(zip([new_node] * m, targets))
997
+
998
+ # Add one node to the list for each new edge just created.
999
+ attachment_preference.extend(targets)
1000
+ # The new node has m edges to it, plus itself: m + 1
1001
+ attachment_preference.extend([new_node] * (m + 1))
1002
+ new_node += 1
1003
+ return G
1004
+
1005
+
1006
+ @py_random_state(3)
1007
+ @nx._dispatchable(graphs=None, returns_graph=True)
1008
+ def powerlaw_cluster_graph(n, m, p, seed=None, *, create_using=None):
1009
+ """Holme and Kim algorithm for growing graphs with powerlaw
1010
+ degree distribution and approximate average clustering.
1011
+
1012
+ Parameters
1013
+ ----------
1014
+ n : int
1015
+ the number of nodes
1016
+ m : int
1017
+ the number of random edges to add for each new node
1018
+ p : float,
1019
+ Probability of adding a triangle after adding a random edge
1020
+ seed : integer, random_state, or None (default)
1021
+ Indicator of random number generation state.
1022
+ See :ref:`Randomness<randomness>`.
1023
+ create_using : Graph constructor, optional (default=nx.Graph)
1024
+ Graph type to create. If graph instance, then cleared before populated.
1025
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
1026
+
1027
+ Notes
1028
+ -----
1029
+ The average clustering has a hard time getting above a certain
1030
+ cutoff that depends on `m`. This cutoff is often quite low. The
1031
+ transitivity (fraction of triangles to possible triangles) seems to
1032
+ decrease with network size.
1033
+
1034
+ It is essentially the Barabási–Albert (BA) growth model with an
1035
+ extra step that each random edge is followed by a chance of
1036
+ making an edge to one of its neighbors too (and thus a triangle).
1037
+
1038
+ This algorithm improves on BA in the sense that it enables a
1039
+ higher average clustering to be attained if desired.
1040
+
1041
+ It seems possible to have a disconnected graph with this algorithm
1042
+ since the initial `m` nodes may not be all linked to a new node
1043
+ on the first iteration like the BA model.
1044
+
1045
+ Raises
1046
+ ------
1047
+ NetworkXError
1048
+ If `m` does not satisfy ``1 <= m <= n`` or `p` does not
1049
+ satisfy ``0 <= p <= 1``.
1050
+
1051
+ References
1052
+ ----------
1053
+ .. [1] P. Holme and B. J. Kim,
1054
+ "Growing scale-free networks with tunable clustering",
1055
+ Phys. Rev. E, 65, 026107, 2002.
1056
+ """
1057
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
1058
+ if m < 1 or n < m:
1059
+ raise nx.NetworkXError(f"NetworkXError must have m>1 and m<n, m={m},n={n}")
1060
+
1061
+ if p > 1 or p < 0:
1062
+ raise nx.NetworkXError(f"NetworkXError p must be in [0,1], p={p}")
1063
+
1064
+ G = empty_graph(m, create_using) # add m initial nodes (m0 in barabasi-speak)
1065
+ repeated_nodes = list(G) # list of existing nodes to sample from
1066
+ # with nodes repeated once for each adjacent edge
1067
+ source = m # next node is m
1068
+ while source < n: # Now add the other n-1 nodes
1069
+ possible_targets = _random_subset(repeated_nodes, m, seed)
1070
+ # do one preferential attachment for new node
1071
+ target = possible_targets.pop()
1072
+ G.add_edge(source, target)
1073
+ repeated_nodes.append(target) # add one node to list for each new link
1074
+ count = 1
1075
+ while count < m: # add m-1 more new links
1076
+ if seed.random() < p: # clustering step: add triangle
1077
+ neighborhood = [
1078
+ nbr
1079
+ for nbr in G.neighbors(target)
1080
+ if not G.has_edge(source, nbr) and nbr != source
1081
+ ]
1082
+ if neighborhood: # if there is a neighbor without a link
1083
+ nbr = seed.choice(neighborhood)
1084
+ G.add_edge(source, nbr) # add triangle
1085
+ repeated_nodes.append(nbr)
1086
+ count = count + 1
1087
+ continue # go to top of while loop
1088
+ # else do preferential attachment step if above fails
1089
+ target = possible_targets.pop()
1090
+ G.add_edge(source, target)
1091
+ repeated_nodes.append(target)
1092
+ count = count + 1
1093
+
1094
+ repeated_nodes.extend([source] * m) # add source node to list m times
1095
+ source += 1
1096
+ return G
1097
+
1098
+
1099
+ @py_random_state(3)
1100
+ @nx._dispatchable(graphs=None, returns_graph=True)
1101
+ def random_lobster_graph(n, p1, p2, seed=None, *, create_using=None):
1102
+ """Returns a random lobster graph.
1103
+
1104
+ A lobster is a tree that reduces to a caterpillar when pruning all
1105
+ leaf nodes. A caterpillar is a tree that reduces to a path graph
1106
+ when pruning all leaf nodes; setting `p2` to zero produces a caterpillar.
1107
+
1108
+ This implementation iterates on the probabilities `p1` and `p2` to add
1109
+ edges at levels 1 and 2, respectively. Graphs are therefore constructed
1110
+ iteratively with uniform randomness at each level rather than being selected
1111
+ uniformly at random from the set of all possible lobsters.
1112
+
1113
+ Parameters
1114
+ ----------
1115
+ n : int
1116
+ The expected number of nodes in the backbone
1117
+ p1 : float
1118
+ Probability of adding an edge to the backbone
1119
+ p2 : float
1120
+ Probability of adding an edge one level beyond backbone
1121
+ seed : integer, random_state, or None (default)
1122
+ Indicator of random number generation state.
1123
+ See :ref:`Randomness<randomness>`.
1124
+ create_using : Graph constructor, optional (default=nx.Graph)
1125
+ Graph type to create. If graph instance, then cleared before populated.
1126
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
1127
+
1128
+ Raises
1129
+ ------
1130
+ NetworkXError
1131
+ If `p1` or `p2` parameters are >= 1 because the while loops would never finish.
1132
+ """
1133
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
1134
+ p1, p2 = abs(p1), abs(p2)
1135
+ if any(p >= 1 for p in [p1, p2]):
1136
+ raise nx.NetworkXError("Probability values for `p1` and `p2` must both be < 1.")
1137
+
1138
+ # a necessary ingredient in any self-respecting graph library
1139
+ llen = int(2 * seed.random() * n + 0.5)
1140
+ L = path_graph(llen, create_using)
1141
+ # build caterpillar: add edges to path graph with probability p1
1142
+ current_node = llen - 1
1143
+ for n in range(llen):
1144
+ while seed.random() < p1: # add fuzzy caterpillar parts
1145
+ current_node += 1
1146
+ L.add_edge(n, current_node)
1147
+ cat_node = current_node
1148
+ while seed.random() < p2: # add crunchy lobster bits
1149
+ current_node += 1
1150
+ L.add_edge(cat_node, current_node)
1151
+ return L # voila, un lobster!
1152
+
1153
+
1154
+ @py_random_state(3)
1155
+ @nx._dispatchable(graphs=None, returns_graph=True)
1156
+ def random_lobster(n, p1, p2, seed=None, *, create_using=None):
1157
+ """
1158
+ .. deprecated:: 3.5
1159
+ `random_lobster` is a deprecated alias
1160
+ for `random_lobster_graph`.
1161
+ Use `random_lobster_graph` instead.
1162
+ """
1163
+ import warnings
1164
+
1165
+ warnings.warn(
1166
+ "`random_lobster` is deprecated, use `random_lobster_graph` instead.",
1167
+ category=DeprecationWarning,
1168
+ stacklevel=2,
1169
+ )
1170
+ return random_lobster_graph(n, p1, p2, seed=seed, create_using=create_using)
1171
+
1172
+
1173
+ @py_random_state(1)
1174
+ @nx._dispatchable(graphs=None, returns_graph=True)
1175
+ def random_shell_graph(constructor, seed=None, *, create_using=None):
1176
+ """Returns a random shell graph for the constructor given.
1177
+
1178
+ Parameters
1179
+ ----------
1180
+ constructor : list of three-tuples
1181
+ Represents the parameters for a shell, starting at the center
1182
+ shell. Each element of the list must be of the form `(n, m,
1183
+ d)`, where `n` is the number of nodes in the shell, `m` is
1184
+ the number of edges in the shell, and `d` is the ratio of
1185
+ inter-shell (next) edges to intra-shell edges. If `d` is zero,
1186
+ there will be no intra-shell edges, and if `d` is one there
1187
+ will be all possible intra-shell edges.
1188
+ seed : integer, random_state, or None (default)
1189
+ Indicator of random number generation state.
1190
+ See :ref:`Randomness<randomness>`.
1191
+ create_using : Graph constructor, optional (default=nx.Graph)
1192
+ Graph type to create. Graph instances are not supported.
1193
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
1194
+
1195
+ Examples
1196
+ --------
1197
+ >>> constructor = [(10, 20, 0.8), (20, 40, 0.8)]
1198
+ >>> G = nx.random_shell_graph(constructor)
1199
+
1200
+ """
1201
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
1202
+ G = empty_graph(0, create_using)
1203
+
1204
+ glist = []
1205
+ intra_edges = []
1206
+ nnodes = 0
1207
+ # create gnm graphs for each shell
1208
+ for n, m, d in constructor:
1209
+ inter_edges = int(m * d)
1210
+ intra_edges.append(m - inter_edges)
1211
+ g = nx.convert_node_labels_to_integers(
1212
+ gnm_random_graph(n, inter_edges, seed=seed, create_using=G.__class__),
1213
+ first_label=nnodes,
1214
+ )
1215
+ glist.append(g)
1216
+ nnodes += n
1217
+ G = nx.operators.union(G, g)
1218
+
1219
+ # connect the shells randomly
1220
+ for gi in range(len(glist) - 1):
1221
+ nlist1 = list(glist[gi])
1222
+ nlist2 = list(glist[gi + 1])
1223
+ total_edges = intra_edges[gi]
1224
+ edge_count = 0
1225
+ while edge_count < total_edges:
1226
+ u = seed.choice(nlist1)
1227
+ v = seed.choice(nlist2)
1228
+ if u == v or G.has_edge(u, v):
1229
+ continue
1230
+ else:
1231
+ G.add_edge(u, v)
1232
+ edge_count = edge_count + 1
1233
+ return G
1234
+
1235
+
1236
+ @py_random_state(2)
1237
+ @nx._dispatchable(graphs=None, returns_graph=True)
1238
+ def random_powerlaw_tree(n, gamma=3, seed=None, tries=100, *, create_using=None):
1239
+ """Returns a tree with a power law degree distribution.
1240
+
1241
+ Parameters
1242
+ ----------
1243
+ n : int
1244
+ The number of nodes.
1245
+ gamma : float
1246
+ Exponent of the power law.
1247
+ seed : integer, random_state, or None (default)
1248
+ Indicator of random number generation state.
1249
+ See :ref:`Randomness<randomness>`.
1250
+ tries : int
1251
+ Number of attempts to adjust the sequence to make it a tree.
1252
+ create_using : Graph constructor, optional (default=nx.Graph)
1253
+ Graph type to create. If graph instance, then cleared before populated.
1254
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
1255
+
1256
+ Raises
1257
+ ------
1258
+ NetworkXError
1259
+ If no valid sequence is found within the maximum number of
1260
+ attempts.
1261
+
1262
+ Notes
1263
+ -----
1264
+ A trial power law degree sequence is chosen and then elements are
1265
+ swapped with new elements from a powerlaw distribution until the
1266
+ sequence makes a tree (by checking, for example, that the number of
1267
+ edges is one smaller than the number of nodes).
1268
+
1269
+ """
1270
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
1271
+ # This call may raise a NetworkXError if the number of tries is succeeded.
1272
+ seq = random_powerlaw_tree_sequence(n, gamma=gamma, seed=seed, tries=tries)
1273
+ G = degree_sequence_tree(seq, create_using)
1274
+ return G
1275
+
1276
+
1277
+ @py_random_state(2)
1278
+ @nx._dispatchable(graphs=None)
1279
+ def random_powerlaw_tree_sequence(n, gamma=3, seed=None, tries=100):
1280
+ """Returns a degree sequence for a tree with a power law distribution.
1281
+
1282
+ Parameters
1283
+ ----------
1284
+ n : int,
1285
+ The number of nodes.
1286
+ gamma : float
1287
+ Exponent of the power law.
1288
+ seed : integer, random_state, or None (default)
1289
+ Indicator of random number generation state.
1290
+ See :ref:`Randomness<randomness>`.
1291
+ tries : int
1292
+ Number of attempts to adjust the sequence to make it a tree.
1293
+
1294
+ Raises
1295
+ ------
1296
+ NetworkXError
1297
+ If no valid sequence is found within the maximum number of
1298
+ attempts.
1299
+
1300
+ Notes
1301
+ -----
1302
+ A trial power law degree sequence is chosen and then elements are
1303
+ swapped with new elements from a power law distribution until
1304
+ the sequence makes a tree (by checking, for example, that the number of
1305
+ edges is one smaller than the number of nodes).
1306
+
1307
+ """
1308
+ # get trial sequence
1309
+ z = nx.utils.powerlaw_sequence(n, exponent=gamma, seed=seed)
1310
+ # round to integer values in the range [0,n]
1311
+ zseq = [min(n, max(round(s), 0)) for s in z]
1312
+
1313
+ # another sequence to swap values from
1314
+ z = nx.utils.powerlaw_sequence(tries, exponent=gamma, seed=seed)
1315
+ # round to integer values in the range [0,n]
1316
+ swap = [min(n, max(round(s), 0)) for s in z]
1317
+
1318
+ for _ in swap:
1319
+ valid, _ = nx.utils.is_valid_tree_degree_sequence(zseq)
1320
+ if valid:
1321
+ return zseq
1322
+ index = seed.randint(0, n - 1)
1323
+ zseq[index] = swap.pop()
1324
+
1325
+ raise nx.NetworkXError(
1326
+ f"Exceeded max ({tries}) attempts for a valid tree sequence."
1327
+ )
1328
+
1329
+
1330
+ @py_random_state(3)
1331
+ @nx._dispatchable(graphs=None, returns_graph=True)
1332
+ def random_kernel_graph(
1333
+ n, kernel_integral, kernel_root=None, seed=None, *, create_using=None
1334
+ ):
1335
+ r"""Returns an random graph based on the specified kernel.
1336
+
1337
+ The algorithm chooses each of the $[n(n-1)]/2$ possible edges with
1338
+ probability specified by a kernel $\kappa(x,y)$ [1]_. The kernel
1339
+ $\kappa(x,y)$ must be a symmetric (in $x,y$), non-negative,
1340
+ bounded function.
1341
+
1342
+ Parameters
1343
+ ----------
1344
+ n : int
1345
+ The number of nodes
1346
+ kernel_integral : function
1347
+ Function that returns the definite integral of the kernel $\kappa(x,y)$,
1348
+ $F(y,a,b) := \int_a^b \kappa(x,y)dx$
1349
+ kernel_root: function (optional)
1350
+ Function that returns the root $b$ of the equation $F(y,a,b) = r$.
1351
+ If None, the root is found using :func:`scipy.optimize.brentq`
1352
+ (this requires SciPy).
1353
+ seed : integer, random_state, or None (default)
1354
+ Indicator of random number generation state.
1355
+ See :ref:`Randomness<randomness>`.
1356
+ create_using : Graph constructor, optional (default=nx.Graph)
1357
+ Graph type to create. If graph instance, then cleared before populated.
1358
+ Multigraph and directed types are not supported and raise a ``NetworkXError``.
1359
+
1360
+ Notes
1361
+ -----
1362
+ The kernel is specified through its definite integral which must be
1363
+ provided as one of the arguments. If the integral and root of the
1364
+ kernel integral can be found in $O(1)$ time then this algorithm runs in
1365
+ time $O(n+m)$ where m is the expected number of edges [2]_.
1366
+
1367
+ The nodes are set to integers from $0$ to $n-1$.
1368
+
1369
+ Examples
1370
+ --------
1371
+ Generate an Erdős–Rényi random graph $G(n,c/n)$, with kernel
1372
+ $\kappa(x,y)=c$ where $c$ is the mean expected degree.
1373
+
1374
+ >>> def integral(u, w, z):
1375
+ ... return c * (z - w)
1376
+ >>> def root(u, w, r):
1377
+ ... return r / c + w
1378
+ >>> c = 1
1379
+ >>> graph = nx.random_kernel_graph(1000, integral, root)
1380
+
1381
+ See Also
1382
+ --------
1383
+ gnp_random_graph
1384
+ expected_degree_graph
1385
+
1386
+ References
1387
+ ----------
1388
+ .. [1] Bollobás, Béla, Janson, S. and Riordan, O.
1389
+ "The phase transition in inhomogeneous random graphs",
1390
+ *Random Structures Algorithms*, 31, 3--122, 2007.
1391
+
1392
+ .. [2] Hagberg A, Lemons N (2015),
1393
+ "Fast Generation of Sparse Random Kernel Graphs".
1394
+ PLoS ONE 10(9): e0135177, 2015. doi:10.1371/journal.pone.0135177
1395
+ """
1396
+ create_using = check_create_using(create_using, directed=False, multigraph=False)
1397
+ if kernel_root is None:
1398
+ import scipy as sp
1399
+
1400
+ def kernel_root(y, a, r):
1401
+ def my_function(b):
1402
+ return kernel_integral(y, a, b) - r
1403
+
1404
+ return sp.optimize.brentq(my_function, a, 1)
1405
+
1406
+ graph = nx.empty_graph(create_using=create_using)
1407
+ graph.add_nodes_from(range(n))
1408
+ (i, j) = (1, 1)
1409
+ while i < n:
1410
+ r = -math.log(1 - seed.random()) # (1-seed.random()) in (0, 1]
1411
+ if kernel_integral(i / n, j / n, 1) <= r:
1412
+ i, j = i + 1, i + 1
1413
+ else:
1414
+ j = math.ceil(n * kernel_root(i / n, j / n, r))
1415
+ graph.add_edge(i - 1, j - 1)
1416
+ return graph