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.
- package/docs/kr/architecture.md +2 -2
- package/docs/kr/follow-ups/2026-07-10-final-report-option-3.md +51 -0
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/workers/report-writer-worker.md +1 -0
- package/runtime/prompts/launch.template.md +34 -0
- package/runtime/prompts/lead/convergence.md +2 -0
- package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
- package/runtime/prompts/lead/report-writer.md +1 -1
- package/runtime/prompts/profiles/implementation-planning.md +1 -0
- package/runtime/python/okstra_ctl/implementation_stage.py +46 -39
- package/runtime/python/okstra_ctl/incremental_carry.py +70 -0
- package/runtime/python/okstra_ctl/incremental_scope.py +89 -0
- package/runtime/python/okstra_ctl/report_views.py +151 -12
- package/runtime/python/okstra_ctl/run.py +24 -24
- package/runtime/python/okstra_ctl/stage_targets.py +26 -0
- package/runtime/python/okstra_ctl/worktree.py +1 -1
- package/runtime/python/okstra_token_usage/claude.py +58 -19
- package/runtime/python/okstra_token_usage/collect.py +3 -1
- package/runtime/python/okstra_vendor/__init__.py +3 -0
- package/runtime/schemas/final-report-v1.0.schema.json +39 -0
- package/runtime/templates/reports/final-report.template.md +27 -0
- package/runtime/templates/reports/i18n/en.json +23 -12
- package/runtime/templates/reports/i18n/ko.json +23 -12
- package/runtime/templates/reports/report.css +55 -0
- package/runtime/templates/reports/report.js +53 -1
- package/runtime/validators/validate-run.py +50 -0
- package/src/cli-registry.mjs +14 -0
- package/src/commands/execute/incremental-carry.mjs +20 -0
- package/src/commands/execute/incremental-scope.mjs +20 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_approx_clust_coeff.py +0 -41
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +0 -112
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +0 -199
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +0 -146
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +0 -59
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +0 -78
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +0 -303
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +0 -8
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +0 -94
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +0 -31
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +0 -306
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +0 -1014
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +0 -274
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +0 -68
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/base_test.py +0 -81
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +0 -143
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +0 -122
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +0 -174
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +0 -107
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +0 -87
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_basic.py +0 -125
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +0 -192
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +0 -84
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +0 -33
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +0 -240
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +0 -334
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +0 -407
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +0 -218
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +0 -327
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +0 -138
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +0 -409
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +0 -35
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +0 -80
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality.py +0 -923
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +0 -354
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +0 -274
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +0 -259
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +0 -147
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +0 -43
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +0 -144
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +0 -73
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +0 -186
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +0 -277
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +0 -122
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +0 -345
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +0 -220
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +0 -344
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +0 -87
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +0 -140
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +0 -82
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +0 -110
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +0 -302
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +0 -64
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/tests/test_coloring.py +0 -863
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_asyn_fluid.py +0 -147
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +0 -157
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +0 -85
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +0 -106
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +0 -91
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +0 -241
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +0 -138
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +0 -76
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +0 -264
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +0 -152
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +0 -340
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +0 -139
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +0 -26
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_attracting.py +0 -70
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +0 -248
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +0 -138
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +0 -55
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +0 -193
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +0 -96
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_connectivity.py +0 -421
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +0 -309
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +0 -249
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +0 -502
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +0 -488
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +0 -323
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +0 -280
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +0 -102
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gl1.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/gw1.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/netgen-2.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_gomory_hu.py +0 -128
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +0 -573
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +0 -155
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +0 -475
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +0 -481
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.A99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/iso_r01_s80.B99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.A99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/si2_b06_m200.B99 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_ismags.py +0 -719
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +0 -103
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +0 -490
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +0 -64
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +0 -212
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +0 -202
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +0 -1655
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +0 -3118
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +0 -196
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_hits.py +0 -77
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +0 -213
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +0 -544
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_all.py +0 -328
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +0 -451
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +0 -491
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +0 -55
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_astar.py +0 -254
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +0 -212
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +0 -88
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +0 -511
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +0 -149
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +0 -983
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +0 -23
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +0 -154
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +0 -144
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +0 -109
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +0 -136
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +0 -129
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +0 -300
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +0 -678
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +0 -80
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +0 -266
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +0 -85
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +0 -171
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +0 -984
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +0 -340
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +0 -835
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +0 -831
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +0 -85
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +0 -299
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +0 -115
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +0 -58
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +0 -314
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +0 -872
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +0 -163
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +0 -46
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +0 -24
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +0 -26
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +0 -615
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +0 -459
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +0 -556
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +0 -179
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +0 -62
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +0 -15
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +0 -140
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +0 -60
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +0 -27
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +0 -274
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +0 -556
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +0 -57
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +0 -37
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +0 -88
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +0 -149
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +0 -1158
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +0 -803
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +0 -76
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +0 -8
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +0 -138
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +0 -191
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +0 -642
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +0 -179
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +0 -270
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +0 -431
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +0 -161
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +0 -248
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +0 -41
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +0 -103
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +0 -54
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +0 -157
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_beamsearch.py +0 -25
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +0 -203
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +0 -307
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +0 -147
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +0 -131
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_branchings.py +0 -624
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +0 -114
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +0 -79
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +0 -99
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +0 -934
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +0 -53
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +0 -174
- package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +0 -192
- package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +0 -476
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +0 -362
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +0 -331
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +0 -110
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +0 -177
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +0 -1045
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +0 -950
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +0 -12
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +0 -349
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +0 -459
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +0 -528
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +0 -1421
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +0 -131
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +0 -371
- package/runtime/python/okstra_vendor/networkx/conftest.py +0 -261
- package/runtime/python/okstra_vendor/networkx/drawing/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_complex.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_empty_graph.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_house_with_colors.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_labels_and_colors.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_display_shortest_path.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/baseline/test_house_with_colors.png +0 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_agraph.py +0 -237
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +0 -229
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +0 -285
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +0 -631
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +0 -146
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +0 -1582
- package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +0 -75
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +0 -642
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +0 -20
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +0 -362
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +0 -224
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +0 -189
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +0 -103
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +0 -39
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +0 -182
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +0 -488
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +0 -133
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +0 -221
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +0 -28
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +0 -144
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +0 -125
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +0 -264
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +0 -316
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +0 -30
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +0 -82
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +0 -33
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +0 -495
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +0 -220
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +0 -49
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +0 -72
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +0 -92
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +0 -64
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +0 -195
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +0 -15
- package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +0 -400
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +0 -108
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +0 -40
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +0 -275
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +0 -334
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +0 -86
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +0 -70
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_adjacency.py +0 -78
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +0 -78
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +0 -109
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +0 -48
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +0 -354
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +0 -318
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +0 -612
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +0 -744
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +0 -181
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +0 -1531
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +0 -30
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +0 -63
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +0 -128
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +0 -166
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +0 -1742
- package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +0 -248
- package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +0 -321
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +0 -531
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +0 -349
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +0 -281
- package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +0 -40
- package/runtime/python/okstra_vendor/networkx/tests/test_import.py +0 -11
- package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +0 -96
- package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +0 -349
- package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +0 -8
- package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +0 -11
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +0 -225
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +0 -263
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +0 -510
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +0 -131
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +0 -268
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +0 -393
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +0 -53
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +0 -63
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +0 -55
|
@@ -1,934 +0,0 @@
|
|
|
1
|
-
"""Unit tests for the :mod:`networkx.algorithms.tree.mst` module."""
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
|
|
5
|
-
import networkx as nx
|
|
6
|
-
from networkx.utils import edges_equal, nodes_equal
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def test_unknown_algorithm():
|
|
10
|
-
with pytest.raises(ValueError):
|
|
11
|
-
nx.minimum_spanning_tree(nx.Graph(), algorithm="random")
|
|
12
|
-
with pytest.raises(
|
|
13
|
-
ValueError, match="random is not a valid choice for an algorithm."
|
|
14
|
-
):
|
|
15
|
-
nx.maximum_spanning_edges(nx.Graph(), algorithm="random")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class MinimumSpanningTreeTestBase:
|
|
19
|
-
"""Base class for test classes for minimum spanning tree algorithms.
|
|
20
|
-
This class contains some common tests that will be inherited by
|
|
21
|
-
subclasses. Each subclass must have a class attribute
|
|
22
|
-
:data:`algorithm` that is a string representing the algorithm to
|
|
23
|
-
run, as described under the ``algorithm`` keyword argument for the
|
|
24
|
-
:func:`networkx.minimum_spanning_edges` function. Subclasses can
|
|
25
|
-
then implement any algorithm-specific tests.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
def setup_method(self, method):
|
|
29
|
-
"""Creates an example graph and stores the expected minimum and
|
|
30
|
-
maximum spanning tree edges.
|
|
31
|
-
"""
|
|
32
|
-
# This stores the class attribute `algorithm` in an instance attribute.
|
|
33
|
-
self.algo = self.algorithm
|
|
34
|
-
# This example graph comes from Wikipedia:
|
|
35
|
-
# https://en.wikipedia.org/wiki/Kruskal's_algorithm
|
|
36
|
-
edges = [
|
|
37
|
-
(0, 1, 7),
|
|
38
|
-
(0, 3, 5),
|
|
39
|
-
(1, 2, 8),
|
|
40
|
-
(1, 3, 9),
|
|
41
|
-
(1, 4, 7),
|
|
42
|
-
(2, 4, 5),
|
|
43
|
-
(3, 4, 15),
|
|
44
|
-
(3, 5, 6),
|
|
45
|
-
(4, 5, 8),
|
|
46
|
-
(4, 6, 9),
|
|
47
|
-
(5, 6, 11),
|
|
48
|
-
]
|
|
49
|
-
self.G = nx.Graph()
|
|
50
|
-
self.G.add_weighted_edges_from(edges)
|
|
51
|
-
self.minimum_spanning_edgelist = [
|
|
52
|
-
(0, 1, {"weight": 7}),
|
|
53
|
-
(0, 3, {"weight": 5}),
|
|
54
|
-
(1, 4, {"weight": 7}),
|
|
55
|
-
(2, 4, {"weight": 5}),
|
|
56
|
-
(3, 5, {"weight": 6}),
|
|
57
|
-
(4, 6, {"weight": 9}),
|
|
58
|
-
]
|
|
59
|
-
self.maximum_spanning_edgelist = [
|
|
60
|
-
(0, 1, {"weight": 7}),
|
|
61
|
-
(1, 2, {"weight": 8}),
|
|
62
|
-
(1, 3, {"weight": 9}),
|
|
63
|
-
(3, 4, {"weight": 15}),
|
|
64
|
-
(4, 6, {"weight": 9}),
|
|
65
|
-
(5, 6, {"weight": 11}),
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
def test_minimum_edges(self):
|
|
69
|
-
edges = nx.minimum_spanning_edges(self.G, algorithm=self.algo)
|
|
70
|
-
# Edges from the spanning edges functions don't come in sorted
|
|
71
|
-
# orientation, so we need to sort each edge individually.
|
|
72
|
-
actual = sorted((min(u, v), max(u, v), d) for u, v, d in edges)
|
|
73
|
-
assert edges_equal(actual, self.minimum_spanning_edgelist)
|
|
74
|
-
|
|
75
|
-
def test_maximum_edges(self):
|
|
76
|
-
edges = nx.maximum_spanning_edges(self.G, algorithm=self.algo)
|
|
77
|
-
# Edges from the spanning edges functions don't come in sorted
|
|
78
|
-
# orientation, so we need to sort each edge individually.
|
|
79
|
-
actual = sorted((min(u, v), max(u, v), d) for u, v, d in edges)
|
|
80
|
-
assert edges_equal(actual, self.maximum_spanning_edgelist)
|
|
81
|
-
|
|
82
|
-
def test_without_data(self):
|
|
83
|
-
edges = nx.minimum_spanning_edges(self.G, algorithm=self.algo, data=False)
|
|
84
|
-
# Edges from the spanning edges functions don't come in sorted
|
|
85
|
-
# orientation, so we need to sort each edge individually.
|
|
86
|
-
actual = sorted((min(u, v), max(u, v)) for u, v in edges)
|
|
87
|
-
expected = [(u, v) for u, v, d in self.minimum_spanning_edgelist]
|
|
88
|
-
assert edges_equal(actual, expected)
|
|
89
|
-
|
|
90
|
-
def test_nan_weights(self):
|
|
91
|
-
# Edge weights NaN never appear in the spanning tree. see #2164
|
|
92
|
-
G = self.G
|
|
93
|
-
G.add_edge(0, 12, weight=float("nan"))
|
|
94
|
-
edges = nx.minimum_spanning_edges(
|
|
95
|
-
G, algorithm=self.algo, data=False, ignore_nan=True
|
|
96
|
-
)
|
|
97
|
-
actual = sorted((min(u, v), max(u, v)) for u, v in edges)
|
|
98
|
-
expected = [(u, v) for u, v, d in self.minimum_spanning_edgelist]
|
|
99
|
-
assert edges_equal(actual, expected)
|
|
100
|
-
# Now test for raising exception
|
|
101
|
-
edges = nx.minimum_spanning_edges(
|
|
102
|
-
G, algorithm=self.algo, data=False, ignore_nan=False
|
|
103
|
-
)
|
|
104
|
-
with pytest.raises(ValueError):
|
|
105
|
-
list(edges)
|
|
106
|
-
# test default for ignore_nan as False
|
|
107
|
-
edges = nx.minimum_spanning_edges(G, algorithm=self.algo, data=False)
|
|
108
|
-
with pytest.raises(ValueError):
|
|
109
|
-
list(edges)
|
|
110
|
-
|
|
111
|
-
def test_nan_weights_MultiGraph(self):
|
|
112
|
-
G = nx.MultiGraph()
|
|
113
|
-
G.add_edge(0, 12, weight=float("nan"))
|
|
114
|
-
edges = nx.minimum_spanning_edges(
|
|
115
|
-
G, algorithm="prim", data=False, ignore_nan=False
|
|
116
|
-
)
|
|
117
|
-
with pytest.raises(ValueError):
|
|
118
|
-
list(edges)
|
|
119
|
-
# test default for ignore_nan as False
|
|
120
|
-
edges = nx.minimum_spanning_edges(G, algorithm="prim", data=False)
|
|
121
|
-
with pytest.raises(ValueError):
|
|
122
|
-
list(edges)
|
|
123
|
-
|
|
124
|
-
def test_nan_weights_order(self):
|
|
125
|
-
# now try again with a nan edge at the beginning of G.nodes
|
|
126
|
-
edges = [
|
|
127
|
-
(0, 1, 7),
|
|
128
|
-
(0, 3, 5),
|
|
129
|
-
(1, 2, 8),
|
|
130
|
-
(1, 3, 9),
|
|
131
|
-
(1, 4, 7),
|
|
132
|
-
(2, 4, 5),
|
|
133
|
-
(3, 4, 15),
|
|
134
|
-
(3, 5, 6),
|
|
135
|
-
(4, 5, 8),
|
|
136
|
-
(4, 6, 9),
|
|
137
|
-
(5, 6, 11),
|
|
138
|
-
]
|
|
139
|
-
G = nx.Graph()
|
|
140
|
-
G.add_weighted_edges_from([(u + 1, v + 1, wt) for u, v, wt in edges])
|
|
141
|
-
G.add_edge(0, 7, weight=float("nan"))
|
|
142
|
-
edges = nx.minimum_spanning_edges(
|
|
143
|
-
G, algorithm=self.algo, data=False, ignore_nan=True
|
|
144
|
-
)
|
|
145
|
-
actual = sorted((min(u, v), max(u, v)) for u, v in edges)
|
|
146
|
-
shift = [(u + 1, v + 1) for u, v, d in self.minimum_spanning_edgelist]
|
|
147
|
-
assert edges_equal(actual, shift)
|
|
148
|
-
|
|
149
|
-
def test_isolated_node(self):
|
|
150
|
-
# now try again with an isolated node
|
|
151
|
-
edges = [
|
|
152
|
-
(0, 1, 7),
|
|
153
|
-
(0, 3, 5),
|
|
154
|
-
(1, 2, 8),
|
|
155
|
-
(1, 3, 9),
|
|
156
|
-
(1, 4, 7),
|
|
157
|
-
(2, 4, 5),
|
|
158
|
-
(3, 4, 15),
|
|
159
|
-
(3, 5, 6),
|
|
160
|
-
(4, 5, 8),
|
|
161
|
-
(4, 6, 9),
|
|
162
|
-
(5, 6, 11),
|
|
163
|
-
]
|
|
164
|
-
G = nx.Graph()
|
|
165
|
-
G.add_weighted_edges_from([(u + 1, v + 1, wt) for u, v, wt in edges])
|
|
166
|
-
G.add_node(0)
|
|
167
|
-
edges = nx.minimum_spanning_edges(
|
|
168
|
-
G, algorithm=self.algo, data=False, ignore_nan=True
|
|
169
|
-
)
|
|
170
|
-
actual = sorted((min(u, v), max(u, v)) for u, v in edges)
|
|
171
|
-
shift = [(u + 1, v + 1) for u, v, d in self.minimum_spanning_edgelist]
|
|
172
|
-
assert edges_equal(actual, shift)
|
|
173
|
-
|
|
174
|
-
def test_minimum_tree(self):
|
|
175
|
-
T = nx.minimum_spanning_tree(self.G, algorithm=self.algo)
|
|
176
|
-
actual = sorted(T.edges(data=True))
|
|
177
|
-
assert edges_equal(actual, self.minimum_spanning_edgelist)
|
|
178
|
-
|
|
179
|
-
def test_maximum_tree(self):
|
|
180
|
-
T = nx.maximum_spanning_tree(self.G, algorithm=self.algo)
|
|
181
|
-
actual = sorted(T.edges(data=True))
|
|
182
|
-
assert edges_equal(actual, self.maximum_spanning_edgelist)
|
|
183
|
-
|
|
184
|
-
def test_disconnected(self):
|
|
185
|
-
G = nx.Graph([(0, 1, {"weight": 1}), (2, 3, {"weight": 2})])
|
|
186
|
-
T = nx.minimum_spanning_tree(G, algorithm=self.algo)
|
|
187
|
-
assert nodes_equal(list(T), list(range(4)))
|
|
188
|
-
assert edges_equal(list(T.edges()), [(0, 1), (2, 3)])
|
|
189
|
-
|
|
190
|
-
def test_empty_graph(self):
|
|
191
|
-
G = nx.empty_graph(3)
|
|
192
|
-
T = nx.minimum_spanning_tree(G, algorithm=self.algo)
|
|
193
|
-
assert nodes_equal(sorted(T), list(range(3)))
|
|
194
|
-
assert T.number_of_edges() == 0
|
|
195
|
-
|
|
196
|
-
def test_attributes(self):
|
|
197
|
-
G = nx.Graph()
|
|
198
|
-
G.add_edge(1, 2, weight=1, color="red", distance=7)
|
|
199
|
-
G.add_edge(2, 3, weight=1, color="green", distance=2)
|
|
200
|
-
G.add_edge(1, 3, weight=10, color="blue", distance=1)
|
|
201
|
-
G.graph["foo"] = "bar"
|
|
202
|
-
T = nx.minimum_spanning_tree(G, algorithm=self.algo)
|
|
203
|
-
assert T.graph == G.graph
|
|
204
|
-
assert nodes_equal(T, G)
|
|
205
|
-
for u, v in T.edges():
|
|
206
|
-
assert T.adj[u][v] == G.adj[u][v]
|
|
207
|
-
|
|
208
|
-
def test_weight_attribute(self):
|
|
209
|
-
G = nx.Graph()
|
|
210
|
-
G.add_edge(0, 1, weight=1, distance=7)
|
|
211
|
-
G.add_edge(0, 2, weight=30, distance=1)
|
|
212
|
-
G.add_edge(1, 2, weight=1, distance=1)
|
|
213
|
-
G.add_node(3)
|
|
214
|
-
T = nx.minimum_spanning_tree(G, algorithm=self.algo, weight="distance")
|
|
215
|
-
assert nodes_equal(sorted(T), list(range(4)))
|
|
216
|
-
assert edges_equal(sorted(T.edges()), [(0, 2), (1, 2)])
|
|
217
|
-
T = nx.maximum_spanning_tree(G, algorithm=self.algo, weight="distance")
|
|
218
|
-
assert nodes_equal(sorted(T), list(range(4)))
|
|
219
|
-
assert edges_equal(sorted(T.edges()), [(0, 1), (0, 2)])
|
|
220
|
-
|
|
221
|
-
def test_minimum_spanning_edges_directed_raises(self):
|
|
222
|
-
DG = nx.DiGraph()
|
|
223
|
-
DG.add_edge(0, 1, weight=1)
|
|
224
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
225
|
-
list(nx.minimum_spanning_edges(DG, algorithm=self.algo))
|
|
226
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
227
|
-
list(nx.maximum_spanning_edges(DG, algorithm=self.algo))
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
class TestBoruvka(MinimumSpanningTreeTestBase):
|
|
231
|
-
"""Unit tests for computing a minimum (or maximum) spanning tree
|
|
232
|
-
using Borůvka's algorithm.
|
|
233
|
-
"""
|
|
234
|
-
|
|
235
|
-
algorithm = "boruvka"
|
|
236
|
-
|
|
237
|
-
def test_unicode_name(self):
|
|
238
|
-
"""Tests that using a Unicode string can correctly indicate
|
|
239
|
-
Borůvka's algorithm.
|
|
240
|
-
"""
|
|
241
|
-
edges = nx.minimum_spanning_edges(self.G, algorithm="borůvka")
|
|
242
|
-
# Edges from the spanning edges functions don't come in sorted
|
|
243
|
-
# orientation, so we need to sort each edge individually.
|
|
244
|
-
actual = sorted((min(u, v), max(u, v), d) for u, v, d in edges)
|
|
245
|
-
assert edges_equal(actual, self.minimum_spanning_edgelist)
|
|
246
|
-
|
|
247
|
-
def test_minimum_spanning_edges_multigraph_raises(self):
|
|
248
|
-
MG = nx.MultiGraph()
|
|
249
|
-
MG.add_edge(0, 1, weight=1)
|
|
250
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
251
|
-
list(nx.minimum_spanning_edges(MG, algorithm=self.algo))
|
|
252
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
253
|
-
list(nx.maximum_spanning_edges(MG, algorithm=self.algo))
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
class MultigraphMSTTestBase(MinimumSpanningTreeTestBase):
|
|
257
|
-
# Abstract class
|
|
258
|
-
|
|
259
|
-
def test_multigraph_keys_min(self):
|
|
260
|
-
"""Tests that the minimum spanning edges of a multigraph
|
|
261
|
-
preserves edge keys.
|
|
262
|
-
"""
|
|
263
|
-
G = nx.MultiGraph()
|
|
264
|
-
G.add_edge(0, 1, key="a", weight=2)
|
|
265
|
-
G.add_edge(0, 1, key="b", weight=1)
|
|
266
|
-
min_edges = nx.minimum_spanning_edges
|
|
267
|
-
mst_edges = min_edges(G, algorithm=self.algo, data=False)
|
|
268
|
-
assert edges_equal([(0, 1, "b")], list(mst_edges))
|
|
269
|
-
|
|
270
|
-
def test_multigraph_keys_max(self):
|
|
271
|
-
"""Tests that the maximum spanning edges of a multigraph
|
|
272
|
-
preserves edge keys.
|
|
273
|
-
"""
|
|
274
|
-
G = nx.MultiGraph()
|
|
275
|
-
G.add_edge(0, 1, key="a", weight=2)
|
|
276
|
-
G.add_edge(0, 1, key="b", weight=1)
|
|
277
|
-
max_edges = nx.maximum_spanning_edges
|
|
278
|
-
mst_edges = max_edges(G, algorithm=self.algo, data=False)
|
|
279
|
-
assert edges_equal([(0, 1, "a")], list(mst_edges))
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
class TestKruskal(MultigraphMSTTestBase):
|
|
283
|
-
"""Unit tests for computing a minimum (or maximum) spanning tree
|
|
284
|
-
using Kruskal's algorithm.
|
|
285
|
-
"""
|
|
286
|
-
|
|
287
|
-
algorithm = "kruskal"
|
|
288
|
-
|
|
289
|
-
def test_key_data_bool(self):
|
|
290
|
-
"""Tests that the keys and data values are included in
|
|
291
|
-
MST edges based on whether keys and data parameters are
|
|
292
|
-
true or false"""
|
|
293
|
-
G = nx.MultiGraph()
|
|
294
|
-
G.add_edge(1, 2, key=1, weight=2)
|
|
295
|
-
G.add_edge(1, 2, key=2, weight=3)
|
|
296
|
-
G.add_edge(3, 2, key=1, weight=2)
|
|
297
|
-
G.add_edge(3, 1, key=1, weight=4)
|
|
298
|
-
|
|
299
|
-
# keys are included and data is not included
|
|
300
|
-
mst_edges = nx.minimum_spanning_edges(
|
|
301
|
-
G, algorithm=self.algo, keys=True, data=False
|
|
302
|
-
)
|
|
303
|
-
assert edges_equal([(1, 2, 1), (2, 3, 1)], list(mst_edges))
|
|
304
|
-
|
|
305
|
-
# keys are not included and data is included
|
|
306
|
-
mst_edges = nx.minimum_spanning_edges(
|
|
307
|
-
G, algorithm=self.algo, keys=False, data=True
|
|
308
|
-
)
|
|
309
|
-
assert edges_equal(
|
|
310
|
-
[(1, 2, {"weight": 2}), (2, 3, {"weight": 2})], list(mst_edges)
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
# both keys and data are not included
|
|
314
|
-
mst_edges = nx.minimum_spanning_edges(
|
|
315
|
-
G, algorithm=self.algo, keys=False, data=False
|
|
316
|
-
)
|
|
317
|
-
assert edges_equal([(1, 2), (2, 3)], list(mst_edges))
|
|
318
|
-
|
|
319
|
-
# both keys and data are included
|
|
320
|
-
mst_edges = nx.minimum_spanning_edges(
|
|
321
|
-
G, algorithm=self.algo, keys=True, data=True
|
|
322
|
-
)
|
|
323
|
-
assert edges_equal(
|
|
324
|
-
[(1, 2, 1, {"weight": 2}), (2, 3, 1, {"weight": 2})], list(mst_edges)
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
class TestPrim(MultigraphMSTTestBase):
|
|
329
|
-
"""Unit tests for computing a minimum (or maximum) spanning tree
|
|
330
|
-
using Prim's algorithm.
|
|
331
|
-
"""
|
|
332
|
-
|
|
333
|
-
algorithm = "prim"
|
|
334
|
-
|
|
335
|
-
def test_prim_mst_edges_simple_graph(self):
|
|
336
|
-
H = nx.Graph()
|
|
337
|
-
H.add_edge(1, 2, key=2, weight=3)
|
|
338
|
-
H.add_edge(3, 2, key=1, weight=2)
|
|
339
|
-
H.add_edge(3, 1, key=1, weight=4)
|
|
340
|
-
|
|
341
|
-
mst_edges = nx.minimum_spanning_edges(H, algorithm=self.algo, ignore_nan=True)
|
|
342
|
-
assert edges_equal(
|
|
343
|
-
[(1, 2, {"key": 2, "weight": 3}), (2, 3, {"key": 1, "weight": 2})],
|
|
344
|
-
list(mst_edges),
|
|
345
|
-
)
|
|
346
|
-
|
|
347
|
-
def test_ignore_nan(self):
|
|
348
|
-
"""Tests that the edges with NaN weights are ignored or
|
|
349
|
-
raise an Error based on ignore_nan is true or false"""
|
|
350
|
-
H = nx.MultiGraph()
|
|
351
|
-
H.add_edge(1, 2, key=1, weight=float("nan"))
|
|
352
|
-
H.add_edge(1, 2, key=2, weight=3)
|
|
353
|
-
H.add_edge(3, 2, key=1, weight=2)
|
|
354
|
-
H.add_edge(3, 1, key=1, weight=4)
|
|
355
|
-
|
|
356
|
-
# NaN weight edges are ignored when ignore_nan=True
|
|
357
|
-
mst_edges = nx.minimum_spanning_edges(H, algorithm=self.algo, ignore_nan=True)
|
|
358
|
-
assert edges_equal(
|
|
359
|
-
[(1, 2, 2, {"weight": 3}), (2, 3, 1, {"weight": 2})], list(mst_edges)
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
# NaN weight edges raise Error when ignore_nan=False
|
|
363
|
-
with pytest.raises(ValueError):
|
|
364
|
-
list(nx.minimum_spanning_edges(H, algorithm=self.algo, ignore_nan=False))
|
|
365
|
-
|
|
366
|
-
def test_multigraph_keys_tree(self):
|
|
367
|
-
G = nx.MultiGraph()
|
|
368
|
-
G.add_edge(0, 1, key="a", weight=2)
|
|
369
|
-
G.add_edge(0, 1, key="b", weight=1)
|
|
370
|
-
T = nx.minimum_spanning_tree(G, algorithm=self.algo)
|
|
371
|
-
assert edges_equal([(0, 1, 1)], list(T.edges(data="weight")))
|
|
372
|
-
|
|
373
|
-
def test_multigraph_keys_tree_max(self):
|
|
374
|
-
G = nx.MultiGraph()
|
|
375
|
-
G.add_edge(0, 1, key="a", weight=2)
|
|
376
|
-
G.add_edge(0, 1, key="b", weight=1)
|
|
377
|
-
T = nx.maximum_spanning_tree(G, algorithm=self.algo)
|
|
378
|
-
assert edges_equal([(0, 1, 2)], list(T.edges(data="weight")))
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
class TestSpanningTreeIterator:
|
|
382
|
-
"""
|
|
383
|
-
Tests the spanning tree iterator on the example graph in the 2005 Sörensen
|
|
384
|
-
and Janssens paper An Algorithm to Generate all Spanning Trees of a Graph in
|
|
385
|
-
Order of Increasing Cost
|
|
386
|
-
"""
|
|
387
|
-
|
|
388
|
-
def setup_method(self):
|
|
389
|
-
# Original Graph
|
|
390
|
-
edges = [(0, 1, 5), (1, 2, 4), (1, 4, 6), (2, 3, 5), (2, 4, 7), (3, 4, 3)]
|
|
391
|
-
self.G = nx.Graph()
|
|
392
|
-
self.G.add_weighted_edges_from(edges)
|
|
393
|
-
# List of lists of spanning trees in increasing order
|
|
394
|
-
self.spanning_trees = [
|
|
395
|
-
# 1, MST, cost = 17
|
|
396
|
-
[
|
|
397
|
-
(0, 1, {"weight": 5}),
|
|
398
|
-
(1, 2, {"weight": 4}),
|
|
399
|
-
(2, 3, {"weight": 5}),
|
|
400
|
-
(3, 4, {"weight": 3}),
|
|
401
|
-
],
|
|
402
|
-
# 2, cost = 18
|
|
403
|
-
[
|
|
404
|
-
(0, 1, {"weight": 5}),
|
|
405
|
-
(1, 2, {"weight": 4}),
|
|
406
|
-
(1, 4, {"weight": 6}),
|
|
407
|
-
(3, 4, {"weight": 3}),
|
|
408
|
-
],
|
|
409
|
-
# 3, cost = 19
|
|
410
|
-
[
|
|
411
|
-
(0, 1, {"weight": 5}),
|
|
412
|
-
(1, 4, {"weight": 6}),
|
|
413
|
-
(2, 3, {"weight": 5}),
|
|
414
|
-
(3, 4, {"weight": 3}),
|
|
415
|
-
],
|
|
416
|
-
# 4, cost = 19
|
|
417
|
-
[
|
|
418
|
-
(0, 1, {"weight": 5}),
|
|
419
|
-
(1, 2, {"weight": 4}),
|
|
420
|
-
(2, 4, {"weight": 7}),
|
|
421
|
-
(3, 4, {"weight": 3}),
|
|
422
|
-
],
|
|
423
|
-
# 5, cost = 20
|
|
424
|
-
[
|
|
425
|
-
(0, 1, {"weight": 5}),
|
|
426
|
-
(1, 2, {"weight": 4}),
|
|
427
|
-
(1, 4, {"weight": 6}),
|
|
428
|
-
(2, 3, {"weight": 5}),
|
|
429
|
-
],
|
|
430
|
-
# 6, cost = 21
|
|
431
|
-
[
|
|
432
|
-
(0, 1, {"weight": 5}),
|
|
433
|
-
(1, 4, {"weight": 6}),
|
|
434
|
-
(2, 4, {"weight": 7}),
|
|
435
|
-
(3, 4, {"weight": 3}),
|
|
436
|
-
],
|
|
437
|
-
# 7, cost = 21
|
|
438
|
-
[
|
|
439
|
-
(0, 1, {"weight": 5}),
|
|
440
|
-
(1, 2, {"weight": 4}),
|
|
441
|
-
(2, 3, {"weight": 5}),
|
|
442
|
-
(2, 4, {"weight": 7}),
|
|
443
|
-
],
|
|
444
|
-
# 8, cost = 23
|
|
445
|
-
[
|
|
446
|
-
(0, 1, {"weight": 5}),
|
|
447
|
-
(1, 4, {"weight": 6}),
|
|
448
|
-
(2, 3, {"weight": 5}),
|
|
449
|
-
(2, 4, {"weight": 7}),
|
|
450
|
-
],
|
|
451
|
-
]
|
|
452
|
-
|
|
453
|
-
def test_minimum_spanning_tree_iterator(self):
|
|
454
|
-
"""
|
|
455
|
-
Tests that the spanning trees are correctly returned in increasing order
|
|
456
|
-
"""
|
|
457
|
-
tree_index = 0
|
|
458
|
-
for tree in nx.SpanningTreeIterator(self.G):
|
|
459
|
-
actual = sorted(tree.edges(data=True))
|
|
460
|
-
assert edges_equal(actual, self.spanning_trees[tree_index])
|
|
461
|
-
tree_index += 1
|
|
462
|
-
|
|
463
|
-
def test_maximum_spanning_tree_iterator(self):
|
|
464
|
-
"""
|
|
465
|
-
Tests that the spanning trees are correctly returned in decreasing order
|
|
466
|
-
"""
|
|
467
|
-
tree_index = 7
|
|
468
|
-
for tree in nx.SpanningTreeIterator(self.G, minimum=False):
|
|
469
|
-
actual = sorted(tree.edges(data=True))
|
|
470
|
-
assert edges_equal(actual, self.spanning_trees[tree_index])
|
|
471
|
-
tree_index -= 1
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
class TestSpanningTreeMultiGraphIterator:
|
|
475
|
-
"""
|
|
476
|
-
Uses the same graph as the above class but with an added edge of twice the weight.
|
|
477
|
-
"""
|
|
478
|
-
|
|
479
|
-
def setup_method(self):
|
|
480
|
-
# New graph
|
|
481
|
-
edges = [
|
|
482
|
-
(0, 1, 5),
|
|
483
|
-
(0, 1, 10),
|
|
484
|
-
(1, 2, 4),
|
|
485
|
-
(1, 2, 8),
|
|
486
|
-
(1, 4, 6),
|
|
487
|
-
(1, 4, 12),
|
|
488
|
-
(2, 3, 5),
|
|
489
|
-
(2, 3, 10),
|
|
490
|
-
(2, 4, 7),
|
|
491
|
-
(2, 4, 14),
|
|
492
|
-
(3, 4, 3),
|
|
493
|
-
(3, 4, 6),
|
|
494
|
-
]
|
|
495
|
-
self.G = nx.MultiGraph()
|
|
496
|
-
self.G.add_weighted_edges_from(edges)
|
|
497
|
-
|
|
498
|
-
# There are 128 trees. I'd rather not list all 128 here, and computing them
|
|
499
|
-
# on such a small graph actually doesn't take that long.
|
|
500
|
-
from itertools import combinations
|
|
501
|
-
|
|
502
|
-
self.spanning_trees = []
|
|
503
|
-
for e in combinations(self.G.edges, 4):
|
|
504
|
-
tree = self.G.edge_subgraph(e)
|
|
505
|
-
if nx.is_tree(tree):
|
|
506
|
-
self.spanning_trees.append(sorted(tree.edges(keys=True, data=True)))
|
|
507
|
-
|
|
508
|
-
def test_minimum_spanning_tree_iterator_multigraph(self):
|
|
509
|
-
"""
|
|
510
|
-
Tests that the spanning trees are correctly returned in increasing order
|
|
511
|
-
"""
|
|
512
|
-
tree_index = 0
|
|
513
|
-
last_weight = 0
|
|
514
|
-
for tree in nx.SpanningTreeIterator(self.G):
|
|
515
|
-
actual = sorted(tree.edges(keys=True, data=True))
|
|
516
|
-
weight = sum([e[3]["weight"] for e in actual])
|
|
517
|
-
assert actual in self.spanning_trees
|
|
518
|
-
assert weight >= last_weight
|
|
519
|
-
tree_index += 1
|
|
520
|
-
|
|
521
|
-
def test_maximum_spanning_tree_iterator_multigraph(self):
|
|
522
|
-
"""
|
|
523
|
-
Tests that the spanning trees are correctly returned in decreasing order
|
|
524
|
-
"""
|
|
525
|
-
tree_index = 127
|
|
526
|
-
# Maximum weight tree is 46
|
|
527
|
-
last_weight = 50
|
|
528
|
-
for tree in nx.SpanningTreeIterator(self.G, minimum=False):
|
|
529
|
-
actual = sorted(tree.edges(keys=True, data=True))
|
|
530
|
-
weight = sum([e[3]["weight"] for e in actual])
|
|
531
|
-
assert actual in self.spanning_trees
|
|
532
|
-
assert weight <= last_weight
|
|
533
|
-
tree_index -= 1
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
def test_random_spanning_tree_multiplicative_small():
|
|
537
|
-
"""
|
|
538
|
-
Using a fixed seed, sample one tree for repeatability.
|
|
539
|
-
"""
|
|
540
|
-
from math import exp
|
|
541
|
-
|
|
542
|
-
pytest.importorskip("scipy")
|
|
543
|
-
|
|
544
|
-
gamma = {
|
|
545
|
-
(0, 1): -0.6383,
|
|
546
|
-
(0, 2): -0.6827,
|
|
547
|
-
(0, 5): 0,
|
|
548
|
-
(1, 2): -1.0781,
|
|
549
|
-
(1, 4): 0,
|
|
550
|
-
(2, 3): 0,
|
|
551
|
-
(5, 3): -0.2820,
|
|
552
|
-
(5, 4): -0.3327,
|
|
553
|
-
(4, 3): -0.9927,
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
# The undirected support of gamma
|
|
557
|
-
G = nx.Graph()
|
|
558
|
-
for u, v in gamma:
|
|
559
|
-
G.add_edge(u, v, lambda_key=exp(gamma[(u, v)]))
|
|
560
|
-
|
|
561
|
-
solution_edges = [(2, 3), (3, 4), (0, 5), (5, 4), (4, 1)]
|
|
562
|
-
solution = nx.Graph()
|
|
563
|
-
solution.add_edges_from(solution_edges)
|
|
564
|
-
|
|
565
|
-
sampled_tree = nx.random_spanning_tree(G, "lambda_key", seed=42)
|
|
566
|
-
|
|
567
|
-
assert nx.utils.edges_equal(solution.edges, sampled_tree.edges)
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
@pytest.mark.slow
|
|
571
|
-
def test_random_spanning_tree_multiplicative_large():
|
|
572
|
-
"""
|
|
573
|
-
Sample many trees from the distribution created in the last test
|
|
574
|
-
"""
|
|
575
|
-
from math import exp
|
|
576
|
-
from random import Random
|
|
577
|
-
|
|
578
|
-
pytest.importorskip("numpy")
|
|
579
|
-
stats = pytest.importorskip("scipy.stats")
|
|
580
|
-
|
|
581
|
-
gamma = {
|
|
582
|
-
(0, 1): -0.6383,
|
|
583
|
-
(0, 2): -0.6827,
|
|
584
|
-
(0, 5): 0,
|
|
585
|
-
(1, 2): -1.0781,
|
|
586
|
-
(1, 4): 0,
|
|
587
|
-
(2, 3): 0,
|
|
588
|
-
(5, 3): -0.2820,
|
|
589
|
-
(5, 4): -0.3327,
|
|
590
|
-
(4, 3): -0.9927,
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
# The undirected support of gamma
|
|
594
|
-
G = nx.Graph()
|
|
595
|
-
for u, v in gamma:
|
|
596
|
-
G.add_edge(u, v, lambda_key=exp(gamma[(u, v)]))
|
|
597
|
-
|
|
598
|
-
# Find the multiplicative weight for each tree.
|
|
599
|
-
total_weight = 0
|
|
600
|
-
tree_expected = {}
|
|
601
|
-
for t in nx.SpanningTreeIterator(G):
|
|
602
|
-
# Find the multiplicative weight of the spanning tree
|
|
603
|
-
weight = 1
|
|
604
|
-
for u, v, d in t.edges(data="lambda_key"):
|
|
605
|
-
weight *= d
|
|
606
|
-
tree_expected[t] = weight
|
|
607
|
-
total_weight += weight
|
|
608
|
-
|
|
609
|
-
# Assert that every tree has an entry in the expected distribution
|
|
610
|
-
assert len(tree_expected) == 75
|
|
611
|
-
|
|
612
|
-
# Set the sample size and then calculate the expected number of times we
|
|
613
|
-
# expect to see each tree. This test uses a near minimum sample size where
|
|
614
|
-
# the most unlikely tree has an expected frequency of 5.15.
|
|
615
|
-
# (Minimum required is 5)
|
|
616
|
-
#
|
|
617
|
-
# Here we also initialize the tree_actual dict so that we know the keys
|
|
618
|
-
# match between the two. We will later take advantage of the fact that since
|
|
619
|
-
# python 3.7 dict order is guaranteed so the expected and actual data will
|
|
620
|
-
# have the same order.
|
|
621
|
-
sample_size = 1200
|
|
622
|
-
tree_actual = {}
|
|
623
|
-
for t in tree_expected:
|
|
624
|
-
tree_expected[t] = (tree_expected[t] / total_weight) * sample_size
|
|
625
|
-
tree_actual[t] = 0
|
|
626
|
-
|
|
627
|
-
# Sample the spanning trees
|
|
628
|
-
#
|
|
629
|
-
# Assert that they are actually trees and record which of the 75 trees we
|
|
630
|
-
# have sampled.
|
|
631
|
-
#
|
|
632
|
-
# For repeatability, we want to take advantage of the decorators in NetworkX
|
|
633
|
-
# to randomly sample the same sample each time. However, if we pass in a
|
|
634
|
-
# constant seed to sample_spanning_tree we will get the same tree each time.
|
|
635
|
-
# Instead, we can create our own random number generator with a fixed seed
|
|
636
|
-
# and pass those into sample_spanning_tree.
|
|
637
|
-
rng = Random(37)
|
|
638
|
-
for _ in range(sample_size):
|
|
639
|
-
sampled_tree = nx.random_spanning_tree(G, "lambda_key", seed=rng)
|
|
640
|
-
assert nx.is_tree(sampled_tree)
|
|
641
|
-
|
|
642
|
-
for t in tree_expected:
|
|
643
|
-
if nx.utils.edges_equal(t.edges, sampled_tree.edges):
|
|
644
|
-
tree_actual[t] += 1
|
|
645
|
-
break
|
|
646
|
-
|
|
647
|
-
# Conduct a Chi squared test to see if the actual distribution matches the
|
|
648
|
-
# expected one at an alpha = 0.05 significance level.
|
|
649
|
-
#
|
|
650
|
-
# H_0: The distribution of trees in tree_actual matches the normalized product
|
|
651
|
-
# of the edge weights in the tree.
|
|
652
|
-
#
|
|
653
|
-
# H_a: The distribution of trees in tree_actual follows some other
|
|
654
|
-
# distribution of spanning trees.
|
|
655
|
-
_, p = stats.chisquare(list(tree_actual.values()), list(tree_expected.values()))
|
|
656
|
-
|
|
657
|
-
# Assert that p is greater than the significance level so that we do not
|
|
658
|
-
# reject the null hypothesis
|
|
659
|
-
assert not p < 0.05
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
def test_random_spanning_tree_additive_small():
|
|
663
|
-
"""
|
|
664
|
-
Sample a single spanning tree from the additive method.
|
|
665
|
-
"""
|
|
666
|
-
pytest.importorskip("scipy")
|
|
667
|
-
|
|
668
|
-
edges = {
|
|
669
|
-
(0, 1): 1,
|
|
670
|
-
(0, 2): 1,
|
|
671
|
-
(0, 5): 3,
|
|
672
|
-
(1, 2): 2,
|
|
673
|
-
(1, 4): 3,
|
|
674
|
-
(2, 3): 3,
|
|
675
|
-
(5, 3): 4,
|
|
676
|
-
(5, 4): 5,
|
|
677
|
-
(4, 3): 4,
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
# Build the graph
|
|
681
|
-
G = nx.Graph()
|
|
682
|
-
for u, v in edges:
|
|
683
|
-
G.add_edge(u, v, weight=edges[(u, v)])
|
|
684
|
-
|
|
685
|
-
solution_edges = [(0, 2), (1, 2), (2, 3), (3, 4), (3, 5)]
|
|
686
|
-
solution = nx.Graph()
|
|
687
|
-
solution.add_edges_from(solution_edges)
|
|
688
|
-
|
|
689
|
-
sampled_tree = nx.random_spanning_tree(
|
|
690
|
-
G, weight="weight", multiplicative=False, seed=37
|
|
691
|
-
)
|
|
692
|
-
|
|
693
|
-
assert nx.utils.edges_equal(solution.edges, sampled_tree.edges)
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
@pytest.mark.slow
|
|
697
|
-
def test_random_spanning_tree_additive_large():
|
|
698
|
-
"""
|
|
699
|
-
Sample many spanning trees from the additive method.
|
|
700
|
-
"""
|
|
701
|
-
from random import Random
|
|
702
|
-
|
|
703
|
-
pytest.importorskip("numpy")
|
|
704
|
-
stats = pytest.importorskip("scipy.stats")
|
|
705
|
-
|
|
706
|
-
edges = {
|
|
707
|
-
(0, 1): 1,
|
|
708
|
-
(0, 2): 1,
|
|
709
|
-
(0, 5): 3,
|
|
710
|
-
(1, 2): 2,
|
|
711
|
-
(1, 4): 3,
|
|
712
|
-
(2, 3): 3,
|
|
713
|
-
(5, 3): 4,
|
|
714
|
-
(5, 4): 5,
|
|
715
|
-
(4, 3): 4,
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
# Build the graph
|
|
719
|
-
G = nx.Graph()
|
|
720
|
-
for u, v in edges:
|
|
721
|
-
G.add_edge(u, v, weight=edges[(u, v)])
|
|
722
|
-
|
|
723
|
-
# Find the additive weight for each tree.
|
|
724
|
-
total_weight = 0
|
|
725
|
-
tree_expected = {}
|
|
726
|
-
for t in nx.SpanningTreeIterator(G):
|
|
727
|
-
# Find the multiplicative weight of the spanning tree
|
|
728
|
-
weight = 0
|
|
729
|
-
for u, v, d in t.edges(data="weight"):
|
|
730
|
-
weight += d
|
|
731
|
-
tree_expected[t] = weight
|
|
732
|
-
total_weight += weight
|
|
733
|
-
|
|
734
|
-
# Assert that every tree has an entry in the expected distribution
|
|
735
|
-
assert len(tree_expected) == 75
|
|
736
|
-
|
|
737
|
-
# Set the sample size and then calculate the expected number of times we
|
|
738
|
-
# expect to see each tree. This test uses a near minimum sample size where
|
|
739
|
-
# the most unlikely tree has an expected frequency of 5.07.
|
|
740
|
-
# (Minimum required is 5)
|
|
741
|
-
#
|
|
742
|
-
# Here we also initialize the tree_actual dict so that we know the keys
|
|
743
|
-
# match between the two. We will later take advantage of the fact that since
|
|
744
|
-
# python 3.7 dict order is guaranteed so the expected and actual data will
|
|
745
|
-
# have the same order.
|
|
746
|
-
sample_size = 500
|
|
747
|
-
tree_actual = {}
|
|
748
|
-
for t in tree_expected:
|
|
749
|
-
tree_expected[t] = (tree_expected[t] / total_weight) * sample_size
|
|
750
|
-
tree_actual[t] = 0
|
|
751
|
-
|
|
752
|
-
# Sample the spanning trees
|
|
753
|
-
#
|
|
754
|
-
# Assert that they are actually trees and record which of the 75 trees we
|
|
755
|
-
# have sampled.
|
|
756
|
-
#
|
|
757
|
-
# For repeatability, we want to take advantage of the decorators in NetworkX
|
|
758
|
-
# to randomly sample the same sample each time. However, if we pass in a
|
|
759
|
-
# constant seed to sample_spanning_tree we will get the same tree each time.
|
|
760
|
-
# Instead, we can create our own random number generator with a fixed seed
|
|
761
|
-
# and pass those into sample_spanning_tree.
|
|
762
|
-
rng = Random(37)
|
|
763
|
-
for _ in range(sample_size):
|
|
764
|
-
sampled_tree = nx.random_spanning_tree(
|
|
765
|
-
G, "weight", multiplicative=False, seed=rng
|
|
766
|
-
)
|
|
767
|
-
assert nx.is_tree(sampled_tree)
|
|
768
|
-
|
|
769
|
-
for t in tree_expected:
|
|
770
|
-
if nx.utils.edges_equal(t.edges, sampled_tree.edges):
|
|
771
|
-
tree_actual[t] += 1
|
|
772
|
-
break
|
|
773
|
-
|
|
774
|
-
# Conduct a Chi squared test to see if the actual distribution matches the
|
|
775
|
-
# expected one at an alpha = 0.05 significance level.
|
|
776
|
-
#
|
|
777
|
-
# H_0: The distribution of trees in tree_actual matches the normalized product
|
|
778
|
-
# of the edge weights in the tree.
|
|
779
|
-
#
|
|
780
|
-
# H_a: The distribution of trees in tree_actual follows some other
|
|
781
|
-
# distribution of spanning trees.
|
|
782
|
-
_, p = stats.chisquare(list(tree_actual.values()), list(tree_expected.values()))
|
|
783
|
-
|
|
784
|
-
# Assert that p is greater than the significance level so that we do not
|
|
785
|
-
# reject the null hypothesis
|
|
786
|
-
assert not p < 0.05
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
def test_random_spanning_tree_empty_graph():
|
|
790
|
-
G = nx.Graph()
|
|
791
|
-
rst = nx.tree.random_spanning_tree(G)
|
|
792
|
-
assert len(rst.nodes) == 0
|
|
793
|
-
assert len(rst.edges) == 0
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
def test_random_spanning_tree_single_node_graph():
|
|
797
|
-
G = nx.Graph()
|
|
798
|
-
G.add_node(0)
|
|
799
|
-
rst = nx.tree.random_spanning_tree(G)
|
|
800
|
-
assert len(rst.nodes) == 1
|
|
801
|
-
assert len(rst.edges) == 0
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
def test_random_spanning_tree_single_node_loop():
|
|
805
|
-
G = nx.Graph()
|
|
806
|
-
G.add_node(0)
|
|
807
|
-
G.add_edge(0, 0)
|
|
808
|
-
rst = nx.tree.random_spanning_tree(G)
|
|
809
|
-
assert len(rst.nodes) == 1
|
|
810
|
-
assert len(rst.edges) == 0
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
class TestNumberSpanningTrees:
|
|
814
|
-
@classmethod
|
|
815
|
-
def setup_class(cls):
|
|
816
|
-
global np
|
|
817
|
-
np = pytest.importorskip("numpy")
|
|
818
|
-
sp = pytest.importorskip("scipy")
|
|
819
|
-
|
|
820
|
-
def test_nst_disconnected(self):
|
|
821
|
-
G = nx.empty_graph(2)
|
|
822
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 0)
|
|
823
|
-
|
|
824
|
-
def test_nst_no_nodes(self):
|
|
825
|
-
G = nx.Graph()
|
|
826
|
-
with pytest.raises(nx.NetworkXPointlessConcept):
|
|
827
|
-
nx.number_of_spanning_trees(G)
|
|
828
|
-
|
|
829
|
-
def test_nst_weight(self):
|
|
830
|
-
G = nx.Graph()
|
|
831
|
-
G.add_edge(1, 2, weight=1)
|
|
832
|
-
G.add_edge(1, 3, weight=1)
|
|
833
|
-
G.add_edge(2, 3, weight=2)
|
|
834
|
-
# weights are ignored
|
|
835
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 3)
|
|
836
|
-
# including weight
|
|
837
|
-
assert np.isclose(nx.number_of_spanning_trees(G, weight="weight"), 5)
|
|
838
|
-
|
|
839
|
-
def test_nst_negative_weight(self):
|
|
840
|
-
G = nx.Graph()
|
|
841
|
-
G.add_edge(1, 2, weight=1)
|
|
842
|
-
G.add_edge(1, 3, weight=-1)
|
|
843
|
-
G.add_edge(2, 3, weight=-2)
|
|
844
|
-
# weights are ignored
|
|
845
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 3)
|
|
846
|
-
# including weight
|
|
847
|
-
assert np.isclose(nx.number_of_spanning_trees(G, weight="weight"), -1)
|
|
848
|
-
|
|
849
|
-
def test_nst_selfloop(self):
|
|
850
|
-
# self-loops are ignored
|
|
851
|
-
G = nx.complete_graph(3)
|
|
852
|
-
G.add_edge(1, 1)
|
|
853
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 3)
|
|
854
|
-
|
|
855
|
-
def test_nst_multigraph(self):
|
|
856
|
-
G = nx.MultiGraph()
|
|
857
|
-
G.add_edge(1, 2)
|
|
858
|
-
G.add_edge(1, 2)
|
|
859
|
-
G.add_edge(1, 3)
|
|
860
|
-
G.add_edge(2, 3)
|
|
861
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 5)
|
|
862
|
-
|
|
863
|
-
def test_nst_complete_graph(self):
|
|
864
|
-
# this is known as Cayley's formula
|
|
865
|
-
N = 5
|
|
866
|
-
G = nx.complete_graph(N)
|
|
867
|
-
assert np.isclose(nx.number_of_spanning_trees(G), N ** (N - 2))
|
|
868
|
-
|
|
869
|
-
def test_nst_path_graph(self):
|
|
870
|
-
G = nx.path_graph(5)
|
|
871
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 1)
|
|
872
|
-
|
|
873
|
-
def test_nst_cycle_graph(self):
|
|
874
|
-
G = nx.cycle_graph(5)
|
|
875
|
-
assert np.isclose(nx.number_of_spanning_trees(G), 5)
|
|
876
|
-
|
|
877
|
-
def test_nst_directed_noroot(self):
|
|
878
|
-
G = nx.empty_graph(3, create_using=nx.MultiDiGraph)
|
|
879
|
-
with pytest.raises(nx.NetworkXError):
|
|
880
|
-
nx.number_of_spanning_trees(G)
|
|
881
|
-
|
|
882
|
-
def test_nst_directed_root_not_exist(self):
|
|
883
|
-
G = nx.empty_graph(3, create_using=nx.MultiDiGraph)
|
|
884
|
-
with pytest.raises(nx.NetworkXError):
|
|
885
|
-
nx.number_of_spanning_trees(G, root=42)
|
|
886
|
-
|
|
887
|
-
def test_nst_directed_not_weak_connected(self):
|
|
888
|
-
G = nx.DiGraph()
|
|
889
|
-
G.add_edge(1, 2)
|
|
890
|
-
G.add_edge(3, 4)
|
|
891
|
-
assert np.isclose(nx.number_of_spanning_trees(G, root=1), 0)
|
|
892
|
-
|
|
893
|
-
def test_nst_directed_cycle_graph(self):
|
|
894
|
-
G = nx.DiGraph()
|
|
895
|
-
G = nx.cycle_graph(7, G)
|
|
896
|
-
assert np.isclose(nx.number_of_spanning_trees(G, root=0), 1)
|
|
897
|
-
|
|
898
|
-
def test_nst_directed_complete_graph(self):
|
|
899
|
-
G = nx.DiGraph()
|
|
900
|
-
G = nx.complete_graph(7, G)
|
|
901
|
-
assert np.isclose(nx.number_of_spanning_trees(G, root=0), 7**5)
|
|
902
|
-
|
|
903
|
-
def test_nst_directed_multi(self):
|
|
904
|
-
G = nx.MultiDiGraph()
|
|
905
|
-
G = nx.cycle_graph(3, G)
|
|
906
|
-
G.add_edge(1, 2)
|
|
907
|
-
assert np.isclose(nx.number_of_spanning_trees(G, root=0), 2)
|
|
908
|
-
|
|
909
|
-
def test_nst_directed_selfloop(self):
|
|
910
|
-
G = nx.MultiDiGraph()
|
|
911
|
-
G = nx.cycle_graph(3, G)
|
|
912
|
-
G.add_edge(1, 1)
|
|
913
|
-
assert np.isclose(nx.number_of_spanning_trees(G, root=0), 1)
|
|
914
|
-
|
|
915
|
-
def test_nst_directed_weak_connected(self):
|
|
916
|
-
G = nx.MultiDiGraph()
|
|
917
|
-
G = nx.cycle_graph(3, G)
|
|
918
|
-
G.remove_edge(1, 2)
|
|
919
|
-
assert np.isclose(nx.number_of_spanning_trees(G, root=0), 0)
|
|
920
|
-
|
|
921
|
-
def test_nst_directed_weighted(self):
|
|
922
|
-
# from root=1:
|
|
923
|
-
# arborescence 1: 1->2, 1->3, weight=2*1
|
|
924
|
-
# arborescence 2: 1->2, 2->3, weight=2*3
|
|
925
|
-
G = nx.DiGraph()
|
|
926
|
-
G.add_edge(1, 2, weight=2)
|
|
927
|
-
G.add_edge(1, 3, weight=1)
|
|
928
|
-
G.add_edge(2, 3, weight=3)
|
|
929
|
-
Nst = nx.number_of_spanning_trees(G, root=1, weight="weight")
|
|
930
|
-
assert np.isclose(Nst, 8)
|
|
931
|
-
Nst = nx.number_of_spanning_trees(G, root=2, weight="weight")
|
|
932
|
-
assert np.isclose(Nst, 0)
|
|
933
|
-
Nst = nx.number_of_spanning_trees(G, root=3, weight="weight")
|
|
934
|
-
assert np.isclose(Nst, 0)
|