okstra 0.130.3 → 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 (367) 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 +21 -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/report_views.py +32 -5
  27. package/runtime/python/okstra_ctl/run.py +15 -3
  28. package/runtime/python/okstra_ctl/worker_prompt_contract.py +14 -6
  29. package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -1
  30. package/runtime/python/okstra_vendor/__init__.py +0 -44
  31. package/runtime/schemas/final-report-v1.0.schema.json +101 -6
  32. package/runtime/skills/okstra-run/SKILL.md +11 -4
  33. package/runtime/skills/okstra-setup/SKILL.md +3 -2
  34. package/runtime/skills/okstra-setup/references/project-config.md +16 -7
  35. package/runtime/templates/reports/final-report.template.md +18 -12
  36. package/runtime/templates/reports/i18n/en.json +1 -0
  37. package/runtime/templates/reports/i18n/ko.json +1 -0
  38. package/runtime/templates/reports/report.css +18 -0
  39. package/runtime/validators/lib/fixtures.sh +6 -0
  40. package/runtime/validators/validate-run.py +1722 -98
  41. package/src/cli-registry.mjs +0 -7
  42. package/src/commands/lifecycle/doctor.mjs +0 -9
  43. package/src/lib/skill-catalog.mjs +0 -1
  44. package/docs/for-ai/skills/okstra-graphify.md +0 -64
  45. package/runtime/python/okstra_ctl/graphify_cmd.py +0 -225
  46. package/runtime/python/okstra_vendor/graphify/.vendored-version +0 -1
  47. package/runtime/python/okstra_vendor/graphify/__init__.py +0 -28
  48. package/runtime/python/okstra_vendor/graphify/__main__.py +0 -1371
  49. package/runtime/python/okstra_vendor/graphify/analyze.py +0 -540
  50. package/runtime/python/okstra_vendor/graphify/benchmark.py +0 -129
  51. package/runtime/python/okstra_vendor/graphify/build.py +0 -107
  52. package/runtime/python/okstra_vendor/graphify/cache.py +0 -169
  53. package/runtime/python/okstra_vendor/graphify/cluster.py +0 -137
  54. package/runtime/python/okstra_vendor/graphify/detect.py +0 -510
  55. package/runtime/python/okstra_vendor/graphify/export.py +0 -1014
  56. package/runtime/python/okstra_vendor/graphify/extract.py +0 -3277
  57. package/runtime/python/okstra_vendor/graphify/hooks.py +0 -220
  58. package/runtime/python/okstra_vendor/graphify/ingest.py +0 -297
  59. package/runtime/python/okstra_vendor/graphify/manifest.py +0 -4
  60. package/runtime/python/okstra_vendor/graphify/report.py +0 -175
  61. package/runtime/python/okstra_vendor/graphify/security.py +0 -203
  62. package/runtime/python/okstra_vendor/graphify/serve.py +0 -373
  63. package/runtime/python/okstra_vendor/graphify/skill-aider.md +0 -1184
  64. package/runtime/python/okstra_vendor/graphify/skill-claw.md +0 -1184
  65. package/runtime/python/okstra_vendor/graphify/skill-codex.md +0 -1242
  66. package/runtime/python/okstra_vendor/graphify/skill-copilot.md +0 -1268
  67. package/runtime/python/okstra_vendor/graphify/skill-droid.md +0 -1239
  68. package/runtime/python/okstra_vendor/graphify/skill-kiro.md +0 -1183
  69. package/runtime/python/okstra_vendor/graphify/skill-opencode.md +0 -1238
  70. package/runtime/python/okstra_vendor/graphify/skill-trae.md +0 -1208
  71. package/runtime/python/okstra_vendor/graphify/skill-vscode.md +0 -253
  72. package/runtime/python/okstra_vendor/graphify/skill-windows.md +0 -1245
  73. package/runtime/python/okstra_vendor/graphify/skill.md +0 -1319
  74. package/runtime/python/okstra_vendor/graphify/transcribe.py +0 -182
  75. package/runtime/python/okstra_vendor/graphify/validate.py +0 -72
  76. package/runtime/python/okstra_vendor/graphify/watch.py +0 -188
  77. package/runtime/python/okstra_vendor/graphify/wiki.py +0 -214
  78. package/runtime/python/okstra_vendor/networkx/__init__.py +0 -62
  79. package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +0 -134
  80. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +0 -26
  81. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +0 -259
  82. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +0 -71
  83. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +0 -412
  84. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +0 -396
  85. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +0 -150
  86. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +0 -149
  87. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +0 -369
  88. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +0 -44
  89. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +0 -143
  90. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +0 -53
  91. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +0 -265
  92. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +0 -1508
  93. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +0 -255
  94. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +0 -83
  95. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +0 -5
  96. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +0 -122
  97. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +0 -302
  98. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +0 -255
  99. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +0 -160
  100. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +0 -127
  101. package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +0 -164
  102. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +0 -88
  103. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +0 -322
  104. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +0 -290
  105. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +0 -289
  106. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +0 -57
  107. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +0 -360
  108. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +0 -105
  109. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +0 -603
  110. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +0 -316
  111. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +0 -590
  112. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +0 -232
  113. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +0 -526
  114. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +0 -112
  115. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +0 -69
  116. package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +0 -168
  117. package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +0 -205
  118. package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +0 -164
  119. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +0 -20
  120. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +0 -591
  121. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +0 -236
  122. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +0 -282
  123. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +0 -364
  124. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +0 -227
  125. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +0 -96
  126. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +0 -150
  127. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +0 -107
  128. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +0 -357
  129. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +0 -130
  130. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +0 -787
  131. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +0 -88
  132. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +0 -331
  133. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +0 -150
  134. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +0 -200
  135. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +0 -128
  136. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +0 -209
  137. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +0 -141
  138. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +0 -361
  139. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +0 -181
  140. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +0 -95
  141. package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +0 -172
  142. package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +0 -443
  143. package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +0 -818
  144. package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +0 -732
  145. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +0 -4
  146. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +0 -505
  147. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +0 -565
  148. package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +0 -163
  149. package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +0 -28
  150. package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +0 -153
  151. package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +0 -354
  152. package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +0 -171
  153. package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +0 -30
  154. package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +0 -216
  155. package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +0 -79
  156. package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +0 -338
  157. package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +0 -162
  158. package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +0 -220
  159. package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +0 -384
  160. package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +0 -227
  161. package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +0 -452
  162. package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +0 -347
  163. package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +0 -6
  164. package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +0 -115
  165. package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +0 -394
  166. package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +0 -282
  167. package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +0 -71
  168. package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +0 -359
  169. package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +0 -196
  170. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +0 -11
  171. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +0 -811
  172. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +0 -616
  173. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +0 -408
  174. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +0 -1270
  175. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +0 -592
  176. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +0 -220
  177. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +0 -235
  178. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +0 -152
  179. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +0 -88
  180. package/runtime/python/okstra_vendor/networkx/algorithms/core.py +0 -588
  181. package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +0 -142
  182. package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +0 -416
  183. package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +0 -1234
  184. package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +0 -677
  185. package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +0 -1392
  186. package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +0 -1095
  187. package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +0 -272
  188. package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +0 -142
  189. package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +0 -268
  190. package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +0 -167
  191. package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +0 -470
  192. package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +0 -11
  193. package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +0 -370
  194. package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +0 -407
  195. package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +0 -238
  196. package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +0 -241
  197. package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +0 -178
  198. package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +0 -611
  199. package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +0 -356
  200. package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +0 -662
  201. package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +0 -425
  202. package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +0 -300
  203. package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +0 -194
  204. package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +0 -435
  205. package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +0 -483
  206. package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +0 -57
  207. package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +0 -196
  208. package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +0 -107
  209. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +0 -7
  210. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +0 -1306
  211. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +0 -336
  212. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +0 -1262
  213. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +0 -352
  214. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +0 -308
  215. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +0 -264
  216. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +0 -1102
  217. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +0 -192
  218. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +0 -2
  219. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +0 -337
  220. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +0 -498
  221. package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +0 -687
  222. package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +0 -280
  223. package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +0 -1148
  224. package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +0 -27
  225. package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +0 -738
  226. package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +0 -78
  227. package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +0 -59
  228. package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +0 -219
  229. package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +0 -155
  230. package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +0 -4
  231. package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +0 -324
  232. package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +0 -468
  233. package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +0 -633
  234. package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +0 -77
  235. package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +0 -73
  236. package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +0 -464
  237. package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +0 -1463
  238. package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +0 -306
  239. package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +0 -98
  240. package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +0 -167
  241. package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +0 -138
  242. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +0 -5
  243. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +0 -239
  244. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +0 -264
  245. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +0 -716
  246. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +0 -625
  247. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +0 -2542
  248. package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +0 -2107
  249. package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +0 -966
  250. package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +0 -404
  251. package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +0 -30
  252. package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +0 -296
  253. package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +0 -374
  254. package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +0 -564
  255. package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +0 -406
  256. package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +0 -981
  257. package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +0 -142
  258. package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +0 -406
  259. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +0 -5
  260. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +0 -90
  261. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +0 -576
  262. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +0 -529
  263. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +0 -185
  264. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +0 -182
  265. package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +0 -7
  266. package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +0 -1042
  267. package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +0 -413
  268. package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +0 -88
  269. package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +0 -219
  270. package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +0 -1281
  271. package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +0 -106
  272. package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +0 -273
  273. package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +0 -500
  274. package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +0 -76
  275. package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +0 -86
  276. package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +0 -77
  277. package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +0 -278
  278. package/runtime/python/okstra_vendor/networkx/classes/__init__.py +0 -13
  279. package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +0 -435
  280. package/runtime/python/okstra_vendor/networkx/classes/digraph.py +0 -1363
  281. package/runtime/python/okstra_vendor/networkx/classes/filters.py +0 -95
  282. package/runtime/python/okstra_vendor/networkx/classes/function.py +0 -1549
  283. package/runtime/python/okstra_vendor/networkx/classes/graph.py +0 -2082
  284. package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +0 -269
  285. package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +0 -977
  286. package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +0 -1294
  287. package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +0 -1447
  288. package/runtime/python/okstra_vendor/networkx/convert.py +0 -502
  289. package/runtime/python/okstra_vendor/networkx/convert_matrix.py +0 -1314
  290. package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +0 -7
  291. package/runtime/python/okstra_vendor/networkx/drawing/layout.py +0 -2036
  292. package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +0 -470
  293. package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +0 -570
  294. package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +0 -361
  295. package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +0 -2978
  296. package/runtime/python/okstra_vendor/networkx/exception.py +0 -131
  297. package/runtime/python/okstra_vendor/networkx/generators/__init__.py +0 -34
  298. package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
  299. package/runtime/python/okstra_vendor/networkx/generators/atlas.py +0 -227
  300. package/runtime/python/okstra_vendor/networkx/generators/classic.py +0 -1091
  301. package/runtime/python/okstra_vendor/networkx/generators/cographs.py +0 -68
  302. package/runtime/python/okstra_vendor/networkx/generators/community.py +0 -1070
  303. package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +0 -886
  304. package/runtime/python/okstra_vendor/networkx/generators/directed.py +0 -572
  305. package/runtime/python/okstra_vendor/networkx/generators/duplication.py +0 -174
  306. package/runtime/python/okstra_vendor/networkx/generators/ego.py +0 -66
  307. package/runtime/python/okstra_vendor/networkx/generators/expanders.py +0 -499
  308. package/runtime/python/okstra_vendor/networkx/generators/geometric.py +0 -1037
  309. package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +0 -163
  310. package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +0 -443
  311. package/runtime/python/okstra_vendor/networkx/generators/intersection.py +0 -125
  312. package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +0 -70
  313. package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +0 -664
  314. package/runtime/python/okstra_vendor/networkx/generators/lattice.py +0 -405
  315. package/runtime/python/okstra_vendor/networkx/generators/line.py +0 -501
  316. package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +0 -110
  317. package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +0 -259
  318. package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +0 -117
  319. package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +0 -1416
  320. package/runtime/python/okstra_vendor/networkx/generators/small.py +0 -1070
  321. package/runtime/python/okstra_vendor/networkx/generators/social.py +0 -554
  322. package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +0 -120
  323. package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +0 -54
  324. package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +0 -131
  325. package/runtime/python/okstra_vendor/networkx/generators/time_series.py +0 -74
  326. package/runtime/python/okstra_vendor/networkx/generators/trees.py +0 -1070
  327. package/runtime/python/okstra_vendor/networkx/generators/triads.py +0 -94
  328. package/runtime/python/okstra_vendor/networkx/lazy_imports.py +0 -188
  329. package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +0 -13
  330. package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +0 -650
  331. package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +0 -466
  332. package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +0 -77
  333. package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +0 -168
  334. package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +0 -512
  335. package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +0 -166
  336. package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +0 -186
  337. package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +0 -17
  338. package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +0 -330
  339. package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +0 -489
  340. package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +0 -1084
  341. package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +0 -879
  342. package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +0 -427
  343. package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +0 -1053
  344. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +0 -19
  345. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +0 -156
  346. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +0 -190
  347. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +0 -261
  348. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +0 -137
  349. package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +0 -108
  350. package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +0 -393
  351. package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +0 -113
  352. package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +0 -286
  353. package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +0 -379
  354. package/runtime/python/okstra_vendor/networkx/readwrite/text.py +0 -851
  355. package/runtime/python/okstra_vendor/networkx/relabel.py +0 -285
  356. package/runtime/python/okstra_vendor/networkx/utils/__init__.py +0 -8
  357. package/runtime/python/okstra_vendor/networkx/utils/backends.py +0 -2171
  358. package/runtime/python/okstra_vendor/networkx/utils/configs.py +0 -396
  359. package/runtime/python/okstra_vendor/networkx/utils/decorators.py +0 -1233
  360. package/runtime/python/okstra_vendor/networkx/utils/heaps.py +0 -338
  361. package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +0 -297
  362. package/runtime/python/okstra_vendor/networkx/utils/misc.py +0 -703
  363. package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +0 -198
  364. package/runtime/python/okstra_vendor/networkx/utils/rcm.py +0 -159
  365. package/runtime/python/okstra_vendor/networkx/utils/union_find.py +0 -106
  366. package/runtime/skills/okstra-graphify/SKILL.md +0 -169
  367. package/src/commands/graphify.mjs +0 -32
@@ -1,662 +0,0 @@
1
- """
2
- Minimum cost flow algorithms on directed connected graphs.
3
- """
4
-
5
- __all__ = ["network_simplex"]
6
-
7
- from itertools import chain, islice, repeat
8
- from math import ceil, sqrt
9
-
10
- import networkx as nx
11
- from networkx.utils import not_implemented_for
12
-
13
-
14
- class _DataEssentialsAndFunctions:
15
- def __init__(
16
- self, G, multigraph, demand="demand", capacity="capacity", weight="weight"
17
- ):
18
- # Number all nodes and edges and hereafter reference them using ONLY their numbers
19
- self.node_list = list(G) # nodes
20
- self.node_indices = {u: i for i, u in enumerate(self.node_list)} # node indices
21
- self.node_demands = [
22
- G.nodes[u].get(demand, 0) for u in self.node_list
23
- ] # node demands
24
-
25
- self.edge_sources = [] # edge sources
26
- self.edge_targets = [] # edge targets
27
- if multigraph:
28
- self.edge_keys = [] # edge keys
29
- self.edge_indices = {} # edge indices
30
- self.edge_capacities = [] # edge capacities
31
- self.edge_weights = [] # edge weights
32
-
33
- if not multigraph:
34
- edges = G.edges(data=True)
35
- else:
36
- edges = G.edges(data=True, keys=True)
37
-
38
- inf = float("inf")
39
- edges = (e for e in edges if e[0] != e[1] and e[-1].get(capacity, inf) != 0)
40
- for i, e in enumerate(edges):
41
- self.edge_sources.append(self.node_indices[e[0]])
42
- self.edge_targets.append(self.node_indices[e[1]])
43
- if multigraph:
44
- self.edge_keys.append(e[2])
45
- self.edge_indices[e[:-1]] = i
46
- self.edge_capacities.append(e[-1].get(capacity, inf))
47
- self.edge_weights.append(e[-1].get(weight, 0))
48
-
49
- # spanning tree specific data to be initialized
50
-
51
- self.edge_count = None # number of edges
52
- self.edge_flow = None # edge flows
53
- self.node_potentials = None # node potentials
54
- self.parent = None # parent nodes
55
- self.parent_edge = None # edges to parents
56
- self.subtree_size = None # subtree sizes
57
- self.next_node_dft = None # next nodes in depth-first thread
58
- self.prev_node_dft = None # previous nodes in depth-first thread
59
- self.last_descendent_dft = None # last descendants in depth-first thread
60
- self._spanning_tree_initialized = (
61
- False # False until initialize_spanning_tree() is called
62
- )
63
-
64
- def initialize_spanning_tree(self, n, faux_inf):
65
- self.edge_count = len(self.edge_indices) # number of edges
66
- self.edge_flow = list(
67
- chain(repeat(0, self.edge_count), (abs(d) for d in self.node_demands))
68
- ) # edge flows
69
- self.node_potentials = [
70
- faux_inf if d <= 0 else -faux_inf for d in self.node_demands
71
- ] # node potentials
72
- self.parent = list(chain(repeat(-1, n), [None])) # parent nodes
73
- self.parent_edge = list(
74
- range(self.edge_count, self.edge_count + n)
75
- ) # edges to parents
76
- self.subtree_size = list(chain(repeat(1, n), [n + 1])) # subtree sizes
77
- self.next_node_dft = list(
78
- chain(range(1, n), [-1, 0])
79
- ) # next nodes in depth-first thread
80
- self.prev_node_dft = list(range(-1, n)) # previous nodes in depth-first thread
81
- self.last_descendent_dft = list(
82
- chain(range(n), [n - 1])
83
- ) # last descendants in depth-first thread
84
- self._spanning_tree_initialized = True # True only if all the assignments pass
85
-
86
- def find_apex(self, p, q):
87
- """
88
- Find the lowest common ancestor of nodes p and q in the spanning tree.
89
- """
90
- size_p = self.subtree_size[p]
91
- size_q = self.subtree_size[q]
92
- while True:
93
- while size_p < size_q:
94
- p = self.parent[p]
95
- size_p = self.subtree_size[p]
96
- while size_p > size_q:
97
- q = self.parent[q]
98
- size_q = self.subtree_size[q]
99
- if size_p == size_q:
100
- if p != q:
101
- p = self.parent[p]
102
- size_p = self.subtree_size[p]
103
- q = self.parent[q]
104
- size_q = self.subtree_size[q]
105
- else:
106
- return p
107
-
108
- def trace_path(self, p, w):
109
- """
110
- Returns the nodes and edges on the path from node p to its ancestor w.
111
- """
112
- Wn = [p]
113
- We = []
114
- while p != w:
115
- We.append(self.parent_edge[p])
116
- p = self.parent[p]
117
- Wn.append(p)
118
- return Wn, We
119
-
120
- def find_cycle(self, i, p, q):
121
- """
122
- Returns the nodes and edges on the cycle containing edge i == (p, q)
123
- when the latter is added to the spanning tree.
124
-
125
- The cycle is oriented in the direction from p to q.
126
- """
127
- w = self.find_apex(p, q)
128
- Wn, We = self.trace_path(p, w)
129
- Wn.reverse()
130
- We.reverse()
131
- if We != [i]:
132
- We.append(i)
133
- WnR, WeR = self.trace_path(q, w)
134
- del WnR[-1]
135
- Wn += WnR
136
- We += WeR
137
- return Wn, We
138
-
139
- def augment_flow(self, Wn, We, f):
140
- """
141
- Augment f units of flow along a cycle represented by Wn and We.
142
- """
143
- for i, p in zip(We, Wn):
144
- if self.edge_sources[i] == p:
145
- self.edge_flow[i] += f
146
- else:
147
- self.edge_flow[i] -= f
148
-
149
- def trace_subtree(self, p):
150
- """
151
- Yield the nodes in the subtree rooted at a node p.
152
- """
153
- yield p
154
- l = self.last_descendent_dft[p]
155
- while p != l:
156
- p = self.next_node_dft[p]
157
- yield p
158
-
159
- def remove_edge(self, s, t):
160
- """
161
- Remove an edge (s, t) where parent[t] == s from the spanning tree.
162
- """
163
- size_t = self.subtree_size[t]
164
- prev_t = self.prev_node_dft[t]
165
- last_t = self.last_descendent_dft[t]
166
- next_last_t = self.next_node_dft[last_t]
167
- # Remove (s, t).
168
- self.parent[t] = None
169
- self.parent_edge[t] = None
170
- # Remove the subtree rooted at t from the depth-first thread.
171
- self.next_node_dft[prev_t] = next_last_t
172
- self.prev_node_dft[next_last_t] = prev_t
173
- self.next_node_dft[last_t] = t
174
- self.prev_node_dft[t] = last_t
175
- # Update the subtree sizes and last descendants of the (old) ancestors
176
- # of t.
177
- while s is not None:
178
- self.subtree_size[s] -= size_t
179
- if self.last_descendent_dft[s] == last_t:
180
- self.last_descendent_dft[s] = prev_t
181
- s = self.parent[s]
182
-
183
- def make_root(self, q):
184
- """
185
- Make a node q the root of its containing subtree.
186
- """
187
- ancestors = []
188
- while q is not None:
189
- ancestors.append(q)
190
- q = self.parent[q]
191
- ancestors.reverse()
192
- for p, q in zip(ancestors, islice(ancestors, 1, None)):
193
- size_p = self.subtree_size[p]
194
- last_p = self.last_descendent_dft[p]
195
- prev_q = self.prev_node_dft[q]
196
- last_q = self.last_descendent_dft[q]
197
- next_last_q = self.next_node_dft[last_q]
198
- # Make p a child of q.
199
- self.parent[p] = q
200
- self.parent[q] = None
201
- self.parent_edge[p] = self.parent_edge[q]
202
- self.parent_edge[q] = None
203
- self.subtree_size[p] = size_p - self.subtree_size[q]
204
- self.subtree_size[q] = size_p
205
- # Remove the subtree rooted at q from the depth-first thread.
206
- self.next_node_dft[prev_q] = next_last_q
207
- self.prev_node_dft[next_last_q] = prev_q
208
- self.next_node_dft[last_q] = q
209
- self.prev_node_dft[q] = last_q
210
- if last_p == last_q:
211
- self.last_descendent_dft[p] = prev_q
212
- last_p = prev_q
213
- # Add the remaining parts of the subtree rooted at p as a subtree
214
- # of q in the depth-first thread.
215
- self.prev_node_dft[p] = last_q
216
- self.next_node_dft[last_q] = p
217
- self.next_node_dft[last_p] = q
218
- self.prev_node_dft[q] = last_p
219
- self.last_descendent_dft[q] = last_p
220
-
221
- def add_edge(self, i, p, q):
222
- """
223
- Add an edge (p, q) to the spanning tree where q is the root of a subtree.
224
- """
225
- last_p = self.last_descendent_dft[p]
226
- next_last_p = self.next_node_dft[last_p]
227
- size_q = self.subtree_size[q]
228
- last_q = self.last_descendent_dft[q]
229
- # Make q a child of p.
230
- self.parent[q] = p
231
- self.parent_edge[q] = i
232
- # Insert the subtree rooted at q into the depth-first thread.
233
- self.next_node_dft[last_p] = q
234
- self.prev_node_dft[q] = last_p
235
- self.prev_node_dft[next_last_p] = last_q
236
- self.next_node_dft[last_q] = next_last_p
237
- # Update the subtree sizes and last descendants of the (new) ancestors
238
- # of q.
239
- while p is not None:
240
- self.subtree_size[p] += size_q
241
- if self.last_descendent_dft[p] == last_p:
242
- self.last_descendent_dft[p] = last_q
243
- p = self.parent[p]
244
-
245
- def update_potentials(self, i, p, q):
246
- """
247
- Update the potentials of the nodes in the subtree rooted at a node
248
- q connected to its parent p by an edge i.
249
- """
250
- if q == self.edge_targets[i]:
251
- d = self.node_potentials[p] - self.edge_weights[i] - self.node_potentials[q]
252
- else:
253
- d = self.node_potentials[p] + self.edge_weights[i] - self.node_potentials[q]
254
- for q in self.trace_subtree(q):
255
- self.node_potentials[q] += d
256
-
257
- def reduced_cost(self, i):
258
- """Returns the reduced cost of an edge i."""
259
- c = (
260
- self.edge_weights[i]
261
- - self.node_potentials[self.edge_sources[i]]
262
- + self.node_potentials[self.edge_targets[i]]
263
- )
264
- return c if self.edge_flow[i] == 0 else -c
265
-
266
- def find_entering_edges(self):
267
- """Yield entering edges until none can be found."""
268
- if self.edge_count == 0:
269
- return
270
-
271
- # Entering edges are found by combining Dantzig's rule and Bland's
272
- # rule. The edges are cyclically grouped into blocks of size B. Within
273
- # each block, Dantzig's rule is applied to find an entering edge. The
274
- # blocks to search is determined following Bland's rule.
275
- B = int(ceil(sqrt(self.edge_count))) # pivot block size
276
- M = (self.edge_count + B - 1) // B # number of blocks needed to cover all edges
277
- m = 0 # number of consecutive blocks without eligible
278
- # entering edges
279
- f = 0 # first edge in block
280
- while m < M:
281
- # Determine the next block of edges.
282
- l = f + B
283
- if l <= self.edge_count:
284
- edges = range(f, l)
285
- else:
286
- l -= self.edge_count
287
- edges = chain(range(f, self.edge_count), range(l))
288
- f = l
289
- # Find the first edge with the lowest reduced cost.
290
- i = min(edges, key=self.reduced_cost)
291
- c = self.reduced_cost(i)
292
- if c >= 0:
293
- # No entering edge found in the current block.
294
- m += 1
295
- else:
296
- # Entering edge found.
297
- if self.edge_flow[i] == 0:
298
- p = self.edge_sources[i]
299
- q = self.edge_targets[i]
300
- else:
301
- p = self.edge_targets[i]
302
- q = self.edge_sources[i]
303
- yield i, p, q
304
- m = 0
305
- # All edges have nonnegative reduced costs. The current flow is
306
- # optimal.
307
-
308
- def residual_capacity(self, i, p):
309
- """Returns the residual capacity of an edge i in the direction away
310
- from its endpoint p.
311
- """
312
- return (
313
- self.edge_capacities[i] - self.edge_flow[i]
314
- if self.edge_sources[i] == p
315
- else self.edge_flow[i]
316
- )
317
-
318
- def find_leaving_edge(self, Wn, We):
319
- """Returns the leaving edge in a cycle represented by Wn and We."""
320
- j, s = min(
321
- zip(reversed(We), reversed(Wn)),
322
- key=lambda i_p: self.residual_capacity(*i_p),
323
- )
324
- t = self.edge_targets[j] if self.edge_sources[j] == s else self.edge_sources[j]
325
- return j, s, t
326
-
327
-
328
- @not_implemented_for("undirected")
329
- @nx._dispatchable(
330
- node_attrs="demand", edge_attrs={"capacity": float("inf"), "weight": 0}
331
- )
332
- def network_simplex(G, demand="demand", capacity="capacity", weight="weight"):
333
- r"""Find a minimum cost flow satisfying all demands in digraph G.
334
-
335
- This is a primal network simplex algorithm that uses the leaving
336
- arc rule to prevent cycling.
337
-
338
- G is a digraph with edge costs and capacities and in which nodes
339
- have demand, i.e., they want to send or receive some amount of
340
- flow. A negative demand means that the node wants to send flow, a
341
- positive demand means that the node want to receive flow. A flow on
342
- the digraph G satisfies all demand if the net flow into each node
343
- is equal to the demand of that node.
344
-
345
- Parameters
346
- ----------
347
- G : NetworkX graph
348
- DiGraph on which a minimum cost flow satisfying all demands is
349
- to be found.
350
-
351
- demand : string
352
- Nodes of the graph G are expected to have an attribute demand
353
- that indicates how much flow a node wants to send (negative
354
- demand) or receive (positive demand). Note that the sum of the
355
- demands should be 0 otherwise the problem in not feasible. If
356
- this attribute is not present, a node is considered to have 0
357
- demand. Default value: 'demand'.
358
-
359
- capacity : string
360
- Edges of the graph G are expected to have an attribute capacity
361
- that indicates how much flow the edge can support. If this
362
- attribute is not present, the edge is considered to have
363
- infinite capacity. Default value: 'capacity'.
364
-
365
- weight : string
366
- Edges of the graph G are expected to have an attribute weight
367
- that indicates the cost incurred by sending one unit of flow on
368
- that edge. If not present, the weight is considered to be 0.
369
- Default value: 'weight'.
370
-
371
- Returns
372
- -------
373
- flowCost : integer, float
374
- Cost of a minimum cost flow satisfying all demands.
375
-
376
- flowDict : dictionary
377
- Dictionary of dictionaries keyed by nodes such that
378
- flowDict[u][v] is the flow edge (u, v).
379
-
380
- Raises
381
- ------
382
- NetworkXError
383
- This exception is raised if the input graph is not directed or
384
- not connected.
385
-
386
- NetworkXUnfeasible
387
- This exception is raised in the following situations:
388
-
389
- * The sum of the demands is not zero. Then, there is no
390
- flow satisfying all demands.
391
- * There is no flow satisfying all demand.
392
-
393
- NetworkXUnbounded
394
- This exception is raised if the digraph G has a cycle of
395
- negative cost and infinite capacity. Then, the cost of a flow
396
- satisfying all demands is unbounded below.
397
-
398
- Notes
399
- -----
400
- This algorithm is not guaranteed to work if edge weights or demands
401
- are floating point numbers (overflows and roundoff errors can
402
- cause problems). As a workaround you can use integer numbers by
403
- multiplying the relevant edge attributes by a convenient
404
- constant factor (eg 100).
405
-
406
- See also
407
- --------
408
- cost_of_flow, max_flow_min_cost, min_cost_flow, min_cost_flow_cost
409
-
410
- Examples
411
- --------
412
- A simple example of a min cost flow problem.
413
-
414
- >>> G = nx.DiGraph()
415
- >>> G.add_node("a", demand=-5)
416
- >>> G.add_node("d", demand=5)
417
- >>> G.add_edge("a", "b", weight=3, capacity=4)
418
- >>> G.add_edge("a", "c", weight=6, capacity=10)
419
- >>> G.add_edge("b", "d", weight=1, capacity=9)
420
- >>> G.add_edge("c", "d", weight=2, capacity=5)
421
- >>> flowCost, flowDict = nx.network_simplex(G)
422
- >>> flowCost
423
- 24
424
- >>> flowDict
425
- {'a': {'b': 4, 'c': 1}, 'd': {}, 'b': {'d': 4}, 'c': {'d': 1}}
426
-
427
- The mincost flow algorithm can also be used to solve shortest path
428
- problems. To find the shortest path between two nodes u and v,
429
- give all edges an infinite capacity, give node u a demand of -1 and
430
- node v a demand a 1. Then run the network simplex. The value of a
431
- min cost flow will be the distance between u and v and edges
432
- carrying positive flow will indicate the path.
433
-
434
- >>> G = nx.DiGraph()
435
- >>> G.add_weighted_edges_from(
436
- ... [
437
- ... ("s", "u", 10),
438
- ... ("s", "x", 5),
439
- ... ("u", "v", 1),
440
- ... ("u", "x", 2),
441
- ... ("v", "y", 1),
442
- ... ("x", "u", 3),
443
- ... ("x", "v", 5),
444
- ... ("x", "y", 2),
445
- ... ("y", "s", 7),
446
- ... ("y", "v", 6),
447
- ... ]
448
- ... )
449
- >>> G.add_node("s", demand=-1)
450
- >>> G.add_node("v", demand=1)
451
- >>> flowCost, flowDict = nx.network_simplex(G)
452
- >>> flowCost == nx.shortest_path_length(G, "s", "v", weight="weight")
453
- True
454
- >>> sorted([(u, v) for u in flowDict for v in flowDict[u] if flowDict[u][v] > 0])
455
- [('s', 'x'), ('u', 'v'), ('x', 'u')]
456
- >>> nx.shortest_path(G, "s", "v", weight="weight")
457
- ['s', 'x', 'u', 'v']
458
-
459
- It is possible to change the name of the attributes used for the
460
- algorithm.
461
-
462
- >>> G = nx.DiGraph()
463
- >>> G.add_node("p", spam=-4)
464
- >>> G.add_node("q", spam=2)
465
- >>> G.add_node("a", spam=-2)
466
- >>> G.add_node("d", spam=-1)
467
- >>> G.add_node("t", spam=2)
468
- >>> G.add_node("w", spam=3)
469
- >>> G.add_edge("p", "q", cost=7, vacancies=5)
470
- >>> G.add_edge("p", "a", cost=1, vacancies=4)
471
- >>> G.add_edge("q", "d", cost=2, vacancies=3)
472
- >>> G.add_edge("t", "q", cost=1, vacancies=2)
473
- >>> G.add_edge("a", "t", cost=2, vacancies=4)
474
- >>> G.add_edge("d", "w", cost=3, vacancies=4)
475
- >>> G.add_edge("t", "w", cost=4, vacancies=1)
476
- >>> flowCost, flowDict = nx.network_simplex(
477
- ... G, demand="spam", capacity="vacancies", weight="cost"
478
- ... )
479
- >>> flowCost
480
- 37
481
- >>> flowDict
482
- {'p': {'q': 2, 'a': 2}, 'q': {'d': 1}, 'a': {'t': 4}, 'd': {'w': 2}, 't': {'q': 1, 'w': 1}, 'w': {}}
483
-
484
- References
485
- ----------
486
- .. [1] Z. Kiraly, P. Kovacs.
487
- Efficient implementation of minimum-cost flow algorithms.
488
- Acta Universitatis Sapientiae, Informatica 4(1):67--118. 2012.
489
- .. [2] R. Barr, F. Glover, D. Klingman.
490
- Enhancement of spanning tree labeling procedures for network
491
- optimization.
492
- INFOR 17(1):16--34. 1979.
493
- """
494
- ###########################################################################
495
- # Problem essentials extraction and sanity check
496
- ###########################################################################
497
-
498
- if len(G) == 0:
499
- raise nx.NetworkXError("graph has no nodes")
500
-
501
- multigraph = G.is_multigraph()
502
-
503
- # extracting data essential to problem
504
- DEAF = _DataEssentialsAndFunctions(
505
- G, multigraph, demand=demand, capacity=capacity, weight=weight
506
- )
507
-
508
- ###########################################################################
509
- # Quick Error Detection
510
- ###########################################################################
511
-
512
- inf = float("inf")
513
- for u, d in zip(DEAF.node_list, DEAF.node_demands):
514
- if abs(d) == inf:
515
- raise nx.NetworkXError(f"node {u!r} has infinite demand")
516
- for e, w in zip(DEAF.edge_indices, DEAF.edge_weights):
517
- if abs(w) == inf:
518
- raise nx.NetworkXError(f"edge {e!r} has infinite weight")
519
- if not multigraph:
520
- edges = nx.selfloop_edges(G, data=True)
521
- else:
522
- edges = nx.selfloop_edges(G, data=True, keys=True)
523
- for e in edges:
524
- if abs(e[-1].get(weight, 0)) == inf:
525
- raise nx.NetworkXError(f"edge {e[:-1]!r} has infinite weight")
526
-
527
- ###########################################################################
528
- # Quick Infeasibility Detection
529
- ###########################################################################
530
-
531
- if sum(DEAF.node_demands) != 0:
532
- raise nx.NetworkXUnfeasible("total node demand is not zero")
533
- for e, c in zip(DEAF.edge_indices, DEAF.edge_capacities):
534
- if c < 0:
535
- raise nx.NetworkXUnfeasible(f"edge {e!r} has negative capacity")
536
- if not multigraph:
537
- edges = nx.selfloop_edges(G, data=True)
538
- else:
539
- edges = nx.selfloop_edges(G, data=True, keys=True)
540
- for e in edges:
541
- if e[-1].get(capacity, inf) < 0:
542
- raise nx.NetworkXUnfeasible(f"edge {e[:-1]!r} has negative capacity")
543
-
544
- ###########################################################################
545
- # Initialization
546
- ###########################################################################
547
-
548
- # Add a dummy node -1 and connect all existing nodes to it with infinite-
549
- # capacity dummy edges. Node -1 will serve as the root of the
550
- # spanning tree of the network simplex method. The new edges will used to
551
- # trivially satisfy the node demands and create an initial strongly
552
- # feasible spanning tree.
553
- for i, d in enumerate(DEAF.node_demands):
554
- # Must be greater-than here. Zero-demand nodes must have
555
- # edges pointing towards the root to ensure strong feasibility.
556
- if d > 0:
557
- DEAF.edge_sources.append(-1)
558
- DEAF.edge_targets.append(i)
559
- else:
560
- DEAF.edge_sources.append(i)
561
- DEAF.edge_targets.append(-1)
562
- faux_inf = (
563
- 3
564
- * max(
565
- sum(c for c in DEAF.edge_capacities if c < inf),
566
- sum(abs(w) for w in DEAF.edge_weights),
567
- sum(abs(d) for d in DEAF.node_demands),
568
- )
569
- or 1
570
- )
571
-
572
- n = len(DEAF.node_list) # number of nodes
573
- DEAF.edge_weights.extend(repeat(faux_inf, n))
574
- DEAF.edge_capacities.extend(repeat(faux_inf, n))
575
-
576
- # Construct the initial spanning tree.
577
- DEAF.initialize_spanning_tree(n, faux_inf)
578
-
579
- ###########################################################################
580
- # Pivot loop
581
- ###########################################################################
582
-
583
- for i, p, q in DEAF.find_entering_edges():
584
- Wn, We = DEAF.find_cycle(i, p, q)
585
- j, s, t = DEAF.find_leaving_edge(Wn, We)
586
- DEAF.augment_flow(Wn, We, DEAF.residual_capacity(j, s))
587
- # Do nothing more if the entering edge is the same as the leaving edge.
588
- if i != j:
589
- if DEAF.parent[t] != s:
590
- # Ensure that s is the parent of t.
591
- s, t = t, s
592
- if We.index(i) > We.index(j):
593
- # Ensure that q is in the subtree rooted at t.
594
- p, q = q, p
595
- DEAF.remove_edge(s, t)
596
- DEAF.make_root(q)
597
- DEAF.add_edge(i, p, q)
598
- DEAF.update_potentials(i, p, q)
599
-
600
- ###########################################################################
601
- # Infeasibility and unboundedness detection
602
- ###########################################################################
603
-
604
- if any(DEAF.edge_flow[i] != 0 for i in range(-n, 0)):
605
- raise nx.NetworkXUnfeasible("no flow satisfies all node demands")
606
-
607
- if any(DEAF.edge_flow[i] * 2 >= faux_inf for i in range(DEAF.edge_count)) or any(
608
- e[-1].get(capacity, inf) == inf and e[-1].get(weight, 0) < 0
609
- for e in nx.selfloop_edges(G, data=True)
610
- ):
611
- raise nx.NetworkXUnbounded("negative cycle with infinite capacity found")
612
-
613
- ###########################################################################
614
- # Flow cost calculation and flow dict construction
615
- ###########################################################################
616
-
617
- del DEAF.edge_flow[DEAF.edge_count :]
618
- flow_cost = sum(w * x for w, x in zip(DEAF.edge_weights, DEAF.edge_flow))
619
- flow_dict = {n: {} for n in DEAF.node_list}
620
-
621
- def add_entry(e):
622
- """Add a flow dict entry."""
623
- d = flow_dict[e[0]]
624
- for k in e[1:-2]:
625
- try:
626
- d = d[k]
627
- except KeyError:
628
- t = {}
629
- d[k] = t
630
- d = t
631
- d[e[-2]] = e[-1]
632
-
633
- DEAF.edge_sources = (
634
- DEAF.node_list[s] for s in DEAF.edge_sources
635
- ) # Use original nodes.
636
- DEAF.edge_targets = (
637
- DEAF.node_list[t] for t in DEAF.edge_targets
638
- ) # Use original nodes.
639
- if not multigraph:
640
- for e in zip(DEAF.edge_sources, DEAF.edge_targets, DEAF.edge_flow):
641
- add_entry(e)
642
- edges = G.edges(data=True)
643
- else:
644
- for e in zip(
645
- DEAF.edge_sources, DEAF.edge_targets, DEAF.edge_keys, DEAF.edge_flow
646
- ):
647
- add_entry(e)
648
- edges = G.edges(data=True, keys=True)
649
- for e in edges:
650
- if e[0] != e[1]:
651
- if e[-1].get(capacity, inf) == 0:
652
- add_entry(e[:-1] + (0,))
653
- else:
654
- w = e[-1].get(weight, 0)
655
- if w >= 0:
656
- add_entry(e[:-1] + (0,))
657
- else:
658
- c = e[-1][capacity]
659
- flow_cost += w * c
660
- add_entry(e[:-1] + (c,))
661
-
662
- return flow_cost, flow_dict