okstra 0.130.4 → 0.131.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/README.md +0 -1
  2. package/docs/architecture.md +2 -2
  3. package/docs/cli.md +1 -1
  4. package/docs/for-ai/README.md +0 -2
  5. package/docs/for-ai/skills/okstra-run.md +13 -2
  6. package/docs/for-ai/skills/okstra-setup.md +4 -1
  7. package/docs/project-structure-overview.md +5 -4
  8. package/docs/task-process/implementation-planning.md +13 -0
  9. package/docs/task-process/implementation.md +17 -2
  10. package/package.json +1 -1
  11. package/runtime/BUILD.json +2 -2
  12. package/runtime/agents/workers/report-writer-worker.md +7 -0
  13. package/runtime/bin/lib/okstra/usage.sh +4 -4
  14. package/runtime/prompts/lead/okstra-lead-contract.md +2 -2
  15. package/runtime/prompts/lead/plan-body-verification.md +26 -5
  16. package/runtime/prompts/lead/report-writer.md +6 -2
  17. package/runtime/prompts/profiles/_common-contract.md +2 -1
  18. package/runtime/prompts/profiles/_implementation-deliverable.md +6 -1
  19. package/runtime/prompts/profiles/_implementation-executor.md +2 -2
  20. package/runtime/prompts/profiles/_implementation-verifier.md +33 -10
  21. package/runtime/prompts/profiles/final-verification.md +21 -6
  22. package/runtime/prompts/profiles/implementation-planning.md +16 -4
  23. package/runtime/python/okstra_ctl/codex_dispatch.py +31 -0
  24. package/runtime/python/okstra_ctl/conformance.py +49 -11
  25. package/runtime/python/okstra_ctl/report_finalize.py +52 -1
  26. package/runtime/python/okstra_ctl/run.py +15 -3
  27. package/runtime/python/okstra_ctl/worker_prompt_contract.py +14 -6
  28. package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -1
  29. package/runtime/python/okstra_vendor/__init__.py +0 -44
  30. package/runtime/schemas/final-report-v1.0.schema.json +99 -5
  31. package/runtime/skills/okstra-run/SKILL.md +11 -4
  32. package/runtime/skills/okstra-setup/SKILL.md +3 -2
  33. package/runtime/skills/okstra-setup/references/project-config.md +16 -7
  34. package/runtime/templates/reports/final-report.template.md +15 -9
  35. package/runtime/templates/reports/i18n/en.json +1 -0
  36. package/runtime/templates/reports/i18n/ko.json +1 -0
  37. package/runtime/validators/lib/fixtures.sh +6 -0
  38. package/runtime/validators/validate-run.py +2019 -96
  39. package/src/cli-registry.mjs +0 -7
  40. package/src/commands/lifecycle/doctor.mjs +0 -9
  41. package/src/lib/skill-catalog.mjs +0 -1
  42. package/docs/for-ai/skills/okstra-graphify.md +0 -64
  43. package/runtime/python/okstra_ctl/graphify_cmd.py +0 -225
  44. package/runtime/python/okstra_vendor/graphify/.vendored-version +0 -1
  45. package/runtime/python/okstra_vendor/graphify/__init__.py +0 -28
  46. package/runtime/python/okstra_vendor/graphify/__main__.py +0 -1371
  47. package/runtime/python/okstra_vendor/graphify/analyze.py +0 -540
  48. package/runtime/python/okstra_vendor/graphify/benchmark.py +0 -129
  49. package/runtime/python/okstra_vendor/graphify/build.py +0 -107
  50. package/runtime/python/okstra_vendor/graphify/cache.py +0 -169
  51. package/runtime/python/okstra_vendor/graphify/cluster.py +0 -137
  52. package/runtime/python/okstra_vendor/graphify/detect.py +0 -510
  53. package/runtime/python/okstra_vendor/graphify/export.py +0 -1014
  54. package/runtime/python/okstra_vendor/graphify/extract.py +0 -3277
  55. package/runtime/python/okstra_vendor/graphify/hooks.py +0 -220
  56. package/runtime/python/okstra_vendor/graphify/ingest.py +0 -297
  57. package/runtime/python/okstra_vendor/graphify/manifest.py +0 -4
  58. package/runtime/python/okstra_vendor/graphify/report.py +0 -175
  59. package/runtime/python/okstra_vendor/graphify/security.py +0 -203
  60. package/runtime/python/okstra_vendor/graphify/serve.py +0 -373
  61. package/runtime/python/okstra_vendor/graphify/skill-aider.md +0 -1184
  62. package/runtime/python/okstra_vendor/graphify/skill-claw.md +0 -1184
  63. package/runtime/python/okstra_vendor/graphify/skill-codex.md +0 -1242
  64. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +0 -1268
  65. package/runtime/python/okstra_vendor/graphify/skill-droid.md +0 -1239
  66. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +0 -1183
  67. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +0 -1238
  68. package/runtime/python/okstra_vendor/graphify/skill-trae.md +0 -1208
  69. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +0 -253
  70. package/runtime/python/okstra_vendor/graphify/skill-windows.md +0 -1245
  71. package/runtime/python/okstra_vendor/graphify/skill.md +0 -1319
  72. package/runtime/python/okstra_vendor/graphify/transcribe.py +0 -182
  73. package/runtime/python/okstra_vendor/graphify/validate.py +0 -72
  74. package/runtime/python/okstra_vendor/graphify/watch.py +0 -188
  75. package/runtime/python/okstra_vendor/graphify/wiki.py +0 -214
  76. package/runtime/python/okstra_vendor/networkx/__init__.py +0 -62
  77. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +0 -134
  78. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +0 -26
  79. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +0 -259
  80. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +0 -71
  81. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +0 -412
  82. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +0 -396
  83. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +0 -150
  84. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +0 -149
  85. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +0 -369
  86. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +0 -44
  87. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +0 -143
  88. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +0 -53
  89. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +0 -265
  90. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +0 -1508
  91. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +0 -255
  92. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +0 -83
  93. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +0 -5
  94. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +0 -122
  95. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +0 -302
  96. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +0 -255
  97. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +0 -160
  98. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +0 -127
  99. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +0 -164
  100. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +0 -88
  101. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +0 -322
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +0 -290
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +0 -289
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +0 -57
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +0 -360
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +0 -105
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +0 -603
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +0 -316
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +0 -590
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +0 -232
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +0 -526
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +0 -112
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +0 -69
  114. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +0 -168
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +0 -205
  116. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +0 -164
  117. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +0 -20
  118. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +0 -591
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +0 -236
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +0 -282
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +0 -364
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +0 -227
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +0 -96
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +0 -150
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +0 -107
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +0 -357
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +0 -130
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +0 -787
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +0 -88
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +0 -331
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +0 -150
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +0 -200
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +0 -128
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +0 -209
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +0 -141
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +0 -361
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +0 -181
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +0 -95
  139. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +0 -172
  140. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +0 -443
  141. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +0 -818
  142. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +0 -732
  143. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +0 -4
  144. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +0 -505
  145. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +0 -565
  146. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +0 -163
  147. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +0 -28
  148. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +0 -153
  149. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +0 -354
  150. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +0 -171
  151. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +0 -30
  152. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +0 -216
  153. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +0 -79
  154. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +0 -338
  155. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +0 -162
  156. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +0 -220
  157. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +0 -384
  158. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +0 -227
  159. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +0 -452
  160. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +0 -347
  161. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +0 -6
  162. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +0 -115
  163. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +0 -394
  164. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +0 -282
  165. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +0 -71
  166. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +0 -359
  167. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +0 -196
  168. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +0 -11
  169. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +0 -811
  170. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +0 -616
  171. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +0 -408
  172. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +0 -1270
  173. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +0 -592
  174. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +0 -220
  175. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +0 -235
  176. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +0 -152
  177. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +0 -88
  178. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +0 -588
  179. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +0 -142
  180. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +0 -416
  181. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +0 -1234
  182. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +0 -677
  183. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +0 -1392
  184. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +0 -1095
  185. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +0 -272
  186. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +0 -142
  187. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +0 -268
  188. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +0 -167
  189. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +0 -470
  190. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +0 -11
  191. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +0 -370
  192. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +0 -407
  193. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +0 -238
  194. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +0 -241
  195. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +0 -178
  196. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +0 -611
  197. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +0 -356
  198. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +0 -662
  199. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +0 -425
  200. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +0 -300
  201. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +0 -194
  202. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +0 -435
  203. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +0 -483
  204. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +0 -57
  205. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +0 -196
  206. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +0 -107
  207. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +0 -7
  208. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +0 -1306
  209. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +0 -336
  210. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +0 -1262
  211. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +0 -352
  212. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +0 -308
  213. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +0 -264
  214. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +0 -1102
  215. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +0 -192
  216. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +0 -2
  217. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +0 -337
  218. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +0 -498
  219. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +0 -687
  220. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +0 -280
  221. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +0 -1148
  222. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +0 -27
  223. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +0 -738
  224. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +0 -78
  225. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +0 -59
  226. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +0 -219
  227. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +0 -155
  228. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +0 -4
  229. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +0 -324
  230. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +0 -468
  231. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +0 -633
  232. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +0 -77
  233. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +0 -73
  234. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +0 -464
  235. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +0 -1463
  236. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +0 -306
  237. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +0 -98
  238. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +0 -167
  239. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +0 -138
  240. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +0 -5
  241. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +0 -239
  242. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +0 -264
  243. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +0 -716
  244. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +0 -625
  245. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +0 -2542
  246. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +0 -2107
  247. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +0 -966
  248. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +0 -404
  249. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +0 -30
  250. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +0 -296
  251. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +0 -374
  252. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +0 -564
  253. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +0 -406
  254. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +0 -981
  255. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +0 -142
  256. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +0 -406
  257. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +0 -5
  258. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +0 -90
  259. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +0 -576
  260. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +0 -529
  261. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +0 -185
  262. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +0 -182
  263. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +0 -7
  264. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +0 -1042
  265. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +0 -413
  266. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +0 -88
  267. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +0 -219
  268. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +0 -1281
  269. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +0 -106
  270. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +0 -273
  271. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +0 -500
  272. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +0 -76
  273. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +0 -86
  274. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +0 -77
  275. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +0 -278
  276. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +0 -13
  277. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +0 -435
  278. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +0 -1363
  279. package/runtime/python/okstra_vendor/networkx/classes/filters.py +0 -95
  280. package/runtime/python/okstra_vendor/networkx/classes/function.py +0 -1549
  281. package/runtime/python/okstra_vendor/networkx/classes/graph.py +0 -2082
  282. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +0 -269
  283. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +0 -977
  284. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +0 -1294
  285. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +0 -1447
  286. package/runtime/python/okstra_vendor/networkx/convert.py +0 -502
  287. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +0 -1314
  288. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +0 -7
  289. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +0 -2036
  290. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +0 -470
  291. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +0 -570
  292. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +0 -361
  293. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +0 -2978
  294. package/runtime/python/okstra_vendor/networkx/exception.py +0 -131
  295. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +0 -34
  296. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  297. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +0 -227
  298. package/runtime/python/okstra_vendor/networkx/generators/classic.py +0 -1091
  299. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +0 -68
  300. package/runtime/python/okstra_vendor/networkx/generators/community.py +0 -1070
  301. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +0 -886
  302. package/runtime/python/okstra_vendor/networkx/generators/directed.py +0 -572
  303. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +0 -174
  304. package/runtime/python/okstra_vendor/networkx/generators/ego.py +0 -66
  305. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +0 -499
  306. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +0 -1037
  307. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +0 -163
  308. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +0 -443
  309. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +0 -125
  310. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +0 -70
  311. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +0 -664
  312. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +0 -405
  313. package/runtime/python/okstra_vendor/networkx/generators/line.py +0 -501
  314. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +0 -110
  315. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +0 -259
  316. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +0 -117
  317. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +0 -1416
  318. package/runtime/python/okstra_vendor/networkx/generators/small.py +0 -1070
  319. package/runtime/python/okstra_vendor/networkx/generators/social.py +0 -554
  320. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +0 -120
  321. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +0 -54
  322. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +0 -131
  323. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +0 -74
  324. package/runtime/python/okstra_vendor/networkx/generators/trees.py +0 -1070
  325. package/runtime/python/okstra_vendor/networkx/generators/triads.py +0 -94
  326. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +0 -188
  327. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +0 -13
  328. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +0 -650
  329. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +0 -466
  330. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +0 -77
  331. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +0 -168
  332. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +0 -512
  333. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +0 -166
  334. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +0 -186
  335. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +0 -17
  336. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +0 -330
  337. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +0 -489
  338. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +0 -1084
  339. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +0 -879
  340. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +0 -427
  341. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +0 -1053
  342. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +0 -19
  343. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +0 -156
  344. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +0 -190
  345. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +0 -261
  346. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +0 -137
  347. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +0 -108
  348. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +0 -393
  349. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +0 -113
  350. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +0 -286
  351. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +0 -379
  352. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +0 -851
  353. package/runtime/python/okstra_vendor/networkx/relabel.py +0 -285
  354. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +0 -8
  355. package/runtime/python/okstra_vendor/networkx/utils/backends.py +0 -2171
  356. package/runtime/python/okstra_vendor/networkx/utils/configs.py +0 -396
  357. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +0 -1233
  358. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +0 -338
  359. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +0 -297
  360. package/runtime/python/okstra_vendor/networkx/utils/misc.py +0 -703
  361. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +0 -198
  362. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +0 -159
  363. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +0 -106
  364. package/runtime/skills/okstra-graphify/SKILL.md +0 -169
  365. package/src/commands/graphify.mjs +0 -32
@@ -1,413 +0,0 @@
1
- """Functions for encoding and decoding trees.
2
-
3
- Since a tree is a highly restricted form of graph, it can be represented
4
- concisely in several ways. This module includes functions for encoding
5
- and decoding trees in the form of nested tuples and Prüfer
6
- sequences. The former requires a rooted tree, whereas the latter can be
7
- applied to unrooted trees. Furthermore, there is a bijection from Prüfer
8
- sequences to labeled trees.
9
-
10
- """
11
-
12
- from collections import Counter
13
- from itertools import chain
14
-
15
- import networkx as nx
16
- from networkx.utils import not_implemented_for
17
-
18
- __all__ = [
19
- "from_nested_tuple",
20
- "from_prufer_sequence",
21
- "NotATree",
22
- "to_nested_tuple",
23
- "to_prufer_sequence",
24
- ]
25
-
26
-
27
- class NotATree(nx.NetworkXException):
28
- """Raised when a function expects a tree (that is, a connected
29
- undirected graph with no cycles) but gets a non-tree graph as input
30
- instead.
31
-
32
- """
33
-
34
-
35
- @not_implemented_for("directed")
36
- @nx._dispatchable(graphs="T")
37
- def to_nested_tuple(T, root, canonical_form=False):
38
- """Returns a nested tuple representation of the given tree.
39
-
40
- The nested tuple representation of a tree is defined
41
- recursively. The tree with one node and no edges is represented by
42
- the empty tuple, ``()``. A tree with ``k`` subtrees is represented
43
- by a tuple of length ``k`` in which each element is the nested tuple
44
- representation of a subtree.
45
-
46
- Parameters
47
- ----------
48
- T : NetworkX graph
49
- An undirected graph object representing a tree.
50
-
51
- root : node
52
- The node in ``T`` to interpret as the root of the tree.
53
-
54
- canonical_form : bool
55
- If ``True``, each tuple is sorted so that the function returns
56
- a canonical form for rooted trees. This means "lighter" subtrees
57
- will appear as nested tuples before "heavier" subtrees. In this
58
- way, each isomorphic rooted tree has the same nested tuple
59
- representation.
60
-
61
- Returns
62
- -------
63
- tuple
64
- A nested tuple representation of the tree.
65
-
66
- Notes
67
- -----
68
- This function is *not* the inverse of :func:`from_nested_tuple`; the
69
- only guarantee is that the rooted trees are isomorphic.
70
-
71
- See also
72
- --------
73
- from_nested_tuple
74
- to_prufer_sequence
75
-
76
- Examples
77
- --------
78
- The tree need not be a balanced binary tree::
79
-
80
- >>> T = nx.Graph()
81
- >>> T.add_edges_from([(0, 1), (0, 2), (0, 3)])
82
- >>> T.add_edges_from([(1, 4), (1, 5)])
83
- >>> T.add_edges_from([(3, 6), (3, 7)])
84
- >>> root = 0
85
- >>> nx.to_nested_tuple(T, root)
86
- (((), ()), (), ((), ()))
87
-
88
- Continuing the above example, if ``canonical_form`` is ``True``, the
89
- nested tuples will be sorted::
90
-
91
- >>> nx.to_nested_tuple(T, root, canonical_form=True)
92
- ((), ((), ()), ((), ()))
93
-
94
- Even the path graph can be interpreted as a tree::
95
-
96
- >>> T = nx.path_graph(4)
97
- >>> root = 0
98
- >>> nx.to_nested_tuple(T, root)
99
- ((((),),),)
100
-
101
- """
102
-
103
- def _make_tuple(T, root, _parent):
104
- """Recursively compute the nested tuple representation of the
105
- given rooted tree.
106
-
107
- ``_parent`` is the parent node of ``root`` in the supertree in
108
- which ``T`` is a subtree, or ``None`` if ``root`` is the root of
109
- the supertree. This argument is used to determine which
110
- neighbors of ``root`` are children and which is the parent.
111
-
112
- """
113
- # Get the neighbors of `root` that are not the parent node. We
114
- # are guaranteed that `root` is always in `T` by construction.
115
- children = set(T[root]) - {_parent}
116
- if len(children) == 0:
117
- return ()
118
- nested = (_make_tuple(T, v, root) for v in children)
119
- if canonical_form:
120
- nested = sorted(nested)
121
- return tuple(nested)
122
-
123
- # Do some sanity checks on the input.
124
- if not nx.is_tree(T):
125
- raise nx.NotATree("provided graph is not a tree")
126
- if root not in T:
127
- raise nx.NodeNotFound(f"Graph {T} contains no node {root}")
128
-
129
- return _make_tuple(T, root, None)
130
-
131
-
132
- @nx._dispatchable(graphs=None, returns_graph=True)
133
- def from_nested_tuple(sequence, sensible_relabeling=False):
134
- """Returns the rooted tree corresponding to the given nested tuple.
135
-
136
- The nested tuple representation of a tree is defined
137
- recursively. The tree with one node and no edges is represented by
138
- the empty tuple, ``()``. A tree with ``k`` subtrees is represented
139
- by a tuple of length ``k`` in which each element is the nested tuple
140
- representation of a subtree.
141
-
142
- Parameters
143
- ----------
144
- sequence : tuple
145
- A nested tuple representing a rooted tree.
146
-
147
- sensible_relabeling : bool
148
- Whether to relabel the nodes of the tree so that nodes are
149
- labeled in increasing order according to their breadth-first
150
- search order from the root node.
151
-
152
- Returns
153
- -------
154
- NetworkX graph
155
- The tree corresponding to the given nested tuple, whose root
156
- node is node 0. If ``sensible_labeling`` is ``True``, nodes will
157
- be labeled in breadth-first search order starting from the root
158
- node.
159
-
160
- Notes
161
- -----
162
- This function is *not* the inverse of :func:`to_nested_tuple`; the
163
- only guarantee is that the rooted trees are isomorphic.
164
-
165
- See also
166
- --------
167
- to_nested_tuple
168
- from_prufer_sequence
169
-
170
- Examples
171
- --------
172
- Sensible relabeling ensures that the nodes are labeled from the root
173
- starting at 0::
174
-
175
- >>> balanced = (((), ()), ((), ()))
176
- >>> T = nx.from_nested_tuple(balanced, sensible_relabeling=True)
177
- >>> edges = [(0, 1), (0, 2), (1, 3), (1, 4), (2, 5), (2, 6)]
178
- >>> all((u, v) in T.edges() or (v, u) in T.edges() for (u, v) in edges)
179
- True
180
-
181
- """
182
-
183
- def _make_tree(sequence):
184
- """Recursively creates a tree from the given sequence of nested
185
- tuples.
186
-
187
- This function employs the :func:`~networkx.tree.join` function
188
- to recursively join subtrees into a larger tree.
189
-
190
- """
191
- # The empty sequence represents the empty tree, which is the
192
- # (unique) graph with a single node. We mark the single node
193
- # with an attribute that indicates that it is the root of the
194
- # graph.
195
- if len(sequence) == 0:
196
- return nx.empty_graph(1)
197
- # For a nonempty sequence, get the subtrees for each child
198
- # sequence and join all the subtrees at their roots. After
199
- # joining the subtrees, the root is node 0.
200
- return nx.tree.join_trees([(_make_tree(child), 0) for child in sequence])
201
-
202
- # Make the tree and remove the `is_root` node attribute added by the
203
- # helper function.
204
- T = _make_tree(sequence)
205
- if sensible_relabeling:
206
- # Relabel the nodes according to their breadth-first search
207
- # order, starting from the root node (that is, the node 0).
208
- bfs_nodes = chain([0], (v for u, v in nx.bfs_edges(T, 0)))
209
- labels = {v: i for i, v in enumerate(bfs_nodes)}
210
- # We would like to use `copy=False`, but `relabel_nodes` doesn't
211
- # allow a relabel mapping that can't be topologically sorted.
212
- T = nx.relabel_nodes(T, labels)
213
- return T
214
-
215
-
216
- @not_implemented_for("directed")
217
- @nx._dispatchable(graphs="T")
218
- def to_prufer_sequence(T):
219
- r"""Returns the Prüfer sequence of the given tree.
220
-
221
- A *Prüfer sequence* is a list of *n* - 2 numbers between 0 and
222
- *n* - 1, inclusive. The tree corresponding to a given Prüfer
223
- sequence can be recovered by repeatedly joining a node in the
224
- sequence with a node with the smallest potential degree according to
225
- the sequence.
226
-
227
- Parameters
228
- ----------
229
- T : NetworkX graph
230
- An undirected graph object representing a tree.
231
-
232
- Returns
233
- -------
234
- list
235
- The Prüfer sequence of the given tree.
236
-
237
- Raises
238
- ------
239
- NetworkXPointlessConcept
240
- If the number of nodes in `T` is less than two.
241
-
242
- NotATree
243
- If `T` is not a tree.
244
-
245
- KeyError
246
- If the set of nodes in `T` is not {0, …, *n* - 1}.
247
-
248
- Notes
249
- -----
250
- There is a bijection from labeled trees to Prüfer sequences. This
251
- function is the inverse of the :func:`from_prufer_sequence`
252
- function.
253
-
254
- Sometimes Prüfer sequences use nodes labeled from 1 to *n* instead
255
- of from 0 to *n* - 1. This function requires nodes to be labeled in
256
- the latter form. You can use :func:`~networkx.relabel_nodes` to
257
- relabel the nodes of your tree to the appropriate format.
258
-
259
- This implementation is from [1]_ and has a running time of
260
- $O(n)$.
261
-
262
- See also
263
- --------
264
- to_nested_tuple
265
- from_prufer_sequence
266
-
267
- References
268
- ----------
269
- .. [1] Wang, Xiaodong, Lei Wang, and Yingjie Wu.
270
- "An optimal algorithm for Prufer codes."
271
- *Journal of Software Engineering and Applications* 2.02 (2009): 111.
272
- <https://doi.org/10.4236/jsea.2009.22016>
273
-
274
- Examples
275
- --------
276
- There is a bijection between Prüfer sequences and labeled trees, so
277
- this function is the inverse of the :func:`from_prufer_sequence`
278
- function:
279
-
280
- >>> edges = [(0, 3), (1, 3), (2, 3), (3, 4), (4, 5)]
281
- >>> tree = nx.Graph(edges)
282
- >>> sequence = nx.to_prufer_sequence(tree)
283
- >>> sequence
284
- [3, 3, 3, 4]
285
- >>> tree2 = nx.from_prufer_sequence(sequence)
286
- >>> list(tree2.edges()) == edges
287
- True
288
-
289
- """
290
- # Perform some sanity checks on the input.
291
- n = len(T)
292
- if n < 2:
293
- msg = "Prüfer sequence undefined for trees with fewer than two nodes"
294
- raise nx.NetworkXPointlessConcept(msg)
295
- if not nx.is_tree(T):
296
- raise nx.NotATree("provided graph is not a tree")
297
- if set(T) != set(range(n)):
298
- raise KeyError("tree must have node labels {0, ..., n - 1}")
299
-
300
- degree = dict(T.degree())
301
-
302
- def parents(u):
303
- return next(v for v in T[u] if degree[v] > 1)
304
-
305
- index = u = next(k for k in range(n) if degree[k] == 1)
306
- result = []
307
- for i in range(n - 2):
308
- v = parents(u)
309
- result.append(v)
310
- degree[v] -= 1
311
- if v < index and degree[v] == 1:
312
- u = v
313
- else:
314
- index = u = next(k for k in range(index + 1, n) if degree[k] == 1)
315
- return result
316
-
317
-
318
- @nx._dispatchable(graphs=None, returns_graph=True)
319
- def from_prufer_sequence(sequence):
320
- r"""Returns the tree corresponding to the given Prüfer sequence.
321
-
322
- A *Prüfer sequence* is a list of *n* - 2 numbers between 0 and
323
- *n* - 1, inclusive. The tree corresponding to a given Prüfer
324
- sequence can be recovered by repeatedly joining a node in the
325
- sequence with a node with the smallest potential degree according to
326
- the sequence.
327
-
328
- Parameters
329
- ----------
330
- sequence : list
331
- A Prüfer sequence, which is a list of *n* - 2 integers between
332
- zero and *n* - 1, inclusive.
333
-
334
- Returns
335
- -------
336
- NetworkX graph
337
- The tree corresponding to the given Prüfer sequence.
338
-
339
- Raises
340
- ------
341
- NetworkXError
342
- If the Prüfer sequence is not valid.
343
-
344
- Notes
345
- -----
346
- There is a bijection from labeled trees to Prüfer sequences. This
347
- function is the inverse of the :func:`from_prufer_sequence` function.
348
-
349
- Sometimes Prüfer sequences use nodes labeled from 1 to *n* instead
350
- of from 0 to *n* - 1. This function requires nodes to be labeled in
351
- the latter form. You can use :func:`networkx.relabel_nodes` to
352
- relabel the nodes of your tree to the appropriate format.
353
-
354
- This implementation is from [1]_ and has a running time of
355
- $O(n)$.
356
-
357
- References
358
- ----------
359
- .. [1] Wang, Xiaodong, Lei Wang, and Yingjie Wu.
360
- "An optimal algorithm for Prufer codes."
361
- *Journal of Software Engineering and Applications* 2.02 (2009): 111.
362
- <https://doi.org/10.4236/jsea.2009.22016>
363
-
364
- See also
365
- --------
366
- from_nested_tuple
367
- to_prufer_sequence
368
-
369
- Examples
370
- --------
371
- There is a bijection between Prüfer sequences and labeled trees, so
372
- this function is the inverse of the :func:`to_prufer_sequence`
373
- function:
374
-
375
- >>> edges = [(0, 3), (1, 3), (2, 3), (3, 4), (4, 5)]
376
- >>> tree = nx.Graph(edges)
377
- >>> sequence = nx.to_prufer_sequence(tree)
378
- >>> sequence
379
- [3, 3, 3, 4]
380
- >>> tree2 = nx.from_prufer_sequence(sequence)
381
- >>> list(tree2.edges()) == edges
382
- True
383
-
384
- """
385
- n = len(sequence) + 2
386
- # `degree` stores the remaining degree (plus one) for each node. The
387
- # degree of a node in the decoded tree is one more than the number
388
- # of times it appears in the code.
389
- degree = Counter(chain(sequence, range(n)))
390
- T = nx.empty_graph(n)
391
- # `not_orphaned` is the set of nodes that have a parent in the
392
- # tree. After the loop, there should be exactly two nodes that are
393
- # not in this set.
394
- not_orphaned = set()
395
- index = u = next(k for k in range(n) if degree[k] == 1)
396
- for v in sequence:
397
- # check the validity of the prufer sequence
398
- if v < 0 or v > n - 1:
399
- raise nx.NetworkXError(
400
- f"Invalid Prufer sequence: Values must be between 0 and {n - 1}, got {v}"
401
- )
402
- T.add_edge(u, v)
403
- not_orphaned.add(u)
404
- degree[v] -= 1
405
- if v < index and degree[v] == 1:
406
- u = v
407
- else:
408
- index = u = next(k for k in range(index + 1, n) if degree[k] == 1)
409
- # At this point, there must be exactly two orphaned nodes; join them.
410
- orphans = set(T) - not_orphaned
411
- u, v = orphans
412
- T.add_edge(u, v)
413
- return T
@@ -1,88 +0,0 @@
1
- r"""Function for computing a junction tree of a graph."""
2
-
3
- from itertools import combinations
4
-
5
- import networkx as nx
6
- from networkx.algorithms import chordal_graph_cliques, complete_to_chordal_graph, moral
7
- from networkx.utils import not_implemented_for
8
-
9
- __all__ = ["junction_tree"]
10
-
11
-
12
- @not_implemented_for("multigraph")
13
- @nx._dispatchable(returns_graph=True)
14
- def junction_tree(G):
15
- r"""Returns a junction tree of a given graph.
16
-
17
- A junction tree (or clique tree) is constructed from a (un)directed graph G.
18
- The tree is constructed based on a moralized and triangulated version of G.
19
- The tree's nodes consist of maximal cliques and sepsets of the revised graph.
20
- The sepset of two cliques is the intersection of the nodes of these cliques,
21
- e.g. the sepset of (A,B,C) and (A,C,E,F) is (A,C). These nodes are often called
22
- "variables" in this literature. The tree is bipartite with each sepset
23
- connected to its two cliques.
24
-
25
- Junction Trees are not unique as the order of clique consideration determines
26
- which sepsets are included.
27
-
28
- The junction tree algorithm consists of five steps [1]_:
29
-
30
- 1. Moralize the graph
31
- 2. Triangulate the graph
32
- 3. Find maximal cliques
33
- 4. Build the tree from cliques, connecting cliques with shared
34
- nodes, set edge-weight to number of shared variables
35
- 5. Find maximum spanning tree
36
-
37
-
38
- Parameters
39
- ----------
40
- G : networkx.Graph
41
- Directed or undirected graph.
42
-
43
- Returns
44
- -------
45
- junction_tree : networkx.Graph
46
- The corresponding junction tree of `G`.
47
-
48
- Raises
49
- ------
50
- NetworkXNotImplemented
51
- Raised if `G` is an instance of `MultiGraph` or `MultiDiGraph`.
52
-
53
- References
54
- ----------
55
- .. [1] Junction tree algorithm:
56
- https://en.wikipedia.org/wiki/Junction_tree_algorithm
57
-
58
- .. [2] Finn V. Jensen and Frank Jensen. 1994. Optimal
59
- junction trees. In Proceedings of the Tenth international
60
- conference on Uncertainty in artificial intelligence (UAI’94).
61
- Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, 360–366.
62
- """
63
-
64
- clique_graph = nx.Graph()
65
-
66
- if G.is_directed():
67
- G = moral.moral_graph(G)
68
- chordal_graph, _ = complete_to_chordal_graph(G)
69
-
70
- cliques = [tuple(sorted(i)) for i in chordal_graph_cliques(chordal_graph)]
71
- clique_graph.add_nodes_from(cliques, type="clique")
72
-
73
- for edge in combinations(cliques, 2):
74
- set_edge_0 = set(edge[0])
75
- set_edge_1 = set(edge[1])
76
- if not set_edge_0.isdisjoint(set_edge_1):
77
- sepset = tuple(sorted(set_edge_0.intersection(set_edge_1)))
78
- clique_graph.add_edge(edge[0], edge[1], weight=len(sepset), sepset=sepset)
79
-
80
- junction_tree = nx.maximum_spanning_tree(clique_graph)
81
-
82
- for edge in list(junction_tree.edges(data=True)):
83
- junction_tree.add_node(edge[2]["sepset"], type="sepset")
84
- junction_tree.add_edge(edge[0], edge[2]["sepset"])
85
- junction_tree.add_edge(edge[1], edge[2]["sepset"])
86
- junction_tree.remove_edge(edge[0], edge[1])
87
-
88
- return junction_tree