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,565 +0,0 @@
1
- """
2
- Greedy graph coloring using various strategies.
3
- """
4
-
5
- import itertools
6
- from collections import defaultdict, deque
7
-
8
- import networkx as nx
9
- from networkx.utils import arbitrary_element, py_random_state
10
-
11
- __all__ = [
12
- "greedy_color",
13
- "strategy_connected_sequential",
14
- "strategy_connected_sequential_bfs",
15
- "strategy_connected_sequential_dfs",
16
- "strategy_independent_set",
17
- "strategy_largest_first",
18
- "strategy_random_sequential",
19
- "strategy_saturation_largest_first",
20
- "strategy_smallest_last",
21
- ]
22
-
23
-
24
- def strategy_largest_first(G, colors):
25
- """Returns a list of the nodes of ``G`` in decreasing order by
26
- degree.
27
-
28
- ``G`` is a NetworkX graph. ``colors`` is ignored.
29
-
30
- """
31
- return sorted(G, key=G.degree, reverse=True)
32
-
33
-
34
- @py_random_state(2)
35
- def strategy_random_sequential(G, colors, seed=None):
36
- """Returns a random permutation of the nodes of ``G`` as a list.
37
-
38
- ``G`` is a NetworkX graph. ``colors`` is ignored.
39
-
40
- seed : integer, random_state, or None (default)
41
- Indicator of random number generation state.
42
- See :ref:`Randomness<randomness>`.
43
- """
44
- nodes = list(G)
45
- seed.shuffle(nodes)
46
- return nodes
47
-
48
-
49
- def strategy_smallest_last(G, colors):
50
- """Returns a deque of the nodes of ``G``, "smallest" last.
51
-
52
- Specifically, the degrees of each node are tracked in a bucket queue.
53
- From this, the node of minimum degree is repeatedly popped from the
54
- graph, updating its neighbors' degrees.
55
-
56
- ``G`` is a NetworkX graph. ``colors`` is ignored.
57
-
58
- This implementation of the strategy runs in $O(n + m)$ time
59
- (ignoring polylogarithmic factors), where $n$ is the number of nodes
60
- and $m$ is the number of edges.
61
-
62
- This strategy is related to :func:`strategy_independent_set`: if we
63
- interpret each node removed as an independent set of size one, then
64
- this strategy chooses an independent set of size one instead of a
65
- maximal independent set.
66
-
67
- """
68
- H = G.copy()
69
- result = deque()
70
-
71
- # Build initial degree list (i.e. the bucket queue data structure)
72
- degrees = defaultdict(set) # set(), for fast random-access removals
73
- lbound = float("inf")
74
- for node, d in H.degree():
75
- degrees[d].add(node)
76
- lbound = min(lbound, d) # Lower bound on min-degree.
77
-
78
- def find_min_degree():
79
- # Save time by starting the iterator at `lbound`, not 0.
80
- # The value that we find will be our new `lbound`, which we set later.
81
- return next(d for d in itertools.count(lbound) if d in degrees)
82
-
83
- for _ in G:
84
- # Pop a min-degree node and add it to the list.
85
- min_degree = find_min_degree()
86
- u = degrees[min_degree].pop()
87
- if not degrees[min_degree]: # Clean up the degree list.
88
- del degrees[min_degree]
89
- result.appendleft(u)
90
-
91
- # Update degrees of removed node's neighbors.
92
- for v in H[u]:
93
- degree = H.degree(v)
94
- degrees[degree].remove(v)
95
- if not degrees[degree]: # Clean up the degree list.
96
- del degrees[degree]
97
- degrees[degree - 1].add(v)
98
-
99
- # Finally, remove the node.
100
- H.remove_node(u)
101
- lbound = min_degree - 1 # Subtract 1 in case of tied neighbors.
102
-
103
- return result
104
-
105
-
106
- def _maximal_independent_set(G):
107
- """Returns a maximal independent set of nodes in ``G`` by repeatedly
108
- choosing an independent node of minimum degree (with respect to the
109
- subgraph of unchosen nodes).
110
-
111
- """
112
- result = set()
113
- remaining = set(G)
114
- while remaining:
115
- G = G.subgraph(remaining)
116
- v = min(remaining, key=G.degree)
117
- result.add(v)
118
- remaining -= set(G[v]) | {v}
119
- return result
120
-
121
-
122
- def strategy_independent_set(G, colors):
123
- """Uses a greedy independent set removal strategy to determine the
124
- colors.
125
-
126
- This function updates ``colors`` **in-place** and return ``None``,
127
- unlike the other strategy functions in this module.
128
-
129
- This algorithm repeatedly finds and removes a maximal independent
130
- set, assigning each node in the set an unused color.
131
-
132
- ``G`` is a NetworkX graph.
133
-
134
- This strategy is related to :func:`strategy_smallest_last`: in that
135
- strategy, an independent set of size one is chosen at each step
136
- instead of a maximal independent set.
137
-
138
- """
139
- remaining_nodes = set(G)
140
- while len(remaining_nodes) > 0:
141
- nodes = _maximal_independent_set(G.subgraph(remaining_nodes))
142
- remaining_nodes -= nodes
143
- yield from nodes
144
-
145
-
146
- def strategy_connected_sequential_bfs(G, colors):
147
- """Returns an iterable over nodes in ``G`` in the order given by a
148
- breadth-first traversal.
149
-
150
- The generated sequence has the property that for each node except
151
- the first, at least one neighbor appeared earlier in the sequence.
152
-
153
- ``G`` is a NetworkX graph. ``colors`` is ignored.
154
-
155
- """
156
- return strategy_connected_sequential(G, colors, "bfs")
157
-
158
-
159
- def strategy_connected_sequential_dfs(G, colors):
160
- """Returns an iterable over nodes in ``G`` in the order given by a
161
- depth-first traversal.
162
-
163
- The generated sequence has the property that for each node except
164
- the first, at least one neighbor appeared earlier in the sequence.
165
-
166
- ``G`` is a NetworkX graph. ``colors`` is ignored.
167
-
168
- """
169
- return strategy_connected_sequential(G, colors, "dfs")
170
-
171
-
172
- def strategy_connected_sequential(G, colors, traversal="bfs"):
173
- """Returns an iterable over nodes in ``G`` in the order given by a
174
- breadth-first or depth-first traversal.
175
-
176
- ``traversal`` must be one of the strings ``'dfs'`` or ``'bfs'``,
177
- representing depth-first traversal or breadth-first traversal,
178
- respectively.
179
-
180
- The generated sequence has the property that for each node except
181
- the first, at least one neighbor appeared earlier in the sequence.
182
-
183
- ``G`` is a NetworkX graph. ``colors`` is ignored.
184
-
185
- """
186
- if traversal == "bfs":
187
- traverse = nx.bfs_edges
188
- elif traversal == "dfs":
189
- traverse = nx.dfs_edges
190
- else:
191
- raise nx.NetworkXError(
192
- "Please specify one of the strings 'bfs' or"
193
- " 'dfs' for connected sequential ordering"
194
- )
195
- for component in nx.connected_components(G):
196
- source = arbitrary_element(component)
197
- # Yield the source node, then all the nodes in the specified
198
- # traversal order.
199
- yield source
200
- for _, end in traverse(G.subgraph(component), source):
201
- yield end
202
-
203
-
204
- def strategy_saturation_largest_first(G, colors):
205
- """Iterates over all the nodes of ``G`` in "saturation order" (also
206
- known as "DSATUR").
207
-
208
- ``G`` is a NetworkX graph. ``colors`` is a dictionary mapping nodes of
209
- ``G`` to colors, for those nodes that have already been colored.
210
-
211
- """
212
- distinct_colors = {v: set() for v in G}
213
-
214
- # Add the node color assignments given in colors to the
215
- # distinct colors set for each neighbor of that node
216
- for node, color in colors.items():
217
- for neighbor in G[node]:
218
- distinct_colors[neighbor].add(color)
219
-
220
- # Check that the color assignments in colors are valid
221
- # i.e. no neighboring nodes have the same color
222
- if len(colors) >= 2:
223
- for node, color in colors.items():
224
- if color in distinct_colors[node]:
225
- raise nx.NetworkXError("Neighboring nodes must have different colors")
226
-
227
- # If 0 nodes have been colored, simply choose the node of highest degree.
228
- if not colors:
229
- node = max(G, key=G.degree)
230
- yield node
231
- # Add the color 0 to the distinct colors set for each
232
- # neighbor of that node.
233
- for v in G[node]:
234
- distinct_colors[v].add(0)
235
-
236
- while len(G) != len(colors):
237
- # Update the distinct color sets for the neighbors.
238
- for node, color in colors.items():
239
- for neighbor in G[node]:
240
- distinct_colors[neighbor].add(color)
241
-
242
- # Compute the maximum saturation and the set of nodes that
243
- # achieve that saturation.
244
- saturation = {v: len(c) for v, c in distinct_colors.items() if v not in colors}
245
- # Yield the node with the highest saturation, and break ties by
246
- # degree.
247
- node = max(saturation, key=lambda v: (saturation[v], G.degree(v)))
248
- yield node
249
-
250
-
251
- #: Dictionary mapping name of a strategy as a string to the strategy function.
252
- STRATEGIES = {
253
- "largest_first": strategy_largest_first,
254
- "random_sequential": strategy_random_sequential,
255
- "smallest_last": strategy_smallest_last,
256
- "independent_set": strategy_independent_set,
257
- "connected_sequential_bfs": strategy_connected_sequential_bfs,
258
- "connected_sequential_dfs": strategy_connected_sequential_dfs,
259
- "connected_sequential": strategy_connected_sequential,
260
- "saturation_largest_first": strategy_saturation_largest_first,
261
- "DSATUR": strategy_saturation_largest_first,
262
- }
263
-
264
-
265
- @nx._dispatchable
266
- def greedy_color(G, strategy="largest_first", interchange=False):
267
- """Color a graph using various strategies of greedy graph coloring.
268
-
269
- Attempts to color a graph using as few colors as possible, where no
270
- neighbors of a node can have same color as the node itself. The
271
- given strategy determines the order in which nodes are colored.
272
-
273
- The strategies are described in [1]_, and smallest-last is based on
274
- [2]_.
275
-
276
- Parameters
277
- ----------
278
- G : NetworkX graph
279
-
280
- strategy : string or function(G, colors)
281
- A function (or a string representing a function) that provides
282
- the coloring strategy, by returning nodes in the ordering they
283
- should be colored. ``G`` is the graph, and ``colors`` is a
284
- dictionary of the currently assigned colors, keyed by nodes. The
285
- function must return an iterable over all the nodes in ``G``.
286
-
287
- If the strategy function is an iterator generator (that is, a
288
- function with ``yield`` statements), keep in mind that the
289
- ``colors`` dictionary will be updated after each ``yield``, since
290
- this function chooses colors greedily.
291
-
292
- If ``strategy`` is a string, it must be one of the following,
293
- each of which represents one of the built-in strategy functions.
294
-
295
- * ``'largest_first'``
296
- * ``'random_sequential'``
297
- * ``'smallest_last'``
298
- * ``'independent_set'``
299
- * ``'connected_sequential_bfs'``
300
- * ``'connected_sequential_dfs'``
301
- * ``'connected_sequential'`` (alias for the previous strategy)
302
- * ``'saturation_largest_first'``
303
- * ``'DSATUR'`` (alias for the previous strategy)
304
-
305
- interchange: bool
306
- Will use the color interchange algorithm described by [3]_ if set
307
- to ``True``.
308
-
309
- Note that ``saturation_largest_first`` and ``independent_set``
310
- do not work with interchange. Furthermore, if you use
311
- interchange with your own strategy function, you cannot rely
312
- on the values in the ``colors`` argument.
313
-
314
- Returns
315
- -------
316
- A dictionary with keys representing nodes and values representing
317
- corresponding coloring.
318
-
319
- Examples
320
- --------
321
- >>> G = nx.cycle_graph(4)
322
- >>> d = nx.coloring.greedy_color(G, strategy="largest_first")
323
- >>> d in [{0: 0, 1: 1, 2: 0, 3: 1}, {0: 1, 1: 0, 2: 1, 3: 0}]
324
- True
325
-
326
- Raises
327
- ------
328
- NetworkXPointlessConcept
329
- If ``strategy`` is ``saturation_largest_first`` or
330
- ``independent_set`` and ``interchange`` is ``True``.
331
-
332
- References
333
- ----------
334
- .. [1] Adrian Kosowski, and Krzysztof Manuszewski,
335
- Classical Coloring of Graphs, Graph Colorings, 2-19, 2004.
336
- ISBN 0-8218-3458-4.
337
- .. [2] David W. Matula, and Leland L. Beck, "Smallest-last
338
- ordering and clustering and graph coloring algorithms." *J. ACM* 30,
339
- 3 (July 1983), 417–427. <https://doi.org/10.1145/2402.322385>
340
- .. [3] Maciej M. Sysło, Narsingh Deo, Janusz S. Kowalik,
341
- Discrete Optimization Algorithms with Pascal Programs, 415-424, 1983.
342
- ISBN 0-486-45353-7.
343
-
344
- """
345
- if len(G) == 0:
346
- return {}
347
- # Determine the strategy provided by the caller.
348
- strategy = STRATEGIES.get(strategy, strategy)
349
- if not callable(strategy):
350
- raise nx.NetworkXError(
351
- f"strategy must be callable or a valid string. {strategy} not valid."
352
- )
353
- # Perform some validation on the arguments before executing any
354
- # strategy functions.
355
- if interchange:
356
- if strategy is strategy_independent_set:
357
- msg = "interchange cannot be used with independent_set"
358
- raise nx.NetworkXPointlessConcept(msg)
359
- if strategy is strategy_saturation_largest_first:
360
- msg = "interchange cannot be used with saturation_largest_first"
361
- raise nx.NetworkXPointlessConcept(msg)
362
- colors = {}
363
- nodes = strategy(G, colors)
364
- if interchange:
365
- return _greedy_coloring_with_interchange(G, nodes)
366
- for u in nodes:
367
- # Set to keep track of colors of neighbors
368
- nbr_colors = {colors[v] for v in G[u] if v in colors}
369
- # Find the first unused color.
370
- for color in itertools.count():
371
- if color not in nbr_colors:
372
- break
373
- # Assign the new color to the current node.
374
- colors[u] = color
375
- return colors
376
-
377
-
378
- # Tools for coloring with interchanges
379
- class _Node:
380
- __slots__ = ["node_id", "color", "adj_list", "adj_color"]
381
-
382
- def __init__(self, node_id, n):
383
- self.node_id = node_id
384
- self.color = -1
385
- self.adj_list = None
386
- self.adj_color = [None for _ in range(n)]
387
-
388
- def __repr__(self):
389
- return (
390
- f"Node_id: {self.node_id}, Color: {self.color}, "
391
- f"Adj_list: ({self.adj_list}), adj_color: ({self.adj_color})"
392
- )
393
-
394
- def assign_color(self, adj_entry, color):
395
- adj_entry.col_prev = None
396
- adj_entry.col_next = self.adj_color[color]
397
- self.adj_color[color] = adj_entry
398
- if adj_entry.col_next is not None:
399
- adj_entry.col_next.col_prev = adj_entry
400
-
401
- def clear_color(self, adj_entry, color):
402
- if adj_entry.col_prev is None:
403
- self.adj_color[color] = adj_entry.col_next
404
- else:
405
- adj_entry.col_prev.col_next = adj_entry.col_next
406
- if adj_entry.col_next is not None:
407
- adj_entry.col_next.col_prev = adj_entry.col_prev
408
-
409
- def iter_neighbors(self):
410
- adj_node = self.adj_list
411
- while adj_node is not None:
412
- yield adj_node
413
- adj_node = adj_node.next
414
-
415
- def iter_neighbors_color(self, color):
416
- adj_color_node = self.adj_color[color]
417
- while adj_color_node is not None:
418
- yield adj_color_node.node_id
419
- adj_color_node = adj_color_node.col_next
420
-
421
-
422
- class _AdjEntry:
423
- __slots__ = ["node_id", "next", "mate", "col_next", "col_prev"]
424
-
425
- def __init__(self, node_id):
426
- self.node_id = node_id
427
- self.next = None
428
- self.mate = None
429
- self.col_next = None
430
- self.col_prev = None
431
-
432
- def __repr__(self):
433
- col_next = None if self.col_next is None else self.col_next.node_id
434
- col_prev = None if self.col_prev is None else self.col_prev.node_id
435
- return (
436
- f"Node_id: {self.node_id}, Next: ({self.next}), "
437
- f"Mate: ({self.mate.node_id}), "
438
- f"col_next: ({col_next}), col_prev: ({col_prev})"
439
- )
440
-
441
-
442
- def _greedy_coloring_with_interchange(G, nodes):
443
- """Return a coloring for `original_graph` using interchange approach
444
-
445
- This procedure is an adaption of the algorithm described by [1]_,
446
- and is an implementation of coloring with interchange. Please be
447
- advised, that the datastructures used are rather complex because
448
- they are optimized to minimize the time spent identifying
449
- subcomponents of the graph, which are possible candidates for color
450
- interchange.
451
-
452
- Parameters
453
- ----------
454
- G : NetworkX graph
455
- The graph to be colored
456
-
457
- nodes : list
458
- nodes ordered using the strategy of choice
459
-
460
- Returns
461
- -------
462
- dict :
463
- A dictionary keyed by node to a color value
464
-
465
- References
466
- ----------
467
- .. [1] Maciej M. Syslo, Narsingh Deo, Janusz S. Kowalik,
468
- Discrete Optimization Algorithms with Pascal Programs, 415-424, 1983.
469
- ISBN 0-486-45353-7.
470
- """
471
- n = len(G)
472
-
473
- graph = {node: _Node(node, n) for node in G}
474
-
475
- for node1, node2 in G.edges():
476
- adj_entry1 = _AdjEntry(node2)
477
- adj_entry2 = _AdjEntry(node1)
478
- adj_entry1.mate = adj_entry2
479
- adj_entry2.mate = adj_entry1
480
- node1_head = graph[node1].adj_list
481
- adj_entry1.next = node1_head
482
- graph[node1].adj_list = adj_entry1
483
- node2_head = graph[node2].adj_list
484
- adj_entry2.next = node2_head
485
- graph[node2].adj_list = adj_entry2
486
-
487
- k = 0
488
- for node in nodes:
489
- # Find the smallest possible, unused color
490
- neighbors = graph[node].iter_neighbors()
491
- col_used = {graph[adj_node.node_id].color for adj_node in neighbors}
492
- col_used.discard(-1)
493
- k1 = next(itertools.dropwhile(lambda x: x in col_used, itertools.count()))
494
-
495
- # k1 is now the lowest available color
496
- if k1 > k:
497
- connected = True
498
- visited = set()
499
- col1 = -1
500
- col2 = -1
501
- while connected and col1 < k:
502
- col1 += 1
503
- neighbor_cols = graph[node].iter_neighbors_color(col1)
504
- col1_adj = list(neighbor_cols)
505
-
506
- col2 = col1
507
- while connected and col2 < k:
508
- col2 += 1
509
- visited = set(col1_adj)
510
- frontier = list(col1_adj)
511
- i = 0
512
- while i < len(frontier):
513
- search_node = frontier[i]
514
- i += 1
515
- col_opp = col2 if graph[search_node].color == col1 else col1
516
- neighbor_cols = graph[search_node].iter_neighbors_color(col_opp)
517
-
518
- for neighbor in neighbor_cols:
519
- if neighbor not in visited:
520
- visited.add(neighbor)
521
- frontier.append(neighbor)
522
-
523
- # Search if node is not adj to any col2 vertex
524
- connected = (
525
- len(
526
- visited.intersection(graph[node].iter_neighbors_color(col2))
527
- )
528
- > 0
529
- )
530
-
531
- # If connected is false then we can swap !!!
532
- if not connected:
533
- # Update all the nodes in the component
534
- for search_node in visited:
535
- graph[search_node].color = (
536
- col2 if graph[search_node].color == col1 else col1
537
- )
538
- col2_adj = graph[search_node].adj_color[col2]
539
- graph[search_node].adj_color[col2] = graph[search_node].adj_color[
540
- col1
541
- ]
542
- graph[search_node].adj_color[col1] = col2_adj
543
-
544
- # Update all the neighboring nodes
545
- for search_node in visited:
546
- col = graph[search_node].color
547
- col_opp = col1 if col == col2 else col2
548
- for adj_node in graph[search_node].iter_neighbors():
549
- if graph[adj_node.node_id].color != col_opp:
550
- # Direct reference to entry
551
- adj_mate = adj_node.mate
552
- graph[adj_node.node_id].clear_color(adj_mate, col_opp)
553
- graph[adj_node.node_id].assign_color(adj_mate, col)
554
- k1 = col1
555
-
556
- # We can color this node color k1
557
- graph[node].color = k1
558
- k = max(k1, k)
559
-
560
- # Update the neighbors of this node
561
- for adj_node in graph[node].iter_neighbors():
562
- adj_mate = adj_node.mate
563
- graph[adj_node.node_id].assign_color(adj_mate, k1)
564
-
565
- return {node.node_id: node.color for node in graph.values()}