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,831 +0,0 @@
|
|
|
1
|
-
import itertools
|
|
2
|
-
import math
|
|
3
|
-
from random import Random
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
|
|
7
|
-
import networkx as nx
|
|
8
|
-
from networkx import convert_node_labels_to_integers as cnlti
|
|
9
|
-
from networkx.algorithms.distance_measures import _extrema_bounding
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def test__extrema_bounding_invalid_compute_kwarg():
|
|
13
|
-
G = nx.path_graph(3)
|
|
14
|
-
with pytest.raises(ValueError, match="compute must be one of"):
|
|
15
|
-
_extrema_bounding(G, compute="spam")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class TestDistance:
|
|
19
|
-
def setup_method(self):
|
|
20
|
-
self.G = cnlti(nx.grid_2d_graph(4, 4), first_label=1, ordering="sorted")
|
|
21
|
-
|
|
22
|
-
@pytest.mark.parametrize("seed", list(range(10)))
|
|
23
|
-
@pytest.mark.parametrize("n", list(range(10, 20)))
|
|
24
|
-
@pytest.mark.parametrize("prob", [x / 10 for x in range(0, 10, 2)])
|
|
25
|
-
def test_use_bounds_on_off_consistency(self, seed, n, prob):
|
|
26
|
-
"""Test for consistency of distance metrics when using usebounds=True.
|
|
27
|
-
|
|
28
|
-
We validate consistency for `networkx.diameter`, `networkx.radius`, `networkx.periphery`
|
|
29
|
-
and `networkx.center` when passing `usebounds=True`. Expectation is that method
|
|
30
|
-
returns the same result whether we pass usebounds=True or not.
|
|
31
|
-
|
|
32
|
-
For this we generate random connected graphs and validate method returns the same.
|
|
33
|
-
"""
|
|
34
|
-
metrics = [nx.diameter, nx.radius, nx.periphery, nx.center]
|
|
35
|
-
max_weight = [5, 10, 1000]
|
|
36
|
-
rng = Random(seed)
|
|
37
|
-
# we compose it with a random tree to ensure graph is connected
|
|
38
|
-
G = nx.compose(
|
|
39
|
-
nx.random_labeled_tree(n, seed=rng),
|
|
40
|
-
nx.erdos_renyi_graph(n, prob, seed=rng),
|
|
41
|
-
)
|
|
42
|
-
for metric in metrics:
|
|
43
|
-
# checking unweighted case
|
|
44
|
-
assert metric(G) == metric(G, usebounds=True)
|
|
45
|
-
for w in max_weight:
|
|
46
|
-
for u, v in G.edges():
|
|
47
|
-
G[u][v]["w"] = rng.randint(0, w)
|
|
48
|
-
# checking weighted case
|
|
49
|
-
assert metric(G, weight="w") == metric(G, weight="w", usebounds=True)
|
|
50
|
-
|
|
51
|
-
def test_eccentricity(self):
|
|
52
|
-
assert nx.eccentricity(self.G, 1) == 6
|
|
53
|
-
e = nx.eccentricity(self.G)
|
|
54
|
-
assert e[1] == 6
|
|
55
|
-
|
|
56
|
-
sp = dict(nx.shortest_path_length(self.G))
|
|
57
|
-
e = nx.eccentricity(self.G, sp=sp)
|
|
58
|
-
assert e[1] == 6
|
|
59
|
-
|
|
60
|
-
e = nx.eccentricity(self.G, v=1)
|
|
61
|
-
assert e == 6
|
|
62
|
-
|
|
63
|
-
# This behavior changed in version 1.8 (ticket #739)
|
|
64
|
-
e = nx.eccentricity(self.G, v=[1, 1])
|
|
65
|
-
assert e[1] == 6
|
|
66
|
-
e = nx.eccentricity(self.G, v=[1, 2])
|
|
67
|
-
assert e[1] == 6
|
|
68
|
-
|
|
69
|
-
# test against graph with one node
|
|
70
|
-
G = nx.path_graph(1)
|
|
71
|
-
e = nx.eccentricity(G)
|
|
72
|
-
assert e[0] == 0
|
|
73
|
-
e = nx.eccentricity(G, v=0)
|
|
74
|
-
assert e == 0
|
|
75
|
-
pytest.raises(nx.NetworkXError, nx.eccentricity, G, 1)
|
|
76
|
-
|
|
77
|
-
# test against empty graph
|
|
78
|
-
G = nx.empty_graph()
|
|
79
|
-
e = nx.eccentricity(G)
|
|
80
|
-
assert e == {}
|
|
81
|
-
|
|
82
|
-
def test_diameter(self):
|
|
83
|
-
assert nx.diameter(self.G) == 6
|
|
84
|
-
|
|
85
|
-
def test_harmonic_diameter(self):
|
|
86
|
-
assert nx.harmonic_diameter(self.G) == pytest.approx(2.0477815699658715)
|
|
87
|
-
assert nx.harmonic_diameter(nx.star_graph(3)) == pytest.approx(1.333333)
|
|
88
|
-
|
|
89
|
-
def test_harmonic_diameter_empty(self):
|
|
90
|
-
assert math.isnan(nx.harmonic_diameter(nx.empty_graph()))
|
|
91
|
-
|
|
92
|
-
def test_harmonic_diameter_single_node(self):
|
|
93
|
-
assert math.isnan(nx.harmonic_diameter(nx.empty_graph(1)))
|
|
94
|
-
|
|
95
|
-
def test_harmonic_diameter_discrete(self):
|
|
96
|
-
assert math.isinf(nx.harmonic_diameter(nx.empty_graph(3)))
|
|
97
|
-
|
|
98
|
-
def test_harmonic_diameter_not_strongly_connected(self):
|
|
99
|
-
DG = nx.DiGraph()
|
|
100
|
-
DG.add_edge(0, 1)
|
|
101
|
-
assert nx.harmonic_diameter(DG) == 2
|
|
102
|
-
|
|
103
|
-
def test_harmonic_diameter_weighted_paths(self):
|
|
104
|
-
G = nx.star_graph(3)
|
|
105
|
-
# check defaults
|
|
106
|
-
G.add_weighted_edges_from([(*e, 1) for i, e in enumerate(G.edges)], "weight")
|
|
107
|
-
assert nx.harmonic_diameter(G) == pytest.approx(1.333333)
|
|
108
|
-
assert nx.harmonic_diameter(G, weight="weight") == pytest.approx(1.333333)
|
|
109
|
-
|
|
110
|
-
# check impact of weights and alternate weight name
|
|
111
|
-
G.add_weighted_edges_from([(*e, i) for i, e in enumerate(G.edges)], "dist")
|
|
112
|
-
assert nx.harmonic_diameter(G, weight="dist") == pytest.approx(1.8)
|
|
113
|
-
|
|
114
|
-
def test_radius(self):
|
|
115
|
-
assert nx.radius(self.G) == 4
|
|
116
|
-
|
|
117
|
-
def test_periphery(self):
|
|
118
|
-
assert set(nx.periphery(self.G)) == {1, 4, 13, 16}
|
|
119
|
-
|
|
120
|
-
def test_center_simple_tree(self):
|
|
121
|
-
G = nx.Graph([(1, 2), (1, 3), (2, 4), (2, 5)])
|
|
122
|
-
assert nx.center(G) == [1, 2]
|
|
123
|
-
|
|
124
|
-
@pytest.mark.parametrize("r", range(2, 5))
|
|
125
|
-
@pytest.mark.parametrize("h", range(1, 5))
|
|
126
|
-
def test_center_balanced_tree(self, r, h):
|
|
127
|
-
G = nx.balanced_tree(r, h)
|
|
128
|
-
assert nx.center(G) == [0]
|
|
129
|
-
|
|
130
|
-
def test_center(self):
|
|
131
|
-
assert set(nx.center(self.G)) == {6, 7, 10, 11}
|
|
132
|
-
|
|
133
|
-
@pytest.mark.parametrize("n", [1, 2, 99, 100])
|
|
134
|
-
def test_center_path_graphs(self, n):
|
|
135
|
-
G = nx.path_graph(n)
|
|
136
|
-
expected = {(n - 1) // 2, math.ceil((n - 1) / 2)}
|
|
137
|
-
assert set(nx.center(G)) == expected
|
|
138
|
-
|
|
139
|
-
def test_bound_diameter(self):
|
|
140
|
-
assert nx.diameter(self.G, usebounds=True) == 6
|
|
141
|
-
|
|
142
|
-
def test_bound_radius(self):
|
|
143
|
-
assert nx.radius(self.G, usebounds=True) == 4
|
|
144
|
-
|
|
145
|
-
def test_bound_periphery(self):
|
|
146
|
-
result = {1, 4, 13, 16}
|
|
147
|
-
assert set(nx.periphery(self.G, usebounds=True)) == result
|
|
148
|
-
|
|
149
|
-
def test_bound_center(self):
|
|
150
|
-
result = {6, 7, 10, 11}
|
|
151
|
-
assert set(nx.center(self.G, usebounds=True)) == result
|
|
152
|
-
|
|
153
|
-
def test_radius_exception(self):
|
|
154
|
-
G = nx.Graph()
|
|
155
|
-
G.add_edge(1, 2)
|
|
156
|
-
G.add_edge(3, 4)
|
|
157
|
-
pytest.raises(nx.NetworkXError, nx.diameter, G)
|
|
158
|
-
|
|
159
|
-
def test_eccentricity_infinite(self):
|
|
160
|
-
with pytest.raises(nx.NetworkXError):
|
|
161
|
-
G = nx.Graph([(1, 2), (3, 4)])
|
|
162
|
-
e = nx.eccentricity(G)
|
|
163
|
-
|
|
164
|
-
def test_eccentricity_undirected_not_connected(self):
|
|
165
|
-
with pytest.raises(nx.NetworkXError):
|
|
166
|
-
G = nx.Graph([(1, 2), (3, 4)])
|
|
167
|
-
e = nx.eccentricity(G, sp=1)
|
|
168
|
-
|
|
169
|
-
def test_eccentricity_directed_weakly_connected(self):
|
|
170
|
-
with pytest.raises(nx.NetworkXError):
|
|
171
|
-
DG = nx.DiGraph([(1, 2), (1, 3)])
|
|
172
|
-
nx.eccentricity(DG)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
class TestWeightedDistance:
|
|
176
|
-
def setup_method(self):
|
|
177
|
-
G = nx.Graph()
|
|
178
|
-
G.add_edge(0, 1, weight=0.6, cost=0.6, high_cost=6)
|
|
179
|
-
G.add_edge(0, 2, weight=0.2, cost=0.2, high_cost=2)
|
|
180
|
-
G.add_edge(2, 3, weight=0.1, cost=0.1, high_cost=1)
|
|
181
|
-
G.add_edge(2, 4, weight=0.7, cost=0.7, high_cost=7)
|
|
182
|
-
G.add_edge(2, 5, weight=0.9, cost=0.9, high_cost=9)
|
|
183
|
-
G.add_edge(1, 5, weight=0.3, cost=0.3, high_cost=3)
|
|
184
|
-
self.G = G
|
|
185
|
-
self.weight_fn = lambda v, u, e: 2
|
|
186
|
-
|
|
187
|
-
def test_eccentricity_weight_None(self):
|
|
188
|
-
assert nx.eccentricity(self.G, 1, weight=None) == 3
|
|
189
|
-
e = nx.eccentricity(self.G, weight=None)
|
|
190
|
-
assert e[1] == 3
|
|
191
|
-
|
|
192
|
-
e = nx.eccentricity(self.G, v=1, weight=None)
|
|
193
|
-
assert e == 3
|
|
194
|
-
|
|
195
|
-
# This behavior changed in version 1.8 (ticket #739)
|
|
196
|
-
e = nx.eccentricity(self.G, v=[1, 1], weight=None)
|
|
197
|
-
assert e[1] == 3
|
|
198
|
-
e = nx.eccentricity(self.G, v=[1, 2], weight=None)
|
|
199
|
-
assert e[1] == 3
|
|
200
|
-
|
|
201
|
-
def test_eccentricity_weight_attr(self):
|
|
202
|
-
assert nx.eccentricity(self.G, 1, weight="weight") == 1.5
|
|
203
|
-
e = nx.eccentricity(self.G, weight="weight")
|
|
204
|
-
assert (
|
|
205
|
-
e
|
|
206
|
-
== nx.eccentricity(self.G, weight="cost")
|
|
207
|
-
!= nx.eccentricity(self.G, weight="high_cost")
|
|
208
|
-
)
|
|
209
|
-
assert e[1] == 1.5
|
|
210
|
-
|
|
211
|
-
e = nx.eccentricity(self.G, v=1, weight="weight")
|
|
212
|
-
assert e == 1.5
|
|
213
|
-
|
|
214
|
-
# This behavior changed in version 1.8 (ticket #739)
|
|
215
|
-
e = nx.eccentricity(self.G, v=[1, 1], weight="weight")
|
|
216
|
-
assert e[1] == 1.5
|
|
217
|
-
e = nx.eccentricity(self.G, v=[1, 2], weight="weight")
|
|
218
|
-
assert e[1] == 1.5
|
|
219
|
-
|
|
220
|
-
def test_eccentricity_weight_fn(self):
|
|
221
|
-
assert nx.eccentricity(self.G, 1, weight=self.weight_fn) == 6
|
|
222
|
-
e = nx.eccentricity(self.G, weight=self.weight_fn)
|
|
223
|
-
assert e[1] == 6
|
|
224
|
-
|
|
225
|
-
e = nx.eccentricity(self.G, v=1, weight=self.weight_fn)
|
|
226
|
-
assert e == 6
|
|
227
|
-
|
|
228
|
-
# This behavior changed in version 1.8 (ticket #739)
|
|
229
|
-
e = nx.eccentricity(self.G, v=[1, 1], weight=self.weight_fn)
|
|
230
|
-
assert e[1] == 6
|
|
231
|
-
e = nx.eccentricity(self.G, v=[1, 2], weight=self.weight_fn)
|
|
232
|
-
assert e[1] == 6
|
|
233
|
-
|
|
234
|
-
def test_diameter_weight_None(self):
|
|
235
|
-
assert nx.diameter(self.G, weight=None) == 3
|
|
236
|
-
|
|
237
|
-
def test_diameter_weight_attr(self):
|
|
238
|
-
assert (
|
|
239
|
-
nx.diameter(self.G, weight="weight")
|
|
240
|
-
== nx.diameter(self.G, weight="cost")
|
|
241
|
-
== 1.6
|
|
242
|
-
!= nx.diameter(self.G, weight="high_cost")
|
|
243
|
-
)
|
|
244
|
-
|
|
245
|
-
def test_diameter_weight_fn(self):
|
|
246
|
-
assert nx.diameter(self.G, weight=self.weight_fn) == 6
|
|
247
|
-
|
|
248
|
-
def test_radius_weight_None(self):
|
|
249
|
-
assert pytest.approx(nx.radius(self.G, weight=None)) == 2
|
|
250
|
-
|
|
251
|
-
def test_radius_weight_attr(self):
|
|
252
|
-
assert (
|
|
253
|
-
pytest.approx(nx.radius(self.G, weight="weight"))
|
|
254
|
-
== pytest.approx(nx.radius(self.G, weight="cost"))
|
|
255
|
-
== 0.9
|
|
256
|
-
!= nx.radius(self.G, weight="high_cost")
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
def test_radius_weight_fn(self):
|
|
260
|
-
assert nx.radius(self.G, weight=self.weight_fn) == 4
|
|
261
|
-
|
|
262
|
-
def test_periphery_weight_None(self):
|
|
263
|
-
for v in set(nx.periphery(self.G, weight=None)):
|
|
264
|
-
assert nx.eccentricity(self.G, v, weight=None) == nx.diameter(
|
|
265
|
-
self.G, weight=None
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
def test_periphery_weight_attr(self):
|
|
269
|
-
periphery = set(nx.periphery(self.G, weight="weight"))
|
|
270
|
-
assert (
|
|
271
|
-
periphery
|
|
272
|
-
== set(nx.periphery(self.G, weight="cost"))
|
|
273
|
-
== set(nx.periphery(self.G, weight="high_cost"))
|
|
274
|
-
)
|
|
275
|
-
for v in periphery:
|
|
276
|
-
assert (
|
|
277
|
-
nx.eccentricity(self.G, v, weight="high_cost")
|
|
278
|
-
!= nx.eccentricity(self.G, v, weight="weight")
|
|
279
|
-
== nx.eccentricity(self.G, v, weight="cost")
|
|
280
|
-
== nx.diameter(self.G, weight="weight")
|
|
281
|
-
== nx.diameter(self.G, weight="cost")
|
|
282
|
-
!= nx.diameter(self.G, weight="high_cost")
|
|
283
|
-
)
|
|
284
|
-
assert nx.eccentricity(self.G, v, weight="high_cost") == nx.diameter(
|
|
285
|
-
self.G, weight="high_cost"
|
|
286
|
-
)
|
|
287
|
-
|
|
288
|
-
def test_periphery_weight_fn(self):
|
|
289
|
-
for v in set(nx.periphery(self.G, weight=self.weight_fn)):
|
|
290
|
-
assert nx.eccentricity(self.G, v, weight=self.weight_fn) == nx.diameter(
|
|
291
|
-
self.G, weight=self.weight_fn
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
def test_center_weight_None(self):
|
|
295
|
-
for v in set(nx.center(self.G, weight=None)):
|
|
296
|
-
assert pytest.approx(nx.eccentricity(self.G, v, weight=None)) == nx.radius(
|
|
297
|
-
self.G, weight=None
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
def test_center_weight_attr(self):
|
|
301
|
-
center = set(nx.center(self.G, weight="weight"))
|
|
302
|
-
assert (
|
|
303
|
-
center
|
|
304
|
-
== set(nx.center(self.G, weight="cost"))
|
|
305
|
-
!= set(nx.center(self.G, weight="high_cost"))
|
|
306
|
-
)
|
|
307
|
-
for v in center:
|
|
308
|
-
assert (
|
|
309
|
-
nx.eccentricity(self.G, v, weight="high_cost")
|
|
310
|
-
!= pytest.approx(nx.eccentricity(self.G, v, weight="weight"))
|
|
311
|
-
== pytest.approx(nx.eccentricity(self.G, v, weight="cost"))
|
|
312
|
-
== nx.radius(self.G, weight="weight")
|
|
313
|
-
== nx.radius(self.G, weight="cost")
|
|
314
|
-
!= nx.radius(self.G, weight="high_cost")
|
|
315
|
-
)
|
|
316
|
-
assert nx.eccentricity(self.G, v, weight="high_cost") == nx.radius(
|
|
317
|
-
self.G, weight="high_cost"
|
|
318
|
-
)
|
|
319
|
-
|
|
320
|
-
def test_center_weight_fn(self):
|
|
321
|
-
for v in set(nx.center(self.G, weight=self.weight_fn)):
|
|
322
|
-
assert nx.eccentricity(self.G, v, weight=self.weight_fn) == nx.radius(
|
|
323
|
-
self.G, weight=self.weight_fn
|
|
324
|
-
)
|
|
325
|
-
|
|
326
|
-
def test_bound_diameter_weight_None(self):
|
|
327
|
-
assert nx.diameter(self.G, usebounds=True, weight=None) == 3
|
|
328
|
-
|
|
329
|
-
def test_bound_diameter_weight_attr(self):
|
|
330
|
-
assert (
|
|
331
|
-
nx.diameter(self.G, usebounds=True, weight="high_cost")
|
|
332
|
-
!= nx.diameter(self.G, usebounds=True, weight="weight")
|
|
333
|
-
== nx.diameter(self.G, usebounds=True, weight="cost")
|
|
334
|
-
== 1.6
|
|
335
|
-
!= nx.diameter(self.G, usebounds=True, weight="high_cost")
|
|
336
|
-
)
|
|
337
|
-
assert nx.diameter(self.G, usebounds=True, weight="high_cost") == nx.diameter(
|
|
338
|
-
self.G, usebounds=True, weight="high_cost"
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
def test_bound_diameter_weight_fn(self):
|
|
342
|
-
assert nx.diameter(self.G, usebounds=True, weight=self.weight_fn) == 6
|
|
343
|
-
|
|
344
|
-
def test_bound_radius_weight_None(self):
|
|
345
|
-
assert pytest.approx(nx.radius(self.G, usebounds=True, weight=None)) == 2
|
|
346
|
-
|
|
347
|
-
def test_bound_radius_weight_attr(self):
|
|
348
|
-
assert (
|
|
349
|
-
nx.radius(self.G, usebounds=True, weight="high_cost")
|
|
350
|
-
!= pytest.approx(nx.radius(self.G, usebounds=True, weight="weight"))
|
|
351
|
-
== pytest.approx(nx.radius(self.G, usebounds=True, weight="cost"))
|
|
352
|
-
== 0.9
|
|
353
|
-
!= nx.radius(self.G, usebounds=True, weight="high_cost")
|
|
354
|
-
)
|
|
355
|
-
assert nx.radius(self.G, usebounds=True, weight="high_cost") == nx.radius(
|
|
356
|
-
self.G, usebounds=True, weight="high_cost"
|
|
357
|
-
)
|
|
358
|
-
|
|
359
|
-
def test_bound_radius_weight_fn(self):
|
|
360
|
-
assert nx.radius(self.G, usebounds=True, weight=self.weight_fn) == 4
|
|
361
|
-
|
|
362
|
-
def test_bound_periphery_weight_None(self):
|
|
363
|
-
result = {1, 3, 4}
|
|
364
|
-
assert set(nx.periphery(self.G, usebounds=True, weight=None)) == result
|
|
365
|
-
|
|
366
|
-
def test_bound_periphery_weight_attr(self):
|
|
367
|
-
result = {4, 5}
|
|
368
|
-
assert (
|
|
369
|
-
set(nx.periphery(self.G, usebounds=True, weight="weight"))
|
|
370
|
-
== set(nx.periphery(self.G, usebounds=True, weight="cost"))
|
|
371
|
-
== result
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
def test_bound_periphery_weight_fn(self):
|
|
375
|
-
result = {1, 3, 4}
|
|
376
|
-
assert (
|
|
377
|
-
set(nx.periphery(self.G, usebounds=True, weight=self.weight_fn)) == result
|
|
378
|
-
)
|
|
379
|
-
|
|
380
|
-
def test_bound_center_weight_None(self):
|
|
381
|
-
result = {0, 2, 5}
|
|
382
|
-
assert set(nx.center(self.G, usebounds=True, weight=None)) == result
|
|
383
|
-
|
|
384
|
-
def test_bound_center_weight_attr(self):
|
|
385
|
-
result = {0}
|
|
386
|
-
assert (
|
|
387
|
-
set(nx.center(self.G, usebounds=True, weight="weight"))
|
|
388
|
-
== set(nx.center(self.G, usebounds=True, weight="cost"))
|
|
389
|
-
== result
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
def test_bound_center_weight_fn(self):
|
|
393
|
-
result = {0, 2, 5}
|
|
394
|
-
assert set(nx.center(self.G, usebounds=True, weight=self.weight_fn)) == result
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
class TestResistanceDistance:
|
|
398
|
-
@classmethod
|
|
399
|
-
def setup_class(cls):
|
|
400
|
-
global np
|
|
401
|
-
np = pytest.importorskip("numpy")
|
|
402
|
-
sp = pytest.importorskip("scipy")
|
|
403
|
-
|
|
404
|
-
def setup_method(self):
|
|
405
|
-
G = nx.Graph()
|
|
406
|
-
G.add_edge(1, 2, weight=2)
|
|
407
|
-
G.add_edge(2, 3, weight=4)
|
|
408
|
-
G.add_edge(3, 4, weight=1)
|
|
409
|
-
G.add_edge(1, 4, weight=3)
|
|
410
|
-
self.G = G
|
|
411
|
-
|
|
412
|
-
def test_resistance_distance_directed_graph(self):
|
|
413
|
-
G = nx.DiGraph()
|
|
414
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
415
|
-
nx.resistance_distance(G)
|
|
416
|
-
|
|
417
|
-
def test_resistance_distance_empty(self):
|
|
418
|
-
G = nx.Graph()
|
|
419
|
-
with pytest.raises(nx.NetworkXError):
|
|
420
|
-
nx.resistance_distance(G)
|
|
421
|
-
|
|
422
|
-
def test_resistance_distance_not_connected(self):
|
|
423
|
-
with pytest.raises(nx.NetworkXError):
|
|
424
|
-
self.G.add_node(5)
|
|
425
|
-
nx.resistance_distance(self.G, 1, 5)
|
|
426
|
-
|
|
427
|
-
def test_resistance_distance_nodeA_not_in_graph(self):
|
|
428
|
-
with pytest.raises(nx.NetworkXError):
|
|
429
|
-
nx.resistance_distance(self.G, 9, 1)
|
|
430
|
-
|
|
431
|
-
def test_resistance_distance_nodeB_not_in_graph(self):
|
|
432
|
-
with pytest.raises(nx.NetworkXError):
|
|
433
|
-
nx.resistance_distance(self.G, 1, 9)
|
|
434
|
-
|
|
435
|
-
def test_resistance_distance(self):
|
|
436
|
-
rd = nx.resistance_distance(self.G, 1, 3, "weight", True)
|
|
437
|
-
test_data = 1 / (1 / (2 + 4) + 1 / (1 + 3))
|
|
438
|
-
assert round(rd, 5) == round(test_data, 5)
|
|
439
|
-
|
|
440
|
-
def test_resistance_distance_noinv(self):
|
|
441
|
-
rd = nx.resistance_distance(self.G, 1, 3, "weight", False)
|
|
442
|
-
test_data = 1 / (1 / (1 / 2 + 1 / 4) + 1 / (1 / 1 + 1 / 3))
|
|
443
|
-
assert round(rd, 5) == round(test_data, 5)
|
|
444
|
-
|
|
445
|
-
def test_resistance_distance_no_weight(self):
|
|
446
|
-
rd = nx.resistance_distance(self.G, 1, 3)
|
|
447
|
-
assert round(rd, 5) == 1
|
|
448
|
-
|
|
449
|
-
def test_resistance_distance_neg_weight(self):
|
|
450
|
-
self.G[2][3]["weight"] = -4
|
|
451
|
-
rd = nx.resistance_distance(self.G, 1, 3, "weight", True)
|
|
452
|
-
test_data = 1 / (1 / (2 + -4) + 1 / (1 + 3))
|
|
453
|
-
assert round(rd, 5) == round(test_data, 5)
|
|
454
|
-
|
|
455
|
-
def test_multigraph(self):
|
|
456
|
-
G = nx.MultiGraph()
|
|
457
|
-
G.add_edge(1, 2, weight=2)
|
|
458
|
-
G.add_edge(2, 3, weight=4)
|
|
459
|
-
G.add_edge(3, 4, weight=1)
|
|
460
|
-
G.add_edge(1, 4, weight=3)
|
|
461
|
-
rd = nx.resistance_distance(G, 1, 3, "weight", True)
|
|
462
|
-
assert np.isclose(rd, 1 / (1 / (2 + 4) + 1 / (1 + 3)))
|
|
463
|
-
|
|
464
|
-
def test_resistance_distance_div0(self):
|
|
465
|
-
with pytest.raises(ZeroDivisionError):
|
|
466
|
-
self.G[1][2]["weight"] = 0
|
|
467
|
-
nx.resistance_distance(self.G, 1, 3, "weight")
|
|
468
|
-
|
|
469
|
-
def test_resistance_distance_same_node(self):
|
|
470
|
-
assert nx.resistance_distance(self.G, 1, 1) == 0
|
|
471
|
-
|
|
472
|
-
def test_resistance_distance_only_nodeA(self):
|
|
473
|
-
rd = nx.resistance_distance(self.G, nodeA=1)
|
|
474
|
-
test_data = {}
|
|
475
|
-
test_data[1] = 0
|
|
476
|
-
test_data[2] = 0.75
|
|
477
|
-
test_data[3] = 1
|
|
478
|
-
test_data[4] = 0.75
|
|
479
|
-
assert isinstance(rd, dict)
|
|
480
|
-
assert sorted(rd.keys()) == sorted(test_data.keys())
|
|
481
|
-
for key in rd:
|
|
482
|
-
assert np.isclose(rd[key], test_data[key])
|
|
483
|
-
|
|
484
|
-
def test_resistance_distance_only_nodeB(self):
|
|
485
|
-
rd = nx.resistance_distance(self.G, nodeB=1)
|
|
486
|
-
test_data = {}
|
|
487
|
-
test_data[1] = 0
|
|
488
|
-
test_data[2] = 0.75
|
|
489
|
-
test_data[3] = 1
|
|
490
|
-
test_data[4] = 0.75
|
|
491
|
-
assert isinstance(rd, dict)
|
|
492
|
-
assert sorted(rd.keys()) == sorted(test_data.keys())
|
|
493
|
-
for key in rd:
|
|
494
|
-
assert np.isclose(rd[key], test_data[key])
|
|
495
|
-
|
|
496
|
-
def test_resistance_distance_all(self):
|
|
497
|
-
rd = nx.resistance_distance(self.G)
|
|
498
|
-
assert isinstance(rd, dict)
|
|
499
|
-
assert round(rd[1][3], 5) == 1
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
class TestEffectiveGraphResistance:
|
|
503
|
-
@classmethod
|
|
504
|
-
def setup_class(cls):
|
|
505
|
-
global np
|
|
506
|
-
np = pytest.importorskip("numpy")
|
|
507
|
-
sp = pytest.importorskip("scipy")
|
|
508
|
-
|
|
509
|
-
def setup_method(self):
|
|
510
|
-
G = nx.Graph()
|
|
511
|
-
G.add_edge(1, 2, weight=2)
|
|
512
|
-
G.add_edge(1, 3, weight=1)
|
|
513
|
-
G.add_edge(2, 3, weight=4)
|
|
514
|
-
self.G = G
|
|
515
|
-
|
|
516
|
-
def test_effective_graph_resistance_directed_graph(self):
|
|
517
|
-
G = nx.DiGraph()
|
|
518
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
519
|
-
nx.effective_graph_resistance(G)
|
|
520
|
-
|
|
521
|
-
def test_effective_graph_resistance_empty(self):
|
|
522
|
-
G = nx.Graph()
|
|
523
|
-
with pytest.raises(nx.NetworkXError):
|
|
524
|
-
nx.effective_graph_resistance(G)
|
|
525
|
-
|
|
526
|
-
def test_effective_graph_resistance_not_connected(self):
|
|
527
|
-
G = nx.Graph([(1, 2), (3, 4)])
|
|
528
|
-
RG = nx.effective_graph_resistance(G)
|
|
529
|
-
assert np.isinf(RG)
|
|
530
|
-
|
|
531
|
-
def test_effective_graph_resistance(self):
|
|
532
|
-
RG = nx.effective_graph_resistance(self.G, "weight", True)
|
|
533
|
-
rd12 = 1 / (1 / (1 + 4) + 1 / 2)
|
|
534
|
-
rd13 = 1 / (1 / (1 + 2) + 1 / 4)
|
|
535
|
-
rd23 = 1 / (1 / (2 + 4) + 1 / 1)
|
|
536
|
-
assert np.isclose(RG, rd12 + rd13 + rd23)
|
|
537
|
-
|
|
538
|
-
def test_effective_graph_resistance_noinv(self):
|
|
539
|
-
RG = nx.effective_graph_resistance(self.G, "weight", False)
|
|
540
|
-
rd12 = 1 / (1 / (1 / 1 + 1 / 4) + 1 / (1 / 2))
|
|
541
|
-
rd13 = 1 / (1 / (1 / 1 + 1 / 2) + 1 / (1 / 4))
|
|
542
|
-
rd23 = 1 / (1 / (1 / 2 + 1 / 4) + 1 / (1 / 1))
|
|
543
|
-
assert np.isclose(RG, rd12 + rd13 + rd23)
|
|
544
|
-
|
|
545
|
-
def test_effective_graph_resistance_no_weight(self):
|
|
546
|
-
RG = nx.effective_graph_resistance(self.G)
|
|
547
|
-
assert np.isclose(RG, 2)
|
|
548
|
-
|
|
549
|
-
def test_effective_graph_resistance_neg_weight(self):
|
|
550
|
-
self.G[2][3]["weight"] = -4
|
|
551
|
-
RG = nx.effective_graph_resistance(self.G, "weight", True)
|
|
552
|
-
rd12 = 1 / (1 / (1 + -4) + 1 / 2)
|
|
553
|
-
rd13 = 1 / (1 / (1 + 2) + 1 / (-4))
|
|
554
|
-
rd23 = 1 / (1 / (2 + -4) + 1 / 1)
|
|
555
|
-
assert np.isclose(RG, rd12 + rd13 + rd23)
|
|
556
|
-
|
|
557
|
-
def test_effective_graph_resistance_multigraph(self):
|
|
558
|
-
G = nx.MultiGraph()
|
|
559
|
-
G.add_edge(1, 2, weight=2)
|
|
560
|
-
G.add_edge(1, 3, weight=1)
|
|
561
|
-
G.add_edge(2, 3, weight=1)
|
|
562
|
-
G.add_edge(2, 3, weight=3)
|
|
563
|
-
RG = nx.effective_graph_resistance(G, "weight", True)
|
|
564
|
-
edge23 = 1 / (1 / 1 + 1 / 3)
|
|
565
|
-
rd12 = 1 / (1 / (1 + edge23) + 1 / 2)
|
|
566
|
-
rd13 = 1 / (1 / (1 + 2) + 1 / edge23)
|
|
567
|
-
rd23 = 1 / (1 / (2 + edge23) + 1 / 1)
|
|
568
|
-
assert np.isclose(RG, rd12 + rd13 + rd23)
|
|
569
|
-
|
|
570
|
-
def test_effective_graph_resistance_div0(self):
|
|
571
|
-
with pytest.raises(ZeroDivisionError):
|
|
572
|
-
self.G[1][2]["weight"] = 0
|
|
573
|
-
nx.effective_graph_resistance(self.G, "weight")
|
|
574
|
-
|
|
575
|
-
def test_effective_graph_resistance_complete_graph(self):
|
|
576
|
-
N = 10
|
|
577
|
-
G = nx.complete_graph(N)
|
|
578
|
-
RG = nx.effective_graph_resistance(G)
|
|
579
|
-
assert np.isclose(RG, N - 1)
|
|
580
|
-
|
|
581
|
-
def test_effective_graph_resistance_path_graph(self):
|
|
582
|
-
N = 10
|
|
583
|
-
G = nx.path_graph(N)
|
|
584
|
-
RG = nx.effective_graph_resistance(G)
|
|
585
|
-
assert np.isclose(RG, (N - 1) * N * (N + 1) // 6)
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
class TestBarycenter:
|
|
589
|
-
"""Test :func:`networkx.algorithms.distance_measures.barycenter`."""
|
|
590
|
-
|
|
591
|
-
def barycenter_as_subgraph(self, g, **kwargs):
|
|
592
|
-
"""Return the subgraph induced on the barycenter of g"""
|
|
593
|
-
b = nx.barycenter(g, **kwargs)
|
|
594
|
-
assert isinstance(b, list)
|
|
595
|
-
assert set(b) <= set(g)
|
|
596
|
-
return g.subgraph(b)
|
|
597
|
-
|
|
598
|
-
def test_must_be_connected(self):
|
|
599
|
-
pytest.raises(nx.NetworkXNoPath, nx.barycenter, nx.empty_graph(5))
|
|
600
|
-
|
|
601
|
-
def test_sp_kwarg(self):
|
|
602
|
-
# Complete graph K_5. Normally it works...
|
|
603
|
-
K_5 = nx.complete_graph(5)
|
|
604
|
-
sp = dict(nx.shortest_path_length(K_5))
|
|
605
|
-
assert nx.barycenter(K_5, sp=sp) == list(K_5)
|
|
606
|
-
|
|
607
|
-
# ...but not with the weight argument
|
|
608
|
-
for u, v, data in K_5.edges.data():
|
|
609
|
-
data["weight"] = 1
|
|
610
|
-
pytest.raises(ValueError, nx.barycenter, K_5, sp=sp, weight="weight")
|
|
611
|
-
|
|
612
|
-
# ...and a corrupted sp can make it seem like K_5 is disconnected
|
|
613
|
-
del sp[0][1]
|
|
614
|
-
pytest.raises(nx.NetworkXNoPath, nx.barycenter, K_5, sp=sp)
|
|
615
|
-
|
|
616
|
-
def test_trees(self):
|
|
617
|
-
"""The barycenter of a tree is a single vertex or an edge.
|
|
618
|
-
|
|
619
|
-
See [West01]_, p. 78.
|
|
620
|
-
"""
|
|
621
|
-
prng = Random(0xDEADBEEF)
|
|
622
|
-
for i in range(50):
|
|
623
|
-
RT = nx.random_labeled_tree(prng.randint(1, 75), seed=prng)
|
|
624
|
-
b = self.barycenter_as_subgraph(RT)
|
|
625
|
-
if len(b) == 2:
|
|
626
|
-
assert b.size() == 1
|
|
627
|
-
else:
|
|
628
|
-
assert len(b) == 1
|
|
629
|
-
assert b.size() == 0
|
|
630
|
-
|
|
631
|
-
def test_this_one_specific_tree(self):
|
|
632
|
-
"""Test the tree pictured at the bottom of [West01]_, p. 78."""
|
|
633
|
-
g = nx.Graph(
|
|
634
|
-
{
|
|
635
|
-
"a": ["b"],
|
|
636
|
-
"b": ["a", "x"],
|
|
637
|
-
"x": ["b", "y"],
|
|
638
|
-
"y": ["x", "z"],
|
|
639
|
-
"z": ["y", 0, 1, 2, 3, 4],
|
|
640
|
-
0: ["z"],
|
|
641
|
-
1: ["z"],
|
|
642
|
-
2: ["z"],
|
|
643
|
-
3: ["z"],
|
|
644
|
-
4: ["z"],
|
|
645
|
-
}
|
|
646
|
-
)
|
|
647
|
-
b = self.barycenter_as_subgraph(g, attr="barycentricity")
|
|
648
|
-
assert list(b) == ["z"]
|
|
649
|
-
assert not b.edges
|
|
650
|
-
expected_barycentricity = {
|
|
651
|
-
0: 23,
|
|
652
|
-
1: 23,
|
|
653
|
-
2: 23,
|
|
654
|
-
3: 23,
|
|
655
|
-
4: 23,
|
|
656
|
-
"a": 35,
|
|
657
|
-
"b": 27,
|
|
658
|
-
"x": 21,
|
|
659
|
-
"y": 17,
|
|
660
|
-
"z": 15,
|
|
661
|
-
}
|
|
662
|
-
for node, barycentricity in expected_barycentricity.items():
|
|
663
|
-
assert g.nodes[node]["barycentricity"] == barycentricity
|
|
664
|
-
|
|
665
|
-
# Doubling weights should do nothing but double the barycentricities
|
|
666
|
-
for edge in g.edges:
|
|
667
|
-
g.edges[edge]["weight"] = 2
|
|
668
|
-
b = self.barycenter_as_subgraph(g, weight="weight", attr="barycentricity2")
|
|
669
|
-
assert list(b) == ["z"]
|
|
670
|
-
assert not b.edges
|
|
671
|
-
for node, barycentricity in expected_barycentricity.items():
|
|
672
|
-
assert g.nodes[node]["barycentricity2"] == barycentricity * 2
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
class TestKemenyConstant:
|
|
676
|
-
@classmethod
|
|
677
|
-
def setup_class(cls):
|
|
678
|
-
global np
|
|
679
|
-
np = pytest.importorskip("numpy")
|
|
680
|
-
sp = pytest.importorskip("scipy")
|
|
681
|
-
|
|
682
|
-
def setup_method(self):
|
|
683
|
-
G = nx.Graph()
|
|
684
|
-
w12 = 2
|
|
685
|
-
w13 = 3
|
|
686
|
-
w23 = 4
|
|
687
|
-
G.add_edge(1, 2, weight=w12)
|
|
688
|
-
G.add_edge(1, 3, weight=w13)
|
|
689
|
-
G.add_edge(2, 3, weight=w23)
|
|
690
|
-
self.G = G
|
|
691
|
-
|
|
692
|
-
def test_kemeny_constant_directed(self):
|
|
693
|
-
G = nx.DiGraph()
|
|
694
|
-
G.add_edge(1, 2)
|
|
695
|
-
G.add_edge(1, 3)
|
|
696
|
-
G.add_edge(2, 3)
|
|
697
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
698
|
-
nx.kemeny_constant(G)
|
|
699
|
-
|
|
700
|
-
def test_kemeny_constant_not_connected(self):
|
|
701
|
-
self.G.add_node(5)
|
|
702
|
-
with pytest.raises(nx.NetworkXError):
|
|
703
|
-
nx.kemeny_constant(self.G)
|
|
704
|
-
|
|
705
|
-
def test_kemeny_constant_no_nodes(self):
|
|
706
|
-
G = nx.Graph()
|
|
707
|
-
with pytest.raises(nx.NetworkXError):
|
|
708
|
-
nx.kemeny_constant(G)
|
|
709
|
-
|
|
710
|
-
def test_kemeny_constant_negative_weight(self):
|
|
711
|
-
G = nx.Graph()
|
|
712
|
-
w12 = 2
|
|
713
|
-
w13 = 3
|
|
714
|
-
w23 = -10
|
|
715
|
-
G.add_edge(1, 2, weight=w12)
|
|
716
|
-
G.add_edge(1, 3, weight=w13)
|
|
717
|
-
G.add_edge(2, 3, weight=w23)
|
|
718
|
-
with pytest.raises(nx.NetworkXError):
|
|
719
|
-
nx.kemeny_constant(G, weight="weight")
|
|
720
|
-
|
|
721
|
-
def test_kemeny_constant(self):
|
|
722
|
-
K = nx.kemeny_constant(self.G, weight="weight")
|
|
723
|
-
w12 = 2
|
|
724
|
-
w13 = 3
|
|
725
|
-
w23 = 4
|
|
726
|
-
test_data = (
|
|
727
|
-
3
|
|
728
|
-
/ 2
|
|
729
|
-
* (w12 + w13)
|
|
730
|
-
* (w12 + w23)
|
|
731
|
-
* (w13 + w23)
|
|
732
|
-
/ (
|
|
733
|
-
w12**2 * (w13 + w23)
|
|
734
|
-
+ w13**2 * (w12 + w23)
|
|
735
|
-
+ w23**2 * (w12 + w13)
|
|
736
|
-
+ 3 * w12 * w13 * w23
|
|
737
|
-
)
|
|
738
|
-
)
|
|
739
|
-
assert np.isclose(K, test_data)
|
|
740
|
-
|
|
741
|
-
def test_kemeny_constant_no_weight(self):
|
|
742
|
-
K = nx.kemeny_constant(self.G)
|
|
743
|
-
assert np.isclose(K, 4 / 3)
|
|
744
|
-
|
|
745
|
-
def test_kemeny_constant_multigraph(self):
|
|
746
|
-
G = nx.MultiGraph()
|
|
747
|
-
w12_1 = 2
|
|
748
|
-
w12_2 = 1
|
|
749
|
-
w13 = 3
|
|
750
|
-
w23 = 4
|
|
751
|
-
G.add_edge(1, 2, weight=w12_1)
|
|
752
|
-
G.add_edge(1, 2, weight=w12_2)
|
|
753
|
-
G.add_edge(1, 3, weight=w13)
|
|
754
|
-
G.add_edge(2, 3, weight=w23)
|
|
755
|
-
K = nx.kemeny_constant(G, weight="weight")
|
|
756
|
-
w12 = w12_1 + w12_2
|
|
757
|
-
test_data = (
|
|
758
|
-
3
|
|
759
|
-
/ 2
|
|
760
|
-
* (w12 + w13)
|
|
761
|
-
* (w12 + w23)
|
|
762
|
-
* (w13 + w23)
|
|
763
|
-
/ (
|
|
764
|
-
w12**2 * (w13 + w23)
|
|
765
|
-
+ w13**2 * (w12 + w23)
|
|
766
|
-
+ w23**2 * (w12 + w13)
|
|
767
|
-
+ 3 * w12 * w13 * w23
|
|
768
|
-
)
|
|
769
|
-
)
|
|
770
|
-
assert np.isclose(K, test_data)
|
|
771
|
-
|
|
772
|
-
def test_kemeny_constant_weight0(self):
|
|
773
|
-
G = nx.Graph()
|
|
774
|
-
w12 = 0
|
|
775
|
-
w13 = 3
|
|
776
|
-
w23 = 4
|
|
777
|
-
G.add_edge(1, 2, weight=w12)
|
|
778
|
-
G.add_edge(1, 3, weight=w13)
|
|
779
|
-
G.add_edge(2, 3, weight=w23)
|
|
780
|
-
K = nx.kemeny_constant(G, weight="weight")
|
|
781
|
-
test_data = (
|
|
782
|
-
3
|
|
783
|
-
/ 2
|
|
784
|
-
* (w12 + w13)
|
|
785
|
-
* (w12 + w23)
|
|
786
|
-
* (w13 + w23)
|
|
787
|
-
/ (
|
|
788
|
-
w12**2 * (w13 + w23)
|
|
789
|
-
+ w13**2 * (w12 + w23)
|
|
790
|
-
+ w23**2 * (w12 + w13)
|
|
791
|
-
+ 3 * w12 * w13 * w23
|
|
792
|
-
)
|
|
793
|
-
)
|
|
794
|
-
assert np.isclose(K, test_data)
|
|
795
|
-
|
|
796
|
-
def test_kemeny_constant_selfloop(self):
|
|
797
|
-
G = nx.Graph()
|
|
798
|
-
w11 = 1
|
|
799
|
-
w12 = 2
|
|
800
|
-
w13 = 3
|
|
801
|
-
w23 = 4
|
|
802
|
-
G.add_edge(1, 1, weight=w11)
|
|
803
|
-
G.add_edge(1, 2, weight=w12)
|
|
804
|
-
G.add_edge(1, 3, weight=w13)
|
|
805
|
-
G.add_edge(2, 3, weight=w23)
|
|
806
|
-
K = nx.kemeny_constant(G, weight="weight")
|
|
807
|
-
test_data = (
|
|
808
|
-
(2 * w11 + 3 * w12 + 3 * w13)
|
|
809
|
-
* (w12 + w23)
|
|
810
|
-
* (w13 + w23)
|
|
811
|
-
/ (
|
|
812
|
-
(w12 * w13 + w12 * w23 + w13 * w23)
|
|
813
|
-
* (w11 + 2 * w12 + 2 * w13 + 2 * w23)
|
|
814
|
-
)
|
|
815
|
-
)
|
|
816
|
-
assert np.isclose(K, test_data)
|
|
817
|
-
|
|
818
|
-
def test_kemeny_constant_complete_bipartite_graph(self):
|
|
819
|
-
# Theorem 1 in https://www.sciencedirect.com/science/article/pii/S0166218X20302912
|
|
820
|
-
n1 = 5
|
|
821
|
-
n2 = 4
|
|
822
|
-
G = nx.complete_bipartite_graph(n1, n2)
|
|
823
|
-
K = nx.kemeny_constant(G)
|
|
824
|
-
assert np.isclose(K, n1 + n2 - 3 / 2)
|
|
825
|
-
|
|
826
|
-
def test_kemeny_constant_path_graph(self):
|
|
827
|
-
# Theorem 2 in https://www.sciencedirect.com/science/article/pii/S0166218X20302912
|
|
828
|
-
n = 10
|
|
829
|
-
G = nx.path_graph(n)
|
|
830
|
-
K = nx.kemeny_constant(G)
|
|
831
|
-
assert np.isclose(K, n**2 / 3 - 2 * n / 3 + 1 / 2)
|