okstra 0.114.0 → 0.116.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 (337) hide show
  1. package/docs/kr/architecture.md +2 -2
  2. package/docs/kr/follow-ups/2026-07-10-final-report-option-3.md +51 -0
  3. package/package.json +1 -1
  4. package/runtime/BUILD.json +2 -2
  5. package/runtime/agents/workers/report-writer-worker.md +1 -0
  6. package/runtime/prompts/launch.template.md +34 -0
  7. package/runtime/prompts/lead/convergence.md +2 -0
  8. package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
  9. package/runtime/prompts/lead/report-writer.md +1 -1
  10. package/runtime/prompts/profiles/implementation-planning.md +1 -0
  11. package/runtime/python/okstra_ctl/implementation_stage.py +46 -39
  12. package/runtime/python/okstra_ctl/incremental_carry.py +70 -0
  13. package/runtime/python/okstra_ctl/incremental_scope.py +89 -0
  14. package/runtime/python/okstra_ctl/report_views.py +151 -12
  15. package/runtime/python/okstra_ctl/run.py +24 -24
  16. package/runtime/python/okstra_ctl/stage_targets.py +26 -0
  17. package/runtime/python/okstra_ctl/worktree.py +1 -1
  18. package/runtime/python/okstra_token_usage/claude.py +58 -19
  19. package/runtime/python/okstra_token_usage/collect.py +3 -1
  20. package/runtime/python/okstra_vendor/__init__.py +3 -0
  21. package/runtime/schemas/final-report-v1.0.schema.json +39 -0
  22. package/runtime/templates/reports/final-report.template.md +27 -0
  23. package/runtime/templates/reports/i18n/en.json +23 -12
  24. package/runtime/templates/reports/i18n/ko.json +23 -12
  25. package/runtime/templates/reports/report.css +55 -0
  26. package/runtime/templates/reports/report.js +53 -1
  27. package/runtime/validators/validate-run.py +50 -0
  28. package/src/cli-registry.mjs +14 -0
  29. package/src/commands/execute/incremental-carry.mjs +20 -0
  30. package/src/commands/execute/incremental-scope.mjs +20 -0
  31. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  32. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +0 -41
  33. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +0 -112
  34. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +0 -199
  35. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +0 -146
  36. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +0 -59
  37. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +0 -78
  38. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +0 -303
  39. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +0 -8
  40. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +0 -94
  41. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +0 -31
  42. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +0 -306
  43. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +0 -1014
  44. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +0 -274
  45. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +0 -68
  46. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  47. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +0 -81
  48. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +0 -143
  49. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +0 -122
  50. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +0 -174
  51. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +0 -107
  52. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +0 -87
  53. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  54. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +0 -125
  55. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +0 -192
  56. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +0 -84
  57. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +0 -33
  58. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +0 -240
  59. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +0 -334
  60. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +0 -407
  61. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +0 -218
  62. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +0 -327
  63. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +0 -138
  64. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +0 -409
  65. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +0 -35
  66. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +0 -80
  67. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  68. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +0 -923
  69. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +0 -354
  70. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +0 -274
  71. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +0 -259
  72. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +0 -147
  73. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +0 -43
  74. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +0 -144
  75. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +0 -73
  76. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +0 -186
  77. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +0 -277
  78. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +0 -122
  79. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +0 -345
  80. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +0 -220
  81. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +0 -344
  82. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +0 -87
  83. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +0 -140
  84. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +0 -82
  85. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +0 -110
  86. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +0 -302
  87. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +0 -64
  88. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  89. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +0 -863
  90. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  91. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +0 -147
  92. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +0 -157
  93. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +0 -85
  94. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +0 -106
  95. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +0 -91
  96. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +0 -241
  97. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +0 -138
  98. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +0 -76
  99. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +0 -264
  100. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +0 -152
  101. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +0 -340
  102. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +0 -139
  103. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +0 -26
  104. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  105. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +0 -70
  106. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +0 -248
  107. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +0 -138
  108. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +0 -55
  109. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +0 -193
  110. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +0 -96
  111. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +0 -421
  113. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +0 -309
  114. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +0 -249
  115. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +0 -502
  116. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +0 -488
  117. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +0 -323
  118. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +0 -280
  119. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +0 -102
  120. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +0 -128
  125. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +0 -573
  126. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +0 -155
  127. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +0 -475
  128. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +0 -481
  129. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  130. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  131. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  132. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  133. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  135. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +0 -719
  136. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +0 -103
  137. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +0 -490
  138. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +0 -64
  139. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +0 -212
  140. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +0 -202
  141. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +0 -1655
  142. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +0 -3118
  143. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +0 -196
  144. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  145. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +0 -77
  146. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +0 -213
  147. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +0 -544
  148. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  149. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +0 -328
  150. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +0 -451
  151. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +0 -491
  152. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +0 -55
  153. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  154. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +0 -254
  155. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +0 -212
  156. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +0 -88
  157. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +0 -511
  158. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +0 -149
  159. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +0 -983
  160. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  161. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +0 -23
  162. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +0 -154
  163. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +0 -144
  164. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +0 -109
  165. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +0 -136
  166. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +0 -129
  167. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +0 -300
  168. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +0 -678
  169. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +0 -80
  170. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +0 -266
  171. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +0 -85
  172. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +0 -171
  173. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +0 -984
  174. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +0 -340
  175. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +0 -835
  176. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +0 -831
  177. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +0 -85
  178. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +0 -299
  179. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +0 -115
  180. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +0 -58
  181. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +0 -314
  182. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +0 -872
  183. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +0 -163
  184. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +0 -46
  185. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +0 -24
  186. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +0 -26
  187. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +0 -615
  188. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +0 -459
  189. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +0 -556
  190. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +0 -179
  191. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +0 -62
  192. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +0 -15
  193. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +0 -140
  194. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +0 -60
  195. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +0 -27
  196. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +0 -274
  197. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +0 -556
  198. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +0 -57
  199. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +0 -37
  200. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +0 -88
  201. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +0 -149
  202. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +0 -1158
  203. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +0 -803
  204. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +0 -76
  205. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +0 -8
  206. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +0 -138
  207. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +0 -191
  208. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +0 -642
  209. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +0 -179
  210. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +0 -270
  211. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +0 -431
  212. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +0 -161
  213. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +0 -248
  214. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +0 -41
  215. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +0 -103
  216. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +0 -54
  217. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +0 -157
  218. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  219. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +0 -25
  220. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +0 -203
  221. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +0 -307
  222. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +0 -147
  223. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +0 -131
  224. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  225. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +0 -624
  226. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +0 -114
  227. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +0 -79
  228. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +0 -99
  229. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +0 -934
  230. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +0 -53
  231. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +0 -174
  232. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  233. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +0 -192
  234. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +0 -476
  235. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +0 -362
  236. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +0 -331
  237. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +0 -110
  238. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +0 -177
  239. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +0 -1045
  240. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +0 -950
  241. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +0 -12
  242. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +0 -349
  243. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +0 -459
  244. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +0 -528
  245. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +0 -1421
  246. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +0 -131
  247. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +0 -371
  248. package/runtime/python/okstra_vendor/networkx/conftest.py +0 -261
  249. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  250. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  251. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  252. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  253. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  254. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  255. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  256. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +0 -237
  257. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +0 -229
  258. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +0 -285
  259. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +0 -631
  260. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +0 -146
  261. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +0 -1582
  262. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  263. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +0 -75
  264. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +0 -642
  265. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +0 -20
  266. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +0 -362
  267. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +0 -224
  268. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +0 -189
  269. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +0 -103
  270. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +0 -39
  271. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +0 -182
  272. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +0 -488
  273. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +0 -133
  274. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +0 -221
  275. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +0 -28
  276. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +0 -144
  277. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +0 -125
  278. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +0 -264
  279. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +0 -316
  280. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +0 -30
  281. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +0 -82
  282. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +0 -33
  283. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +0 -495
  284. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +0 -220
  285. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +0 -49
  286. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +0 -72
  287. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +0 -92
  288. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +0 -64
  289. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +0 -195
  290. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +0 -15
  291. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  292. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +0 -400
  293. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +0 -108
  294. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +0 -40
  295. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +0 -275
  296. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +0 -334
  297. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +0 -86
  298. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +0 -70
  299. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  300. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +0 -78
  301. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +0 -78
  302. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +0 -109
  303. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +0 -48
  304. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  305. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +0 -354
  306. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +0 -318
  307. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +0 -612
  308. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +0 -744
  309. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +0 -181
  310. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +0 -1531
  311. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +0 -30
  312. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +0 -63
  313. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +0 -128
  314. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +0 -166
  315. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +0 -1742
  316. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  317. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +0 -248
  318. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +0 -321
  319. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +0 -531
  320. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +0 -349
  321. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +0 -281
  322. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +0 -40
  323. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +0 -11
  324. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +0 -96
  325. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +0 -349
  326. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +0 -8
  327. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  328. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +0 -11
  329. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +0 -225
  330. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +0 -263
  331. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +0 -510
  332. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +0 -131
  333. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +0 -268
  334. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +0 -393
  335. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +0 -53
  336. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +0 -63
  337. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +0 -55
@@ -1,983 +0,0 @@
1
- import pytest
2
-
3
- import networkx as nx
4
- from networkx.utils import pairwise
5
-
6
-
7
- def validate_path(G, s, t, soln_len, path, weight="weight"):
8
- assert path[0] == s
9
- assert path[-1] == t
10
-
11
- if callable(weight):
12
- weight_f = weight
13
- else:
14
- if G.is_multigraph():
15
-
16
- def weight_f(u, v, d):
17
- return min(e.get(weight, 1) for e in d.values())
18
-
19
- else:
20
-
21
- def weight_f(u, v, d):
22
- return d.get(weight, 1)
23
-
24
- computed = sum(weight_f(u, v, G[u][v]) for u, v in pairwise(path))
25
- assert soln_len == computed
26
-
27
-
28
- def validate_length_path(G, s, t, soln_len, length, path, weight="weight"):
29
- assert soln_len == length
30
- validate_path(G, s, t, length, path, weight=weight)
31
-
32
-
33
- class WeightedTestBase:
34
- """Base class for test classes that test functions for computing
35
- shortest paths in weighted graphs.
36
-
37
- """
38
-
39
- def setup_method(self):
40
- """Creates some graphs for use in the unit tests."""
41
- cnlti = nx.convert_node_labels_to_integers
42
- self.grid = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
43
- self.cycle = nx.cycle_graph(7)
44
- self.directed_cycle = nx.cycle_graph(7, create_using=nx.DiGraph())
45
- self.XG = nx.DiGraph()
46
- self.XG.add_weighted_edges_from(
47
- [
48
- ("s", "u", 10),
49
- ("s", "x", 5),
50
- ("u", "v", 1),
51
- ("u", "x", 2),
52
- ("v", "y", 1),
53
- ("x", "u", 3),
54
- ("x", "v", 5),
55
- ("x", "y", 2),
56
- ("y", "s", 7),
57
- ("y", "v", 6),
58
- ]
59
- )
60
- self.MXG = nx.MultiDiGraph(self.XG)
61
- self.MXG.add_edge("s", "u", weight=15)
62
- self.XG2 = nx.DiGraph()
63
- self.XG2.add_weighted_edges_from(
64
- [
65
- [1, 4, 1],
66
- [4, 5, 1],
67
- [5, 6, 1],
68
- [6, 3, 1],
69
- [1, 3, 50],
70
- [1, 2, 100],
71
- [2, 3, 100],
72
- ]
73
- )
74
-
75
- self.XG3 = nx.Graph()
76
- self.XG3.add_weighted_edges_from(
77
- [[0, 1, 2], [1, 2, 12], [2, 3, 1], [3, 4, 5], [4, 5, 1], [5, 0, 10]]
78
- )
79
-
80
- self.XG4 = nx.Graph()
81
- self.XG4.add_weighted_edges_from(
82
- [
83
- [0, 1, 2],
84
- [1, 2, 2],
85
- [2, 3, 1],
86
- [3, 4, 1],
87
- [4, 5, 1],
88
- [5, 6, 1],
89
- [6, 7, 1],
90
- [7, 0, 1],
91
- ]
92
- )
93
- self.MXG4 = nx.MultiGraph(self.XG4)
94
- self.MXG4.add_edge(0, 1, weight=3)
95
- self.G = nx.DiGraph() # no weights
96
- self.G.add_edges_from(
97
- [
98
- ("s", "u"),
99
- ("s", "x"),
100
- ("u", "v"),
101
- ("u", "x"),
102
- ("v", "y"),
103
- ("x", "u"),
104
- ("x", "v"),
105
- ("x", "y"),
106
- ("y", "s"),
107
- ("y", "v"),
108
- ]
109
- )
110
-
111
-
112
- class TestWeightedPath(WeightedTestBase):
113
- def test_dijkstra(self):
114
- (D, P) = nx.single_source_dijkstra(self.XG, "s")
115
- validate_path(self.XG, "s", "v", 9, P["v"])
116
- assert D["v"] == 9
117
-
118
- validate_path(
119
- self.XG, "s", "v", 9, nx.single_source_dijkstra_path(self.XG, "s")["v"]
120
- )
121
- assert nx.single_source_dijkstra_path_length(self.XG, "s")["v"] == 9
122
-
123
- validate_path(
124
- self.XG, "s", "v", 9, nx.single_source_dijkstra(self.XG, "s")[1]["v"]
125
- )
126
- validate_path(
127
- self.MXG, "s", "v", 9, nx.single_source_dijkstra_path(self.MXG, "s")["v"]
128
- )
129
-
130
- GG = self.XG.to_undirected()
131
- # make sure we get lower weight
132
- # to_undirected might choose either edge with weight 2 or weight 3
133
- GG["u"]["x"]["weight"] = 2
134
- (D, P) = nx.single_source_dijkstra(GG, "s")
135
- validate_path(GG, "s", "v", 8, P["v"])
136
- assert D["v"] == 8 # uses lower weight of 2 on u<->x edge
137
- validate_path(GG, "s", "v", 8, nx.dijkstra_path(GG, "s", "v"))
138
- assert nx.dijkstra_path_length(GG, "s", "v") == 8
139
-
140
- validate_path(self.XG2, 1, 3, 4, nx.dijkstra_path(self.XG2, 1, 3))
141
- validate_path(self.XG3, 0, 3, 15, nx.dijkstra_path(self.XG3, 0, 3))
142
- assert nx.dijkstra_path_length(self.XG3, 0, 3) == 15
143
- validate_path(self.XG4, 0, 2, 4, nx.dijkstra_path(self.XG4, 0, 2))
144
- assert nx.dijkstra_path_length(self.XG4, 0, 2) == 4
145
- validate_path(self.MXG4, 0, 2, 4, nx.dijkstra_path(self.MXG4, 0, 2))
146
- validate_path(
147
- self.G, "s", "v", 2, nx.single_source_dijkstra(self.G, "s", "v")[1]
148
- )
149
- validate_path(
150
- self.G, "s", "v", 2, nx.single_source_dijkstra(self.G, "s")[1]["v"]
151
- )
152
-
153
- validate_path(self.G, "s", "v", 2, nx.dijkstra_path(self.G, "s", "v"))
154
- assert nx.dijkstra_path_length(self.G, "s", "v") == 2
155
-
156
- # NetworkXError: node s not reachable from moon
157
- pytest.raises(nx.NetworkXNoPath, nx.dijkstra_path, self.G, "s", "moon")
158
- pytest.raises(nx.NetworkXNoPath, nx.dijkstra_path_length, self.G, "s", "moon")
159
-
160
- validate_path(self.cycle, 0, 3, 3, nx.dijkstra_path(self.cycle, 0, 3))
161
- validate_path(self.cycle, 0, 4, 3, nx.dijkstra_path(self.cycle, 0, 4))
162
-
163
- assert nx.single_source_dijkstra(self.cycle, 0, 0) == (0, [0])
164
-
165
- def test_bidirectional_dijkstra(self):
166
- validate_length_path(
167
- self.XG, "s", "v", 9, *nx.bidirectional_dijkstra(self.XG, "s", "v")
168
- )
169
- validate_length_path(
170
- self.G, "s", "v", 2, *nx.bidirectional_dijkstra(self.G, "s", "v")
171
- )
172
- validate_length_path(
173
- self.cycle, 0, 3, 3, *nx.bidirectional_dijkstra(self.cycle, 0, 3)
174
- )
175
- validate_length_path(
176
- self.cycle, 0, 4, 3, *nx.bidirectional_dijkstra(self.cycle, 0, 4)
177
- )
178
- validate_length_path(
179
- self.XG3, 0, 3, 15, *nx.bidirectional_dijkstra(self.XG3, 0, 3)
180
- )
181
- validate_length_path(
182
- self.XG4, 0, 2, 4, *nx.bidirectional_dijkstra(self.XG4, 0, 2)
183
- )
184
-
185
- # need more tests here
186
- P = nx.single_source_dijkstra_path(self.XG, "s")["v"]
187
- validate_path(
188
- self.XG,
189
- "s",
190
- "v",
191
- sum(self.XG[u][v]["weight"] for u, v in zip(P[:-1], P[1:])),
192
- nx.dijkstra_path(self.XG, "s", "v"),
193
- )
194
-
195
- # check absent source
196
- G = nx.path_graph(2)
197
- pytest.raises(nx.NodeNotFound, nx.bidirectional_dijkstra, G, 3, 0)
198
-
199
- def test_weight_functions(self):
200
- def heuristic(*z):
201
- return sum(val**2 for val in z)
202
-
203
- def getpath(pred, v, s):
204
- return [v] if v == s else getpath(pred, pred[v], s) + [v]
205
-
206
- def goldberg_radzik(g, s, t, weight="weight"):
207
- pred, dist = nx.goldberg_radzik(g, s, weight=weight)
208
- dist = dist[t]
209
- return dist, getpath(pred, t, s)
210
-
211
- def astar(g, s, t, weight="weight"):
212
- path = nx.astar_path(g, s, t, heuristic, weight=weight)
213
- dist = nx.astar_path_length(g, s, t, heuristic, weight=weight)
214
- return dist, path
215
-
216
- def vlp(G, s, t, l, F, w):
217
- res = F(G, s, t, weight=w)
218
- validate_length_path(G, s, t, l, *res, weight=w)
219
-
220
- G = self.cycle
221
- s = 6
222
- t = 4
223
- path = [6] + list(range(t + 1))
224
-
225
- def weight(u, v, _):
226
- return 1 + v**2
227
-
228
- length = sum(weight(u, v, None) for u, v in pairwise(path))
229
- vlp(G, s, t, length, nx.bidirectional_dijkstra, weight)
230
- vlp(G, s, t, length, nx.single_source_dijkstra, weight)
231
- vlp(G, s, t, length, nx.single_source_bellman_ford, weight)
232
- vlp(G, s, t, length, goldberg_radzik, weight)
233
- vlp(G, s, t, length, astar, weight)
234
-
235
- def weight(u, v, _):
236
- return 2 ** (u * v)
237
-
238
- length = sum(weight(u, v, None) for u, v in pairwise(path))
239
- vlp(G, s, t, length, nx.bidirectional_dijkstra, weight)
240
- vlp(G, s, t, length, nx.single_source_dijkstra, weight)
241
- vlp(G, s, t, length, nx.single_source_bellman_ford, weight)
242
- vlp(G, s, t, length, goldberg_radzik, weight)
243
- vlp(G, s, t, length, astar, weight)
244
-
245
- def test_bidirectional_dijkstra_no_path(self):
246
- with pytest.raises(nx.NetworkXNoPath):
247
- G = nx.Graph()
248
- nx.add_path(G, [1, 2, 3])
249
- nx.add_path(G, [4, 5, 6])
250
- path = nx.bidirectional_dijkstra(G, 1, 6)
251
-
252
- @pytest.mark.parametrize(
253
- "fn",
254
- (
255
- nx.dijkstra_path,
256
- nx.dijkstra_path_length,
257
- nx.single_source_dijkstra_path,
258
- nx.single_source_dijkstra_path_length,
259
- nx.single_source_dijkstra,
260
- nx.dijkstra_predecessor_and_distance,
261
- ),
262
- )
263
- def test_absent_source(self, fn):
264
- G = nx.path_graph(2)
265
- with pytest.raises(nx.NodeNotFound):
266
- fn(G, 3, 0)
267
- # Test when source == target, which is handled specially by some functions
268
- with pytest.raises(nx.NodeNotFound):
269
- fn(G, 3, 3)
270
-
271
- def test_dijkstra_predecessor1(self):
272
- G = nx.path_graph(4)
273
- assert nx.dijkstra_predecessor_and_distance(G, 0) == (
274
- {0: [], 1: [0], 2: [1], 3: [2]},
275
- {0: 0, 1: 1, 2: 2, 3: 3},
276
- )
277
-
278
- def test_dijkstra_predecessor2(self):
279
- # 4-cycle
280
- G = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 0)])
281
- pred, dist = nx.dijkstra_predecessor_and_distance(G, (0))
282
- assert pred[0] == []
283
- assert pred[1] == [0]
284
- assert pred[2] in [[1, 3], [3, 1]]
285
- assert pred[3] == [0]
286
- assert dist == {0: 0, 1: 1, 2: 2, 3: 1}
287
-
288
- def test_dijkstra_predecessor3(self):
289
- XG = nx.DiGraph()
290
- XG.add_weighted_edges_from(
291
- [
292
- ("s", "u", 10),
293
- ("s", "x", 5),
294
- ("u", "v", 1),
295
- ("u", "x", 2),
296
- ("v", "y", 1),
297
- ("x", "u", 3),
298
- ("x", "v", 5),
299
- ("x", "y", 2),
300
- ("y", "s", 7),
301
- ("y", "v", 6),
302
- ]
303
- )
304
- (P, D) = nx.dijkstra_predecessor_and_distance(XG, "s")
305
- assert P["v"] == ["u"]
306
- assert D["v"] == 9
307
- (P, D) = nx.dijkstra_predecessor_and_distance(XG, "s", cutoff=8)
308
- assert "v" not in D
309
-
310
- def test_single_source_dijkstra_path_length(self):
311
- pl = nx.single_source_dijkstra_path_length
312
- assert dict(pl(self.MXG4, 0))[2] == 4
313
- spl = pl(self.MXG4, 0, cutoff=2)
314
- assert 2 not in spl
315
-
316
- def test_bidirectional_dijkstra_multigraph(self):
317
- G = nx.MultiGraph()
318
- G.add_edge("a", "b", weight=10)
319
- G.add_edge("a", "b", weight=100)
320
- dp = nx.bidirectional_dijkstra(G, "a", "b")
321
- assert dp == (10, ["a", "b"])
322
-
323
- def test_dijkstra_pred_distance_multigraph(self):
324
- G = nx.MultiGraph()
325
- G.add_edge("a", "b", key="short", foo=5, weight=100)
326
- G.add_edge("a", "b", key="long", bar=1, weight=110)
327
- p, d = nx.dijkstra_predecessor_and_distance(G, "a")
328
- assert p == {"a": [], "b": ["a"]}
329
- assert d == {"a": 0, "b": 100}
330
-
331
- def test_negative_edge_cycle(self):
332
- G = nx.cycle_graph(5, create_using=nx.DiGraph())
333
- assert not nx.negative_edge_cycle(G)
334
- G.add_edge(8, 9, weight=-7)
335
- G.add_edge(9, 8, weight=3)
336
- graph_size = len(G)
337
- assert nx.negative_edge_cycle(G)
338
- assert graph_size == len(G)
339
- pytest.raises(ValueError, nx.single_source_dijkstra_path_length, G, 8)
340
- pytest.raises(ValueError, nx.single_source_dijkstra, G, 8)
341
- pytest.raises(ValueError, nx.dijkstra_predecessor_and_distance, G, 8)
342
- G.add_edge(9, 10)
343
- pytest.raises(ValueError, nx.bidirectional_dijkstra, G, 8, 10)
344
- G = nx.MultiDiGraph()
345
- G.add_edge(2, 2, weight=-1)
346
- assert nx.negative_edge_cycle(G)
347
-
348
- def test_negative_edge_cycle_empty(self):
349
- G = nx.DiGraph()
350
- assert not nx.negative_edge_cycle(G)
351
-
352
- def test_negative_edge_cycle_custom_weight_key(self):
353
- d = nx.DiGraph()
354
- d.add_edge("a", "b", w=-2)
355
- d.add_edge("b", "a", w=-1)
356
- assert nx.negative_edge_cycle(d, weight="w")
357
-
358
- def test_weight_function(self):
359
- """Tests that a callable weight is interpreted as a weight
360
- function instead of an edge attribute.
361
-
362
- """
363
- # Create a triangle in which the edge from node 0 to node 2 has
364
- # a large weight and the other two edges have a small weight.
365
- G = nx.complete_graph(3)
366
- G.adj[0][2]["weight"] = 10
367
- G.adj[0][1]["weight"] = 1
368
- G.adj[1][2]["weight"] = 1
369
-
370
- # The weight function will take the multiplicative inverse of
371
- # the weights on the edges. This way, weights that were large
372
- # before now become small and vice versa.
373
-
374
- def weight(u, v, d):
375
- return 1 / d["weight"]
376
-
377
- # The shortest path from 0 to 2 using the actual weights on the
378
- # edges should be [0, 1, 2].
379
- distance, path = nx.single_source_dijkstra(G, 0, 2)
380
- assert distance == 2
381
- assert path == [0, 1, 2]
382
- # However, with the above weight function, the shortest path
383
- # should be [0, 2], since that has a very small weight.
384
- distance, path = nx.single_source_dijkstra(G, 0, 2, weight=weight)
385
- assert distance == 1 / 10
386
- assert path == [0, 2]
387
-
388
- def test_all_pairs_dijkstra_path(self):
389
- cycle = nx.cycle_graph(7)
390
- p = dict(nx.all_pairs_dijkstra_path(cycle))
391
- assert p[0][3] == [0, 1, 2, 3]
392
-
393
- cycle[1][2]["weight"] = 10
394
- p = dict(nx.all_pairs_dijkstra_path(cycle))
395
- assert p[0][3] == [0, 6, 5, 4, 3]
396
-
397
- def test_all_pairs_dijkstra_path_length(self):
398
- cycle = nx.cycle_graph(7)
399
- pl = dict(nx.all_pairs_dijkstra_path_length(cycle))
400
- assert pl[0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}
401
-
402
- cycle[1][2]["weight"] = 10
403
- pl = dict(nx.all_pairs_dijkstra_path_length(cycle))
404
- assert pl[0] == {0: 0, 1: 1, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1}
405
-
406
- def test_all_pairs_dijkstra(self):
407
- cycle = nx.cycle_graph(7)
408
- out = dict(nx.all_pairs_dijkstra(cycle))
409
- assert out[0][0] == {0: 0, 1: 1, 2: 2, 3: 3, 4: 3, 5: 2, 6: 1}
410
- assert out[0][1][3] == [0, 1, 2, 3]
411
-
412
- cycle[1][2]["weight"] = 10
413
- out = dict(nx.all_pairs_dijkstra(cycle))
414
- assert out[0][0] == {0: 0, 1: 1, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1}
415
- assert out[0][1][3] == [0, 6, 5, 4, 3]
416
-
417
-
418
- class TestDijkstraPathLength:
419
- """Unit tests for the :func:`networkx.dijkstra_path_length`
420
- function.
421
-
422
- """
423
-
424
- def test_weight_function(self):
425
- """Tests for computing the length of the shortest path using
426
- Dijkstra's algorithm with a user-defined weight function.
427
-
428
- """
429
- # Create a triangle in which the edge from node 0 to node 2 has
430
- # a large weight and the other two edges have a small weight.
431
- G = nx.complete_graph(3)
432
- G.adj[0][2]["weight"] = 10
433
- G.adj[0][1]["weight"] = 1
434
- G.adj[1][2]["weight"] = 1
435
-
436
- # The weight function will take the multiplicative inverse of
437
- # the weights on the edges. This way, weights that were large
438
- # before now become small and vice versa.
439
-
440
- def weight(u, v, d):
441
- return 1 / d["weight"]
442
-
443
- # The shortest path from 0 to 2 using the actual weights on the
444
- # edges should be [0, 1, 2]. However, with the above weight
445
- # function, the shortest path should be [0, 2], since that has a
446
- # very small weight.
447
- length = nx.dijkstra_path_length(G, 0, 2, weight=weight)
448
- assert length == 1 / 10
449
-
450
-
451
- class TestMultiSourceDijkstra:
452
- """Unit tests for the multi-source dialect of Dijkstra's shortest
453
- path algorithms.
454
-
455
- """
456
-
457
- def test_no_sources(self):
458
- with pytest.raises(ValueError):
459
- nx.multi_source_dijkstra(nx.Graph(), {})
460
-
461
- def test_path_no_sources(self):
462
- with pytest.raises(ValueError):
463
- nx.multi_source_dijkstra_path(nx.Graph(), {})
464
-
465
- def test_path_length_no_sources(self):
466
- with pytest.raises(ValueError):
467
- nx.multi_source_dijkstra_path_length(nx.Graph(), {})
468
-
469
- @pytest.mark.parametrize(
470
- "fn",
471
- (
472
- nx.multi_source_dijkstra_path,
473
- nx.multi_source_dijkstra_path_length,
474
- nx.multi_source_dijkstra,
475
- ),
476
- )
477
- def test_absent_source(self, fn):
478
- G = nx.path_graph(2)
479
- with pytest.raises(nx.NodeNotFound):
480
- fn(G, [3], 0)
481
- with pytest.raises(nx.NodeNotFound):
482
- fn(G, [3], 3)
483
-
484
- def test_two_sources(self):
485
- edges = [(0, 1, 1), (1, 2, 1), (2, 3, 10), (3, 4, 1)]
486
- G = nx.Graph()
487
- G.add_weighted_edges_from(edges)
488
- sources = {0, 4}
489
- distances, paths = nx.multi_source_dijkstra(G, sources)
490
- expected_distances = {0: 0, 1: 1, 2: 2, 3: 1, 4: 0}
491
- expected_paths = {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [4, 3], 4: [4]}
492
- assert distances == expected_distances
493
- assert paths == expected_paths
494
-
495
- def test_simple_paths(self):
496
- G = nx.path_graph(4)
497
- lengths = nx.multi_source_dijkstra_path_length(G, [0])
498
- assert lengths == {n: n for n in G}
499
- paths = nx.multi_source_dijkstra_path(G, [0])
500
- assert paths == {n: list(range(n + 1)) for n in G}
501
-
502
-
503
- class TestBellmanFordAndGoldbergRadzik(WeightedTestBase):
504
- def test_single_node_graph(self):
505
- G = nx.DiGraph()
506
- G.add_node(0)
507
- assert nx.single_source_bellman_ford_path(G, 0) == {0: [0]}
508
- assert nx.single_source_bellman_ford_path_length(G, 0) == {0: 0}
509
- assert nx.single_source_bellman_ford(G, 0) == ({0: 0}, {0: [0]})
510
- assert nx.bellman_ford_predecessor_and_distance(G, 0) == ({0: []}, {0: 0})
511
- assert nx.goldberg_radzik(G, 0) == ({0: None}, {0: 0})
512
-
513
- def test_absent_source_bellman_ford(self):
514
- # the check is in _bellman_ford; this provides regression testing
515
- # against later changes to "client" Bellman-Ford functions
516
- G = nx.path_graph(2)
517
- for fn in (
518
- nx.bellman_ford_predecessor_and_distance,
519
- nx.bellman_ford_path,
520
- nx.bellman_ford_path_length,
521
- nx.single_source_bellman_ford_path,
522
- nx.single_source_bellman_ford_path_length,
523
- nx.single_source_bellman_ford,
524
- ):
525
- pytest.raises(nx.NodeNotFound, fn, G, 3, 0)
526
- pytest.raises(nx.NodeNotFound, fn, G, 3, 3)
527
-
528
- def test_absent_source_goldberg_radzik(self):
529
- with pytest.raises(nx.NodeNotFound):
530
- G = nx.path_graph(2)
531
- nx.goldberg_radzik(G, 3, 0)
532
-
533
- def test_negative_cycle_heuristic(self):
534
- G = nx.DiGraph()
535
- G.add_edge(0, 1, weight=-1)
536
- G.add_edge(1, 2, weight=-1)
537
- G.add_edge(2, 3, weight=-1)
538
- G.add_edge(3, 0, weight=3)
539
- assert not nx.negative_edge_cycle(G, heuristic=True)
540
- G.add_edge(2, 0, weight=1.999)
541
- assert nx.negative_edge_cycle(G, heuristic=True)
542
- G.edges[2, 0]["weight"] = 2
543
- assert not nx.negative_edge_cycle(G, heuristic=True)
544
-
545
- def test_negative_cycle_consistency(self):
546
- import random
547
-
548
- unif = random.uniform
549
- for random_seed in range(2): # range(20):
550
- random.seed(random_seed)
551
- for density in [0.1, 0.9]: # .3, .7, .9]:
552
- for N in [1, 10, 20]: # range(1, 60 - int(30 * density)):
553
- for max_cost in [1, 90]: # [1, 10, 40, 90]:
554
- G = nx.binomial_graph(N, density, seed=4, directed=True)
555
- edges = ((u, v, unif(-1, max_cost)) for u, v in G.edges)
556
- G.add_weighted_edges_from(edges)
557
-
558
- no_heuristic = nx.negative_edge_cycle(G, heuristic=False)
559
- with_heuristic = nx.negative_edge_cycle(G, heuristic=True)
560
- assert no_heuristic == with_heuristic
561
-
562
- def test_negative_cycle(self):
563
- G = nx.cycle_graph(5, create_using=nx.DiGraph())
564
- G.add_edge(1, 2, weight=-7)
565
- for i in range(5):
566
- pytest.raises(
567
- nx.NetworkXUnbounded, nx.single_source_bellman_ford_path, G, i
568
- )
569
- pytest.raises(
570
- nx.NetworkXUnbounded, nx.single_source_bellman_ford_path_length, G, i
571
- )
572
- pytest.raises(nx.NetworkXUnbounded, nx.single_source_bellman_ford, G, i)
573
- pytest.raises(
574
- nx.NetworkXUnbounded, nx.bellman_ford_predecessor_and_distance, G, i
575
- )
576
- pytest.raises(nx.NetworkXUnbounded, nx.goldberg_radzik, G, i)
577
- G = nx.cycle_graph(5) # undirected Graph
578
- G.add_edge(1, 2, weight=-3)
579
- for i in range(5):
580
- pytest.raises(
581
- nx.NetworkXUnbounded, nx.single_source_bellman_ford_path, G, i
582
- )
583
- pytest.raises(
584
- nx.NetworkXUnbounded, nx.single_source_bellman_ford_path_length, G, i
585
- )
586
- pytest.raises(nx.NetworkXUnbounded, nx.single_source_bellman_ford, G, i)
587
- pytest.raises(
588
- nx.NetworkXUnbounded, nx.bellman_ford_predecessor_and_distance, G, i
589
- )
590
- pytest.raises(nx.NetworkXUnbounded, nx.goldberg_radzik, G, i)
591
- G = nx.DiGraph([(1, 1, {"weight": -1})])
592
- pytest.raises(nx.NetworkXUnbounded, nx.single_source_bellman_ford_path, G, 1)
593
- pytest.raises(
594
- nx.NetworkXUnbounded, nx.single_source_bellman_ford_path_length, G, 1
595
- )
596
- pytest.raises(nx.NetworkXUnbounded, nx.single_source_bellman_ford, G, 1)
597
- pytest.raises(
598
- nx.NetworkXUnbounded, nx.bellman_ford_predecessor_and_distance, G, 1
599
- )
600
- pytest.raises(nx.NetworkXUnbounded, nx.goldberg_radzik, G, 1)
601
- G = nx.MultiDiGraph([(1, 1, {"weight": -1})])
602
- pytest.raises(nx.NetworkXUnbounded, nx.single_source_bellman_ford_path, G, 1)
603
- pytest.raises(
604
- nx.NetworkXUnbounded, nx.single_source_bellman_ford_path_length, G, 1
605
- )
606
- pytest.raises(nx.NetworkXUnbounded, nx.single_source_bellman_ford, G, 1)
607
- pytest.raises(
608
- nx.NetworkXUnbounded, nx.bellman_ford_predecessor_and_distance, G, 1
609
- )
610
- pytest.raises(nx.NetworkXUnbounded, nx.goldberg_radzik, G, 1)
611
-
612
- def test_zero_cycle(self):
613
- G = nx.cycle_graph(5, create_using=nx.DiGraph())
614
- G.add_edge(2, 3, weight=-4)
615
- # check that zero cycle doesn't raise
616
- nx.goldberg_radzik(G, 1)
617
- nx.bellman_ford_predecessor_and_distance(G, 1)
618
-
619
- G.add_edge(2, 3, weight=-4.0001)
620
- # check that negative cycle does raise
621
- pytest.raises(
622
- nx.NetworkXUnbounded, nx.bellman_ford_predecessor_and_distance, G, 1
623
- )
624
- pytest.raises(nx.NetworkXUnbounded, nx.goldberg_radzik, G, 1)
625
-
626
- def test_find_negative_cycle_longer_cycle(self):
627
- G = nx.cycle_graph(5, create_using=nx.DiGraph())
628
- nx.add_cycle(G, [3, 5, 6, 7, 8, 9])
629
- G.add_edge(1, 2, weight=-30)
630
- assert nx.find_negative_cycle(G, 1) == [0, 1, 2, 3, 4, 0]
631
- assert nx.find_negative_cycle(G, 7) == [2, 3, 4, 0, 1, 2]
632
-
633
- def test_find_negative_cycle_no_cycle(self):
634
- G = nx.path_graph(5, create_using=nx.DiGraph())
635
- pytest.raises(nx.NetworkXError, nx.find_negative_cycle, G, 3)
636
-
637
- def test_find_negative_cycle_single_edge(self):
638
- G = nx.Graph()
639
- G.add_edge(0, 1, weight=-1)
640
- assert nx.find_negative_cycle(G, 1) == [1, 0, 1]
641
-
642
- def test_negative_weight(self):
643
- G = nx.cycle_graph(5, create_using=nx.DiGraph())
644
- G.add_edge(1, 2, weight=-3)
645
- assert nx.single_source_bellman_ford_path(G, 0) == {
646
- 0: [0],
647
- 1: [0, 1],
648
- 2: [0, 1, 2],
649
- 3: [0, 1, 2, 3],
650
- 4: [0, 1, 2, 3, 4],
651
- }
652
- assert nx.single_source_bellman_ford_path_length(G, 0) == {
653
- 0: 0,
654
- 1: 1,
655
- 2: -2,
656
- 3: -1,
657
- 4: 0,
658
- }
659
- assert nx.single_source_bellman_ford(G, 0) == (
660
- {0: 0, 1: 1, 2: -2, 3: -1, 4: 0},
661
- {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [0, 1, 2, 3], 4: [0, 1, 2, 3, 4]},
662
- )
663
- assert nx.bellman_ford_predecessor_and_distance(G, 0) == (
664
- {0: [], 1: [0], 2: [1], 3: [2], 4: [3]},
665
- {0: 0, 1: 1, 2: -2, 3: -1, 4: 0},
666
- )
667
- assert nx.goldberg_radzik(G, 0) == (
668
- {0: None, 1: 0, 2: 1, 3: 2, 4: 3},
669
- {0: 0, 1: 1, 2: -2, 3: -1, 4: 0},
670
- )
671
-
672
- def test_not_connected(self):
673
- G = nx.complete_graph(6)
674
- G.add_edge(10, 11)
675
- G.add_edge(10, 12)
676
- assert nx.single_source_bellman_ford_path(G, 0) == {
677
- 0: [0],
678
- 1: [0, 1],
679
- 2: [0, 2],
680
- 3: [0, 3],
681
- 4: [0, 4],
682
- 5: [0, 5],
683
- }
684
- assert nx.single_source_bellman_ford_path_length(G, 0) == {
685
- 0: 0,
686
- 1: 1,
687
- 2: 1,
688
- 3: 1,
689
- 4: 1,
690
- 5: 1,
691
- }
692
- assert nx.single_source_bellman_ford(G, 0) == (
693
- {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1},
694
- {0: [0], 1: [0, 1], 2: [0, 2], 3: [0, 3], 4: [0, 4], 5: [0, 5]},
695
- )
696
- assert nx.bellman_ford_predecessor_and_distance(G, 0) == (
697
- {0: [], 1: [0], 2: [0], 3: [0], 4: [0], 5: [0]},
698
- {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1},
699
- )
700
- assert nx.goldberg_radzik(G, 0) == (
701
- {0: None, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
702
- {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1},
703
- )
704
-
705
- # not connected, with a component not containing the source that
706
- # contains a negative cycle.
707
- G = nx.complete_graph(6)
708
- G.add_edges_from(
709
- [
710
- ("A", "B", {"load": 3}),
711
- ("B", "C", {"load": -10}),
712
- ("C", "A", {"load": 2}),
713
- ]
714
- )
715
- assert nx.single_source_bellman_ford_path(G, 0, weight="load") == {
716
- 0: [0],
717
- 1: [0, 1],
718
- 2: [0, 2],
719
- 3: [0, 3],
720
- 4: [0, 4],
721
- 5: [0, 5],
722
- }
723
- assert nx.single_source_bellman_ford_path_length(G, 0, weight="load") == {
724
- 0: 0,
725
- 1: 1,
726
- 2: 1,
727
- 3: 1,
728
- 4: 1,
729
- 5: 1,
730
- }
731
- assert nx.single_source_bellman_ford(G, 0, weight="load") == (
732
- {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1},
733
- {0: [0], 1: [0, 1], 2: [0, 2], 3: [0, 3], 4: [0, 4], 5: [0, 5]},
734
- )
735
- assert nx.bellman_ford_predecessor_and_distance(G, 0, weight="load") == (
736
- {0: [], 1: [0], 2: [0], 3: [0], 4: [0], 5: [0]},
737
- {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1},
738
- )
739
- assert nx.goldberg_radzik(G, 0, weight="load") == (
740
- {0: None, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0},
741
- {0: 0, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1},
742
- )
743
-
744
- def test_multigraph(self):
745
- assert nx.bellman_ford_path(self.MXG, "s", "v") == ["s", "x", "u", "v"]
746
- assert nx.bellman_ford_path_length(self.MXG, "s", "v") == 9
747
- assert nx.single_source_bellman_ford_path(self.MXG, "s")["v"] == [
748
- "s",
749
- "x",
750
- "u",
751
- "v",
752
- ]
753
- assert nx.single_source_bellman_ford_path_length(self.MXG, "s")["v"] == 9
754
- D, P = nx.single_source_bellman_ford(self.MXG, "s", target="v")
755
- assert D == 9
756
- assert P == ["s", "x", "u", "v"]
757
- P, D = nx.bellman_ford_predecessor_and_distance(self.MXG, "s")
758
- assert P["v"] == ["u"]
759
- assert D["v"] == 9
760
- P, D = nx.goldberg_radzik(self.MXG, "s")
761
- assert P["v"] == "u"
762
- assert D["v"] == 9
763
- assert nx.bellman_ford_path(self.MXG4, 0, 2) == [0, 1, 2]
764
- assert nx.bellman_ford_path_length(self.MXG4, 0, 2) == 4
765
- assert nx.single_source_bellman_ford_path(self.MXG4, 0)[2] == [0, 1, 2]
766
- assert nx.single_source_bellman_ford_path_length(self.MXG4, 0)[2] == 4
767
- D, P = nx.single_source_bellman_ford(self.MXG4, 0, target=2)
768
- assert D == 4
769
- assert P == [0, 1, 2]
770
- P, D = nx.bellman_ford_predecessor_and_distance(self.MXG4, 0)
771
- assert P[2] == [1]
772
- assert D[2] == 4
773
- P, D = nx.goldberg_radzik(self.MXG4, 0)
774
- assert P[2] == 1
775
- assert D[2] == 4
776
-
777
- def test_others(self):
778
- assert nx.bellman_ford_path(self.XG, "s", "v") == ["s", "x", "u", "v"]
779
- assert nx.bellman_ford_path_length(self.XG, "s", "v") == 9
780
- assert nx.single_source_bellman_ford_path(self.XG, "s")["v"] == [
781
- "s",
782
- "x",
783
- "u",
784
- "v",
785
- ]
786
- assert nx.single_source_bellman_ford_path_length(self.XG, "s")["v"] == 9
787
- D, P = nx.single_source_bellman_ford(self.XG, "s", target="v")
788
- assert D == 9
789
- assert P == ["s", "x", "u", "v"]
790
- (P, D) = nx.bellman_ford_predecessor_and_distance(self.XG, "s")
791
- assert P["v"] == ["u"]
792
- assert D["v"] == 9
793
- (P, D) = nx.goldberg_radzik(self.XG, "s")
794
- assert P["v"] == "u"
795
- assert D["v"] == 9
796
-
797
- def test_path_graph(self):
798
- G = nx.path_graph(4)
799
- assert nx.single_source_bellman_ford_path(G, 0) == {
800
- 0: [0],
801
- 1: [0, 1],
802
- 2: [0, 1, 2],
803
- 3: [0, 1, 2, 3],
804
- }
805
- assert nx.single_source_bellman_ford_path_length(G, 0) == {
806
- 0: 0,
807
- 1: 1,
808
- 2: 2,
809
- 3: 3,
810
- }
811
- assert nx.single_source_bellman_ford(G, 0) == (
812
- {0: 0, 1: 1, 2: 2, 3: 3},
813
- {0: [0], 1: [0, 1], 2: [0, 1, 2], 3: [0, 1, 2, 3]},
814
- )
815
- assert nx.bellman_ford_predecessor_and_distance(G, 0) == (
816
- {0: [], 1: [0], 2: [1], 3: [2]},
817
- {0: 0, 1: 1, 2: 2, 3: 3},
818
- )
819
- assert nx.goldberg_radzik(G, 0) == (
820
- {0: None, 1: 0, 2: 1, 3: 2},
821
- {0: 0, 1: 1, 2: 2, 3: 3},
822
- )
823
- assert nx.single_source_bellman_ford_path(G, 3) == {
824
- 0: [3, 2, 1, 0],
825
- 1: [3, 2, 1],
826
- 2: [3, 2],
827
- 3: [3],
828
- }
829
- assert nx.single_source_bellman_ford_path_length(G, 3) == {
830
- 0: 3,
831
- 1: 2,
832
- 2: 1,
833
- 3: 0,
834
- }
835
- assert nx.single_source_bellman_ford(G, 3) == (
836
- {0: 3, 1: 2, 2: 1, 3: 0},
837
- {0: [3, 2, 1, 0], 1: [3, 2, 1], 2: [3, 2], 3: [3]},
838
- )
839
- assert nx.bellman_ford_predecessor_and_distance(G, 3) == (
840
- {0: [1], 1: [2], 2: [3], 3: []},
841
- {0: 3, 1: 2, 2: 1, 3: 0},
842
- )
843
- assert nx.goldberg_radzik(G, 3) == (
844
- {0: 1, 1: 2, 2: 3, 3: None},
845
- {0: 3, 1: 2, 2: 1, 3: 0},
846
- )
847
-
848
- def test_4_cycle(self):
849
- # 4-cycle
850
- G = nx.Graph([(0, 1), (1, 2), (2, 3), (3, 0)])
851
- dist, path = nx.single_source_bellman_ford(G, 0)
852
- assert dist == {0: 0, 1: 1, 2: 2, 3: 1}
853
- assert path[0] == [0]
854
- assert path[1] == [0, 1]
855
- assert path[2] in [[0, 1, 2], [0, 3, 2]]
856
- assert path[3] == [0, 3]
857
-
858
- pred, dist = nx.bellman_ford_predecessor_and_distance(G, 0)
859
- assert pred[0] == []
860
- assert pred[1] == [0]
861
- assert pred[2] in [[1, 3], [3, 1]]
862
- assert pred[3] == [0]
863
- assert dist == {0: 0, 1: 1, 2: 2, 3: 1}
864
-
865
- pred, dist = nx.goldberg_radzik(G, 0)
866
- assert pred[0] is None
867
- assert pred[1] == 0
868
- assert pred[2] in [1, 3]
869
- assert pred[3] == 0
870
- assert dist == {0: 0, 1: 1, 2: 2, 3: 1}
871
-
872
- def test_negative_weight_bf_path(self):
873
- G = nx.DiGraph()
874
- G.add_nodes_from("abcd")
875
- G.add_edge("a", "d", weight=0)
876
- G.add_edge("a", "b", weight=1)
877
- G.add_edge("b", "c", weight=-3)
878
- G.add_edge("c", "d", weight=1)
879
-
880
- assert nx.bellman_ford_path(G, "a", "d") == ["a", "b", "c", "d"]
881
- assert nx.bellman_ford_path_length(G, "a", "d") == -1
882
-
883
- def test_zero_cycle_smoke(self):
884
- D = nx.DiGraph()
885
- D.add_weighted_edges_from([(0, 1, 1), (1, 2, 1), (2, 3, 1), (3, 1, -2)])
886
-
887
- nx.bellman_ford_path(D, 1, 3)
888
- nx.dijkstra_path(D, 1, 3)
889
- nx.bidirectional_dijkstra(D, 1, 3)
890
- # FIXME nx.goldberg_radzik(D, 1)
891
-
892
- def test_skip_visited_unweighted(self):
893
- """Check that `goldberg_radzik` correctly skips visited nodes in `topo_sort`.
894
-
895
- This doesn't reliably get tested by other tests because iterating over
896
- the `relabeled` set is not deterministic.
897
- """
898
- G = nx.Graph([(0, 4), (0, 5), (1, 3), (1, 4), (2, 3), (2, 5), (3, 5), (3, 6)])
899
-
900
- _, dist = nx.goldberg_radzik(G, 4)
901
- assert dist == {0: 1, 1: 1, 2: 3, 3: 2, 4: 0, 5: 2, 6: 3}
902
-
903
-
904
- class TestJohnsonAlgorithm(WeightedTestBase):
905
- def test_single_node_graph(self):
906
- G = nx.DiGraph()
907
- G.add_node(0)
908
- assert nx.johnson(G) == {0: {0: [0]}}
909
-
910
- def test_negative_cycle(self):
911
- G = nx.DiGraph()
912
- G.add_weighted_edges_from(
913
- [
914
- ("0", "3", 3),
915
- ("0", "1", -5),
916
- ("1", "0", -5),
917
- ("0", "2", 2),
918
- ("1", "2", 4),
919
- ("2", "3", 1),
920
- ]
921
- )
922
- pytest.raises(nx.NetworkXUnbounded, nx.johnson, G)
923
- G = nx.Graph()
924
- G.add_weighted_edges_from(
925
- [
926
- ("0", "3", 3),
927
- ("0", "1", -5),
928
- ("1", "0", -5),
929
- ("0", "2", 2),
930
- ("1", "2", 4),
931
- ("2", "3", 1),
932
- ]
933
- )
934
- pytest.raises(nx.NetworkXUnbounded, nx.johnson, G)
935
-
936
- def test_negative_weights(self):
937
- G = nx.DiGraph()
938
- G.add_weighted_edges_from(
939
- [("0", "3", 3), ("0", "1", -5), ("0", "2", 2), ("1", "2", 4), ("2", "3", 1)]
940
- )
941
- paths = nx.johnson(G)
942
- assert paths == {
943
- "1": {"1": ["1"], "3": ["1", "2", "3"], "2": ["1", "2"]},
944
- "0": {
945
- "1": ["0", "1"],
946
- "0": ["0"],
947
- "3": ["0", "1", "2", "3"],
948
- "2": ["0", "1", "2"],
949
- },
950
- "3": {"3": ["3"]},
951
- "2": {"3": ["2", "3"], "2": ["2"]},
952
- }
953
-
954
- def test_unweighted_graph(self):
955
- G = nx.Graph()
956
- G.add_edges_from([(1, 0), (2, 1)])
957
- H = G.copy()
958
- nx.set_edge_attributes(H, values=1, name="weight")
959
- assert nx.johnson(G) == nx.johnson(H)
960
-
961
- def test_partially_weighted_graph_with_negative_edges(self):
962
- G = nx.DiGraph()
963
- G.add_edges_from([(0, 1), (1, 2), (2, 0), (1, 0)])
964
- G[1][0]["weight"] = -2
965
- G[0][1]["weight"] = 3
966
- G[1][2]["weight"] = -4
967
-
968
- H = G.copy()
969
- H[2][0]["weight"] = 1
970
-
971
- I = G.copy()
972
- I[2][0]["weight"] = 8
973
-
974
- assert nx.johnson(G) == nx.johnson(H)
975
- assert nx.johnson(G) != nx.johnson(I)
976
-
977
- def test_graphs(self):
978
- validate_path(self.XG, "s", "v", 9, nx.johnson(self.XG)["s"]["v"])
979
- validate_path(self.MXG, "s", "v", 9, nx.johnson(self.MXG)["s"]["v"])
980
- validate_path(self.XG2, 1, 3, 4, nx.johnson(self.XG2)[1][3])
981
- validate_path(self.XG3, 0, 3, 15, nx.johnson(self.XG3)[0][3])
982
- validate_path(self.XG4, 0, 2, 4, nx.johnson(self.XG4)[0][2])
983
- validate_path(self.MXG4, 0, 2, 4, nx.johnson(self.MXG4)[0][2])