okstra 0.130.4 → 0.131.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 (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 +1722 -98
  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,966 +0,0 @@
1
- from heapq import heappop, heappush
2
- from itertools import count
3
-
4
- import networkx as nx
5
- from networkx.algorithms.shortest_paths.weighted import _weight_function
6
- from networkx.utils import not_implemented_for, pairwise
7
-
8
- __all__ = [
9
- "all_simple_paths",
10
- "is_simple_path",
11
- "shortest_simple_paths",
12
- "all_simple_edge_paths",
13
- ]
14
-
15
-
16
- @nx._dispatchable
17
- def is_simple_path(G, nodes):
18
- """Returns True if and only if `nodes` form a simple path in `G`.
19
-
20
- A *simple path* in a graph is a nonempty sequence of nodes in which
21
- no node appears more than once in the sequence, and each adjacent
22
- pair of nodes in the sequence is adjacent in the graph.
23
-
24
- Parameters
25
- ----------
26
- G : graph
27
- A NetworkX graph.
28
- nodes : list
29
- A list of one or more nodes in the graph `G`.
30
-
31
- Returns
32
- -------
33
- bool
34
- Whether the given list of nodes represents a simple path in `G`.
35
-
36
- Notes
37
- -----
38
- An empty list of nodes is not a path but a list of one node is a
39
- path. Here's an explanation why.
40
-
41
- This function operates on *node paths*. One could also consider
42
- *edge paths*. There is a bijection between node paths and edge
43
- paths.
44
-
45
- The *length of a path* is the number of edges in the path, so a list
46
- of nodes of length *n* corresponds to a path of length *n* - 1.
47
- Thus the smallest edge path would be a list of zero edges, the empty
48
- path. This corresponds to a list of one node.
49
-
50
- To convert between a node path and an edge path, you can use code
51
- like the following::
52
-
53
- >>> from networkx.utils import pairwise
54
- >>> nodes = [0, 1, 2, 3]
55
- >>> edges = list(pairwise(nodes))
56
- >>> edges
57
- [(0, 1), (1, 2), (2, 3)]
58
- >>> nodes = [edges[0][0]] + [v for u, v in edges]
59
- >>> nodes
60
- [0, 1, 2, 3]
61
-
62
- Examples
63
- --------
64
- >>> G = nx.cycle_graph(4)
65
- >>> nx.is_simple_path(G, [2, 3, 0])
66
- True
67
- >>> nx.is_simple_path(G, [0, 2])
68
- False
69
-
70
- """
71
- # The empty list is not a valid path. Could also return
72
- # NetworkXPointlessConcept here.
73
- if len(nodes) == 0:
74
- return False
75
-
76
- # If the list is a single node, just check that the node is actually
77
- # in the graph.
78
- if len(nodes) == 1:
79
- return nodes[0] in G
80
-
81
- # check that all nodes in the list are in the graph, if at least one
82
- # is not in the graph, then this is not a simple path
83
- if not all(n in G for n in nodes):
84
- return False
85
-
86
- # If the list contains repeated nodes, then it's not a simple path
87
- if len(set(nodes)) != len(nodes):
88
- return False
89
-
90
- # Test that each adjacent pair of nodes is adjacent.
91
- return all(v in G[u] for u, v in pairwise(nodes))
92
-
93
-
94
- @nx._dispatchable
95
- def all_simple_paths(G, source, target, cutoff=None):
96
- """Generate all simple paths in the graph G from source to target.
97
-
98
- A simple path is a path with no repeated nodes.
99
-
100
- Parameters
101
- ----------
102
- G : NetworkX graph
103
-
104
- source : node
105
- Starting node for path
106
-
107
- target : nodes
108
- Single node or iterable of nodes at which to end path
109
-
110
- cutoff : integer, optional
111
- Depth to stop the search. Only paths with length <= `cutoff` are returned.
112
- where the mathematical "length of a path" is `len(path) -1` (number of edges).
113
-
114
- Returns
115
- -------
116
- path_generator: generator
117
- A generator that produces lists of simple paths. If there are no paths
118
- between the source and target within the given cutoff the generator
119
- produces no output. If it is possible to traverse the same sequence of
120
- nodes in multiple ways, namely through parallel edges, then it will be
121
- returned multiple times (once for each viable edge combination).
122
-
123
- Examples
124
- --------
125
- This iterator generates lists of nodes::
126
-
127
- >>> G = nx.complete_graph(4)
128
- >>> for path in nx.all_simple_paths(G, source=0, target=3):
129
- ... print(path)
130
- ...
131
- [0, 1, 2, 3]
132
- [0, 1, 3]
133
- [0, 2, 1, 3]
134
- [0, 2, 3]
135
- [0, 3]
136
-
137
- You can generate only those paths that are shorter than a certain
138
- length by using the `cutoff` keyword argument::
139
-
140
- >>> paths = nx.all_simple_paths(G, source=0, target=3, cutoff=2)
141
- >>> print(list(paths))
142
- [[0, 1, 3], [0, 2, 3], [0, 3]]
143
-
144
- To get each path as the corresponding list of edges, you can use the
145
- :func:`networkx.utils.pairwise` helper function::
146
-
147
- >>> paths = nx.all_simple_paths(G, source=0, target=3)
148
- >>> for path in map(nx.utils.pairwise, paths):
149
- ... print(list(path))
150
- [(0, 1), (1, 2), (2, 3)]
151
- [(0, 1), (1, 3)]
152
- [(0, 2), (2, 1), (1, 3)]
153
- [(0, 2), (2, 3)]
154
- [(0, 3)]
155
-
156
- Pass an iterable of nodes as target to generate all paths ending in any of several nodes::
157
-
158
- >>> G = nx.complete_graph(4)
159
- >>> for path in nx.all_simple_paths(G, source=0, target=[3, 2]):
160
- ... print(path)
161
- ...
162
- [0, 1, 2]
163
- [0, 1, 2, 3]
164
- [0, 1, 3]
165
- [0, 1, 3, 2]
166
- [0, 2]
167
- [0, 2, 1, 3]
168
- [0, 2, 3]
169
- [0, 3]
170
- [0, 3, 1, 2]
171
- [0, 3, 2]
172
-
173
- The singleton path from ``source`` to itself is considered a simple path and is
174
- included in the results:
175
-
176
- >>> G = nx.empty_graph(5)
177
- >>> list(nx.all_simple_paths(G, source=0, target=0))
178
- [[0]]
179
-
180
- >>> G = nx.path_graph(3)
181
- >>> list(nx.all_simple_paths(G, source=0, target={0, 1, 2}))
182
- [[0], [0, 1], [0, 1, 2]]
183
-
184
- Iterate over each path from the root nodes to the leaf nodes in a
185
- directed acyclic graph using a functional programming approach::
186
-
187
- >>> from itertools import chain
188
- >>> from itertools import product
189
- >>> from itertools import starmap
190
- >>> from functools import partial
191
- >>>
192
- >>> chaini = chain.from_iterable
193
- >>>
194
- >>> G = nx.DiGraph([(0, 1), (1, 2), (0, 3), (3, 2)])
195
- >>> roots = (v for v, d in G.in_degree() if d == 0)
196
- >>> leaves = (v for v, d in G.out_degree() if d == 0)
197
- >>> all_paths = partial(nx.all_simple_paths, G)
198
- >>> list(chaini(starmap(all_paths, product(roots, leaves))))
199
- [[0, 1, 2], [0, 3, 2]]
200
-
201
- The same list computed using an iterative approach::
202
-
203
- >>> G = nx.DiGraph([(0, 1), (1, 2), (0, 3), (3, 2)])
204
- >>> roots = (v for v, d in G.in_degree() if d == 0)
205
- >>> leaves = (v for v, d in G.out_degree() if d == 0)
206
- >>> all_paths = []
207
- >>> for root in roots:
208
- ... for leaf in leaves:
209
- ... paths = nx.all_simple_paths(G, root, leaf)
210
- ... all_paths.extend(paths)
211
- >>> all_paths
212
- [[0, 1, 2], [0, 3, 2]]
213
-
214
- Iterate over each path from the root nodes to the leaf nodes in a
215
- directed acyclic graph passing all leaves together to avoid unnecessary
216
- compute::
217
-
218
- >>> G = nx.DiGraph([(0, 1), (2, 1), (1, 3), (1, 4)])
219
- >>> roots = (v for v, d in G.in_degree() if d == 0)
220
- >>> leaves = [v for v, d in G.out_degree() if d == 0]
221
- >>> all_paths = []
222
- >>> for root in roots:
223
- ... paths = nx.all_simple_paths(G, root, leaves)
224
- ... all_paths.extend(paths)
225
- >>> all_paths
226
- [[0, 1, 3], [0, 1, 4], [2, 1, 3], [2, 1, 4]]
227
-
228
- If parallel edges offer multiple ways to traverse a given sequence of
229
- nodes, this sequence of nodes will be returned multiple times:
230
-
231
- >>> G = nx.MultiDiGraph([(0, 1), (0, 1), (1, 2)])
232
- >>> list(nx.all_simple_paths(G, 0, 2))
233
- [[0, 1, 2], [0, 1, 2]]
234
-
235
- Notes
236
- -----
237
- This algorithm uses a modified depth-first search to generate the
238
- paths [1]_. A single path can be found in $O(V+E)$ time but the
239
- number of simple paths in a graph can be very large, e.g. $O(n!)$ in
240
- the complete graph of order $n$.
241
-
242
- This function does not check that a path exists between `source` and
243
- `target`. For large graphs, this may result in very long runtimes.
244
- Consider using `has_path` to check that a path exists between `source` and
245
- `target` before calling this function on large graphs.
246
-
247
- References
248
- ----------
249
- .. [1] R. Sedgewick, "Algorithms in C, Part 5: Graph Algorithms",
250
- Addison Wesley Professional, 3rd ed., 2001.
251
-
252
- See Also
253
- --------
254
- all_shortest_paths, shortest_path, has_path
255
-
256
- """
257
- for edge_path in all_simple_edge_paths(G, source, target, cutoff):
258
- yield [source] + [edge[1] for edge in edge_path]
259
-
260
-
261
- @nx._dispatchable
262
- def all_simple_edge_paths(G, source, target, cutoff=None):
263
- """Generate lists of edges for all simple paths in G from source to target.
264
-
265
- A simple path is a path with no repeated nodes.
266
-
267
- Parameters
268
- ----------
269
- G : NetworkX graph
270
-
271
- source : node
272
- Starting node for path
273
-
274
- target : nodes
275
- Single node or iterable of nodes at which to end path
276
-
277
- cutoff : integer, optional
278
- Depth to stop the search. Only paths with length <= `cutoff` are returned.
279
- Note that the length of an edge path is the number of edges.
280
-
281
- Returns
282
- -------
283
- path_generator: generator
284
- A generator that produces lists of simple paths. If there are no paths
285
- between the source and target within the given cutoff the generator
286
- produces no output.
287
- For multigraphs, the list of edges have elements of the form `(u,v,k)`.
288
- Where `k` corresponds to the edge key.
289
-
290
- Examples
291
- --------
292
-
293
- Print the simple path edges of a Graph::
294
-
295
- >>> g = nx.Graph([(1, 2), (2, 4), (1, 3), (3, 4)])
296
- >>> for path in sorted(nx.all_simple_edge_paths(g, 1, 4)):
297
- ... print(path)
298
- [(1, 2), (2, 4)]
299
- [(1, 3), (3, 4)]
300
-
301
- Print the simple path edges of a MultiGraph. Returned edges come with
302
- their associated keys::
303
-
304
- >>> mg = nx.MultiGraph()
305
- >>> mg.add_edge(1, 2, key="k0")
306
- 'k0'
307
- >>> mg.add_edge(1, 2, key="k1")
308
- 'k1'
309
- >>> mg.add_edge(2, 3, key="k0")
310
- 'k0'
311
- >>> for path in sorted(nx.all_simple_edge_paths(mg, 1, 3)):
312
- ... print(path)
313
- [(1, 2, 'k0'), (2, 3, 'k0')]
314
- [(1, 2, 'k1'), (2, 3, 'k0')]
315
-
316
- When ``source`` is one of the targets, the empty path starting and ending at
317
- ``source`` without traversing any edge is considered a valid simple edge path
318
- and is included in the results:
319
-
320
- >>> G = nx.Graph()
321
- >>> G.add_node(0)
322
- >>> paths = list(nx.all_simple_edge_paths(G, 0, 0))
323
- >>> for path in paths:
324
- ... print(path)
325
- []
326
- >>> len(paths)
327
- 1
328
-
329
- You can use the `cutoff` parameter to only generate paths that are
330
- shorter than a certain length:
331
-
332
- >>> g = nx.Graph([(1, 2), (2, 3), (3, 4), (4, 5), (1, 4), (1, 5)])
333
- >>> for path in sorted(nx.all_simple_edge_paths(g, 1, 5)):
334
- ... print(path)
335
- [(1, 2), (2, 3), (3, 4), (4, 5)]
336
- [(1, 4), (4, 5)]
337
- [(1, 5)]
338
- >>> for path in sorted(nx.all_simple_edge_paths(g, 1, 5, cutoff=1)):
339
- ... print(path)
340
- [(1, 5)]
341
- >>> for path in sorted(nx.all_simple_edge_paths(g, 1, 5, cutoff=2)):
342
- ... print(path)
343
- [(1, 4), (4, 5)]
344
- [(1, 5)]
345
-
346
- Notes
347
- -----
348
- This algorithm uses a modified depth-first search to generate the
349
- paths [1]_. A single path can be found in $O(V+E)$ time but the
350
- number of simple paths in a graph can be very large, e.g. $O(n!)$ in
351
- the complete graph of order $n$.
352
-
353
- References
354
- ----------
355
- .. [1] R. Sedgewick, "Algorithms in C, Part 5: Graph Algorithms",
356
- Addison Wesley Professional, 3rd ed., 2001.
357
-
358
- See Also
359
- --------
360
- all_shortest_paths, shortest_path, all_simple_paths
361
-
362
- """
363
- if source not in G:
364
- raise nx.NodeNotFound(f"source node {source} not in graph")
365
-
366
- if target in G:
367
- targets = {target}
368
- else:
369
- try:
370
- targets = set(target)
371
- except TypeError as err:
372
- raise nx.NodeNotFound(f"target node {target} not in graph") from err
373
-
374
- cutoff = cutoff if cutoff is not None else len(G) - 1
375
-
376
- if cutoff >= 0 and targets:
377
- yield from _all_simple_edge_paths(G, source, targets, cutoff)
378
-
379
-
380
- def _all_simple_edge_paths(G, source, targets, cutoff):
381
- # We simulate recursion with a stack, keeping the current path being explored
382
- # and the outgoing edge iterators at each point in the stack.
383
- # To avoid unnecessary checks, the loop is structured in a way such that a path
384
- # is considered for yielding only after a new node/edge is added.
385
- # We bootstrap the search by adding a dummy iterator to the stack that only yields
386
- # a dummy edge to source (so that the trivial path has a chance of being included).
387
-
388
- get_edges = (
389
- (lambda node: G.edges(node, keys=True))
390
- if G.is_multigraph()
391
- else (lambda node: G.edges(node))
392
- )
393
-
394
- # The current_path is a dictionary that maps nodes in the path to the edge that was
395
- # used to enter that node (instead of a list of edges) because we want both a fast
396
- # membership test for nodes in the path and the preservation of insertion order.
397
- current_path = {None: None}
398
- stack = [iter([(None, source)])]
399
-
400
- while stack:
401
- # 1. Try to extend the current path.
402
- next_edge = next((e for e in stack[-1] if e[1] not in current_path), None)
403
- if next_edge is None:
404
- # All edges of the last node in the current path have been explored.
405
- stack.pop()
406
- current_path.popitem()
407
- continue
408
- previous_node, next_node, *_ = next_edge
409
-
410
- # 2. Check if we've reached a target.
411
- if next_node in targets:
412
- yield (list(current_path.values()) + [next_edge])[2:] # remove dummy edge
413
-
414
- # 3. Only expand the search through the next node if it makes sense.
415
- if len(current_path) - 1 < cutoff and (
416
- targets - current_path.keys() - {next_node}
417
- ):
418
- current_path[next_node] = next_edge
419
- stack.append(iter(get_edges(next_node)))
420
-
421
-
422
- @not_implemented_for("multigraph")
423
- @nx._dispatchable(edge_attrs="weight")
424
- def shortest_simple_paths(G, source, target, weight=None):
425
- """Generate all simple paths in the graph G from source to target,
426
- starting from shortest ones.
427
-
428
- A simple path is a path with no repeated nodes.
429
-
430
- If a weighted shortest path search is to be used, no negative weights
431
- are allowed.
432
-
433
- Parameters
434
- ----------
435
- G : NetworkX graph
436
-
437
- source : node
438
- Starting node for path
439
-
440
- target : node
441
- Ending node for path
442
-
443
- weight : string or function
444
- If it is a string, it is the name of the edge attribute to be
445
- used as a weight.
446
-
447
- If it is a function, the weight of an edge is the value returned
448
- by the function. The function must accept exactly three positional
449
- arguments: the two endpoints of an edge and the dictionary of edge
450
- attributes for that edge. The function must return a number or None.
451
- The weight function can be used to hide edges by returning None.
452
- So ``weight = lambda u, v, d: 1 if d['color']=="red" else None``
453
- will find the shortest red path.
454
-
455
- If None all edges are considered to have unit weight. Default
456
- value None.
457
-
458
- Returns
459
- -------
460
- path_generator: generator
461
- A generator that produces lists of simple paths, in order from
462
- shortest to longest.
463
-
464
- Raises
465
- ------
466
- NetworkXNoPath
467
- If no path exists between source and target.
468
-
469
- NetworkXError
470
- If source or target nodes are not in the input graph.
471
-
472
- NetworkXNotImplemented
473
- If the input graph is a Multi[Di]Graph.
474
-
475
- Examples
476
- --------
477
-
478
- >>> G = nx.cycle_graph(7)
479
- >>> paths = list(nx.shortest_simple_paths(G, 0, 3))
480
- >>> print(paths)
481
- [[0, 1, 2, 3], [0, 6, 5, 4, 3]]
482
-
483
- You can use this function to efficiently compute the k shortest/best
484
- paths between two nodes.
485
-
486
- >>> from itertools import islice
487
- >>> def k_shortest_paths(G, source, target, k, weight=None):
488
- ... return list(
489
- ... islice(nx.shortest_simple_paths(G, source, target, weight=weight), k)
490
- ... )
491
- >>> for path in k_shortest_paths(G, 0, 3, 2):
492
- ... print(path)
493
- [0, 1, 2, 3]
494
- [0, 6, 5, 4, 3]
495
-
496
- Notes
497
- -----
498
- This procedure is based on algorithm by Jin Y. Yen [1]_. Finding
499
- the first $K$ paths requires $O(KN^3)$ operations.
500
-
501
- See Also
502
- --------
503
- all_shortest_paths
504
- shortest_path
505
- all_simple_paths
506
-
507
- References
508
- ----------
509
- .. [1] Jin Y. Yen, "Finding the K Shortest Loopless Paths in a
510
- Network", Management Science, Vol. 17, No. 11, Theory Series
511
- (Jul., 1971), pp. 712-716.
512
-
513
- """
514
- if source not in G:
515
- raise nx.NodeNotFound(f"source node {source} not in graph")
516
-
517
- if target not in G:
518
- raise nx.NodeNotFound(f"target node {target} not in graph")
519
-
520
- if weight is None:
521
- length_func = len
522
- shortest_path_func = _bidirectional_shortest_path
523
- else:
524
- wt = _weight_function(G, weight)
525
-
526
- def length_func(path):
527
- return sum(
528
- wt(u, v, G.get_edge_data(u, v)) for (u, v) in zip(path, path[1:])
529
- )
530
-
531
- shortest_path_func = _bidirectional_dijkstra
532
-
533
- listA = []
534
- listB = PathBuffer()
535
- prev_path = None
536
- while True:
537
- if not prev_path:
538
- length, path = shortest_path_func(G, source, target, weight=weight)
539
- listB.push(length, path)
540
- else:
541
- ignore_nodes = set()
542
- ignore_edges = set()
543
- for i in range(1, len(prev_path)):
544
- root = prev_path[:i]
545
- root_length = length_func(root)
546
- for path in listA:
547
- if path[:i] == root:
548
- ignore_edges.add((path[i - 1], path[i]))
549
- try:
550
- length, spur = shortest_path_func(
551
- G,
552
- root[-1],
553
- target,
554
- ignore_nodes=ignore_nodes,
555
- ignore_edges=ignore_edges,
556
- weight=weight,
557
- )
558
- path = root[:-1] + spur
559
- listB.push(root_length + length, path)
560
- except nx.NetworkXNoPath:
561
- pass
562
- ignore_nodes.add(root[-1])
563
-
564
- if listB:
565
- path = listB.pop()
566
- yield path
567
- listA.append(path)
568
- prev_path = path
569
- else:
570
- break
571
-
572
-
573
- class PathBuffer:
574
- def __init__(self):
575
- self.paths = set()
576
- self.sortedpaths = []
577
- self.counter = count()
578
-
579
- def __len__(self):
580
- return len(self.sortedpaths)
581
-
582
- def push(self, cost, path):
583
- hashable_path = tuple(path)
584
- if hashable_path not in self.paths:
585
- heappush(self.sortedpaths, (cost, next(self.counter), path))
586
- self.paths.add(hashable_path)
587
-
588
- def pop(self):
589
- (cost, num, path) = heappop(self.sortedpaths)
590
- hashable_path = tuple(path)
591
- self.paths.remove(hashable_path)
592
- return path
593
-
594
-
595
- def _bidirectional_shortest_path(
596
- G, source, target, ignore_nodes=None, ignore_edges=None, weight=None
597
- ):
598
- """Returns the shortest path between source and target ignoring
599
- nodes and edges in the containers ignore_nodes and ignore_edges.
600
-
601
- This is a custom modification of the standard bidirectional shortest
602
- path implementation at networkx.algorithms.unweighted
603
-
604
- Parameters
605
- ----------
606
- G : NetworkX graph
607
-
608
- source : node
609
- starting node for path
610
-
611
- target : node
612
- ending node for path
613
-
614
- ignore_nodes : container of nodes
615
- nodes to ignore, optional
616
-
617
- ignore_edges : container of edges
618
- edges to ignore, optional
619
-
620
- weight : None
621
- This function accepts a weight argument for convenience of
622
- shortest_simple_paths function. It will be ignored.
623
-
624
- Returns
625
- -------
626
- path: list
627
- List of nodes in a path from source to target.
628
-
629
- Raises
630
- ------
631
- NetworkXNoPath
632
- If no path exists between source and target.
633
-
634
- See Also
635
- --------
636
- shortest_path
637
-
638
- """
639
- # call helper to do the real work
640
- results = _bidirectional_pred_succ(G, source, target, ignore_nodes, ignore_edges)
641
- pred, succ, w = results
642
-
643
- # build path from pred+w+succ
644
- path = []
645
- # from w to target
646
- while w is not None:
647
- path.append(w)
648
- w = succ[w]
649
- # from source to w
650
- w = pred[path[0]]
651
- while w is not None:
652
- path.insert(0, w)
653
- w = pred[w]
654
-
655
- return len(path), path
656
-
657
-
658
- def _bidirectional_pred_succ(G, source, target, ignore_nodes=None, ignore_edges=None):
659
- """Bidirectional shortest path helper.
660
- Returns (pred,succ,w) where
661
- pred is a dictionary of predecessors from w to the source, and
662
- succ is a dictionary of successors from w to the target.
663
- """
664
- # does BFS from both source and target and meets in the middle
665
- if ignore_nodes and (source in ignore_nodes or target in ignore_nodes):
666
- raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
667
- if target == source:
668
- return ({target: None}, {source: None}, source)
669
-
670
- # handle either directed or undirected
671
- if G.is_directed():
672
- Gpred = G.predecessors
673
- Gsucc = G.successors
674
- else:
675
- Gpred = G.neighbors
676
- Gsucc = G.neighbors
677
-
678
- # support optional nodes filter
679
- if ignore_nodes:
680
-
681
- def filter_iter(nodes):
682
- def iterate(v):
683
- for w in nodes(v):
684
- if w not in ignore_nodes:
685
- yield w
686
-
687
- return iterate
688
-
689
- Gpred = filter_iter(Gpred)
690
- Gsucc = filter_iter(Gsucc)
691
-
692
- # support optional edges filter
693
- if ignore_edges:
694
- if G.is_directed():
695
-
696
- def filter_pred_iter(pred_iter):
697
- def iterate(v):
698
- for w in pred_iter(v):
699
- if (w, v) not in ignore_edges:
700
- yield w
701
-
702
- return iterate
703
-
704
- def filter_succ_iter(succ_iter):
705
- def iterate(v):
706
- for w in succ_iter(v):
707
- if (v, w) not in ignore_edges:
708
- yield w
709
-
710
- return iterate
711
-
712
- Gpred = filter_pred_iter(Gpred)
713
- Gsucc = filter_succ_iter(Gsucc)
714
-
715
- else:
716
-
717
- def filter_iter(nodes):
718
- def iterate(v):
719
- for w in nodes(v):
720
- if (v, w) not in ignore_edges and (w, v) not in ignore_edges:
721
- yield w
722
-
723
- return iterate
724
-
725
- Gpred = filter_iter(Gpred)
726
- Gsucc = filter_iter(Gsucc)
727
-
728
- # predecessor and successors in search
729
- pred = {source: None}
730
- succ = {target: None}
731
-
732
- # initialize fringes, start with forward
733
- forward_fringe = [source]
734
- reverse_fringe = [target]
735
-
736
- while forward_fringe and reverse_fringe:
737
- if len(forward_fringe) <= len(reverse_fringe):
738
- this_level = forward_fringe
739
- forward_fringe = []
740
- for v in this_level:
741
- for w in Gsucc(v):
742
- if w not in pred:
743
- forward_fringe.append(w)
744
- pred[w] = v
745
- if w in succ:
746
- # found path
747
- return pred, succ, w
748
- else:
749
- this_level = reverse_fringe
750
- reverse_fringe = []
751
- for v in this_level:
752
- for w in Gpred(v):
753
- if w not in succ:
754
- succ[w] = v
755
- reverse_fringe.append(w)
756
- if w in pred:
757
- # found path
758
- return pred, succ, w
759
-
760
- raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
761
-
762
-
763
- def _bidirectional_dijkstra(
764
- G, source, target, weight="weight", ignore_nodes=None, ignore_edges=None
765
- ):
766
- """Dijkstra's algorithm for shortest paths using bidirectional search.
767
-
768
- This function returns the shortest path between source and target
769
- ignoring nodes and edges in the containers ignore_nodes and
770
- ignore_edges.
771
-
772
- This is a custom modification of the standard Dijkstra bidirectional
773
- shortest path implementation at networkx.algorithms.weighted
774
-
775
- Parameters
776
- ----------
777
- G : NetworkX graph
778
-
779
- source : node
780
- Starting node.
781
-
782
- target : node
783
- Ending node.
784
-
785
- weight: string, function, optional (default='weight')
786
- Edge data key or weight function corresponding to the edge weight
787
- If this is a function, the weight of an edge is the value
788
- returned by the function. The function must accept exactly three
789
- positional arguments: the two endpoints of an edge and the
790
- dictionary of edge attributes for that edge. The function must
791
- return a number or None to indicate a hidden edge.
792
-
793
- ignore_nodes : container of nodes
794
- nodes to ignore, optional
795
-
796
- ignore_edges : container of edges
797
- edges to ignore, optional
798
-
799
- Returns
800
- -------
801
- length : number
802
- Shortest path length.
803
-
804
- Returns a tuple of two dictionaries keyed by node.
805
- The first dictionary stores distance from the source.
806
- The second stores the path from the source to that node.
807
-
808
- Raises
809
- ------
810
- NetworkXNoPath
811
- If no path exists between source and target.
812
-
813
- Notes
814
- -----
815
- Edge weight attributes must be numerical.
816
- Distances are calculated as sums of weighted edges traversed.
817
-
818
- The weight function can be used to hide edges by returning None.
819
- So ``weight = lambda u, v, d: 1 if d['color']=="red" else None``
820
- will find the shortest red path.
821
-
822
- In practice bidirectional Dijkstra is much more than twice as fast as
823
- ordinary Dijkstra.
824
-
825
- Ordinary Dijkstra expands nodes in a sphere-like manner from the
826
- source. The radius of this sphere will eventually be the length
827
- of the shortest path. Bidirectional Dijkstra will expand nodes
828
- from both the source and the target, making two spheres of half
829
- this radius. Volume of the first sphere is pi*r*r while the
830
- others are 2*pi*r/2*r/2, making up half the volume.
831
-
832
- This algorithm is not guaranteed to work if edge weights
833
- are negative or are floating point numbers
834
- (overflows and roundoff errors can cause problems).
835
-
836
- See Also
837
- --------
838
- shortest_path
839
- shortest_path_length
840
- """
841
- if ignore_nodes and (source in ignore_nodes or target in ignore_nodes):
842
- raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
843
- if source == target:
844
- if source not in G:
845
- raise nx.NodeNotFound(f"Node {source} not in graph")
846
- return (0, [source])
847
-
848
- # handle either directed or undirected
849
- if G.is_directed():
850
- Gpred = G.predecessors
851
- Gsucc = G.successors
852
- else:
853
- Gpred = G.neighbors
854
- Gsucc = G.neighbors
855
-
856
- # support optional nodes filter
857
- if ignore_nodes:
858
-
859
- def filter_iter(nodes):
860
- def iterate(v):
861
- for w in nodes(v):
862
- if w not in ignore_nodes:
863
- yield w
864
-
865
- return iterate
866
-
867
- Gpred = filter_iter(Gpred)
868
- Gsucc = filter_iter(Gsucc)
869
-
870
- # support optional edges filter
871
- if ignore_edges:
872
- if G.is_directed():
873
-
874
- def filter_pred_iter(pred_iter):
875
- def iterate(v):
876
- for w in pred_iter(v):
877
- if (w, v) not in ignore_edges:
878
- yield w
879
-
880
- return iterate
881
-
882
- def filter_succ_iter(succ_iter):
883
- def iterate(v):
884
- for w in succ_iter(v):
885
- if (v, w) not in ignore_edges:
886
- yield w
887
-
888
- return iterate
889
-
890
- Gpred = filter_pred_iter(Gpred)
891
- Gsucc = filter_succ_iter(Gsucc)
892
-
893
- else:
894
-
895
- def filter_iter(nodes):
896
- def iterate(v):
897
- for w in nodes(v):
898
- if (v, w) not in ignore_edges and (w, v) not in ignore_edges:
899
- yield w
900
-
901
- return iterate
902
-
903
- Gpred = filter_iter(Gpred)
904
- Gsucc = filter_iter(Gsucc)
905
-
906
- wt = _weight_function(G, weight)
907
- # Init: Forward Backward
908
- dists = [{}, {}] # dictionary of final distances
909
- paths = [{source: [source]}, {target: [target]}] # dictionary of paths
910
- fringe = [[], []] # heap of (distance, node) tuples for
911
- # extracting next node to expand
912
- seen = [{source: 0}, {target: 0}] # dictionary of distances to
913
- # nodes seen
914
- c = count()
915
- # initialize fringe heap
916
- heappush(fringe[0], (0, next(c), source))
917
- heappush(fringe[1], (0, next(c), target))
918
- # neighs for extracting correct neighbor information
919
- neighs = [Gsucc, Gpred]
920
- # variables to hold shortest discovered path
921
- # finaldist = 1e30000
922
- finalpath = []
923
- dir = 1
924
- while fringe[0] and fringe[1]:
925
- # choose direction
926
- # dir == 0 is forward direction and dir == 1 is back
927
- dir = 1 - dir
928
- # extract closest to expand
929
- (dist, _, v) = heappop(fringe[dir])
930
- if v in dists[dir]:
931
- # Shortest path to v has already been found
932
- continue
933
- # update distance
934
- dists[dir][v] = dist # equal to seen[dir][v]
935
- if v in dists[1 - dir]:
936
- # if we have scanned v in both directions we are done
937
- # we have now discovered the shortest path
938
- return (finaldist, finalpath)
939
-
940
- for w in neighs[dir](v):
941
- if dir == 0: # forward
942
- minweight = wt(v, w, G.get_edge_data(v, w))
943
- else: # back, must remember to change v,w->w,v
944
- minweight = wt(w, v, G.get_edge_data(w, v))
945
- if minweight is None:
946
- continue
947
- vwLength = dists[dir][v] + minweight
948
-
949
- if w in dists[dir]:
950
- if vwLength < dists[dir][w]:
951
- raise ValueError("Contradictory paths found: negative weights?")
952
- elif w not in seen[dir] or vwLength < seen[dir][w]:
953
- # relaxing
954
- seen[dir][w] = vwLength
955
- heappush(fringe[dir], (vwLength, next(c), w))
956
- paths[dir][w] = paths[dir][v] + [w]
957
- if w in seen[0] and w in seen[1]:
958
- # see if this path is better than the already
959
- # discovered shortest path
960
- totaldist = seen[0][w] + seen[1][w]
961
- if finalpath == [] or finaldist > totaldist:
962
- finaldist = totaldist
963
- revpath = paths[1][w][:]
964
- revpath.reverse()
965
- finalpath = paths[0][w] + revpath[1:]
966
- raise nx.NetworkXNoPath(f"No path between {source} and {target}.")