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,407 +0,0 @@
1
- """
2
- Capacity scaling minimum cost flow algorithm.
3
- """
4
-
5
- __all__ = ["capacity_scaling"]
6
-
7
- from itertools import chain
8
- from math import log
9
-
10
- import networkx as nx
11
-
12
- from ...utils import BinaryHeap, arbitrary_element, not_implemented_for
13
-
14
-
15
- def _detect_unboundedness(R):
16
- """Detect infinite-capacity negative cycles."""
17
- G = nx.DiGraph()
18
- G.add_nodes_from(R)
19
-
20
- # Value simulating infinity.
21
- inf = R.graph["inf"]
22
- # True infinity.
23
- f_inf = float("inf")
24
- for u in R:
25
- for v, e in R[u].items():
26
- # Compute the minimum weight of infinite-capacity (u, v) edges.
27
- w = f_inf
28
- for k, e in e.items():
29
- if e["capacity"] == inf:
30
- w = min(w, e["weight"])
31
- if w != f_inf:
32
- G.add_edge(u, v, weight=w)
33
-
34
- if nx.negative_edge_cycle(G):
35
- raise nx.NetworkXUnbounded(
36
- "Negative cost cycle of infinite capacity found. "
37
- "Min cost flow may be unbounded below."
38
- )
39
-
40
-
41
- @not_implemented_for("undirected")
42
- def _build_residual_network(G, demand, capacity, weight):
43
- """Build a residual network and initialize a zero flow."""
44
- if sum(G.nodes[u].get(demand, 0) for u in G) != 0:
45
- raise nx.NetworkXUnfeasible("Sum of the demands should be 0.")
46
-
47
- R = nx.MultiDiGraph()
48
- R.add_nodes_from(
49
- (u, {"excess": -G.nodes[u].get(demand, 0), "potential": 0}) for u in G
50
- )
51
-
52
- inf = float("inf")
53
- # Detect selfloops with infinite capacities and negative weights.
54
- for u, v, e in nx.selfloop_edges(G, data=True):
55
- if e.get(weight, 0) < 0 and e.get(capacity, inf) == inf:
56
- raise nx.NetworkXUnbounded(
57
- "Negative cost cycle of infinite capacity found. "
58
- "Min cost flow may be unbounded below."
59
- )
60
-
61
- # Extract edges with positive capacities. Self loops excluded.
62
- if G.is_multigraph():
63
- edge_list = [
64
- (u, v, k, e)
65
- for u, v, k, e in G.edges(data=True, keys=True)
66
- if u != v and e.get(capacity, inf) > 0
67
- ]
68
- else:
69
- edge_list = [
70
- (u, v, 0, e)
71
- for u, v, e in G.edges(data=True)
72
- if u != v and e.get(capacity, inf) > 0
73
- ]
74
- # Simulate infinity with the larger of the sum of absolute node imbalances
75
- # the sum of finite edge capacities or any positive value if both sums are
76
- # zero. This allows the infinite-capacity edges to be distinguished for
77
- # unboundedness detection and directly participate in residual capacity
78
- # calculation.
79
- inf = (
80
- max(
81
- sum(abs(R.nodes[u]["excess"]) for u in R),
82
- 2
83
- * sum(
84
- e[capacity]
85
- for u, v, k, e in edge_list
86
- if capacity in e and e[capacity] != inf
87
- ),
88
- )
89
- or 1
90
- )
91
- for u, v, k, e in edge_list:
92
- r = min(e.get(capacity, inf), inf)
93
- w = e.get(weight, 0)
94
- # Add both (u, v) and (v, u) into the residual network marked with the
95
- # original key. (key[1] == True) indicates the (u, v) is in the
96
- # original network.
97
- R.add_edge(u, v, key=(k, True), capacity=r, weight=w, flow=0)
98
- R.add_edge(v, u, key=(k, False), capacity=0, weight=-w, flow=0)
99
-
100
- # Record the value simulating infinity.
101
- R.graph["inf"] = inf
102
-
103
- _detect_unboundedness(R)
104
-
105
- return R
106
-
107
-
108
- def _build_flow_dict(G, R, capacity, weight):
109
- """Build a flow dictionary from a residual network."""
110
- inf = float("inf")
111
- flow_dict = {}
112
- if G.is_multigraph():
113
- for u in G:
114
- flow_dict[u] = {}
115
- for v, es in G[u].items():
116
- flow_dict[u][v] = {
117
- # Always saturate negative selfloops.
118
- k: (
119
- 0
120
- if (
121
- u != v or e.get(capacity, inf) <= 0 or e.get(weight, 0) >= 0
122
- )
123
- else e[capacity]
124
- )
125
- for k, e in es.items()
126
- }
127
- for v, es in R[u].items():
128
- if v in flow_dict[u]:
129
- flow_dict[u][v].update(
130
- (k[0], e["flow"]) for k, e in es.items() if e["flow"] > 0
131
- )
132
- else:
133
- for u in G:
134
- flow_dict[u] = {
135
- # Always saturate negative selfloops.
136
- v: (
137
- 0
138
- if (u != v or e.get(capacity, inf) <= 0 or e.get(weight, 0) >= 0)
139
- else e[capacity]
140
- )
141
- for v, e in G[u].items()
142
- }
143
- flow_dict[u].update(
144
- (v, e["flow"])
145
- for v, es in R[u].items()
146
- for e in es.values()
147
- if e["flow"] > 0
148
- )
149
- return flow_dict
150
-
151
-
152
- @nx._dispatchable(
153
- node_attrs="demand", edge_attrs={"capacity": float("inf"), "weight": 0}
154
- )
155
- def capacity_scaling(
156
- G, demand="demand", capacity="capacity", weight="weight", heap=BinaryHeap
157
- ):
158
- r"""Find a minimum cost flow satisfying all demands in digraph G.
159
-
160
- This is a capacity scaling successive shortest augmenting path algorithm.
161
-
162
- G is a digraph with edge costs and capacities and in which nodes
163
- have demand, i.e., they want to send or receive some amount of
164
- flow. A negative demand means that the node wants to send flow, a
165
- positive demand means that the node want to receive flow. A flow on
166
- the digraph G satisfies all demand if the net flow into each node
167
- is equal to the demand of that node.
168
-
169
- Parameters
170
- ----------
171
- G : NetworkX graph
172
- DiGraph or MultiDiGraph on which a minimum cost flow satisfying all
173
- demands is to be found.
174
-
175
- demand : string
176
- Nodes of the graph G are expected to have an attribute demand
177
- that indicates how much flow a node wants to send (negative
178
- demand) or receive (positive demand). Note that the sum of the
179
- demands should be 0 otherwise the problem in not feasible. If
180
- this attribute is not present, a node is considered to have 0
181
- demand. Default value: 'demand'.
182
-
183
- capacity : string
184
- Edges of the graph G are expected to have an attribute capacity
185
- that indicates how much flow the edge can support. If this
186
- attribute is not present, the edge is considered to have
187
- infinite capacity. Default value: 'capacity'.
188
-
189
- weight : string
190
- Edges of the graph G are expected to have an attribute weight
191
- that indicates the cost incurred by sending one unit of flow on
192
- that edge. If not present, the weight is considered to be 0.
193
- Default value: 'weight'.
194
-
195
- heap : class
196
- Type of heap to be used in the algorithm. It should be a subclass of
197
- :class:`MinHeap` or implement a compatible interface.
198
-
199
- If a stock heap implementation is to be used, :class:`BinaryHeap` is
200
- recommended over :class:`PairingHeap` for Python implementations without
201
- optimized attribute accesses (e.g., CPython) despite a slower
202
- asymptotic running time. For Python implementations with optimized
203
- attribute accesses (e.g., PyPy), :class:`PairingHeap` provides better
204
- performance. Default value: :class:`BinaryHeap`.
205
-
206
- Returns
207
- -------
208
- flowCost : integer
209
- Cost of a minimum cost flow satisfying all demands.
210
-
211
- flowDict : dictionary
212
- If G is a digraph, a dict-of-dicts keyed by nodes such that
213
- flowDict[u][v] is the flow on edge (u, v).
214
- If G is a MultiDiGraph, a dict-of-dicts-of-dicts keyed by nodes
215
- so that flowDict[u][v][key] is the flow on edge (u, v, key).
216
-
217
- Raises
218
- ------
219
- NetworkXError
220
- This exception is raised if the input graph is not directed,
221
- not connected.
222
-
223
- NetworkXUnfeasible
224
- This exception is raised in the following situations:
225
-
226
- * The sum of the demands is not zero. Then, there is no
227
- flow satisfying all demands.
228
- * There is no flow satisfying all demand.
229
-
230
- NetworkXUnbounded
231
- This exception is raised if the digraph G has a cycle of
232
- negative cost and infinite capacity. Then, the cost of a flow
233
- satisfying all demands is unbounded below.
234
-
235
- Notes
236
- -----
237
- This algorithm does not work if edge weights are floating-point numbers.
238
-
239
- See also
240
- --------
241
- :meth:`network_simplex`
242
-
243
- Examples
244
- --------
245
- A simple example of a min cost flow problem.
246
-
247
- >>> G = nx.DiGraph()
248
- >>> G.add_node("a", demand=-5)
249
- >>> G.add_node("d", demand=5)
250
- >>> G.add_edge("a", "b", weight=3, capacity=4)
251
- >>> G.add_edge("a", "c", weight=6, capacity=10)
252
- >>> G.add_edge("b", "d", weight=1, capacity=9)
253
- >>> G.add_edge("c", "d", weight=2, capacity=5)
254
- >>> flowCost, flowDict = nx.capacity_scaling(G)
255
- >>> flowCost
256
- 24
257
- >>> flowDict
258
- {'a': {'b': 4, 'c': 1}, 'd': {}, 'b': {'d': 4}, 'c': {'d': 1}}
259
-
260
- It is possible to change the name of the attributes used for the
261
- algorithm.
262
-
263
- >>> G = nx.DiGraph()
264
- >>> G.add_node("p", spam=-4)
265
- >>> G.add_node("q", spam=2)
266
- >>> G.add_node("a", spam=-2)
267
- >>> G.add_node("d", spam=-1)
268
- >>> G.add_node("t", spam=2)
269
- >>> G.add_node("w", spam=3)
270
- >>> G.add_edge("p", "q", cost=7, vacancies=5)
271
- >>> G.add_edge("p", "a", cost=1, vacancies=4)
272
- >>> G.add_edge("q", "d", cost=2, vacancies=3)
273
- >>> G.add_edge("t", "q", cost=1, vacancies=2)
274
- >>> G.add_edge("a", "t", cost=2, vacancies=4)
275
- >>> G.add_edge("d", "w", cost=3, vacancies=4)
276
- >>> G.add_edge("t", "w", cost=4, vacancies=1)
277
- >>> flowCost, flowDict = nx.capacity_scaling(
278
- ... G, demand="spam", capacity="vacancies", weight="cost"
279
- ... )
280
- >>> flowCost
281
- 37
282
- >>> flowDict
283
- {'p': {'q': 2, 'a': 2}, 'q': {'d': 1}, 'a': {'t': 4}, 'd': {'w': 2}, 't': {'q': 1, 'w': 1}, 'w': {}}
284
- """
285
- R = _build_residual_network(G, demand, capacity, weight)
286
-
287
- inf = float("inf")
288
- # Account cost of negative selfloops.
289
- flow_cost = sum(
290
- 0
291
- if e.get(capacity, inf) <= 0 or e.get(weight, 0) >= 0
292
- else e[capacity] * e[weight]
293
- for u, v, e in nx.selfloop_edges(G, data=True)
294
- )
295
-
296
- # Determine the maximum edge capacity.
297
- wmax = max(chain([-inf], (e["capacity"] for u, v, e in R.edges(data=True))))
298
- if wmax == -inf:
299
- # Residual network has no edges.
300
- return flow_cost, _build_flow_dict(G, R, capacity, weight)
301
-
302
- R_nodes = R.nodes
303
- R_succ = R.succ
304
-
305
- delta = 2 ** int(log(wmax, 2))
306
- while delta >= 1:
307
- # Saturate Δ-residual edges with negative reduced costs to achieve
308
- # Δ-optimality.
309
- for u in R:
310
- p_u = R_nodes[u]["potential"]
311
- for v, es in R_succ[u].items():
312
- for k, e in es.items():
313
- flow = e["capacity"] - e["flow"]
314
- if e["weight"] - p_u + R_nodes[v]["potential"] < 0:
315
- flow = e["capacity"] - e["flow"]
316
- if flow >= delta:
317
- e["flow"] += flow
318
- R_succ[v][u][(k[0], not k[1])]["flow"] -= flow
319
- R_nodes[u]["excess"] -= flow
320
- R_nodes[v]["excess"] += flow
321
- # Determine the Δ-active nodes.
322
- S = set()
323
- T = set()
324
- S_add = S.add
325
- S_remove = S.remove
326
- T_add = T.add
327
- T_remove = T.remove
328
- for u in R:
329
- excess = R_nodes[u]["excess"]
330
- if excess >= delta:
331
- S_add(u)
332
- elif excess <= -delta:
333
- T_add(u)
334
- # Repeatedly augment flow from S to T along shortest paths until
335
- # Δ-feasibility is achieved.
336
- while S and T:
337
- s = arbitrary_element(S)
338
- t = None
339
- # Search for a shortest path in terms of reduce costs from s to
340
- # any t in T in the Δ-residual network.
341
- d = {}
342
- pred = {s: None}
343
- h = heap()
344
- h_insert = h.insert
345
- h_get = h.get
346
- h_insert(s, 0)
347
- while h:
348
- u, d_u = h.pop()
349
- d[u] = d_u
350
- if u in T:
351
- # Path found.
352
- t = u
353
- break
354
- p_u = R_nodes[u]["potential"]
355
- for v, es in R_succ[u].items():
356
- if v in d:
357
- continue
358
- wmin = inf
359
- # Find the minimum-weighted (u, v) Δ-residual edge.
360
- for k, e in es.items():
361
- if e["capacity"] - e["flow"] >= delta:
362
- w = e["weight"]
363
- if w < wmin:
364
- wmin = w
365
- kmin = k
366
- emin = e
367
- if wmin == inf:
368
- continue
369
- # Update the distance label of v.
370
- d_v = d_u + wmin - p_u + R_nodes[v]["potential"]
371
- if h_insert(v, d_v):
372
- pred[v] = (u, kmin, emin)
373
- if t is not None:
374
- # Augment Δ units of flow from s to t.
375
- while u != s:
376
- v = u
377
- u, k, e = pred[v]
378
- e["flow"] += delta
379
- R_succ[v][u][(k[0], not k[1])]["flow"] -= delta
380
- # Account node excess and deficit.
381
- R_nodes[s]["excess"] -= delta
382
- R_nodes[t]["excess"] += delta
383
- if R_nodes[s]["excess"] < delta:
384
- S_remove(s)
385
- if R_nodes[t]["excess"] > -delta:
386
- T_remove(t)
387
- # Update node potentials.
388
- d_t = d[t]
389
- for u, d_u in d.items():
390
- R_nodes[u]["potential"] -= d_u - d_t
391
- else:
392
- # Path not found.
393
- S_remove(s)
394
- delta //= 2
395
-
396
- if any(R.nodes[u]["excess"] != 0 for u in R):
397
- raise nx.NetworkXUnfeasible("No flow satisfying all demands.")
398
-
399
- # Calculate the flow cost.
400
- for u in R:
401
- for v, es in R_succ[u].items():
402
- for e in es.values():
403
- flow = e["flow"]
404
- if flow > 0:
405
- flow_cost += flow * e["weight"]
406
-
407
- return flow_cost, _build_flow_dict(G, R, capacity, weight)
@@ -1,238 +0,0 @@
1
- """
2
- Dinitz' algorithm for maximum flow problems.
3
- """
4
-
5
- from collections import deque
6
-
7
- import networkx as nx
8
- from networkx.algorithms.flow.utils import build_residual_network
9
- from networkx.utils import pairwise
10
-
11
- __all__ = ["dinitz"]
12
-
13
-
14
- @nx._dispatchable(edge_attrs={"capacity": float("inf")}, returns_graph=True)
15
- def dinitz(G, s, t, capacity="capacity", residual=None, value_only=False, cutoff=None):
16
- """Find a maximum single-commodity flow using Dinitz' algorithm.
17
-
18
- This function returns the residual network resulting after computing
19
- the maximum flow. See below for details about the conventions
20
- NetworkX uses for defining residual networks.
21
-
22
- This algorithm has a running time of $O(n^2 m)$ for $n$ nodes and $m$
23
- edges [1]_.
24
-
25
-
26
- Parameters
27
- ----------
28
- G : NetworkX graph
29
- Edges of the graph are expected to have an attribute called
30
- 'capacity'. If this attribute is not present, the edge is
31
- considered to have infinite capacity.
32
-
33
- s : node
34
- Source node for the flow.
35
-
36
- t : node
37
- Sink node for the flow.
38
-
39
- capacity : string
40
- Edges of the graph G are expected to have an attribute capacity
41
- that indicates how much flow the edge can support. If this
42
- attribute is not present, the edge is considered to have
43
- infinite capacity. Default value: 'capacity'.
44
-
45
- residual : NetworkX graph
46
- Residual network on which the algorithm is to be executed. If None, a
47
- new residual network is created. Default value: None.
48
-
49
- value_only : bool
50
- If True compute only the value of the maximum flow. This parameter
51
- will be ignored by this algorithm because it is not applicable.
52
-
53
- cutoff : integer, float
54
- If specified, the algorithm will terminate when the flow value reaches
55
- or exceeds the cutoff. In this case, it may be unable to immediately
56
- determine a minimum cut. Default value: None.
57
-
58
- Returns
59
- -------
60
- R : NetworkX DiGraph
61
- Residual network after computing the maximum flow.
62
-
63
- Raises
64
- ------
65
- NetworkXError
66
- The algorithm does not support MultiGraph and MultiDiGraph. If
67
- the input graph is an instance of one of these two classes, a
68
- NetworkXError is raised.
69
-
70
- NetworkXUnbounded
71
- If the graph has a path of infinite capacity, the value of a
72
- feasible flow on the graph is unbounded above and the function
73
- raises a NetworkXUnbounded.
74
-
75
- See also
76
- --------
77
- :meth:`maximum_flow`
78
- :meth:`minimum_cut`
79
- :meth:`preflow_push`
80
- :meth:`shortest_augmenting_path`
81
-
82
- Notes
83
- -----
84
- The residual network :samp:`R` from an input graph :samp:`G` has the
85
- same nodes as :samp:`G`. :samp:`R` is a DiGraph that contains a pair
86
- of edges :samp:`(u, v)` and :samp:`(v, u)` iff :samp:`(u, v)` is not a
87
- self-loop, and at least one of :samp:`(u, v)` and :samp:`(v, u)` exists
88
- in :samp:`G`.
89
-
90
- For each edge :samp:`(u, v)` in :samp:`R`, :samp:`R[u][v]['capacity']`
91
- is equal to the capacity of :samp:`(u, v)` in :samp:`G` if it exists
92
- in :samp:`G` or zero otherwise. If the capacity is infinite,
93
- :samp:`R[u][v]['capacity']` will have a high arbitrary finite value
94
- that does not affect the solution of the problem. This value is stored in
95
- :samp:`R.graph['inf']`. For each edge :samp:`(u, v)` in :samp:`R`,
96
- :samp:`R[u][v]['flow']` represents the flow function of :samp:`(u, v)` and
97
- satisfies :samp:`R[u][v]['flow'] == -R[v][u]['flow']`.
98
-
99
- The flow value, defined as the total flow into :samp:`t`, the sink, is
100
- stored in :samp:`R.graph['flow_value']`. If :samp:`cutoff` is not
101
- specified, reachability to :samp:`t` using only edges :samp:`(u, v)` such
102
- that :samp:`R[u][v]['flow'] < R[u][v]['capacity']` induces a minimum
103
- :samp:`s`-:samp:`t` cut.
104
-
105
- Examples
106
- --------
107
- >>> from networkx.algorithms.flow import dinitz
108
-
109
- The functions that implement flow algorithms and output a residual
110
- network, such as this one, are not imported to the base NetworkX
111
- namespace, so you have to explicitly import them from the flow package.
112
-
113
- >>> G = nx.DiGraph()
114
- >>> G.add_edge("x", "a", capacity=3.0)
115
- >>> G.add_edge("x", "b", capacity=1.0)
116
- >>> G.add_edge("a", "c", capacity=3.0)
117
- >>> G.add_edge("b", "c", capacity=5.0)
118
- >>> G.add_edge("b", "d", capacity=4.0)
119
- >>> G.add_edge("d", "e", capacity=2.0)
120
- >>> G.add_edge("c", "y", capacity=2.0)
121
- >>> G.add_edge("e", "y", capacity=3.0)
122
- >>> R = dinitz(G, "x", "y")
123
- >>> flow_value = nx.maximum_flow_value(G, "x", "y")
124
- >>> flow_value
125
- 3.0
126
- >>> flow_value == R.graph["flow_value"]
127
- True
128
-
129
- References
130
- ----------
131
- .. [1] Dinitz' Algorithm: The Original Version and Even's Version.
132
- 2006. Yefim Dinitz. In Theoretical Computer Science. Lecture
133
- Notes in Computer Science. Volume 3895. pp 218-240.
134
- https://doi.org/10.1007/11685654_10
135
-
136
- """
137
- R = dinitz_impl(G, s, t, capacity, residual, cutoff)
138
- R.graph["algorithm"] = "dinitz"
139
- nx._clear_cache(R)
140
- return R
141
-
142
-
143
- def dinitz_impl(G, s, t, capacity, residual, cutoff):
144
- if s not in G:
145
- raise nx.NetworkXError(f"node {str(s)} not in graph")
146
- if t not in G:
147
- raise nx.NetworkXError(f"node {str(t)} not in graph")
148
- if s == t:
149
- raise nx.NetworkXError("source and sink are the same node")
150
-
151
- if residual is None:
152
- R = build_residual_network(G, capacity)
153
- else:
154
- R = residual
155
-
156
- # Initialize/reset the residual network.
157
- for u in R:
158
- for e in R[u].values():
159
- e["flow"] = 0
160
-
161
- # Use an arbitrary high value as infinite. It is computed
162
- # when building the residual network.
163
- INF = R.graph["inf"]
164
-
165
- if cutoff is None:
166
- cutoff = INF
167
-
168
- R_succ = R.succ
169
- R_pred = R.pred
170
-
171
- def breath_first_search():
172
- parents = {}
173
- vertex_dist = {s: 0}
174
- queue = deque([(s, 0)])
175
- # Record all the potential edges of shortest augmenting paths
176
- while queue:
177
- if t in parents:
178
- break
179
- u, dist = queue.popleft()
180
- for v, attr in R_succ[u].items():
181
- if attr["capacity"] - attr["flow"] > 0:
182
- if v in parents:
183
- if vertex_dist[v] == dist + 1:
184
- parents[v].append(u)
185
- else:
186
- parents[v] = deque([u])
187
- vertex_dist[v] = dist + 1
188
- queue.append((v, dist + 1))
189
- return parents
190
-
191
- def depth_first_search(parents):
192
- # DFS to find all the shortest augmenting paths
193
- """Build a path using DFS starting from the sink"""
194
- total_flow = 0
195
- u = t
196
- # path also functions as a stack
197
- path = [u]
198
- # The loop ends with no augmenting path left in the layered graph
199
- while True:
200
- if len(parents[u]) > 0:
201
- v = parents[u][0]
202
- path.append(v)
203
- else:
204
- path.pop()
205
- if len(path) == 0:
206
- break
207
- v = path[-1]
208
- parents[v].popleft()
209
- # Augment the flow along the path found
210
- if v == s:
211
- flow = INF
212
- for u, v in pairwise(path):
213
- flow = min(flow, R_pred[u][v]["capacity"] - R_pred[u][v]["flow"])
214
- for u, v in pairwise(reversed(path)):
215
- R_pred[v][u]["flow"] += flow
216
- R_pred[u][v]["flow"] -= flow
217
- # Find the proper node to continue the search
218
- if R_pred[v][u]["capacity"] - R_pred[v][u]["flow"] == 0:
219
- parents[v].popleft()
220
- while path[-1] != v:
221
- path.pop()
222
- total_flow += flow
223
- v = path[-1]
224
- u = v
225
- return total_flow
226
-
227
- flow_value = 0
228
- while flow_value < cutoff:
229
- parents = breath_first_search()
230
- if t not in parents:
231
- break
232
- this_flow = depth_first_search(parents)
233
- if this_flow * 2 > INF:
234
- raise nx.NetworkXUnbounded("Infinite capacity path, flow unbounded above.")
235
- flow_value += this_flow
236
-
237
- R.graph["flow_value"] = flow_value
238
- return R