okstra 0.114.0 → 0.115.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 (326) 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/lead/okstra-lead-contract.md +1 -1
  7. package/runtime/python/okstra_ctl/implementation_stage.py +46 -39
  8. package/runtime/python/okstra_ctl/report_views.py +151 -12
  9. package/runtime/python/okstra_ctl/run.py +24 -24
  10. package/runtime/python/okstra_ctl/worktree.py +1 -1
  11. package/runtime/python/okstra_token_usage/claude.py +58 -19
  12. package/runtime/python/okstra_token_usage/collect.py +3 -1
  13. package/runtime/python/okstra_vendor/__init__.py +3 -0
  14. package/runtime/schemas/final-report-v1.0.schema.json +20 -0
  15. package/runtime/templates/reports/final-report.template.md +14 -0
  16. package/runtime/templates/reports/i18n/en.json +23 -12
  17. package/runtime/templates/reports/i18n/ko.json +23 -12
  18. package/runtime/templates/reports/report.css +55 -0
  19. package/runtime/templates/reports/report.js +53 -1
  20. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
  21. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +0 -41
  22. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +0 -112
  23. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +0 -199
  24. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +0 -146
  25. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +0 -59
  26. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +0 -78
  27. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +0 -303
  28. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +0 -8
  29. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +0 -94
  30. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +0 -31
  31. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +0 -306
  32. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +0 -1014
  33. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +0 -274
  34. package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +0 -68
  35. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
  36. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +0 -81
  37. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +0 -143
  38. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +0 -122
  39. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +0 -174
  40. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +0 -107
  41. package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +0 -87
  42. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
  43. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +0 -125
  44. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +0 -192
  45. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +0 -84
  46. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +0 -33
  47. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +0 -240
  48. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +0 -334
  49. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +0 -407
  50. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +0 -218
  51. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +0 -327
  52. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +0 -138
  53. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +0 -409
  54. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +0 -35
  55. package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +0 -80
  56. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
  57. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +0 -923
  58. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +0 -354
  59. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +0 -274
  60. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +0 -259
  61. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +0 -147
  62. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +0 -43
  63. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +0 -144
  64. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +0 -73
  65. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +0 -186
  66. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +0 -277
  67. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +0 -122
  68. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +0 -345
  69. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +0 -220
  70. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +0 -344
  71. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +0 -87
  72. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +0 -140
  73. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +0 -82
  74. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +0 -110
  75. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +0 -302
  76. package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +0 -64
  77. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
  78. package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +0 -863
  79. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
  80. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +0 -147
  81. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +0 -157
  82. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +0 -85
  83. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +0 -106
  84. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +0 -91
  85. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +0 -241
  86. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +0 -138
  87. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +0 -76
  88. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +0 -264
  89. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +0 -152
  90. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +0 -340
  91. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +0 -139
  92. package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +0 -26
  93. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
  94. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +0 -70
  95. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +0 -248
  96. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +0 -138
  97. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +0 -55
  98. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +0 -193
  99. package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +0 -96
  100. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
  101. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +0 -421
  102. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +0 -309
  103. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +0 -249
  104. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +0 -502
  105. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +0 -488
  106. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +0 -323
  107. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +0 -280
  108. package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +0 -102
  109. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
  110. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
  111. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
  112. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
  113. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +0 -128
  114. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +0 -573
  115. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +0 -155
  116. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +0 -475
  117. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +0 -481
  118. package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
  119. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
  120. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
  121. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
  122. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
  123. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
  124. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +0 -719
  125. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +0 -103
  126. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +0 -490
  127. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +0 -64
  128. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +0 -212
  129. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +0 -202
  130. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +0 -1655
  131. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +0 -3118
  132. package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +0 -196
  133. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
  134. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +0 -77
  135. package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +0 -213
  136. package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +0 -544
  137. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
  138. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +0 -328
  139. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +0 -451
  140. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +0 -491
  141. package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +0 -55
  142. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
  143. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +0 -254
  144. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +0 -212
  145. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +0 -88
  146. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +0 -511
  147. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +0 -149
  148. package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +0 -983
  149. package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
  150. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +0 -23
  151. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +0 -154
  152. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +0 -144
  153. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +0 -109
  154. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +0 -136
  155. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +0 -129
  156. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +0 -300
  157. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +0 -678
  158. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +0 -80
  159. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +0 -266
  160. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +0 -85
  161. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +0 -171
  162. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +0 -984
  163. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +0 -340
  164. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +0 -835
  165. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +0 -831
  166. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +0 -85
  167. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +0 -299
  168. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +0 -115
  169. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +0 -58
  170. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +0 -314
  171. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +0 -872
  172. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +0 -163
  173. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +0 -46
  174. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +0 -24
  175. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +0 -26
  176. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +0 -615
  177. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +0 -459
  178. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +0 -556
  179. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +0 -179
  180. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +0 -62
  181. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +0 -15
  182. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +0 -140
  183. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +0 -60
  184. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +0 -27
  185. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +0 -274
  186. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +0 -556
  187. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +0 -57
  188. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +0 -37
  189. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +0 -88
  190. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +0 -149
  191. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +0 -1158
  192. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +0 -803
  193. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +0 -76
  194. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +0 -8
  195. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +0 -138
  196. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +0 -191
  197. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +0 -642
  198. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +0 -179
  199. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +0 -270
  200. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +0 -431
  201. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +0 -161
  202. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +0 -248
  203. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +0 -41
  204. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +0 -103
  205. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +0 -54
  206. package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +0 -157
  207. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
  208. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +0 -25
  209. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +0 -203
  210. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +0 -307
  211. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +0 -147
  212. package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +0 -131
  213. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
  214. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +0 -624
  215. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +0 -114
  216. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +0 -79
  217. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +0 -99
  218. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +0 -934
  219. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +0 -53
  220. package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +0 -174
  221. package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
  222. package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +0 -192
  223. package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +0 -476
  224. package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +0 -362
  225. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +0 -331
  226. package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +0 -110
  227. package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +0 -177
  228. package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +0 -1045
  229. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +0 -950
  230. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +0 -12
  231. package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +0 -349
  232. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +0 -459
  233. package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +0 -528
  234. package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +0 -1421
  235. package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +0 -131
  236. package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +0 -371
  237. package/runtime/python/okstra_vendor/networkx/conftest.py +0 -261
  238. package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
  239. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
  240. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
  241. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
  242. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
  243. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
  244. package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
  245. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +0 -237
  246. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +0 -229
  247. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +0 -285
  248. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +0 -631
  249. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +0 -146
  250. package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +0 -1582
  251. package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
  252. package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +0 -75
  253. package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +0 -642
  254. package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +0 -20
  255. package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +0 -362
  256. package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +0 -224
  257. package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +0 -189
  258. package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +0 -103
  259. package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +0 -39
  260. package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +0 -182
  261. package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +0 -488
  262. package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +0 -133
  263. package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +0 -221
  264. package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +0 -28
  265. package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +0 -144
  266. package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +0 -125
  267. package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +0 -264
  268. package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +0 -316
  269. package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +0 -30
  270. package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +0 -82
  271. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +0 -33
  272. package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +0 -495
  273. package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +0 -220
  274. package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +0 -49
  275. package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +0 -72
  276. package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +0 -92
  277. package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +0 -64
  278. package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +0 -195
  279. package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +0 -15
  280. package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
  281. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +0 -400
  282. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +0 -108
  283. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +0 -40
  284. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +0 -275
  285. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +0 -334
  286. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +0 -86
  287. package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +0 -70
  288. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
  289. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +0 -78
  290. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +0 -78
  291. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +0 -109
  292. package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +0 -48
  293. package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
  294. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +0 -354
  295. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +0 -318
  296. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +0 -612
  297. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +0 -744
  298. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +0 -181
  299. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +0 -1531
  300. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +0 -30
  301. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +0 -63
  302. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +0 -128
  303. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +0 -166
  304. package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +0 -1742
  305. package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
  306. package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +0 -248
  307. package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +0 -321
  308. package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +0 -531
  309. package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +0 -349
  310. package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +0 -281
  311. package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +0 -40
  312. package/runtime/python/okstra_vendor/networkx/tests/test_import.py +0 -11
  313. package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +0 -96
  314. package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +0 -349
  315. package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +0 -8
  316. package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
  317. package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +0 -11
  318. package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +0 -225
  319. package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +0 -263
  320. package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +0 -510
  321. package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +0 -131
  322. package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +0 -268
  323. package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +0 -393
  324. package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +0 -53
  325. package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +0 -63
  326. package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +0 -55
@@ -1,1014 +0,0 @@
1
- """Unit tests for the traveling_salesman module."""
2
-
3
- import random
4
-
5
- import pytest
6
-
7
- import networkx as nx
8
- import networkx.algorithms.approximation as nx_app
9
-
10
- pairwise = nx.utils.pairwise
11
-
12
-
13
- def test_christofides_hamiltonian():
14
- random.seed(42)
15
- G = nx.complete_graph(20)
16
- for u, v in G.edges():
17
- G[u][v]["weight"] = random.randint(0, 10)
18
-
19
- H = nx.Graph()
20
- H.add_edges_from(pairwise(nx_app.christofides(G)))
21
- H.remove_edges_from(nx.find_cycle(H))
22
- assert len(H.edges) == 0
23
-
24
- tree = nx.minimum_spanning_tree(G, weight="weight")
25
- H = nx.Graph()
26
- H.add_edges_from(pairwise(nx_app.christofides(G, tree)))
27
- H.remove_edges_from(nx.find_cycle(H))
28
- assert len(H.edges) == 0
29
-
30
-
31
- def test_christofides_incomplete_graph():
32
- G = nx.complete_graph(10)
33
- G.remove_edge(0, 1)
34
- pytest.raises(nx.NetworkXError, nx_app.christofides, G)
35
-
36
-
37
- def test_christofides_ignore_selfloops():
38
- G = nx.complete_graph(5)
39
- G.add_edge(3, 3)
40
- cycle = nx_app.christofides(G)
41
- assert len(cycle) - 1 == len(G) == len(set(cycle))
42
-
43
-
44
- # set up graphs for other tests
45
- class TestBase:
46
- @classmethod
47
- def setup_class(cls):
48
- cls.DG = nx.DiGraph()
49
- cls.DG.add_weighted_edges_from(
50
- {
51
- ("A", "B", 3),
52
- ("A", "C", 17),
53
- ("A", "D", 14),
54
- ("B", "A", 3),
55
- ("B", "C", 12),
56
- ("B", "D", 16),
57
- ("C", "A", 13),
58
- ("C", "B", 12),
59
- ("C", "D", 4),
60
- ("D", "A", 14),
61
- ("D", "B", 15),
62
- ("D", "C", 2),
63
- }
64
- )
65
- cls.DG_cycle = ["D", "C", "B", "A", "D"]
66
- cls.DG_cost = 31.0
67
-
68
- cls.DG2 = nx.DiGraph()
69
- cls.DG2.add_weighted_edges_from(
70
- {
71
- ("A", "B", 3),
72
- ("A", "C", 17),
73
- ("A", "D", 14),
74
- ("B", "A", 30),
75
- ("B", "C", 2),
76
- ("B", "D", 16),
77
- ("C", "A", 33),
78
- ("C", "B", 32),
79
- ("C", "D", 34),
80
- ("D", "A", 14),
81
- ("D", "B", 15),
82
- ("D", "C", 2),
83
- }
84
- )
85
- cls.DG2_cycle = ["D", "A", "B", "C", "D"]
86
- cls.DG2_cost = 53.0
87
-
88
- cls.unweightedUG = nx.complete_graph(5, nx.Graph())
89
- cls.unweightedDG = nx.complete_graph(5, nx.DiGraph())
90
-
91
- cls.incompleteUG = nx.Graph()
92
- cls.incompleteUG.add_weighted_edges_from({(0, 1, 1), (1, 2, 3)})
93
- cls.incompleteDG = nx.DiGraph()
94
- cls.incompleteDG.add_weighted_edges_from({(0, 1, 1), (1, 2, 3)})
95
-
96
- cls.UG = nx.Graph()
97
- cls.UG.add_weighted_edges_from(
98
- {
99
- ("A", "B", 3),
100
- ("A", "C", 17),
101
- ("A", "D", 14),
102
- ("B", "C", 12),
103
- ("B", "D", 16),
104
- ("C", "D", 4),
105
- }
106
- )
107
- cls.UG_cycle = ["D", "C", "B", "A", "D"]
108
- cls.UG_cost = 33.0
109
-
110
- cls.UG2 = nx.Graph()
111
- cls.UG2.add_weighted_edges_from(
112
- {
113
- ("A", "B", 1),
114
- ("A", "C", 15),
115
- ("A", "D", 5),
116
- ("B", "C", 16),
117
- ("B", "D", 8),
118
- ("C", "D", 3),
119
- }
120
- )
121
- cls.UG2_cycle = ["D", "C", "B", "A", "D"]
122
- cls.UG2_cost = 25.0
123
-
124
-
125
- def validate_solution(soln, cost, exp_soln, exp_cost):
126
- assert soln == exp_soln
127
- assert cost == exp_cost
128
-
129
-
130
- def validate_symmetric_solution(soln, cost, exp_soln, exp_cost):
131
- assert soln == exp_soln or soln == exp_soln[::-1]
132
- assert cost == exp_cost
133
-
134
-
135
- class TestGreedyTSP(TestBase):
136
- def test_greedy(self):
137
- cycle = nx_app.greedy_tsp(self.DG, source="D")
138
- cost = sum(self.DG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
139
- validate_solution(cycle, cost, ["D", "C", "B", "A", "D"], 31.0)
140
-
141
- cycle = nx_app.greedy_tsp(self.DG2, source="D")
142
- cost = sum(self.DG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
143
- validate_solution(cycle, cost, ["D", "C", "B", "A", "D"], 78.0)
144
-
145
- cycle = nx_app.greedy_tsp(self.UG, source="D")
146
- cost = sum(self.UG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
147
- validate_solution(cycle, cost, ["D", "C", "B", "A", "D"], 33.0)
148
-
149
- cycle = nx_app.greedy_tsp(self.UG2, source="D")
150
- cost = sum(self.UG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
151
- validate_solution(cycle, cost, ["D", "C", "A", "B", "D"], 27.0)
152
-
153
- def test_not_complete_graph(self):
154
- pytest.raises(nx.NetworkXError, nx_app.greedy_tsp, self.incompleteUG)
155
- pytest.raises(nx.NetworkXError, nx_app.greedy_tsp, self.incompleteDG)
156
-
157
- def test_not_weighted_graph(self):
158
- nx_app.greedy_tsp(self.unweightedUG)
159
- nx_app.greedy_tsp(self.unweightedDG)
160
-
161
- def test_two_nodes(self):
162
- G = nx.Graph()
163
- G.add_weighted_edges_from({(1, 2, 1)})
164
- cycle = nx_app.greedy_tsp(G)
165
- cost = sum(G[n][nbr]["weight"] for n, nbr in pairwise(cycle))
166
- validate_solution(cycle, cost, [1, 2, 1], 2)
167
-
168
- def test_ignore_selfloops(self):
169
- G = nx.complete_graph(5)
170
- G.add_edge(3, 3)
171
- cycle = nx_app.greedy_tsp(G)
172
- assert len(cycle) - 1 == len(G) == len(set(cycle))
173
-
174
-
175
- class TestSimulatedAnnealingTSP(TestBase):
176
- tsp = staticmethod(nx_app.simulated_annealing_tsp)
177
-
178
- def test_simulated_annealing_directed(self):
179
- cycle = self.tsp(self.DG, "greedy", source="D", seed=42)
180
- cost = sum(self.DG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
181
- validate_solution(cycle, cost, self.DG_cycle, self.DG_cost)
182
-
183
- initial_sol = ["D", "B", "A", "C", "D"]
184
- cycle = self.tsp(self.DG, initial_sol, source="D", seed=42)
185
- cost = sum(self.DG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
186
- validate_solution(cycle, cost, self.DG_cycle, self.DG_cost)
187
-
188
- initial_sol = ["D", "A", "C", "B", "D"]
189
- cycle = self.tsp(self.DG, initial_sol, move="1-0", source="D", seed=42)
190
- cost = sum(self.DG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
191
- validate_solution(cycle, cost, self.DG_cycle, self.DG_cost)
192
-
193
- cycle = self.tsp(self.DG2, "greedy", source="D", seed=42)
194
- cost = sum(self.DG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
195
- validate_solution(cycle, cost, self.DG2_cycle, self.DG2_cost)
196
-
197
- cycle = self.tsp(self.DG2, "greedy", move="1-0", source="D", seed=42)
198
- cost = sum(self.DG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
199
- validate_solution(cycle, cost, self.DG2_cycle, self.DG2_cost)
200
-
201
- def test_simulated_annealing_undirected(self):
202
- cycle = self.tsp(self.UG, "greedy", source="D", seed=42)
203
- cost = sum(self.UG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
204
- validate_solution(cycle, cost, self.UG_cycle, self.UG_cost)
205
-
206
- cycle = self.tsp(self.UG2, "greedy", source="D", seed=42)
207
- cost = sum(self.UG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
208
- validate_symmetric_solution(cycle, cost, self.UG2_cycle, self.UG2_cost)
209
-
210
- cycle = self.tsp(self.UG2, "greedy", move="1-0", source="D", seed=42)
211
- cost = sum(self.UG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
212
- validate_symmetric_solution(cycle, cost, self.UG2_cycle, self.UG2_cost)
213
-
214
- def test_error_on_input_order_mistake(self):
215
- # see issue #4846 https://github.com/networkx/networkx/issues/4846
216
- pytest.raises(TypeError, self.tsp, self.UG, weight="weight")
217
- pytest.raises(nx.NetworkXError, self.tsp, self.UG, "weight")
218
-
219
- def test_not_complete_graph(self):
220
- pytest.raises(nx.NetworkXError, self.tsp, self.incompleteUG, "greedy", source=0)
221
- pytest.raises(nx.NetworkXError, self.tsp, self.incompleteDG, "greedy", source=0)
222
-
223
- def test_ignore_selfloops(self):
224
- G = nx.complete_graph(5)
225
- G.add_edge(3, 3)
226
- cycle = self.tsp(G, "greedy")
227
- assert len(cycle) - 1 == len(G) == len(set(cycle))
228
-
229
- def test_not_weighted_graph(self):
230
- self.tsp(self.unweightedUG, "greedy")
231
- self.tsp(self.unweightedDG, "greedy")
232
-
233
- def test_two_nodes(self):
234
- G = nx.Graph()
235
- G.add_weighted_edges_from({(1, 2, 1)})
236
-
237
- cycle = self.tsp(G, "greedy", source=1, seed=42)
238
- cost = sum(G[n][nbr]["weight"] for n, nbr in pairwise(cycle))
239
- validate_solution(cycle, cost, [1, 2, 1], 2)
240
-
241
- cycle = self.tsp(G, [1, 2, 1], source=1, seed=42)
242
- cost = sum(G[n][nbr]["weight"] for n, nbr in pairwise(cycle))
243
- validate_solution(cycle, cost, [1, 2, 1], 2)
244
-
245
- def test_failure_of_costs_too_high_when_iterations_low(self):
246
- # Simulated Annealing Version:
247
- # set number of moves low and alpha high
248
- cycle = self.tsp(
249
- self.DG2, "greedy", source="D", move="1-0", alpha=1, N_inner=1, seed=42
250
- )
251
- cost = sum(self.DG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
252
- assert cost > self.DG2_cost
253
-
254
- # Try with an incorrect initial guess
255
- initial_sol = ["D", "A", "B", "C", "D"]
256
- cycle = self.tsp(
257
- self.DG,
258
- initial_sol,
259
- source="D",
260
- move="1-0",
261
- alpha=0.1,
262
- N_inner=1,
263
- max_iterations=1,
264
- seed=42,
265
- )
266
- cost = sum(self.DG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
267
- assert cost > self.DG_cost
268
-
269
-
270
- class TestThresholdAcceptingTSP(TestSimulatedAnnealingTSP):
271
- tsp = staticmethod(nx_app.threshold_accepting_tsp)
272
-
273
- def test_failure_of_costs_too_high_when_iterations_low(self):
274
- # Threshold Version:
275
- # set number of moves low and number of iterations low
276
- cycle = self.tsp(
277
- self.DG2,
278
- "greedy",
279
- source="D",
280
- move="1-0",
281
- N_inner=1,
282
- max_iterations=1,
283
- seed=4,
284
- )
285
- cost = sum(self.DG2[n][nbr]["weight"] for n, nbr in pairwise(cycle))
286
- assert cost > self.DG2_cost
287
-
288
- # set threshold too low
289
- initial_sol = ["D", "A", "B", "C", "D"]
290
- cycle = self.tsp(
291
- self.DG, initial_sol, source="D", move="1-0", threshold=-3, seed=42
292
- )
293
- cost = sum(self.DG[n][nbr]["weight"] for n, nbr in pairwise(cycle))
294
- assert cost > self.DG_cost
295
-
296
-
297
- # Tests for function traveling_salesman_problem
298
- def test_TSP_method():
299
- G = nx.cycle_graph(9)
300
- G[4][5]["weight"] = 10
301
-
302
- # Test using the old currying method
303
- def sa_tsp(G, weight):
304
- return nx_app.simulated_annealing_tsp(G, "greedy", weight, source=4, seed=1)
305
-
306
- path = nx_app.traveling_salesman_problem(
307
- G,
308
- method=sa_tsp,
309
- cycle=False,
310
- )
311
- assert path == [4, 3, 2, 1, 0, 8, 7, 6, 5]
312
-
313
-
314
- def test_TSP_unweighted():
315
- G = nx.cycle_graph(9)
316
- path = nx_app.traveling_salesman_problem(G, nodes=[3, 6], cycle=False)
317
- assert path in ([3, 4, 5, 6], [6, 5, 4, 3])
318
-
319
- cycle = nx_app.traveling_salesman_problem(G, nodes=[3, 6])
320
- assert cycle in ([3, 4, 5, 6, 5, 4, 3], [6, 5, 4, 3, 4, 5, 6])
321
-
322
-
323
- def test_TSP_weighted():
324
- G = nx.cycle_graph(9)
325
- G[0][1]["weight"] = 2
326
- G[1][2]["weight"] = 2
327
- G[2][3]["weight"] = 2
328
- G[3][4]["weight"] = 4
329
- G[4][5]["weight"] = 5
330
- G[5][6]["weight"] = 4
331
- G[6][7]["weight"] = 2
332
- G[7][8]["weight"] = 2
333
- G[8][0]["weight"] = 2
334
- tsp = nx_app.traveling_salesman_problem
335
-
336
- # path between 3 and 6
337
- expected_paths = ([3, 2, 1, 0, 8, 7, 6], [6, 7, 8, 0, 1, 2, 3])
338
- # cycle between 3 and 6
339
- expected_cycles = (
340
- [3, 2, 1, 0, 8, 7, 6, 7, 8, 0, 1, 2, 3],
341
- [6, 7, 8, 0, 1, 2, 3, 2, 1, 0, 8, 7, 6],
342
- )
343
- # path through all nodes
344
- expected_tourpaths = ([5, 6, 7, 8, 0, 1, 2, 3, 4], [4, 3, 2, 1, 0, 8, 7, 6, 5])
345
-
346
- # Check default method
347
- cycle = tsp(G, nodes=[3, 6], weight="weight")
348
- assert cycle in expected_cycles
349
-
350
- path = tsp(G, nodes=[3, 6], weight="weight", cycle=False)
351
- assert path in expected_paths
352
-
353
- tourpath = tsp(G, weight="weight", cycle=False)
354
- assert tourpath in expected_tourpaths
355
-
356
- # Check all methods
357
- methods = [
358
- (nx_app.christofides, {}),
359
- (nx_app.greedy_tsp, {}),
360
- (
361
- nx_app.simulated_annealing_tsp,
362
- {"init_cycle": "greedy"},
363
- ),
364
- (
365
- nx_app.threshold_accepting_tsp,
366
- {"init_cycle": "greedy"},
367
- ),
368
- ]
369
- for method, kwargs in methods:
370
- cycle = tsp(G, nodes=[3, 6], weight="weight", method=method, **kwargs)
371
- assert cycle in expected_cycles
372
-
373
- path = tsp(
374
- G, nodes=[3, 6], weight="weight", method=method, cycle=False, **kwargs
375
- )
376
- assert path in expected_paths
377
-
378
- tourpath = tsp(G, weight="weight", method=method, cycle=False, **kwargs)
379
- assert tourpath in expected_tourpaths
380
-
381
-
382
- def test_TSP_incomplete_graph_short_path():
383
- G = nx.cycle_graph(9)
384
- G.add_edges_from([(4, 9), (9, 10), (10, 11), (11, 0)])
385
- G[4][5]["weight"] = 5
386
-
387
- cycle = nx_app.traveling_salesman_problem(G)
388
- assert len(cycle) == 17 and len(set(cycle)) == 12
389
-
390
- # make sure that cutting one edge out of complete graph formulation
391
- # cuts out many edges out of the path of the TSP
392
- path = nx_app.traveling_salesman_problem(G, cycle=False)
393
- assert len(path) == 13 and len(set(path)) == 12
394
-
395
-
396
- def test_TSP_alternate_weight():
397
- G = nx.complete_graph(9)
398
- G[0][1]["weight"] = 2
399
- G[1][2]["weight"] = 2
400
- G[2][3]["weight"] = 2
401
- G[3][4]["weight"] = 4
402
- G[4][5]["weight"] = 5
403
- G[5][6]["weight"] = 4
404
- G[6][7]["weight"] = 2
405
- G[7][8]["weight"] = 2
406
- G[8][0]["weight"] = 2
407
-
408
- H = nx.complete_graph(9)
409
- H[0][1]["distance"] = 2
410
- H[1][2]["distance"] = 2
411
- H[2][3]["distance"] = 2
412
- H[3][4]["distance"] = 4
413
- H[4][5]["distance"] = 5
414
- H[5][6]["distance"] = 4
415
- H[6][7]["distance"] = 2
416
- H[7][8]["distance"] = 2
417
- H[8][0]["distance"] = 2
418
-
419
- assert nx_app.traveling_salesman_problem(
420
- G, weight="weight"
421
- ) == nx_app.traveling_salesman_problem(H, weight="distance")
422
-
423
-
424
- def test_held_karp_ascent():
425
- """
426
- Test the Held-Karp relaxation with the ascent method
427
- """
428
- import networkx.algorithms.approximation.traveling_salesman as tsp
429
-
430
- np = pytest.importorskip("numpy")
431
- pytest.importorskip("scipy")
432
-
433
- # Adjacency matrix from page 1153 of the 1970 Held and Karp paper
434
- # which have been edited to be directional, but also symmetric
435
- G_array = np.array(
436
- [
437
- [0, 97, 60, 73, 17, 52],
438
- [97, 0, 41, 52, 90, 30],
439
- [60, 41, 0, 21, 35, 41],
440
- [73, 52, 21, 0, 95, 46],
441
- [17, 90, 35, 95, 0, 81],
442
- [52, 30, 41, 46, 81, 0],
443
- ]
444
- )
445
-
446
- solution_edges = [(1, 3), (2, 4), (3, 2), (4, 0), (5, 1), (0, 5)]
447
-
448
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
449
- opt_hk, z_star = tsp.held_karp_ascent(G)
450
-
451
- # Check that the optimal weights are the same
452
- assert round(opt_hk, 2) == 207.00
453
- # Check that the z_stars are the same
454
- solution = nx.DiGraph()
455
- solution.add_edges_from(solution_edges)
456
- # Use undirected edges for `edges_equal` because the graph is symmetric.
457
- assert nx.utils.edges_equal(z_star.edges, solution.edges)
458
-
459
-
460
- def test_ascent_fractional_solution():
461
- """
462
- Test the ascent method using a modified version of Figure 2 on page 1140
463
- in 'The Traveling Salesman Problem and Minimum Spanning Trees' by Held and
464
- Karp
465
- """
466
- import networkx.algorithms.approximation.traveling_salesman as tsp
467
-
468
- np = pytest.importorskip("numpy")
469
- pytest.importorskip("scipy")
470
-
471
- # This version of Figure 2 has all of the edge weights multiplied by 100
472
- # and is a complete directed graph with infinite edge weights for the
473
- # edges not listed in the original graph
474
- G_array = np.array(
475
- [
476
- [0, 100, 100, 100000, 100000, 1],
477
- [100, 0, 100, 100000, 1, 100000],
478
- [100, 100, 0, 1, 100000, 100000],
479
- [100000, 100000, 1, 0, 100, 100],
480
- [100000, 1, 100000, 100, 0, 100],
481
- [1, 100000, 100000, 100, 100, 0],
482
- ]
483
- )
484
-
485
- solution_z_star = {
486
- (0, 1): 5 / 12,
487
- (0, 2): 5 / 12,
488
- (0, 5): 5 / 6,
489
- (1, 0): 5 / 12,
490
- (1, 2): 1 / 3,
491
- (1, 4): 5 / 6,
492
- (2, 0): 5 / 12,
493
- (2, 1): 1 / 3,
494
- (2, 3): 5 / 6,
495
- (3, 2): 5 / 6,
496
- (3, 4): 1 / 3,
497
- (3, 5): 1 / 2,
498
- (4, 1): 5 / 6,
499
- (4, 3): 1 / 3,
500
- (4, 5): 1 / 2,
501
- (5, 0): 5 / 6,
502
- (5, 3): 1 / 2,
503
- (5, 4): 1 / 2,
504
- }
505
-
506
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
507
- opt_hk, z_star = tsp.held_karp_ascent(G)
508
-
509
- # Check that the optimal weights are the same
510
- assert round(opt_hk, 2) == 303.00
511
- # Check that the z_stars are the same
512
- assert {key: round(z_star[key], 4) for key in z_star} == {
513
- key: round(solution_z_star[key], 4) for key in solution_z_star
514
- }
515
-
516
-
517
- def test_ascent_method_asymmetric():
518
- """
519
- Tests the ascent method using a truly asymmetric graph for which the
520
- solution has been brute forced
521
- """
522
- import networkx.algorithms.approximation.traveling_salesman as tsp
523
-
524
- np = pytest.importorskip("numpy")
525
- pytest.importorskip("scipy")
526
-
527
- G_array = np.array(
528
- [
529
- [0, 26, 63, 59, 69, 31, 41],
530
- [62, 0, 91, 53, 75, 87, 47],
531
- [47, 82, 0, 90, 15, 9, 18],
532
- [68, 19, 5, 0, 58, 34, 93],
533
- [11, 58, 53, 55, 0, 61, 79],
534
- [88, 75, 13, 76, 98, 0, 40],
535
- [41, 61, 55, 88, 46, 45, 0],
536
- ]
537
- )
538
-
539
- solution_edges = [(0, 1), (1, 3), (3, 2), (2, 5), (5, 6), (4, 0), (6, 4)]
540
-
541
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
542
- opt_hk, z_star = tsp.held_karp_ascent(G)
543
-
544
- # Check that the optimal weights are the same
545
- assert round(opt_hk, 2) == 190.00
546
- # Check that the z_stars match.
547
- solution = nx.DiGraph()
548
- solution.add_edges_from(solution_edges)
549
- assert nx.utils.edges_equal(z_star.edges, solution.edges, directed=True)
550
-
551
-
552
- def test_ascent_method_asymmetric_2():
553
- """
554
- Tests the ascent method using a truly asymmetric graph for which the
555
- solution has been brute forced
556
- """
557
- import networkx.algorithms.approximation.traveling_salesman as tsp
558
-
559
- np = pytest.importorskip("numpy")
560
- pytest.importorskip("scipy")
561
-
562
- G_array = np.array(
563
- [
564
- [0, 45, 39, 92, 29, 31],
565
- [72, 0, 4, 12, 21, 60],
566
- [81, 6, 0, 98, 70, 53],
567
- [49, 71, 59, 0, 98, 94],
568
- [74, 95, 24, 43, 0, 47],
569
- [56, 43, 3, 65, 22, 0],
570
- ]
571
- )
572
-
573
- solution_edges = [(0, 5), (5, 4), (1, 3), (3, 0), (2, 1), (4, 2)]
574
-
575
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
576
- opt_hk, z_star = tsp.held_karp_ascent(G)
577
-
578
- # Check that the optimal weights are the same
579
- assert round(opt_hk, 2) == 144.00
580
- # Check that the z_stars match.
581
- solution = nx.DiGraph()
582
- solution.add_edges_from(solution_edges)
583
- assert nx.utils.edges_equal(z_star.edges, solution.edges, directed=True)
584
-
585
-
586
- def test_held_karp_ascent_asymmetric_3():
587
- """
588
- Tests the ascent method using a truly asymmetric graph with a fractional
589
- solution for which the solution has been brute forced.
590
-
591
- In this graph their are two different optimal, integral solutions (which
592
- are also the overall atsp solutions) to the Held Karp relaxation. However,
593
- this particular graph has two different tours of optimal value and the
594
- possible solutions in the held_karp_ascent function are not stored in an
595
- ordered data structure.
596
- """
597
- import networkx.algorithms.approximation.traveling_salesman as tsp
598
-
599
- np = pytest.importorskip("numpy")
600
- pytest.importorskip("scipy")
601
-
602
- G_array = np.array(
603
- [
604
- [0, 1, 5, 2, 7, 4],
605
- [7, 0, 7, 7, 1, 4],
606
- [4, 7, 0, 9, 2, 1],
607
- [7, 2, 7, 0, 4, 4],
608
- [5, 5, 4, 4, 0, 3],
609
- [3, 9, 1, 3, 4, 0],
610
- ]
611
- )
612
-
613
- solution1_edges = [(0, 3), (1, 4), (2, 5), (3, 1), (4, 2), (5, 0)]
614
-
615
- solution2_edges = [(0, 3), (3, 1), (1, 4), (4, 5), (2, 0), (5, 2)]
616
-
617
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
618
- opt_hk, z_star = tsp.held_karp_ascent(G)
619
-
620
- assert round(opt_hk, 2) == 13.00
621
- # Check that the z_stars are the same
622
- solution1 = nx.DiGraph()
623
- solution1.add_edges_from(solution1_edges)
624
- solution2 = nx.DiGraph()
625
- solution2.add_edges_from(solution2_edges)
626
- assert nx.utils.edges_equal(
627
- z_star.edges, solution1.edges, directed=True
628
- ) or nx.utils.edges_equal(z_star.edges, solution2.edges, directed=True)
629
-
630
-
631
- def test_held_karp_ascent_fractional_asymmetric():
632
- """
633
- Tests the ascent method using a truly asymmetric graph with a fractional
634
- solution for which the solution has been brute forced
635
- """
636
- import networkx.algorithms.approximation.traveling_salesman as tsp
637
-
638
- np = pytest.importorskip("numpy")
639
- pytest.importorskip("scipy")
640
-
641
- G_array = np.array(
642
- [
643
- [0, 100, 150, 100000, 100000, 1],
644
- [150, 0, 100, 100000, 1, 100000],
645
- [100, 150, 0, 1, 100000, 100000],
646
- [100000, 100000, 1, 0, 150, 100],
647
- [100000, 2, 100000, 100, 0, 150],
648
- [2, 100000, 100000, 150, 100, 0],
649
- ]
650
- )
651
-
652
- solution_z_star = {
653
- (0, 1): 5 / 12,
654
- (0, 2): 5 / 12,
655
- (0, 5): 5 / 6,
656
- (1, 0): 5 / 12,
657
- (1, 2): 5 / 12,
658
- (1, 4): 5 / 6,
659
- (2, 0): 5 / 12,
660
- (2, 1): 5 / 12,
661
- (2, 3): 5 / 6,
662
- (3, 2): 5 / 6,
663
- (3, 4): 5 / 12,
664
- (3, 5): 5 / 12,
665
- (4, 1): 5 / 6,
666
- (4, 3): 5 / 12,
667
- (4, 5): 5 / 12,
668
- (5, 0): 5 / 6,
669
- (5, 3): 5 / 12,
670
- (5, 4): 5 / 12,
671
- }
672
-
673
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
674
- opt_hk, z_star = tsp.held_karp_ascent(G)
675
-
676
- # Check that the optimal weights are the same
677
- assert round(opt_hk, 2) == 304.00
678
- # Check that the z_stars are the same
679
- assert {key: round(z_star[key], 4) for key in z_star} == {
680
- key: round(solution_z_star[key], 4) for key in solution_z_star
681
- }
682
-
683
-
684
- def test_spanning_tree_distribution():
685
- """
686
- Test that we can create an exponential distribution of spanning trees such
687
- that the probability of each tree is proportional to the product of edge
688
- weights.
689
-
690
- Results of this test have been confirmed with hypothesis testing from the
691
- created distribution.
692
-
693
- This test uses the symmetric, fractional Held Karp solution.
694
- """
695
- import networkx.algorithms.approximation.traveling_salesman as tsp
696
-
697
- pytest.importorskip("numpy")
698
- pytest.importorskip("scipy")
699
-
700
- z_star = {
701
- (0, 1): 5 / 12,
702
- (0, 2): 5 / 12,
703
- (0, 5): 5 / 6,
704
- (1, 0): 5 / 12,
705
- (1, 2): 1 / 3,
706
- (1, 4): 5 / 6,
707
- (2, 0): 5 / 12,
708
- (2, 1): 1 / 3,
709
- (2, 3): 5 / 6,
710
- (3, 2): 5 / 6,
711
- (3, 4): 1 / 3,
712
- (3, 5): 1 / 2,
713
- (4, 1): 5 / 6,
714
- (4, 3): 1 / 3,
715
- (4, 5): 1 / 2,
716
- (5, 0): 5 / 6,
717
- (5, 3): 1 / 2,
718
- (5, 4): 1 / 2,
719
- }
720
-
721
- solution_gamma = {
722
- (0, 1): -0.6383,
723
- (0, 2): -0.6827,
724
- (0, 5): 0,
725
- (1, 2): -1.0781,
726
- (1, 4): 0,
727
- (2, 3): 0,
728
- (5, 3): -0.2820,
729
- (5, 4): -0.3327,
730
- (4, 3): -0.9927,
731
- }
732
-
733
- # The undirected support of z_star
734
- G = nx.MultiGraph()
735
- for u, v in z_star:
736
- if (u, v) in G.edges or (v, u) in G.edges:
737
- continue
738
- G.add_edge(u, v)
739
-
740
- gamma = tsp.spanning_tree_distribution(G, z_star)
741
-
742
- assert {key: round(gamma[key], 4) for key in gamma} == solution_gamma
743
-
744
-
745
- def test_asadpour_tsp():
746
- """
747
- Test the complete asadpour tsp algorithm with the fractional, symmetric
748
- Held Karp solution. This test also uses an incomplete graph as input.
749
- """
750
- # This version of Figure 2 has all of the edge weights multiplied by 100
751
- # and the 0 weight edges have a weight of 1.
752
- pytest.importorskip("numpy")
753
- pytest.importorskip("scipy")
754
-
755
- edge_list = [
756
- (0, 1, 100),
757
- (0, 2, 100),
758
- (0, 5, 1),
759
- (1, 2, 100),
760
- (1, 4, 1),
761
- (2, 3, 1),
762
- (3, 4, 100),
763
- (3, 5, 100),
764
- (4, 5, 100),
765
- (1, 0, 100),
766
- (2, 0, 100),
767
- (5, 0, 1),
768
- (2, 1, 100),
769
- (4, 1, 1),
770
- (3, 2, 1),
771
- (4, 3, 100),
772
- (5, 3, 100),
773
- (5, 4, 100),
774
- ]
775
-
776
- G = nx.DiGraph()
777
- G.add_weighted_edges_from(edge_list)
778
-
779
- tour = nx_app.traveling_salesman_problem(
780
- G, weight="weight", method=nx_app.asadpour_atsp, seed=19
781
- )
782
-
783
- # Check that the returned list is a valid tour. Because this is an
784
- # incomplete graph, the conditions are not as strict. We need the tour to
785
- #
786
- # Start and end at the same node
787
- # Pass through every vertex at least once
788
- # Have a total cost at most ln(6) / ln(ln(6)) = 3.0723 times the optimal
789
- #
790
- # For the second condition it is possible to have the tour pass through the
791
- # same vertex more then. Imagine that the tour on the complete version takes
792
- # an edge not in the original graph. In the output this is substituted with
793
- # the shortest path between those vertices, allowing vertices to appear more
794
- # than once.
795
- #
796
- # Even though we are using a fixed seed, multiple tours have been known to
797
- # be returned. The first two are from the original development of this test,
798
- # and the third one from issue #5913 on GitHub. If other tours are returned,
799
- # add it on the list of expected tours.
800
- expected_tours = [
801
- [1, 4, 5, 0, 2, 3, 2, 1],
802
- [3, 2, 0, 1, 4, 5, 3],
803
- [3, 2, 1, 0, 5, 4, 3],
804
- ]
805
-
806
- assert tour in expected_tours
807
-
808
-
809
- def test_asadpour_real_world():
810
- """
811
- This test uses airline prices between the six largest cities in the US.
812
-
813
- * New York City -> JFK
814
- * Los Angeles -> LAX
815
- * Chicago -> ORD
816
- * Houston -> IAH
817
- * Phoenix -> PHX
818
- * Philadelphia -> PHL
819
-
820
- Flight prices from August 2021 using Delta or American airlines to get
821
- nonstop flight. The brute force solution found the optimal tour to cost $872
822
-
823
- This test also uses the `source` keyword argument to ensure that the tour
824
- always starts at city 0.
825
- """
826
- np = pytest.importorskip("numpy")
827
- pytest.importorskip("scipy")
828
-
829
- G_array = np.array(
830
- [
831
- # JFK LAX ORD IAH PHX PHL
832
- [0, 243, 199, 208, 169, 183], # JFK
833
- [277, 0, 217, 123, 127, 252], # LAX
834
- [297, 197, 0, 197, 123, 177], # ORD
835
- [303, 169, 197, 0, 117, 117], # IAH
836
- [257, 127, 160, 117, 0, 319], # PHX
837
- [183, 332, 217, 117, 319, 0], # PHL
838
- ]
839
- )
840
-
841
- node_list = ["JFK", "LAX", "ORD", "IAH", "PHX", "PHL"]
842
-
843
- expected_tours = [
844
- ["JFK", "LAX", "PHX", "ORD", "IAH", "PHL", "JFK"],
845
- ["JFK", "ORD", "PHX", "LAX", "IAH", "PHL", "JFK"],
846
- ]
847
-
848
- G = nx.from_numpy_array(G_array, nodelist=node_list, create_using=nx.DiGraph)
849
-
850
- tour = nx_app.traveling_salesman_problem(
851
- G, weight="weight", method=nx_app.asadpour_atsp, seed=37, source="JFK"
852
- )
853
-
854
- assert tour in expected_tours
855
-
856
-
857
- def test_asadpour_real_world_path():
858
- """
859
- This test uses airline prices between the six largest cities in the US. This
860
- time using a path, not a cycle.
861
-
862
- * New York City -> JFK
863
- * Los Angeles -> LAX
864
- * Chicago -> ORD
865
- * Houston -> IAH
866
- * Phoenix -> PHX
867
- * Philadelphia -> PHL
868
-
869
- Flight prices from August 2021 using Delta or American airlines to get
870
- nonstop flight. The brute force solution found the optimal tour to cost $872
871
- """
872
- np = pytest.importorskip("numpy")
873
- pytest.importorskip("scipy")
874
-
875
- G_array = np.array(
876
- [
877
- # JFK LAX ORD IAH PHX PHL
878
- [0, 243, 199, 208, 169, 183], # JFK
879
- [277, 0, 217, 123, 127, 252], # LAX
880
- [297, 197, 0, 197, 123, 177], # ORD
881
- [303, 169, 197, 0, 117, 117], # IAH
882
- [257, 127, 160, 117, 0, 319], # PHX
883
- [183, 332, 217, 117, 319, 0], # PHL
884
- ]
885
- )
886
-
887
- node_list = ["JFK", "LAX", "ORD", "IAH", "PHX", "PHL"]
888
-
889
- expected_paths = [
890
- ["ORD", "PHX", "LAX", "IAH", "PHL", "JFK"],
891
- ["JFK", "PHL", "IAH", "ORD", "PHX", "LAX"],
892
- ]
893
-
894
- G = nx.from_numpy_array(G_array, nodelist=node_list, create_using=nx.DiGraph)
895
-
896
- path = nx_app.traveling_salesman_problem(
897
- G, weight="weight", cycle=False, method=nx_app.asadpour_atsp, seed=56
898
- )
899
-
900
- assert path in expected_paths
901
-
902
-
903
- def test_asadpour_disconnected_graph():
904
- """
905
- Test that the proper exception is raised when asadpour_atsp is given an
906
- disconnected graph.
907
- """
908
-
909
- G = nx.complete_graph(4, create_using=nx.DiGraph)
910
- # have to set edge weights so that if the exception is not raised, the
911
- # function will complete and we will fail the test
912
- nx.set_edge_attributes(G, 1, "weight")
913
- G.add_node(5)
914
-
915
- pytest.raises(nx.NetworkXError, nx_app.asadpour_atsp, G)
916
-
917
-
918
- def test_asadpour_incomplete_graph():
919
- """
920
- Test that the proper exception is raised when asadpour_atsp is given an
921
- incomplete graph
922
- """
923
-
924
- G = nx.complete_graph(4, create_using=nx.DiGraph)
925
- # have to set edge weights so that if the exception is not raised, the
926
- # function will complete and we will fail the test
927
- nx.set_edge_attributes(G, 1, "weight")
928
- G.remove_edge(0, 1)
929
-
930
- pytest.raises(nx.NetworkXError, nx_app.asadpour_atsp, G)
931
-
932
-
933
- def test_asadpour_empty_graph():
934
- """
935
- Test the asadpour_atsp function with an empty graph
936
- """
937
- G = nx.DiGraph()
938
-
939
- pytest.raises(nx.NetworkXError, nx_app.asadpour_atsp, G)
940
-
941
-
942
- def test_asadpour_small_graphs():
943
- # 1 node
944
- G = nx.path_graph(1, create_using=nx.DiGraph)
945
- with pytest.raises(nx.NetworkXError, match="at least two nodes"):
946
- nx_app.asadpour_atsp(G)
947
-
948
- # 2 nodes
949
- G = nx.DiGraph()
950
- G.add_weighted_edges_from([(0, 1, 7), (1, 0, 8)])
951
- assert nx_app.asadpour_atsp(G) in [[0, 1], [1, 0]]
952
- assert nx_app.asadpour_atsp(G, source=1) == [1, 0]
953
- assert nx_app.asadpour_atsp(G, source=0) == [0, 1]
954
-
955
-
956
- @pytest.mark.slow
957
- def test_asadpour_integral_held_karp():
958
- """
959
- This test uses an integral held karp solution and the held karp function
960
- will return a graph rather than a dict, bypassing most of the asadpour
961
- algorithm.
962
-
963
- At first glance, this test probably doesn't look like it ensures that we
964
- skip the rest of the asadpour algorithm, but it does. We are not fixing a
965
- see for the random number generator, so if we sample any spanning trees
966
- the approximation would be different basically every time this test is
967
- executed but it is not since held karp is deterministic and we do not
968
- reach the portion of the code with the dependence on random numbers.
969
- """
970
- np = pytest.importorskip("numpy")
971
-
972
- G_array = np.array(
973
- [
974
- [0, 26, 63, 59, 69, 31, 41],
975
- [62, 0, 91, 53, 75, 87, 47],
976
- [47, 82, 0, 90, 15, 9, 18],
977
- [68, 19, 5, 0, 58, 34, 93],
978
- [11, 58, 53, 55, 0, 61, 79],
979
- [88, 75, 13, 76, 98, 0, 40],
980
- [41, 61, 55, 88, 46, 45, 0],
981
- ]
982
- )
983
-
984
- G = nx.from_numpy_array(G_array, create_using=nx.DiGraph)
985
-
986
- for _ in range(2):
987
- tour = nx_app.traveling_salesman_problem(G, method=nx_app.asadpour_atsp)
988
-
989
- assert [1, 3, 2, 5, 2, 6, 4, 0, 1] == tour
990
-
991
-
992
- def test_directed_tsp_impossible():
993
- """
994
- Test the asadpour algorithm with a graph without a hamiltonian circuit
995
- """
996
- pytest.importorskip("numpy")
997
-
998
- # In this graph, once we leave node 0 we cannot return
999
- edges = [
1000
- (0, 1, 10),
1001
- (0, 2, 11),
1002
- (0, 3, 12),
1003
- (1, 2, 4),
1004
- (1, 3, 6),
1005
- (2, 1, 3),
1006
- (2, 3, 2),
1007
- (3, 1, 5),
1008
- (3, 2, 1),
1009
- ]
1010
-
1011
- G = nx.DiGraph()
1012
- G.add_weighted_edges_from(edges)
1013
-
1014
- pytest.raises(nx.NetworkXError, nx_app.traveling_salesman_problem, G)