okstra 0.107.2 → 0.109.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 (649) hide show
  1. package/package.json +1 -1
  2. package/runtime/BUILD.json +2 -2
  3. package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
  4. package/runtime/prompts/profiles/_common-contract.md +3 -2
  5. package/runtime/python/okstra_ctl/graphify_cmd.py +225 -0
  6. package/runtime/python/okstra_ctl/resolve_task_key.py +15 -9
  7. package/runtime/python/okstra_ctl/session.py +44 -0
  8. package/runtime/python/okstra_project/__init__.py +2 -0
  9. package/runtime/python/okstra_project/state.py +36 -0
  10. package/runtime/python/okstra_token_usage/claude.py +15 -9
  11. package/runtime/python/okstra_token_usage/cli.py +23 -0
  12. package/runtime/python/okstra_token_usage/collect.py +163 -4
  13. package/runtime/python/okstra_vendor/__init__.py +41 -0
  14. package/runtime/python/okstra_vendor/graphify/.vendored-version +1 -0
  15. package/runtime/python/okstra_vendor/graphify/__init__.py +28 -0
  16. package/runtime/python/okstra_vendor/graphify/__main__.py +1371 -0
  17. package/runtime/python/okstra_vendor/graphify/analyze.py +540 -0
  18. package/runtime/python/okstra_vendor/graphify/benchmark.py +129 -0
  19. package/runtime/python/okstra_vendor/graphify/build.py +107 -0
  20. package/runtime/python/okstra_vendor/graphify/cache.py +169 -0
  21. package/runtime/python/okstra_vendor/graphify/cluster.py +137 -0
  22. package/runtime/python/okstra_vendor/graphify/detect.py +510 -0
  23. package/runtime/python/okstra_vendor/graphify/export.py +1014 -0
  24. package/runtime/python/okstra_vendor/graphify/extract.py +3277 -0
  25. package/runtime/python/okstra_vendor/graphify/hooks.py +220 -0
  26. package/runtime/python/okstra_vendor/graphify/ingest.py +297 -0
  27. package/runtime/python/okstra_vendor/graphify/manifest.py +4 -0
  28. package/runtime/python/okstra_vendor/graphify/report.py +175 -0
  29. package/runtime/python/okstra_vendor/graphify/security.py +203 -0
  30. package/runtime/python/okstra_vendor/graphify/serve.py +373 -0
  31. package/runtime/python/okstra_vendor/graphify/skill-aider.md +1184 -0
  32. package/runtime/python/okstra_vendor/graphify/skill-claw.md +1184 -0
  33. package/runtime/python/okstra_vendor/graphify/skill-codex.md +1242 -0
  34. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +1268 -0
  35. package/runtime/python/okstra_vendor/graphify/skill-droid.md +1239 -0
  36. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +1183 -0
  37. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +1238 -0
  38. package/runtime/python/okstra_vendor/graphify/skill-trae.md +1208 -0
  39. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +253 -0
  40. package/runtime/python/okstra_vendor/graphify/skill-windows.md +1245 -0
  41. package/runtime/python/okstra_vendor/graphify/skill.md +1319 -0
  42. package/runtime/python/okstra_vendor/graphify/transcribe.py +182 -0
  43. package/runtime/python/okstra_vendor/graphify/validate.py +72 -0
  44. package/runtime/python/okstra_vendor/graphify/watch.py +188 -0
  45. package/runtime/python/okstra_vendor/graphify/wiki.py +214 -0
  46. package/runtime/python/okstra_vendor/networkx/__init__.py +62 -0
  47. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +134 -0
  48. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +26 -0
  49. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +259 -0
  50. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +71 -0
  51. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +412 -0
  52. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +396 -0
  53. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +150 -0
  54. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +149 -0
  55. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +369 -0
  56. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +44 -0
  57. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +143 -0
  58. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +53 -0
  59. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +265 -0
  60. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  61. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +41 -0
  62. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +112 -0
  63. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +199 -0
  64. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +146 -0
  65. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +59 -0
  66. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +78 -0
  67. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +303 -0
  68. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +8 -0
  69. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +94 -0
  70. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +31 -0
  71. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +306 -0
  72. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +1014 -0
  73. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +274 -0
  74. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +68 -0
  75. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +1508 -0
  76. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +255 -0
  77. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +83 -0
  78. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +5 -0
  79. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +122 -0
  80. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +302 -0
  81. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +255 -0
  82. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +160 -0
  83. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +127 -0
  84. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  85. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +81 -0
  86. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +143 -0
  87. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +122 -0
  88. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +174 -0
  89. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +107 -0
  90. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +87 -0
  91. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +164 -0
  92. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +88 -0
  93. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +322 -0
  94. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +290 -0
  95. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +289 -0
  96. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +57 -0
  97. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +360 -0
  98. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +105 -0
  99. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +603 -0
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +316 -0
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +590 -0
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +232 -0
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +526 -0
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +112 -0
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +69 -0
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +125 -0
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +192 -0
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +84 -0
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +33 -0
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +240 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +334 -0
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +407 -0
  114. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +218 -0
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +327 -0
  116. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +138 -0
  117. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +409 -0
  118. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +35 -0
  119. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +80 -0
  120. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +168 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +205 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +164 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +20 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +591 -0
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +236 -0
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +282 -0
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +364 -0
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +227 -0
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +96 -0
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +150 -0
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +107 -0
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +357 -0
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +130 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +787 -0
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +88 -0
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +331 -0
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +150 -0
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +200 -0
  139. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +128 -0
  140. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +209 -0
  141. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +141 -0
  142. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +361 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  144. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +923 -0
  145. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +354 -0
  146. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +274 -0
  147. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +259 -0
  148. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +147 -0
  149. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +43 -0
  150. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +144 -0
  151. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +73 -0
  152. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +186 -0
  153. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +277 -0
  154. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +122 -0
  155. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +345 -0
  156. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +220 -0
  157. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +344 -0
  158. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +87 -0
  159. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +140 -0
  160. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +82 -0
  161. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +110 -0
  162. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +302 -0
  163. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +64 -0
  164. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +181 -0
  165. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +95 -0
  166. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +172 -0
  167. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +443 -0
  168. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +818 -0
  169. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +732 -0
  170. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +4 -0
  171. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +505 -0
  172. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +565 -0
  173. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  174. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +863 -0
  175. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +163 -0
  176. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +28 -0
  177. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +153 -0
  178. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +354 -0
  179. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +171 -0
  180. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +30 -0
  181. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +216 -0
  182. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +79 -0
  183. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +338 -0
  184. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +162 -0
  185. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +220 -0
  186. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +384 -0
  187. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +227 -0
  188. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +452 -0
  189. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +347 -0
  190. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  191. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +147 -0
  192. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +157 -0
  193. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +85 -0
  194. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +106 -0
  195. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +91 -0
  196. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +241 -0
  197. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +138 -0
  198. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +76 -0
  199. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +264 -0
  200. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +152 -0
  201. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +340 -0
  202. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +139 -0
  203. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +26 -0
  204. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +6 -0
  205. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +115 -0
  206. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +394 -0
  207. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +282 -0
  208. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +71 -0
  209. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +359 -0
  210. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  211. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +70 -0
  212. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +248 -0
  213. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +138 -0
  214. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +55 -0
  215. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +193 -0
  216. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +96 -0
  217. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +196 -0
  218. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +11 -0
  219. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +811 -0
  220. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +616 -0
  221. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +408 -0
  222. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +1270 -0
  223. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +592 -0
  224. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +220 -0
  225. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +235 -0
  226. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +152 -0
  227. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  228. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +421 -0
  229. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +309 -0
  230. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +249 -0
  231. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +502 -0
  232. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +488 -0
  233. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +323 -0
  234. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +280 -0
  235. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +102 -0
  236. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +88 -0
  237. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +588 -0
  238. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +142 -0
  239. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +416 -0
  240. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +1234 -0
  241. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +677 -0
  242. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +1392 -0
  243. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +1095 -0
  244. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +272 -0
  245. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +142 -0
  246. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +268 -0
  247. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +167 -0
  248. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +470 -0
  249. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +11 -0
  250. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +370 -0
  251. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +407 -0
  252. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +238 -0
  253. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +241 -0
  254. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +178 -0
  255. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +611 -0
  256. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +356 -0
  257. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +662 -0
  258. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +425 -0
  259. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +300 -0
  260. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  261. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  262. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  263. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  264. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +128 -0
  265. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +573 -0
  266. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +155 -0
  267. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +475 -0
  268. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +481 -0
  269. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  270. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +194 -0
  271. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +435 -0
  272. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +483 -0
  273. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +57 -0
  274. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +196 -0
  275. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +107 -0
  276. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +7 -0
  277. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +1306 -0
  278. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +336 -0
  279. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +1262 -0
  280. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +352 -0
  281. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +308 -0
  282. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  283. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  284. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  285. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  286. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  287. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +719 -0
  288. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +103 -0
  289. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +490 -0
  290. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +64 -0
  291. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +212 -0
  292. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +202 -0
  293. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +1655 -0
  294. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +3118 -0
  295. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +196 -0
  296. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +264 -0
  297. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +1102 -0
  298. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +192 -0
  299. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +2 -0
  300. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +337 -0
  301. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +498 -0
  302. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  303. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +77 -0
  304. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +213 -0
  305. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +687 -0
  306. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +280 -0
  307. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +1148 -0
  308. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +27 -0
  309. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +738 -0
  310. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +544 -0
  311. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +78 -0
  312. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +59 -0
  313. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +219 -0
  314. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +155 -0
  315. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +4 -0
  316. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +324 -0
  317. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +468 -0
  318. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +633 -0
  319. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  320. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +328 -0
  321. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +451 -0
  322. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +491 -0
  323. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +55 -0
  324. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +77 -0
  325. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +73 -0
  326. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +464 -0
  327. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +1463 -0
  328. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +306 -0
  329. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +98 -0
  330. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +167 -0
  331. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +138 -0
  332. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +5 -0
  333. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +239 -0
  334. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +264 -0
  335. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +716 -0
  336. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  337. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +254 -0
  338. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +212 -0
  339. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +88 -0
  340. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +511 -0
  341. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +149 -0
  342. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +983 -0
  343. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +625 -0
  344. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +2542 -0
  345. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +2107 -0
  346. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +966 -0
  347. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +404 -0
  348. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +30 -0
  349. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +296 -0
  350. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +374 -0
  351. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +564 -0
  352. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +406 -0
  353. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  354. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +23 -0
  355. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +154 -0
  356. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +144 -0
  357. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +109 -0
  358. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +136 -0
  359. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +129 -0
  360. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +300 -0
  361. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +678 -0
  362. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +80 -0
  363. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +266 -0
  364. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +85 -0
  365. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +171 -0
  366. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +984 -0
  367. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +340 -0
  368. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +835 -0
  369. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +831 -0
  370. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +85 -0
  371. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +299 -0
  372. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +115 -0
  373. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +58 -0
  374. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +314 -0
  375. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +872 -0
  376. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +163 -0
  377. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +46 -0
  378. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +24 -0
  379. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +26 -0
  380. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +615 -0
  381. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +459 -0
  382. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +556 -0
  383. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +179 -0
  384. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +62 -0
  385. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +15 -0
  386. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +140 -0
  387. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +60 -0
  388. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +27 -0
  389. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +274 -0
  390. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +556 -0
  391. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +57 -0
  392. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +37 -0
  393. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +88 -0
  394. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +149 -0
  395. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +1158 -0
  396. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +803 -0
  397. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +76 -0
  398. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +8 -0
  399. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +138 -0
  400. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +191 -0
  401. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +642 -0
  402. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +179 -0
  403. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +270 -0
  404. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +431 -0
  405. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +161 -0
  406. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +248 -0
  407. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +41 -0
  408. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +103 -0
  409. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +54 -0
  410. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +157 -0
  411. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +981 -0
  412. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +142 -0
  413. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +406 -0
  414. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +5 -0
  415. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +90 -0
  416. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +576 -0
  417. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +529 -0
  418. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +185 -0
  419. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +182 -0
  420. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  421. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +25 -0
  422. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +203 -0
  423. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +307 -0
  424. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +147 -0
  425. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +131 -0
  426. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +7 -0
  427. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +1042 -0
  428. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +413 -0
  429. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +88 -0
  430. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +219 -0
  431. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +1281 -0
  432. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +106 -0
  433. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +273 -0
  434. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  435. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +624 -0
  436. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +114 -0
  437. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +79 -0
  438. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +99 -0
  439. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +934 -0
  440. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +53 -0
  441. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +174 -0
  442. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +500 -0
  443. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +76 -0
  444. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +86 -0
  445. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +77 -0
  446. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +278 -0
  447. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +13 -0
  448. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +435 -0
  449. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +1363 -0
  450. package/runtime/python/okstra_vendor/networkx/classes/filters.py +95 -0
  451. package/runtime/python/okstra_vendor/networkx/classes/function.py +1549 -0
  452. package/runtime/python/okstra_vendor/networkx/classes/graph.py +2082 -0
  453. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +269 -0
  454. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +977 -0
  455. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +1294 -0
  456. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +1447 -0
  457. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  458. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +192 -0
  459. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +476 -0
  460. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +362 -0
  461. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +331 -0
  462. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +110 -0
  463. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +177 -0
  464. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +1045 -0
  465. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +950 -0
  466. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +12 -0
  467. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +349 -0
  468. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +459 -0
  469. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +528 -0
  470. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +1421 -0
  471. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +131 -0
  472. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +371 -0
  473. package/runtime/python/okstra_vendor/networkx/conftest.py +261 -0
  474. package/runtime/python/okstra_vendor/networkx/convert.py +502 -0
  475. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +1314 -0
  476. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +7 -0
  477. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +2036 -0
  478. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +470 -0
  479. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +570 -0
  480. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +361 -0
  481. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +2978 -0
  482. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  483. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  484. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  485. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  486. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  487. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  488. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  489. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +237 -0
  490. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +229 -0
  491. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +285 -0
  492. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +631 -0
  493. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +146 -0
  494. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +1582 -0
  495. package/runtime/python/okstra_vendor/networkx/exception.py +131 -0
  496. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +34 -0
  497. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  498. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +227 -0
  499. package/runtime/python/okstra_vendor/networkx/generators/classic.py +1091 -0
  500. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +68 -0
  501. package/runtime/python/okstra_vendor/networkx/generators/community.py +1070 -0
  502. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +886 -0
  503. package/runtime/python/okstra_vendor/networkx/generators/directed.py +572 -0
  504. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +174 -0
  505. package/runtime/python/okstra_vendor/networkx/generators/ego.py +66 -0
  506. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +499 -0
  507. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +1037 -0
  508. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +163 -0
  509. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +443 -0
  510. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +125 -0
  511. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +70 -0
  512. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +664 -0
  513. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +405 -0
  514. package/runtime/python/okstra_vendor/networkx/generators/line.py +501 -0
  515. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +110 -0
  516. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +259 -0
  517. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +117 -0
  518. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +1416 -0
  519. package/runtime/python/okstra_vendor/networkx/generators/small.py +1070 -0
  520. package/runtime/python/okstra_vendor/networkx/generators/social.py +554 -0
  521. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +120 -0
  522. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +54 -0
  523. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +131 -0
  524. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  525. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +75 -0
  526. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +642 -0
  527. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +20 -0
  528. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +362 -0
  529. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +224 -0
  530. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +189 -0
  531. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +103 -0
  532. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +39 -0
  533. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +182 -0
  534. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +488 -0
  535. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +133 -0
  536. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +221 -0
  537. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +28 -0
  538. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +144 -0
  539. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +125 -0
  540. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +264 -0
  541. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +316 -0
  542. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +30 -0
  543. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +82 -0
  544. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +33 -0
  545. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +495 -0
  546. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +220 -0
  547. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +49 -0
  548. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +72 -0
  549. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +92 -0
  550. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +64 -0
  551. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +195 -0
  552. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +15 -0
  553. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +74 -0
  554. package/runtime/python/okstra_vendor/networkx/generators/trees.py +1070 -0
  555. package/runtime/python/okstra_vendor/networkx/generators/triads.py +94 -0
  556. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +188 -0
  557. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +13 -0
  558. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +650 -0
  559. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +466 -0
  560. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +77 -0
  561. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +168 -0
  562. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +512 -0
  563. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +166 -0
  564. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +186 -0
  565. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  566. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +400 -0
  567. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +108 -0
  568. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +40 -0
  569. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +275 -0
  570. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +334 -0
  571. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +86 -0
  572. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +70 -0
  573. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +17 -0
  574. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +330 -0
  575. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +489 -0
  576. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +1084 -0
  577. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +879 -0
  578. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +427 -0
  579. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +1053 -0
  580. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +19 -0
  581. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +156 -0
  582. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +190 -0
  583. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +261 -0
  584. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  585. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +78 -0
  586. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +78 -0
  587. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +109 -0
  588. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +48 -0
  589. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +137 -0
  590. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +108 -0
  591. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +393 -0
  592. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +113 -0
  593. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +286 -0
  594. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +379 -0
  595. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  596. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +354 -0
  597. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +318 -0
  598. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +612 -0
  599. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +744 -0
  600. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +181 -0
  601. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +1531 -0
  602. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +30 -0
  603. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +63 -0
  604. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +128 -0
  605. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +166 -0
  606. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +1742 -0
  607. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +851 -0
  608. package/runtime/python/okstra_vendor/networkx/relabel.py +285 -0
  609. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  610. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +248 -0
  611. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +321 -0
  612. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +531 -0
  613. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +349 -0
  614. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +281 -0
  615. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +40 -0
  616. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +11 -0
  617. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +96 -0
  618. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +349 -0
  619. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +8 -0
  620. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +8 -0
  621. package/runtime/python/okstra_vendor/networkx/utils/backends.py +2171 -0
  622. package/runtime/python/okstra_vendor/networkx/utils/configs.py +396 -0
  623. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +1233 -0
  624. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +338 -0
  625. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +297 -0
  626. package/runtime/python/okstra_vendor/networkx/utils/misc.py +703 -0
  627. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +198 -0
  628. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +159 -0
  629. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  630. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +11 -0
  631. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +225 -0
  632. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +263 -0
  633. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +510 -0
  634. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +131 -0
  635. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +268 -0
  636. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +393 -0
  637. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +53 -0
  638. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +63 -0
  639. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +55 -0
  640. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +106 -0
  641. package/runtime/skills/okstra-graphify/SKILL.md +161 -0
  642. package/runtime/skills/okstra-inspect/SKILL.md +17 -9
  643. package/runtime/templates/reports/settings.template.json +4 -0
  644. package/runtime/validators/forbidden_actions.py +8 -2
  645. package/runtime/validators/validate_session_conformance.py +26 -5
  646. package/src/cli-registry.mjs +7 -0
  647. package/src/commands/graphify.mjs +32 -0
  648. package/src/commands/lifecycle/doctor.mjs +9 -0
  649. package/src/lib/skill-catalog.mjs +1 -0
@@ -0,0 +1,981 @@
1
+ """
2
+ Threshold Graphs - Creation, manipulation and identification.
3
+ """
4
+
5
+ from math import sqrt
6
+
7
+ import networkx as nx
8
+ from networkx.utils import py_random_state
9
+
10
+ __all__ = ["is_threshold_graph", "find_threshold_graph"]
11
+
12
+
13
+ @nx._dispatchable
14
+ def is_threshold_graph(G):
15
+ """
16
+ Returns `True` if `G` is a threshold graph.
17
+
18
+ Parameters
19
+ ----------
20
+ G : NetworkX graph instance
21
+ An instance of `Graph`, `DiGraph`, `MultiGraph` or `MultiDiGraph`
22
+
23
+ Returns
24
+ -------
25
+ bool
26
+ `True` if `G` is a threshold graph, `False` otherwise.
27
+
28
+ Examples
29
+ --------
30
+ >>> from networkx.algorithms.threshold import is_threshold_graph
31
+ >>> G = nx.path_graph(3)
32
+ >>> is_threshold_graph(G)
33
+ True
34
+ >>> G = nx.barbell_graph(3, 3)
35
+ >>> is_threshold_graph(G)
36
+ False
37
+
38
+ References
39
+ ----------
40
+ .. [1] Threshold graphs: https://en.wikipedia.org/wiki/Threshold_graph
41
+ """
42
+ return is_threshold_sequence([d for n, d in G.degree()])
43
+
44
+
45
+ def is_threshold_sequence(degree_sequence):
46
+ """
47
+ Returns True if the sequence is a threshold degree sequence.
48
+
49
+ Uses the property that a threshold graph must be constructed by
50
+ adding either dominating or isolated nodes. Thus, it can be
51
+ deconstructed iteratively by removing a node of degree zero or a
52
+ node that connects to the remaining nodes. If this deconstruction
53
+ fails then the sequence is not a threshold sequence.
54
+ """
55
+ ds = degree_sequence[:] # get a copy so we don't destroy original
56
+ ds.sort()
57
+ while ds:
58
+ if ds[0] == 0: # if isolated node
59
+ ds.pop(0) # remove it
60
+ continue
61
+ if ds[-1] != len(ds) - 1: # is the largest degree node dominating?
62
+ return False # no, not a threshold degree sequence
63
+ ds.pop() # yes, largest is the dominating node
64
+ ds = [d - 1 for d in ds] # remove it and decrement all degrees
65
+ return True
66
+
67
+
68
+ def creation_sequence(degree_sequence, with_labels=False, compact=False):
69
+ """
70
+ Determines the creation sequence for the given threshold degree sequence.
71
+
72
+ The creation sequence is a list of single characters 'd'
73
+ or 'i': 'd' for dominating or 'i' for isolated vertices.
74
+ Dominating vertices are connected to all vertices present when it
75
+ is added. The first node added is by convention 'd'.
76
+ This list can be converted to a string if desired using "".join(cs)
77
+
78
+ If with_labels==True:
79
+ Returns a list of 2-tuples containing the vertex number
80
+ and a character 'd' or 'i' which describes the type of vertex.
81
+
82
+ If compact==True:
83
+ Returns the creation sequence in a compact form that is the number
84
+ of 'i's and 'd's alternating.
85
+ Examples:
86
+ [1,2,2,3] represents d,i,i,d,d,i,i,i
87
+ [3,1,2] represents d,d,d,i,d,d
88
+
89
+ Notice that the first number is the first vertex to be used for
90
+ construction and so is always 'd'.
91
+
92
+ with_labels and compact cannot both be True.
93
+
94
+ Returns None if the sequence is not a threshold sequence
95
+ """
96
+ if with_labels and compact:
97
+ raise ValueError("compact sequences cannot be labeled")
98
+
99
+ # make an indexed copy
100
+ if isinstance(degree_sequence, dict): # labeled degree sequence
101
+ ds = [[degree, label] for (label, degree) in degree_sequence.items()]
102
+ else:
103
+ ds = [[d, i] for i, d in enumerate(degree_sequence)]
104
+ ds.sort()
105
+ cs = [] # creation sequence
106
+ while ds:
107
+ if ds[0][0] == 0: # isolated node
108
+ (d, v) = ds.pop(0)
109
+ if len(ds) > 0: # make sure we start with a d
110
+ cs.insert(0, (v, "i"))
111
+ else:
112
+ cs.insert(0, (v, "d"))
113
+ continue
114
+ if ds[-1][0] != len(ds) - 1: # Not dominating node
115
+ return None # not a threshold degree sequence
116
+ (d, v) = ds.pop()
117
+ cs.insert(0, (v, "d"))
118
+ ds = [[d[0] - 1, d[1]] for d in ds] # decrement due to removing node
119
+
120
+ if with_labels:
121
+ return cs
122
+ if compact:
123
+ return make_compact(cs)
124
+ return [v[1] for v in cs] # not labeled
125
+
126
+
127
+ def make_compact(creation_sequence):
128
+ """
129
+ Returns the creation sequence in a compact form
130
+ that is the number of 'i's and 'd's alternating.
131
+
132
+ Examples
133
+ --------
134
+ >>> from networkx.algorithms.threshold import make_compact
135
+ >>> make_compact(["d", "i", "i", "d", "d", "i", "i", "i"])
136
+ [1, 2, 2, 3]
137
+ >>> make_compact(["d", "d", "d", "i", "d", "d"])
138
+ [3, 1, 2]
139
+
140
+ Notice that the first number is the first vertex
141
+ to be used for construction and so is always 'd'.
142
+
143
+ Labeled creation sequences lose their labels in the
144
+ compact representation.
145
+
146
+ >>> make_compact([3, 1, 2])
147
+ [3, 1, 2]
148
+ """
149
+ first = creation_sequence[0]
150
+ if isinstance(first, str): # creation sequence
151
+ cs = creation_sequence[:]
152
+ elif isinstance(first, tuple): # labeled creation sequence
153
+ cs = [s[1] for s in creation_sequence]
154
+ elif isinstance(first, int): # compact creation sequence
155
+ return creation_sequence
156
+ else:
157
+ raise TypeError("Not a valid creation sequence type")
158
+
159
+ ccs = []
160
+ count = 1 # count the run lengths of d's or i's.
161
+ for i in range(1, len(cs)):
162
+ if cs[i] == cs[i - 1]:
163
+ count += 1
164
+ else:
165
+ ccs.append(count)
166
+ count = 1
167
+ ccs.append(count) # don't forget the last one
168
+ return ccs
169
+
170
+
171
+ def uncompact(creation_sequence):
172
+ """
173
+ Converts a compact creation sequence for a threshold
174
+ graph to a standard creation sequence (unlabeled).
175
+ If the creation_sequence is already standard, return it.
176
+ See creation_sequence.
177
+ """
178
+ first = creation_sequence[0]
179
+ if isinstance(first, str): # creation sequence
180
+ return creation_sequence
181
+ elif isinstance(first, tuple): # labeled creation sequence
182
+ return creation_sequence
183
+ elif isinstance(first, int): # compact creation sequence
184
+ ccscopy = creation_sequence[:]
185
+ else:
186
+ raise TypeError("Not a valid creation sequence type")
187
+ cs = []
188
+ while ccscopy:
189
+ cs.extend(ccscopy.pop(0) * ["d"])
190
+ if ccscopy:
191
+ cs.extend(ccscopy.pop(0) * ["i"])
192
+ return cs
193
+
194
+
195
+ def creation_sequence_to_weights(creation_sequence):
196
+ """
197
+ Returns a list of node weights which create the threshold
198
+ graph designated by the creation sequence. The weights
199
+ are scaled so that the threshold is 1.0. The order of the
200
+ nodes is the same as that in the creation sequence.
201
+ """
202
+ # Turn input sequence into a labeled creation sequence
203
+ first = creation_sequence[0]
204
+ if isinstance(first, str): # creation sequence
205
+ if isinstance(creation_sequence, list):
206
+ wseq = creation_sequence[:]
207
+ else:
208
+ wseq = list(creation_sequence) # string like 'ddidid'
209
+ elif isinstance(first, tuple): # labeled creation sequence
210
+ wseq = [v[1] for v in creation_sequence]
211
+ elif isinstance(first, int): # compact creation sequence
212
+ wseq = uncompact(creation_sequence)
213
+ else:
214
+ raise TypeError("Not a valid creation sequence type")
215
+ # pass through twice--first backwards
216
+ wseq.reverse()
217
+ w = 0
218
+ prev = "i"
219
+ for j, s in enumerate(wseq):
220
+ if s == "i":
221
+ wseq[j] = w
222
+ prev = s
223
+ elif prev == "i":
224
+ prev = s
225
+ w += 1
226
+ wseq.reverse() # now pass through forwards
227
+ for j, s in enumerate(wseq):
228
+ if s == "d":
229
+ wseq[j] = w
230
+ prev = s
231
+ elif prev == "d":
232
+ prev = s
233
+ w += 1
234
+ # Now scale weights
235
+ if prev == "d":
236
+ w += 1
237
+ wscale = 1 / w
238
+ return [ww * wscale for ww in wseq]
239
+ # return wseq
240
+
241
+
242
+ def weights_to_creation_sequence(
243
+ weights, threshold=1, with_labels=False, compact=False
244
+ ):
245
+ """
246
+ Returns a creation sequence for a threshold graph
247
+ determined by the weights and threshold given as input.
248
+ If the sum of two node weights is greater than the
249
+ threshold value, an edge is created between these nodes.
250
+
251
+ The creation sequence is a list of single characters 'd'
252
+ or 'i': 'd' for dominating or 'i' for isolated vertices.
253
+ Dominating vertices are connected to all vertices present
254
+ when it is added. The first node added is by convention 'd'.
255
+
256
+ If with_labels==True:
257
+ Returns a list of 2-tuples containing the vertex number
258
+ and a character 'd' or 'i' which describes the type of vertex.
259
+
260
+ If compact==True:
261
+ Returns the creation sequence in a compact form that is the number
262
+ of 'i's and 'd's alternating.
263
+ Examples:
264
+ [1,2,2,3] represents d,i,i,d,d,i,i,i
265
+ [3,1,2] represents d,d,d,i,d,d
266
+
267
+ Notice that the first number is the first vertex to be used for
268
+ construction and so is always 'd'.
269
+
270
+ with_labels and compact cannot both be True.
271
+ """
272
+ if with_labels and compact:
273
+ raise ValueError("compact sequences cannot be labeled")
274
+
275
+ # make an indexed copy
276
+ if isinstance(weights, dict): # labeled weights
277
+ wseq = [[w, label] for (label, w) in weights.items()]
278
+ else:
279
+ wseq = [[w, i] for i, w in enumerate(weights)]
280
+ wseq.sort()
281
+ cs = [] # creation sequence
282
+ cutoff = threshold - wseq[-1][0]
283
+ while wseq:
284
+ if wseq[0][0] < cutoff: # isolated node
285
+ (w, label) = wseq.pop(0)
286
+ cs.append((label, "i"))
287
+ else:
288
+ (w, label) = wseq.pop()
289
+ cs.append((label, "d"))
290
+ cutoff = threshold - wseq[-1][0]
291
+ if len(wseq) == 1: # make sure we start with a d
292
+ (w, label) = wseq.pop()
293
+ cs.append((label, "d"))
294
+ # put in correct order
295
+ cs.reverse()
296
+
297
+ if with_labels:
298
+ return cs
299
+ if compact:
300
+ return make_compact(cs)
301
+ return [v[1] for v in cs] # not labeled
302
+
303
+
304
+ # Manipulating NetworkX.Graphs in context of threshold graphs
305
+ @nx._dispatchable(graphs=None, returns_graph=True)
306
+ def threshold_graph(creation_sequence, create_using=None):
307
+ """
308
+ Create a threshold graph from the creation sequence or compact
309
+ creation_sequence.
310
+
311
+ The input sequence can be a
312
+
313
+ creation sequence (e.g. ['d','i','d','d','d','i'])
314
+ labeled creation sequence (e.g. [(0,'d'),(2,'d'),(1,'i')])
315
+ compact creation sequence (e.g. [2,1,1,2,0])
316
+
317
+ Use cs=creation_sequence(degree_sequence,labeled=True)
318
+ to convert a degree sequence to a creation sequence.
319
+
320
+ Returns None if the sequence is not valid
321
+ """
322
+ # Turn input sequence into a labeled creation sequence
323
+ first = creation_sequence[0]
324
+ if isinstance(first, str): # creation sequence
325
+ ci = list(enumerate(creation_sequence))
326
+ elif isinstance(first, tuple): # labeled creation sequence
327
+ ci = creation_sequence[:]
328
+ elif isinstance(first, int): # compact creation sequence
329
+ cs = uncompact(creation_sequence)
330
+ ci = list(enumerate(cs))
331
+ else:
332
+ raise ValueError("not a valid creation sequence")
333
+
334
+ G = nx.empty_graph(0, create_using)
335
+ if G.is_directed():
336
+ raise nx.NetworkXError("Directed Graph not supported")
337
+
338
+ G.name = "Threshold Graph"
339
+
340
+ # add nodes and edges
341
+ # if type is 'i' just add nodea
342
+ # if type is a d connect to everything previous
343
+ while ci:
344
+ (v, node_type) = ci.pop(0)
345
+ if node_type == "d": # dominating type, connect to all existing nodes
346
+ # We use `for u in list(G):` instead of
347
+ # `for u in G:` because we edit the graph `G` in
348
+ # the loop. Hence using an iterator will result in
349
+ # `RuntimeError: dictionary changed size during iteration`
350
+ for u in list(G):
351
+ G.add_edge(v, u)
352
+ G.add_node(v)
353
+ return G
354
+
355
+
356
+ @nx._dispatchable
357
+ def find_alternating_4_cycle(G):
358
+ """
359
+ Returns False if there aren't any alternating 4 cycles.
360
+ Otherwise returns the cycle as [a,b,c,d] where (a,b)
361
+ and (c,d) are edges and (a,c) and (b,d) are not.
362
+ """
363
+ for u, v in G.edges():
364
+ for w in G.nodes():
365
+ if not G.has_edge(u, w) and u != w:
366
+ for x in G.neighbors(w):
367
+ if not G.has_edge(v, x) and v != x:
368
+ return [u, v, w, x]
369
+ return False
370
+
371
+
372
+ @nx._dispatchable(returns_graph=True)
373
+ def find_threshold_graph(G, create_using=None):
374
+ """
375
+ Returns a threshold subgraph that is close to largest in `G`.
376
+
377
+ The threshold graph will contain the largest degree node in G.
378
+
379
+ Parameters
380
+ ----------
381
+ G : NetworkX graph instance
382
+ An instance of `Graph`, or `MultiDiGraph`
383
+ create_using : NetworkX graph class or `None` (default), optional
384
+ Type of graph to use when constructing the threshold graph.
385
+ If `None`, infer the appropriate graph type from the input.
386
+
387
+ Returns
388
+ -------
389
+ graph :
390
+ A graph instance representing the threshold graph
391
+
392
+ Examples
393
+ --------
394
+ >>> from networkx.algorithms.threshold import find_threshold_graph
395
+ >>> G = nx.barbell_graph(3, 3)
396
+ >>> T = find_threshold_graph(G)
397
+ >>> T.nodes # may vary
398
+ NodeView((7, 8, 5, 6))
399
+
400
+ References
401
+ ----------
402
+ .. [1] Threshold graphs: https://en.wikipedia.org/wiki/Threshold_graph
403
+ """
404
+ return threshold_graph(find_creation_sequence(G), create_using)
405
+
406
+
407
+ @nx._dispatchable
408
+ def find_creation_sequence(G):
409
+ """
410
+ Find a threshold subgraph that is close to largest in G.
411
+ Returns the labeled creation sequence of that threshold graph.
412
+ """
413
+ cs = []
414
+ # get a local pointer to the working part of the graph
415
+ H = G
416
+ while H.order() > 0:
417
+ # get new degree sequence on subgraph
418
+ dsdict = dict(H.degree())
419
+ ds = [(d, v) for v, d in dsdict.items()]
420
+ ds.sort()
421
+ # Update threshold graph nodes
422
+ if ds[-1][0] == 0: # all are isolated
423
+ cs.extend(zip(dsdict, ["i"] * (len(ds) - 1) + ["d"]))
424
+ break # Done!
425
+ # pull off isolated nodes
426
+ while ds[0][0] == 0:
427
+ (d, iso) = ds.pop(0)
428
+ cs.append((iso, "i"))
429
+ # find new biggest node
430
+ (d, bigv) = ds.pop()
431
+ # add edges of star to t_g
432
+ cs.append((bigv, "d"))
433
+ # form subgraph of neighbors of big node
434
+ H = H.subgraph(H.neighbors(bigv))
435
+ cs.reverse()
436
+ return cs
437
+
438
+
439
+ # Properties of Threshold Graphs
440
+ def triangles(creation_sequence):
441
+ """
442
+ Compute number of triangles in the threshold graph with the
443
+ given creation sequence.
444
+ """
445
+ # shortcut algorithm that doesn't require computing number
446
+ # of triangles at each node.
447
+ cs = creation_sequence # alias
448
+ dr = cs.count("d") # number of d's in sequence
449
+ ntri = dr * (dr - 1) * (dr - 2) / 6 # number of triangles in clique of nd d's
450
+ # now add dr choose 2 triangles for every 'i' in sequence where
451
+ # dr is the number of d's to the right of the current i
452
+ for i, typ in enumerate(cs):
453
+ if typ == "i":
454
+ ntri += dr * (dr - 1) / 2
455
+ else:
456
+ dr -= 1
457
+ return ntri
458
+
459
+
460
+ def triangle_sequence(creation_sequence):
461
+ """
462
+ Return triangle sequence for the given threshold graph creation sequence.
463
+
464
+ """
465
+ cs = creation_sequence
466
+ seq = []
467
+ dr = cs.count("d") # number of d's to the right of the current pos
468
+ dcur = (dr - 1) * (dr - 2) // 2 # number of triangles through a node of clique dr
469
+ irun = 0 # number of i's in the last run
470
+ drun = 0 # number of d's in the last run
471
+ for i, sym in enumerate(cs):
472
+ if sym == "d":
473
+ drun += 1
474
+ tri = dcur + (dr - 1) * irun # new triangles at this d
475
+ else: # cs[i]="i":
476
+ if prevsym == "d": # new string of i's
477
+ dcur += (dr - 1) * irun # accumulate shared shortest paths
478
+ irun = 0 # reset i run counter
479
+ dr -= drun # reduce number of d's to right
480
+ drun = 0 # reset d run counter
481
+ irun += 1
482
+ tri = dr * (dr - 1) // 2 # new triangles at this i
483
+ seq.append(tri)
484
+ prevsym = sym
485
+ return seq
486
+
487
+
488
+ def cluster_sequence(creation_sequence):
489
+ """
490
+ Return cluster sequence for the given threshold graph creation sequence.
491
+ """
492
+ triseq = triangle_sequence(creation_sequence)
493
+ degseq = degree_sequence(creation_sequence)
494
+ cseq = []
495
+ for i, deg in enumerate(degseq):
496
+ tri = triseq[i]
497
+ if deg <= 1: # isolated vertex or single pair gets cc 0
498
+ cseq.append(0)
499
+ continue
500
+ max_size = (deg * (deg - 1)) // 2
501
+ cseq.append(tri / max_size)
502
+ return cseq
503
+
504
+
505
+ def degree_sequence(creation_sequence):
506
+ """
507
+ Return degree sequence for the threshold graph with the given
508
+ creation sequence
509
+ """
510
+ cs = creation_sequence # alias
511
+ seq = []
512
+ rd = cs.count("d") # number of d to the right
513
+ for i, sym in enumerate(cs):
514
+ if sym == "d":
515
+ rd -= 1
516
+ seq.append(rd + i)
517
+ else:
518
+ seq.append(rd)
519
+ return seq
520
+
521
+
522
+ def density(creation_sequence):
523
+ """
524
+ Return the density of the graph with this creation_sequence.
525
+ The density is the fraction of possible edges present.
526
+ """
527
+ N = len(creation_sequence)
528
+ two_size = sum(degree_sequence(creation_sequence))
529
+ two_possible = N * (N - 1)
530
+ den = two_size / two_possible
531
+ return den
532
+
533
+
534
+ def degree_correlation(creation_sequence):
535
+ """
536
+ Return the degree-degree correlation over all edges.
537
+ """
538
+ cs = creation_sequence
539
+ s1 = 0 # deg_i*deg_j
540
+ s2 = 0 # deg_i^2+deg_j^2
541
+ s3 = 0 # deg_i+deg_j
542
+ m = 0 # number of edges
543
+ rd = cs.count("d") # number of d nodes to the right
544
+ rdi = [i for i, sym in enumerate(cs) if sym == "d"] # index of "d"s
545
+ ds = degree_sequence(cs)
546
+ for i, sym in enumerate(cs):
547
+ if sym == "d":
548
+ rdi.pop(0)
549
+ degi = ds[i]
550
+ for dj in rdi:
551
+ degj = ds[dj]
552
+ s1 += degj * degi
553
+ s2 += degi**2 + degj**2
554
+ s3 += degi + degj
555
+ m += 1
556
+ denom = 2 * m * s2 - s3 * s3
557
+ numer = 4 * m * s1 - s3 * s3
558
+ if denom == 0:
559
+ if numer == 0:
560
+ return 1
561
+ raise ValueError(f"Zero Denominator but Numerator is {numer}")
562
+ return numer / denom
563
+
564
+
565
+ def shortest_path(creation_sequence, u, v):
566
+ """
567
+ Find the shortest path between u and v in a
568
+ threshold graph G with the given creation_sequence.
569
+
570
+ For an unlabeled creation_sequence, the vertices
571
+ u and v must be integers in (0,len(sequence)) referring
572
+ to the position of the desired vertices in the sequence.
573
+
574
+ For a labeled creation_sequence, u and v are labels of vertices.
575
+
576
+ Use cs=creation_sequence(degree_sequence,with_labels=True)
577
+ to convert a degree sequence to a creation sequence.
578
+
579
+ Returns a list of vertices from u to v.
580
+ Example: if they are neighbors, it returns [u,v]
581
+ """
582
+ # Turn input sequence into a labeled creation sequence
583
+ first = creation_sequence[0]
584
+ if isinstance(first, str): # creation sequence
585
+ cs = [(i, creation_sequence[i]) for i in range(len(creation_sequence))]
586
+ elif isinstance(first, tuple): # labeled creation sequence
587
+ cs = creation_sequence[:]
588
+ elif isinstance(first, int): # compact creation sequence
589
+ ci = uncompact(creation_sequence)
590
+ cs = [(i, ci[i]) for i in range(len(ci))]
591
+ else:
592
+ raise TypeError("Not a valid creation sequence type")
593
+
594
+ verts = [s[0] for s in cs]
595
+ if v not in verts:
596
+ raise ValueError(f"Vertex {v} not in graph from creation_sequence")
597
+ if u not in verts:
598
+ raise ValueError(f"Vertex {u} not in graph from creation_sequence")
599
+ # Done checking
600
+ if u == v:
601
+ return [u]
602
+
603
+ uindex = verts.index(u)
604
+ vindex = verts.index(v)
605
+ bigind = max(uindex, vindex)
606
+ if cs[bigind][1] == "d":
607
+ return [u, v]
608
+ # must be that cs[bigind][1]=='i'
609
+ cs = cs[bigind:]
610
+ while cs:
611
+ vert = cs.pop()
612
+ if vert[1] == "d":
613
+ return [u, vert[0], v]
614
+ # All after u are type 'i' so no connection
615
+ return -1
616
+
617
+
618
+ def shortest_path_length(creation_sequence, i):
619
+ """
620
+ Return the shortest path length from indicated node to
621
+ every other node for the threshold graph with the given
622
+ creation sequence.
623
+ Node is indicated by index i in creation_sequence unless
624
+ creation_sequence is labeled in which case, i is taken to
625
+ be the label of the node.
626
+
627
+ Paths lengths in threshold graphs are at most 2.
628
+ Length to unreachable nodes is set to -1.
629
+ """
630
+ # Turn input sequence into a labeled creation sequence
631
+ first = creation_sequence[0]
632
+ if isinstance(first, str): # creation sequence
633
+ if isinstance(creation_sequence, list):
634
+ cs = creation_sequence[:]
635
+ else:
636
+ cs = list(creation_sequence)
637
+ elif isinstance(first, tuple): # labeled creation sequence
638
+ cs = [v[1] for v in creation_sequence]
639
+ i = [v[0] for v in creation_sequence].index(i)
640
+ elif isinstance(first, int): # compact creation sequence
641
+ cs = uncompact(creation_sequence)
642
+ else:
643
+ raise TypeError("Not a valid creation sequence type")
644
+
645
+ # Compute
646
+ N = len(cs)
647
+ spl = [2] * N # length 2 to every node
648
+ spl[i] = 0 # except self which is 0
649
+ # 1 for all d's to the right
650
+ for j in range(i + 1, N):
651
+ if cs[j] == "d":
652
+ spl[j] = 1
653
+ if cs[i] == "d": # 1 for all nodes to the left
654
+ for j in range(i):
655
+ spl[j] = 1
656
+ # and -1 for any trailing i to indicate unreachable
657
+ for j in range(N - 1, 0, -1):
658
+ if cs[j] == "d":
659
+ break
660
+ spl[j] = -1
661
+ return spl
662
+
663
+
664
+ def betweenness_sequence(creation_sequence, normalized=True):
665
+ """
666
+ Return betweenness for the threshold graph with the given creation
667
+ sequence. The result is unscaled. To scale the values
668
+ to the interval [0,1] divide by (n-1)*(n-2).
669
+ """
670
+ cs = creation_sequence
671
+ seq = [] # betweenness
672
+ lastchar = "d" # first node is always a 'd'
673
+ dr = float(cs.count("d")) # number of d's to the right of current pos
674
+ irun = 0 # number of i's in the last run
675
+ drun = 0 # number of d's in the last run
676
+ dlast = 0.0 # betweenness of last d
677
+ for i, c in enumerate(cs):
678
+ if c == "d": # cs[i]=="d":
679
+ # betweenness = amt shared with earlier d's and i's
680
+ # + new isolated nodes covered
681
+ # + new paths to all previous nodes
682
+ b = dlast + (irun - 1) * irun / dr + 2 * irun * (i - drun - irun) / dr
683
+ drun += 1 # update counter
684
+ else: # cs[i]="i":
685
+ if lastchar == "d": # if this is a new run of i's
686
+ dlast = b # accumulate betweenness
687
+ dr -= drun # update number of d's to the right
688
+ drun = 0 # reset d counter
689
+ irun = 0 # reset i counter
690
+ b = 0 # isolated nodes have zero betweenness
691
+ irun += 1 # add another i to the run
692
+ seq.append(float(b))
693
+ lastchar = c
694
+
695
+ # normalize by the number of possible shortest paths
696
+ if normalized:
697
+ order = len(cs)
698
+ scale = 1.0 / ((order - 1) * (order - 2))
699
+ seq = [s * scale for s in seq]
700
+
701
+ return seq
702
+
703
+
704
+ def eigenvectors(creation_sequence):
705
+ """
706
+ Return a 2-tuple of Laplacian eigenvalues and eigenvectors
707
+ for the threshold network with creation_sequence.
708
+ The first value is a list of eigenvalues.
709
+ The second value is a list of eigenvectors.
710
+ The lists are in the same order so corresponding eigenvectors
711
+ and eigenvalues are in the same position in the two lists.
712
+
713
+ Notice that the order of the eigenvalues returned by eigenvalues(cs)
714
+ may not correspond to the order of these eigenvectors.
715
+ """
716
+ ccs = make_compact(creation_sequence)
717
+ N = sum(ccs)
718
+ vec = [0] * N
719
+ val = vec[:]
720
+ # get number of type d nodes to the right (all for first node)
721
+ dr = sum(ccs[::2])
722
+
723
+ nn = ccs[0]
724
+ vec[0] = [1.0 / sqrt(N)] * N
725
+ val[0] = 0
726
+ e = dr
727
+ dr -= nn
728
+ type_d = True
729
+ i = 1
730
+ dd = 1
731
+ while dd < nn:
732
+ scale = 1.0 / sqrt(dd * dd + i)
733
+ vec[i] = i * [-scale] + [dd * scale] + [0] * (N - i - 1)
734
+ val[i] = e
735
+ i += 1
736
+ dd += 1
737
+ if len(ccs) == 1:
738
+ return (val, vec)
739
+ for nn in ccs[1:]:
740
+ scale = 1.0 / sqrt(nn * i * (i + nn))
741
+ vec[i] = i * [-nn * scale] + nn * [i * scale] + [0] * (N - i - nn)
742
+ # find eigenvalue
743
+ type_d = not type_d
744
+ if type_d:
745
+ e = i + dr
746
+ dr -= nn
747
+ else:
748
+ e = dr
749
+ val[i] = e
750
+ st = i
751
+ i += 1
752
+ dd = 1
753
+ while dd < nn:
754
+ scale = 1.0 / sqrt(i - st + dd * dd)
755
+ vec[i] = [0] * st + (i - st) * [-scale] + [dd * scale] + [0] * (N - i - 1)
756
+ val[i] = e
757
+ i += 1
758
+ dd += 1
759
+ return (val, vec)
760
+
761
+
762
+ def spectral_projection(u, eigenpairs):
763
+ """
764
+ Returns the coefficients of each eigenvector
765
+ in a projection of the vector u onto the normalized
766
+ eigenvectors which are contained in eigenpairs.
767
+
768
+ eigenpairs should be a list of two objects. The
769
+ first is a list of eigenvalues and the second a list
770
+ of eigenvectors. The eigenvectors should be lists.
771
+
772
+ There's not a lot of error checking on lengths of
773
+ arrays, etc. so be careful.
774
+ """
775
+ coeff = []
776
+ evect = eigenpairs[1]
777
+ for ev in evect:
778
+ c = sum(evv * uv for (evv, uv) in zip(ev, u))
779
+ coeff.append(c)
780
+ return coeff
781
+
782
+
783
+ def eigenvalues(creation_sequence):
784
+ """
785
+ Return sequence of eigenvalues of the Laplacian of the threshold
786
+ graph for the given creation_sequence.
787
+
788
+ Based on the Ferrer's diagram method. The spectrum is integral
789
+ and is the conjugate of the degree sequence.
790
+
791
+ See::
792
+
793
+ @Article{degree-merris-1994,
794
+ author = {Russel Merris},
795
+ title = {Degree maximal graphs are Laplacian integral},
796
+ journal = {Linear Algebra Appl.},
797
+ year = {1994},
798
+ volume = {199},
799
+ pages = {381--389},
800
+ }
801
+
802
+ """
803
+ degseq = degree_sequence(creation_sequence)
804
+ degseq.sort()
805
+ eiglist = [] # zero is always one eigenvalue
806
+ eig = 0
807
+ row = len(degseq)
808
+ bigdeg = degseq.pop()
809
+ while row:
810
+ if bigdeg < row:
811
+ eiglist.append(eig)
812
+ row -= 1
813
+ else:
814
+ eig += 1
815
+ if degseq:
816
+ bigdeg = degseq.pop()
817
+ else:
818
+ bigdeg = 0
819
+ return eiglist
820
+
821
+
822
+ # Threshold graph creation routines
823
+
824
+
825
+ @py_random_state(2)
826
+ def random_threshold_sequence(n, p, seed=None):
827
+ """
828
+ Create a random threshold sequence of size n.
829
+ A creation sequence is built by randomly choosing d's with
830
+ probability p and i's with probability 1-p.
831
+
832
+ s=nx.random_threshold_sequence(10,0.5)
833
+
834
+ returns a threshold sequence of length 10 with equal
835
+ probably of an i or a d at each position.
836
+
837
+ A "random" threshold graph can be built with
838
+
839
+ G=nx.threshold_graph(s)
840
+
841
+ seed : integer, random_state, or None (default)
842
+ Indicator of random number generation state.
843
+ See :ref:`Randomness<randomness>`.
844
+ """
845
+ if not (0 <= p <= 1):
846
+ raise ValueError("p must be in [0,1]")
847
+
848
+ cs = ["d"] # threshold sequences always start with a d
849
+ for i in range(1, n):
850
+ if seed.random() < p:
851
+ cs.append("d")
852
+ else:
853
+ cs.append("i")
854
+ return cs
855
+
856
+
857
+ # maybe *_d_threshold_sequence routines should
858
+ # be (or be called from) a single routine with a more descriptive name
859
+ # and a keyword parameter?
860
+ def right_d_threshold_sequence(n, m):
861
+ """
862
+ Returns a "right-dominated" threshold sequence with `n` vertices and `m` edges.
863
+
864
+ Each vertex in the sequence is either dominant or isolated.
865
+ In the "right-dominated" version, once the basic sequence is formed,
866
+ isolated vertices may be flipped to dominant from the right in order
867
+ to reach the target number of edges.
868
+
869
+ Parameters
870
+ ----------
871
+ n : int
872
+ Number of vertices.
873
+ m : int
874
+ Number of edges.
875
+
876
+ Returns
877
+ -------
878
+ A list of 'd' (dominant) and 'i' (isolated) forming a right-dominated threshold sequence.
879
+
880
+ Raises
881
+ ------
882
+ ValueError
883
+ If `m` exceeds the maximum number of edges.
884
+
885
+ Examples
886
+ --------
887
+ >>> from networkx.algorithms.threshold import right_d_threshold_sequence
888
+ >>> right_d_threshold_sequence(5, 3)
889
+ ['d', 'i', 'i', 'd', 'i']
890
+ """
891
+
892
+ cs = ["d"] + ["i"] * (n - 1) # create sequence with n insolated nodes
893
+
894
+ # m <n : not enough edges, make disconnected
895
+ if m < n:
896
+ cs[m] = "d"
897
+ return cs
898
+
899
+ # too many edges
900
+ if m > n * (n - 1) / 2:
901
+ raise ValueError("Too many edges for this many nodes.")
902
+
903
+ # connected case m >n-1
904
+ ind = n - 1
905
+ sum = n - 1
906
+ while sum < m:
907
+ cs[ind] = "d"
908
+ ind -= 1
909
+ sum += ind
910
+ ind = m - (sum - ind)
911
+ cs[ind] = "d"
912
+ return cs
913
+
914
+
915
+ def left_d_threshold_sequence(n, m):
916
+ """
917
+ Returns a "left-dominated" threshold sequence with `n` vertices and `m` edges.
918
+
919
+ Each vertex in the sequence is either dominant or isolated.
920
+ In the "left-dominated" version, once the basic sequence is formed,
921
+ isolated vertices may be flipped to dominant from the left in order
922
+ to reach the target number of edges.
923
+
924
+ Parameters
925
+ ----------
926
+ n : int
927
+ Number of vertices.
928
+ m : int
929
+ Number of edges.
930
+
931
+ Returns
932
+ -------
933
+ A list of 'd' (dominant) and 'i' (isolated) forming a left-dominated threshold sequence.
934
+
935
+ Raises
936
+ ------
937
+ ValueError
938
+ If `m` exceeds the maximum number of edges.
939
+
940
+ Examples
941
+ --------
942
+ For certain small cases, both left and right dominated versions produce
943
+ the same sequence. However, for larger values of `m`, the difference in
944
+ flipping order becomes evident. For instance, compare the sequences for
945
+ ``n=6, m=8``:
946
+
947
+ >>> from networkx.algorithms.threshold import left_d_threshold_sequence
948
+ >>> seq = left_d_threshold_sequence(6, 8)
949
+ >>> seq
950
+ ['d', 'd', 'd', 'i', 'i', 'd']
951
+
952
+ In contrast, the right-dominated version yields:
953
+
954
+ >>> from networkx.algorithms.threshold import right_d_threshold_sequence
955
+ >>> right_seq = right_d_threshold_sequence(6, 8)
956
+ >>> right_seq
957
+ ['d', 'i', 'i', 'd', 'i', 'd']
958
+ """
959
+
960
+ cs = ["d"] + ["i"] * (n - 1) # create sequence with n insolated nodes
961
+
962
+ # m <n : not enough edges, make disconnected
963
+ if m < n:
964
+ cs[m] = "d"
965
+ return cs
966
+
967
+ # too many edges
968
+ if m > n * (n - 1) / 2:
969
+ raise ValueError("Too many edges for this many nodes.")
970
+
971
+ # Connected case when M>N-1
972
+ cs[n - 1] = "d"
973
+ sum = n - 1
974
+ ind = 1
975
+ while sum < m:
976
+ cs[ind] = "d"
977
+ sum += ind
978
+ ind += 1
979
+ if sum > m: # be sure not to change the first vertex
980
+ cs[sum - m] = "i"
981
+ return cs