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,984 +0,0 @@
|
|
|
1
|
-
import random
|
|
2
|
-
from itertools import chain, islice, tee
|
|
3
|
-
from math import inf
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
|
|
7
|
-
import networkx as nx
|
|
8
|
-
from networkx.algorithms.traversal.edgedfs import FORWARD, REVERSE
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def check_independent(basis):
|
|
12
|
-
if len(basis) == 0:
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
np = pytest.importorskip("numpy")
|
|
16
|
-
sp = pytest.importorskip("scipy") # Required by incidence_matrix
|
|
17
|
-
|
|
18
|
-
H = nx.Graph()
|
|
19
|
-
for b in basis:
|
|
20
|
-
nx.add_cycle(H, b)
|
|
21
|
-
inc = nx.incidence_matrix(H, oriented=True)
|
|
22
|
-
rank = np.linalg.matrix_rank(inc.toarray(), tol=None, hermitian=False)
|
|
23
|
-
assert inc.shape[1] - rank == len(basis)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class TestCycles:
|
|
27
|
-
@classmethod
|
|
28
|
-
def setup_class(cls):
|
|
29
|
-
G = nx.Graph()
|
|
30
|
-
nx.add_cycle(G, [0, 1, 2, 3])
|
|
31
|
-
nx.add_cycle(G, [0, 3, 4, 5])
|
|
32
|
-
nx.add_cycle(G, [0, 1, 6, 7, 8])
|
|
33
|
-
G.add_edge(8, 9)
|
|
34
|
-
cls.G = G
|
|
35
|
-
|
|
36
|
-
def is_cyclic_permutation(self, a, b):
|
|
37
|
-
n = len(a)
|
|
38
|
-
if len(b) != n:
|
|
39
|
-
return False
|
|
40
|
-
l = a + a
|
|
41
|
-
return any(l[i : i + n] == b for i in range(n))
|
|
42
|
-
|
|
43
|
-
def test_cycle_basis(self):
|
|
44
|
-
G = self.G
|
|
45
|
-
cy = nx.cycle_basis(G, 0)
|
|
46
|
-
sort_cy = sorted(sorted(c) for c in cy)
|
|
47
|
-
assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]]
|
|
48
|
-
cy = nx.cycle_basis(G, 1)
|
|
49
|
-
sort_cy = sorted(sorted(c) for c in cy)
|
|
50
|
-
assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]]
|
|
51
|
-
cy = nx.cycle_basis(G, 9)
|
|
52
|
-
sort_cy = sorted(sorted(c) for c in cy)
|
|
53
|
-
assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5]]
|
|
54
|
-
# test disconnected graphs
|
|
55
|
-
nx.add_cycle(G, "ABC")
|
|
56
|
-
cy = nx.cycle_basis(G, 9)
|
|
57
|
-
sort_cy = sorted(sorted(c) for c in cy[:-1]) + [sorted(cy[-1])]
|
|
58
|
-
assert sort_cy == [[0, 1, 2, 3], [0, 1, 6, 7, 8], [0, 3, 4, 5], ["A", "B", "C"]]
|
|
59
|
-
|
|
60
|
-
def test_cycle_basis2(self):
|
|
61
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
62
|
-
G = nx.DiGraph()
|
|
63
|
-
cy = nx.cycle_basis(G, 0)
|
|
64
|
-
|
|
65
|
-
def test_cycle_basis3(self):
|
|
66
|
-
with pytest.raises(nx.NetworkXNotImplemented):
|
|
67
|
-
G = nx.MultiGraph()
|
|
68
|
-
cy = nx.cycle_basis(G, 0)
|
|
69
|
-
|
|
70
|
-
def test_cycle_basis_ordered(self):
|
|
71
|
-
# see gh-6654 replace sets with (ordered) dicts
|
|
72
|
-
G = nx.cycle_graph(5)
|
|
73
|
-
G.update(nx.cycle_graph(range(3, 8)))
|
|
74
|
-
cbG = nx.cycle_basis(G)
|
|
75
|
-
|
|
76
|
-
perm = {1: 0, 0: 1} # switch 0 and 1
|
|
77
|
-
H = nx.relabel_nodes(G, perm)
|
|
78
|
-
cbH = [[perm.get(n, n) for n in cyc] for cyc in nx.cycle_basis(H)]
|
|
79
|
-
assert cbG == cbH
|
|
80
|
-
|
|
81
|
-
def test_cycle_basis_self_loop(self):
|
|
82
|
-
"""Tests the function for graphs with self loops"""
|
|
83
|
-
G = nx.Graph()
|
|
84
|
-
nx.add_cycle(G, [0, 1, 2, 3])
|
|
85
|
-
nx.add_cycle(G, [0, 0, 6, 2])
|
|
86
|
-
cy = nx.cycle_basis(G)
|
|
87
|
-
sort_cy = sorted(sorted(c) for c in cy)
|
|
88
|
-
assert sort_cy == [[0], [0, 1, 2], [0, 2, 3], [0, 2, 6]]
|
|
89
|
-
|
|
90
|
-
def test_simple_cycles(self):
|
|
91
|
-
edges = [(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1), (2, 2)]
|
|
92
|
-
G = nx.DiGraph(edges)
|
|
93
|
-
cc = sorted(nx.simple_cycles(G))
|
|
94
|
-
ca = [[0], [0, 1, 2], [0, 2], [1, 2], [2]]
|
|
95
|
-
assert len(cc) == len(ca)
|
|
96
|
-
for c in cc:
|
|
97
|
-
assert any(self.is_cyclic_permutation(c, rc) for rc in ca)
|
|
98
|
-
|
|
99
|
-
def test_simple_cycles_singleton(self):
|
|
100
|
-
G = nx.Graph([(0, 0)]) # self-loop
|
|
101
|
-
assert list(nx.simple_cycles(G)) == [[0]]
|
|
102
|
-
|
|
103
|
-
def test_unsortable(self):
|
|
104
|
-
# this test ensures that graphs whose nodes without an intrinsic
|
|
105
|
-
# ordering do not cause issues
|
|
106
|
-
G = nx.DiGraph()
|
|
107
|
-
nx.add_cycle(G, ["a", 1])
|
|
108
|
-
c = list(nx.simple_cycles(G))
|
|
109
|
-
assert len(c) == 1
|
|
110
|
-
|
|
111
|
-
def test_simple_cycles_small(self):
|
|
112
|
-
G = nx.DiGraph()
|
|
113
|
-
nx.add_cycle(G, [1, 2, 3])
|
|
114
|
-
c = sorted(nx.simple_cycles(G))
|
|
115
|
-
assert len(c) == 1
|
|
116
|
-
assert self.is_cyclic_permutation(c[0], [1, 2, 3])
|
|
117
|
-
nx.add_cycle(G, [10, 20, 30])
|
|
118
|
-
cc = sorted(nx.simple_cycles(G))
|
|
119
|
-
assert len(cc) == 2
|
|
120
|
-
ca = [[1, 2, 3], [10, 20, 30]]
|
|
121
|
-
for c in cc:
|
|
122
|
-
assert any(self.is_cyclic_permutation(c, rc) for rc in ca)
|
|
123
|
-
|
|
124
|
-
def test_simple_cycles_empty(self):
|
|
125
|
-
G = nx.DiGraph()
|
|
126
|
-
assert list(nx.simple_cycles(G)) == []
|
|
127
|
-
|
|
128
|
-
def worst_case_graph(self, k):
|
|
129
|
-
# see figure 1 in Johnson's paper
|
|
130
|
-
# this graph has exactly 3k simple cycles
|
|
131
|
-
G = nx.DiGraph()
|
|
132
|
-
for n in range(2, k + 2):
|
|
133
|
-
G.add_edge(1, n)
|
|
134
|
-
G.add_edge(n, k + 2)
|
|
135
|
-
G.add_edge(2 * k + 1, 1)
|
|
136
|
-
for n in range(k + 2, 2 * k + 2):
|
|
137
|
-
G.add_edge(n, 2 * k + 2)
|
|
138
|
-
G.add_edge(n, n + 1)
|
|
139
|
-
G.add_edge(2 * k + 3, k + 2)
|
|
140
|
-
for n in range(2 * k + 3, 3 * k + 3):
|
|
141
|
-
G.add_edge(2 * k + 2, n)
|
|
142
|
-
G.add_edge(n, 3 * k + 3)
|
|
143
|
-
G.add_edge(3 * k + 3, 2 * k + 2)
|
|
144
|
-
return G
|
|
145
|
-
|
|
146
|
-
def test_worst_case_graph(self):
|
|
147
|
-
# see figure 1 in Johnson's paper
|
|
148
|
-
for k in range(3, 10):
|
|
149
|
-
G = self.worst_case_graph(k)
|
|
150
|
-
l = len(list(nx.simple_cycles(G)))
|
|
151
|
-
assert l == 3 * k
|
|
152
|
-
|
|
153
|
-
def test_recursive_simple_and_not(self):
|
|
154
|
-
for k in range(2, 10):
|
|
155
|
-
G = self.worst_case_graph(k)
|
|
156
|
-
cc = sorted(nx.simple_cycles(G))
|
|
157
|
-
rcc = sorted(nx.recursive_simple_cycles(G))
|
|
158
|
-
assert len(cc) == len(rcc)
|
|
159
|
-
for c in cc:
|
|
160
|
-
assert any(self.is_cyclic_permutation(c, r) for r in rcc)
|
|
161
|
-
for rc in rcc:
|
|
162
|
-
assert any(self.is_cyclic_permutation(rc, c) for c in cc)
|
|
163
|
-
|
|
164
|
-
def test_simple_graph_with_reported_bug(self):
|
|
165
|
-
G = nx.DiGraph()
|
|
166
|
-
edges = [
|
|
167
|
-
(0, 2),
|
|
168
|
-
(0, 3),
|
|
169
|
-
(1, 0),
|
|
170
|
-
(1, 3),
|
|
171
|
-
(2, 1),
|
|
172
|
-
(2, 4),
|
|
173
|
-
(3, 2),
|
|
174
|
-
(3, 4),
|
|
175
|
-
(4, 0),
|
|
176
|
-
(4, 1),
|
|
177
|
-
(4, 5),
|
|
178
|
-
(5, 0),
|
|
179
|
-
(5, 1),
|
|
180
|
-
(5, 2),
|
|
181
|
-
(5, 3),
|
|
182
|
-
]
|
|
183
|
-
G.add_edges_from(edges)
|
|
184
|
-
cc = sorted(nx.simple_cycles(G))
|
|
185
|
-
assert len(cc) == 26
|
|
186
|
-
rcc = sorted(nx.recursive_simple_cycles(G))
|
|
187
|
-
assert len(cc) == len(rcc)
|
|
188
|
-
for c in cc:
|
|
189
|
-
assert any(self.is_cyclic_permutation(c, rc) for rc in rcc)
|
|
190
|
-
for rc in rcc:
|
|
191
|
-
assert any(self.is_cyclic_permutation(rc, c) for c in cc)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
def pairwise(iterable):
|
|
195
|
-
a, b = tee(iterable)
|
|
196
|
-
next(b, None)
|
|
197
|
-
return zip(a, b)
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
def cycle_edges(c):
|
|
201
|
-
return pairwise(chain(c, islice(c, 1)))
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
def directed_cycle_edgeset(c):
|
|
205
|
-
return frozenset(cycle_edges(c))
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
def undirected_cycle_edgeset(c):
|
|
209
|
-
if len(c) == 1:
|
|
210
|
-
return frozenset(cycle_edges(c))
|
|
211
|
-
return frozenset(map(frozenset, cycle_edges(c)))
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
def multigraph_cycle_edgeset(c):
|
|
215
|
-
if len(c) <= 2:
|
|
216
|
-
return frozenset(cycle_edges(c))
|
|
217
|
-
else:
|
|
218
|
-
return frozenset(map(frozenset, cycle_edges(c)))
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
class TestCycleEnumeration:
|
|
222
|
-
@staticmethod
|
|
223
|
-
def K(n):
|
|
224
|
-
return nx.complete_graph(n)
|
|
225
|
-
|
|
226
|
-
@staticmethod
|
|
227
|
-
def D(n):
|
|
228
|
-
return nx.complete_graph(n).to_directed()
|
|
229
|
-
|
|
230
|
-
@staticmethod
|
|
231
|
-
def edgeset_function(g):
|
|
232
|
-
if g.is_directed():
|
|
233
|
-
return directed_cycle_edgeset
|
|
234
|
-
elif g.is_multigraph():
|
|
235
|
-
return multigraph_cycle_edgeset
|
|
236
|
-
else:
|
|
237
|
-
return undirected_cycle_edgeset
|
|
238
|
-
|
|
239
|
-
def check_cycle(self, g, c, es, cache, source, original_c, length_bound, chordless):
|
|
240
|
-
if length_bound is not None and len(c) > length_bound:
|
|
241
|
-
raise RuntimeError(
|
|
242
|
-
f"computed cycle {original_c} exceeds length bound {length_bound}"
|
|
243
|
-
)
|
|
244
|
-
if source == "computed":
|
|
245
|
-
if es in cache:
|
|
246
|
-
raise RuntimeError(
|
|
247
|
-
f"computed cycle {original_c} has already been found!"
|
|
248
|
-
)
|
|
249
|
-
else:
|
|
250
|
-
cache[es] = tuple(original_c)
|
|
251
|
-
else:
|
|
252
|
-
if es in cache:
|
|
253
|
-
cache.pop(es)
|
|
254
|
-
else:
|
|
255
|
-
raise RuntimeError(f"expected cycle {original_c} was not computed")
|
|
256
|
-
|
|
257
|
-
if not all(g.has_edge(*e) for e in es):
|
|
258
|
-
raise RuntimeError(
|
|
259
|
-
f"{source} claimed cycle {original_c} is not a cycle of g"
|
|
260
|
-
)
|
|
261
|
-
if chordless and len(g.subgraph(c).edges) > len(c):
|
|
262
|
-
raise RuntimeError(f"{source} cycle {original_c} is not chordless")
|
|
263
|
-
|
|
264
|
-
def check_cycle_algorithm(
|
|
265
|
-
self,
|
|
266
|
-
g,
|
|
267
|
-
expected_cycles,
|
|
268
|
-
length_bound=None,
|
|
269
|
-
chordless=False,
|
|
270
|
-
algorithm=None,
|
|
271
|
-
):
|
|
272
|
-
if algorithm is None:
|
|
273
|
-
algorithm = nx.chordless_cycles if chordless else nx.simple_cycles
|
|
274
|
-
|
|
275
|
-
# note: we shuffle the labels of g to rule out accidentally-correct
|
|
276
|
-
# behavior which occurred during the development of chordless cycle
|
|
277
|
-
# enumeration algorithms
|
|
278
|
-
|
|
279
|
-
relabel = list(range(len(g)))
|
|
280
|
-
rng = random.Random(42)
|
|
281
|
-
rng.shuffle(relabel)
|
|
282
|
-
label = dict(zip(g, relabel))
|
|
283
|
-
unlabel = dict(zip(relabel, g))
|
|
284
|
-
h = nx.relabel_nodes(g, label, copy=True)
|
|
285
|
-
|
|
286
|
-
edgeset = self.edgeset_function(h)
|
|
287
|
-
|
|
288
|
-
params = {}
|
|
289
|
-
if length_bound is not None:
|
|
290
|
-
params["length_bound"] = length_bound
|
|
291
|
-
|
|
292
|
-
cycle_cache = {}
|
|
293
|
-
for c in algorithm(h, **params):
|
|
294
|
-
original_c = [unlabel[x] for x in c]
|
|
295
|
-
es = edgeset(c)
|
|
296
|
-
self.check_cycle(
|
|
297
|
-
h, c, es, cycle_cache, "computed", original_c, length_bound, chordless
|
|
298
|
-
)
|
|
299
|
-
|
|
300
|
-
if isinstance(expected_cycles, int):
|
|
301
|
-
if len(cycle_cache) != expected_cycles:
|
|
302
|
-
raise RuntimeError(
|
|
303
|
-
f"expected {expected_cycles} cycles, got {len(cycle_cache)}"
|
|
304
|
-
)
|
|
305
|
-
return
|
|
306
|
-
for original_c in expected_cycles:
|
|
307
|
-
c = [label[x] for x in original_c]
|
|
308
|
-
es = edgeset(c)
|
|
309
|
-
self.check_cycle(
|
|
310
|
-
h, c, es, cycle_cache, "expected", original_c, length_bound, chordless
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
if len(cycle_cache):
|
|
314
|
-
for c in cycle_cache.values():
|
|
315
|
-
raise RuntimeError(
|
|
316
|
-
f"computed cycle {c} is valid but not in the expected cycle set!"
|
|
317
|
-
)
|
|
318
|
-
|
|
319
|
-
def check_cycle_enumeration_integer_sequence(
|
|
320
|
-
self,
|
|
321
|
-
g_family,
|
|
322
|
-
cycle_counts,
|
|
323
|
-
length_bound=None,
|
|
324
|
-
chordless=False,
|
|
325
|
-
algorithm=None,
|
|
326
|
-
):
|
|
327
|
-
for g, num_cycles in zip(g_family, cycle_counts):
|
|
328
|
-
self.check_cycle_algorithm(
|
|
329
|
-
g,
|
|
330
|
-
num_cycles,
|
|
331
|
-
length_bound=length_bound,
|
|
332
|
-
chordless=chordless,
|
|
333
|
-
algorithm=algorithm,
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
def test_directed_chordless_cycle_digons(self):
|
|
337
|
-
g = nx.DiGraph()
|
|
338
|
-
nx.add_cycle(g, range(5))
|
|
339
|
-
nx.add_cycle(g, range(5)[::-1])
|
|
340
|
-
g.add_edge(0, 0)
|
|
341
|
-
expected_cycles = [(0,), (1, 2), (2, 3), (3, 4)]
|
|
342
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
343
|
-
|
|
344
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True, length_bound=2)
|
|
345
|
-
|
|
346
|
-
expected_cycles = [c for c in expected_cycles if len(c) < 2]
|
|
347
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True, length_bound=1)
|
|
348
|
-
|
|
349
|
-
def test_chordless_cycles_multigraph_self_loops(self):
|
|
350
|
-
G = nx.MultiGraph([(1, 1), (2, 2), (1, 2), (1, 2)])
|
|
351
|
-
expected_cycles = [[1], [2]]
|
|
352
|
-
self.check_cycle_algorithm(G, expected_cycles, chordless=True)
|
|
353
|
-
|
|
354
|
-
G.add_edges_from([(2, 3), (3, 4), (3, 4), (1, 3)])
|
|
355
|
-
expected_cycles = [[1], [2], [3, 4]]
|
|
356
|
-
self.check_cycle_algorithm(G, expected_cycles, chordless=True)
|
|
357
|
-
|
|
358
|
-
def test_directed_chordless_cycle_undirected(self):
|
|
359
|
-
g = nx.DiGraph([(1, 2), (2, 3), (3, 4), (4, 5), (5, 0), (5, 1), (0, 2)])
|
|
360
|
-
expected_cycles = [(0, 2, 3, 4, 5), (1, 2, 3, 4, 5)]
|
|
361
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
362
|
-
|
|
363
|
-
g = nx.DiGraph()
|
|
364
|
-
nx.add_cycle(g, range(5))
|
|
365
|
-
nx.add_cycle(g, range(4, 9))
|
|
366
|
-
g.add_edge(7, 3)
|
|
367
|
-
expected_cycles = [(0, 1, 2, 3, 4), (3, 4, 5, 6, 7), (4, 5, 6, 7, 8)]
|
|
368
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
369
|
-
|
|
370
|
-
g.add_edge(3, 7)
|
|
371
|
-
expected_cycles = [(0, 1, 2, 3, 4), (3, 7), (4, 5, 6, 7, 8)]
|
|
372
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
373
|
-
|
|
374
|
-
expected_cycles = [(3, 7)]
|
|
375
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True, length_bound=4)
|
|
376
|
-
|
|
377
|
-
g.remove_edge(7, 3)
|
|
378
|
-
expected_cycles = [(0, 1, 2, 3, 4), (4, 5, 6, 7, 8)]
|
|
379
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
380
|
-
|
|
381
|
-
g = nx.DiGraph((i, j) for i in range(10) for j in range(i))
|
|
382
|
-
expected_cycles = []
|
|
383
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
384
|
-
|
|
385
|
-
def test_chordless_cycles_directed(self):
|
|
386
|
-
G = nx.DiGraph()
|
|
387
|
-
nx.add_cycle(G, range(5))
|
|
388
|
-
nx.add_cycle(G, range(4, 12))
|
|
389
|
-
expected = [[*range(5)], [*range(4, 12)]]
|
|
390
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
391
|
-
self.check_cycle_algorithm(
|
|
392
|
-
G, [c for c in expected if len(c) <= 5], length_bound=5, chordless=True
|
|
393
|
-
)
|
|
394
|
-
|
|
395
|
-
G.add_edge(7, 3)
|
|
396
|
-
expected.append([*range(3, 8)])
|
|
397
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
398
|
-
self.check_cycle_algorithm(
|
|
399
|
-
G, [c for c in expected if len(c) <= 5], length_bound=5, chordless=True
|
|
400
|
-
)
|
|
401
|
-
|
|
402
|
-
G.add_edge(3, 7)
|
|
403
|
-
expected[-1] = [7, 3]
|
|
404
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
405
|
-
self.check_cycle_algorithm(
|
|
406
|
-
G, [c for c in expected if len(c) <= 5], length_bound=5, chordless=True
|
|
407
|
-
)
|
|
408
|
-
|
|
409
|
-
expected.pop()
|
|
410
|
-
G.remove_edge(7, 3)
|
|
411
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
412
|
-
self.check_cycle_algorithm(
|
|
413
|
-
G, [c for c in expected if len(c) <= 5], length_bound=5, chordless=True
|
|
414
|
-
)
|
|
415
|
-
|
|
416
|
-
def test_directed_chordless_cycle_diclique(self):
|
|
417
|
-
g_family = [self.D(n) for n in range(10)]
|
|
418
|
-
expected_cycles = [(n * n - n) // 2 for n in range(10)]
|
|
419
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
420
|
-
g_family, expected_cycles, chordless=True
|
|
421
|
-
)
|
|
422
|
-
|
|
423
|
-
expected_cycles = [(n * n - n) // 2 for n in range(10)]
|
|
424
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
425
|
-
g_family, expected_cycles, length_bound=2
|
|
426
|
-
)
|
|
427
|
-
|
|
428
|
-
def test_directed_chordless_loop_blockade(self):
|
|
429
|
-
g = nx.DiGraph((i, i) for i in range(10))
|
|
430
|
-
nx.add_cycle(g, range(10))
|
|
431
|
-
expected_cycles = [(i,) for i in range(10)]
|
|
432
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
433
|
-
|
|
434
|
-
self.check_cycle_algorithm(g, expected_cycles, length_bound=1)
|
|
435
|
-
|
|
436
|
-
g = nx.MultiDiGraph(g)
|
|
437
|
-
g.add_edges_from((i, i) for i in range(0, 10, 2))
|
|
438
|
-
expected_cycles = [(i,) for i in range(1, 10, 2)]
|
|
439
|
-
self.check_cycle_algorithm(g, expected_cycles, chordless=True)
|
|
440
|
-
|
|
441
|
-
def test_simple_cycles_notable_clique_sequences(self):
|
|
442
|
-
# A000292: Number of labeled graphs on n+3 nodes that are triangles.
|
|
443
|
-
g_family = [self.K(n) for n in range(2, 12)]
|
|
444
|
-
expected = [0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220]
|
|
445
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
446
|
-
g_family, expected, length_bound=3
|
|
447
|
-
)
|
|
448
|
-
|
|
449
|
-
def triangles(g, **kwargs):
|
|
450
|
-
yield from (c for c in nx.simple_cycles(g, **kwargs) if len(c) == 3)
|
|
451
|
-
|
|
452
|
-
# directed complete graphs have twice as many triangles thanks to reversal
|
|
453
|
-
g_family = [self.D(n) for n in range(2, 12)]
|
|
454
|
-
expected = [2 * e for e in expected]
|
|
455
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
456
|
-
g_family, expected, length_bound=3, algorithm=triangles
|
|
457
|
-
)
|
|
458
|
-
|
|
459
|
-
def four_cycles(g, **kwargs):
|
|
460
|
-
yield from (c for c in nx.simple_cycles(g, **kwargs) if len(c) == 4)
|
|
461
|
-
|
|
462
|
-
# A050534: the number of 4-cycles in the complete graph K_{n+1}
|
|
463
|
-
expected = [0, 0, 0, 3, 15, 45, 105, 210, 378, 630, 990]
|
|
464
|
-
g_family = [self.K(n) for n in range(1, 12)]
|
|
465
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
466
|
-
g_family, expected, length_bound=4, algorithm=four_cycles
|
|
467
|
-
)
|
|
468
|
-
|
|
469
|
-
# directed complete graphs have twice as many 4-cycles thanks to reversal
|
|
470
|
-
expected = [2 * e for e in expected]
|
|
471
|
-
g_family = [self.D(n) for n in range(1, 15)]
|
|
472
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
473
|
-
g_family, expected, length_bound=4, algorithm=four_cycles
|
|
474
|
-
)
|
|
475
|
-
|
|
476
|
-
# A006231: the number of elementary circuits in a complete directed graph with n nodes
|
|
477
|
-
expected = [0, 1, 5, 20, 84, 409, 2365]
|
|
478
|
-
g_family = [self.D(n) for n in range(1, 8)]
|
|
479
|
-
self.check_cycle_enumeration_integer_sequence(g_family, expected)
|
|
480
|
-
|
|
481
|
-
# A002807: Number of cycles in the complete graph on n nodes K_{n}.
|
|
482
|
-
expected = [0, 0, 0, 1, 7, 37, 197, 1172]
|
|
483
|
-
g_family = [self.K(n) for n in range(8)]
|
|
484
|
-
self.check_cycle_enumeration_integer_sequence(g_family, expected)
|
|
485
|
-
|
|
486
|
-
def test_directed_chordless_cycle_parallel_multiedges(self):
|
|
487
|
-
g = nx.MultiGraph()
|
|
488
|
-
|
|
489
|
-
nx.add_cycle(g, range(5))
|
|
490
|
-
expected = [[*range(5)]]
|
|
491
|
-
self.check_cycle_algorithm(g, expected, chordless=True)
|
|
492
|
-
|
|
493
|
-
nx.add_cycle(g, range(5))
|
|
494
|
-
expected = [*cycle_edges(range(5))]
|
|
495
|
-
self.check_cycle_algorithm(g, expected, chordless=True)
|
|
496
|
-
|
|
497
|
-
nx.add_cycle(g, range(5))
|
|
498
|
-
expected = []
|
|
499
|
-
self.check_cycle_algorithm(g, expected, chordless=True)
|
|
500
|
-
|
|
501
|
-
g = nx.MultiDiGraph()
|
|
502
|
-
|
|
503
|
-
nx.add_cycle(g, range(5))
|
|
504
|
-
expected = [[*range(5)]]
|
|
505
|
-
self.check_cycle_algorithm(g, expected, chordless=True)
|
|
506
|
-
|
|
507
|
-
nx.add_cycle(g, range(5))
|
|
508
|
-
self.check_cycle_algorithm(g, [], chordless=True)
|
|
509
|
-
|
|
510
|
-
nx.add_cycle(g, range(5))
|
|
511
|
-
self.check_cycle_algorithm(g, [], chordless=True)
|
|
512
|
-
|
|
513
|
-
g = nx.MultiDiGraph()
|
|
514
|
-
|
|
515
|
-
nx.add_cycle(g, range(5))
|
|
516
|
-
nx.add_cycle(g, range(5)[::-1])
|
|
517
|
-
expected = [*cycle_edges(range(5))]
|
|
518
|
-
self.check_cycle_algorithm(g, expected, chordless=True)
|
|
519
|
-
|
|
520
|
-
nx.add_cycle(g, range(5))
|
|
521
|
-
self.check_cycle_algorithm(g, [], chordless=True)
|
|
522
|
-
|
|
523
|
-
def test_chordless_cycles_graph(self):
|
|
524
|
-
G = nx.Graph()
|
|
525
|
-
nx.add_cycle(G, range(5))
|
|
526
|
-
nx.add_cycle(G, range(4, 12))
|
|
527
|
-
expected = [[*range(5)], [*range(4, 12)]]
|
|
528
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
529
|
-
self.check_cycle_algorithm(
|
|
530
|
-
G, [c for c in expected if len(c) <= 5], length_bound=5, chordless=True
|
|
531
|
-
)
|
|
532
|
-
|
|
533
|
-
G.add_edge(7, 3)
|
|
534
|
-
expected.append([*range(3, 8)])
|
|
535
|
-
expected.append([4, 3, 7, 8, 9, 10, 11])
|
|
536
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
537
|
-
self.check_cycle_algorithm(
|
|
538
|
-
G, [c for c in expected if len(c) <= 5], length_bound=5, chordless=True
|
|
539
|
-
)
|
|
540
|
-
|
|
541
|
-
def test_chordless_cycles_giant_hamiltonian(self):
|
|
542
|
-
# ... o - e - o - e - o ... # o = odd, e = even
|
|
543
|
-
# ... ---/ \-----/ \--- ... # <-- "long" edges
|
|
544
|
-
#
|
|
545
|
-
# each long edge belongs to exactly one triangle, and one giant cycle
|
|
546
|
-
# of length n/2. The remaining edges each belong to a triangle
|
|
547
|
-
|
|
548
|
-
n = 1000
|
|
549
|
-
assert n % 2 == 0
|
|
550
|
-
G = nx.Graph()
|
|
551
|
-
for v in range(n):
|
|
552
|
-
if not v % 2:
|
|
553
|
-
G.add_edge(v, (v + 2) % n)
|
|
554
|
-
G.add_edge(v, (v + 1) % n)
|
|
555
|
-
|
|
556
|
-
expected = [[*range(0, n, 2)]] + [
|
|
557
|
-
[x % n for x in range(i, i + 3)] for i in range(0, n, 2)
|
|
558
|
-
]
|
|
559
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
560
|
-
self.check_cycle_algorithm(
|
|
561
|
-
G, [c for c in expected if len(c) <= 3], length_bound=3, chordless=True
|
|
562
|
-
)
|
|
563
|
-
|
|
564
|
-
# ... o -> e -> o -> e -> o ... # o = odd, e = even
|
|
565
|
-
# ... <---/ \---<---/ \---< ... # <-- "long" edges
|
|
566
|
-
#
|
|
567
|
-
# this time, we orient the short and long edges in opposition
|
|
568
|
-
# the cycle structure of this graph is the same, but we need to reverse
|
|
569
|
-
# the long one in our representation. Also, we need to drop the size
|
|
570
|
-
# because our partitioning algorithm uses strongly connected components
|
|
571
|
-
# instead of separating graphs by their strong articulation points
|
|
572
|
-
|
|
573
|
-
n = 100
|
|
574
|
-
assert n % 2 == 0
|
|
575
|
-
G = nx.DiGraph()
|
|
576
|
-
for v in range(n):
|
|
577
|
-
G.add_edge(v, (v + 1) % n)
|
|
578
|
-
if not v % 2:
|
|
579
|
-
G.add_edge((v + 2) % n, v)
|
|
580
|
-
|
|
581
|
-
expected = [[*range(n - 2, -2, -2)]] + [
|
|
582
|
-
[x % n for x in range(i, i + 3)] for i in range(0, n, 2)
|
|
583
|
-
]
|
|
584
|
-
self.check_cycle_algorithm(G, expected, chordless=True)
|
|
585
|
-
self.check_cycle_algorithm(
|
|
586
|
-
G, [c for c in expected if len(c) <= 3], length_bound=3, chordless=True
|
|
587
|
-
)
|
|
588
|
-
|
|
589
|
-
def test_simple_cycles_acyclic_tournament(self):
|
|
590
|
-
n = 10
|
|
591
|
-
G = nx.DiGraph((x, y) for x in range(n) for y in range(x))
|
|
592
|
-
self.check_cycle_algorithm(G, [])
|
|
593
|
-
self.check_cycle_algorithm(G, [], chordless=True)
|
|
594
|
-
|
|
595
|
-
for k in range(n + 1):
|
|
596
|
-
self.check_cycle_algorithm(G, [], length_bound=k)
|
|
597
|
-
self.check_cycle_algorithm(G, [], length_bound=k, chordless=True)
|
|
598
|
-
|
|
599
|
-
def test_simple_cycles_graph(self):
|
|
600
|
-
testG = nx.cycle_graph(8)
|
|
601
|
-
cyc1 = tuple(range(8))
|
|
602
|
-
self.check_cycle_algorithm(testG, [cyc1])
|
|
603
|
-
|
|
604
|
-
testG.add_edge(4, -1)
|
|
605
|
-
nx.add_path(testG, [3, -2, -3, -4])
|
|
606
|
-
self.check_cycle_algorithm(testG, [cyc1])
|
|
607
|
-
|
|
608
|
-
testG.update(nx.cycle_graph(range(8, 16)))
|
|
609
|
-
cyc2 = tuple(range(8, 16))
|
|
610
|
-
self.check_cycle_algorithm(testG, [cyc1, cyc2])
|
|
611
|
-
|
|
612
|
-
testG.update(nx.cycle_graph(range(4, 12)))
|
|
613
|
-
cyc3 = tuple(range(4, 12))
|
|
614
|
-
expected = {
|
|
615
|
-
(0, 1, 2, 3, 4, 5, 6, 7), # cyc1
|
|
616
|
-
(8, 9, 10, 11, 12, 13, 14, 15), # cyc2
|
|
617
|
-
(4, 5, 6, 7, 8, 9, 10, 11), # cyc3
|
|
618
|
-
(4, 5, 6, 7, 8, 15, 14, 13, 12, 11), # cyc2 + cyc3
|
|
619
|
-
(0, 1, 2, 3, 4, 11, 10, 9, 8, 7), # cyc1 + cyc3
|
|
620
|
-
(0, 1, 2, 3, 4, 11, 12, 13, 14, 15, 8, 7), # cyc1 + cyc2 + cyc3
|
|
621
|
-
}
|
|
622
|
-
self.check_cycle_algorithm(testG, expected)
|
|
623
|
-
assert len(expected) == (2**3 - 1) - 1 # 1 disjoint comb: cyc1 + cyc2
|
|
624
|
-
|
|
625
|
-
# Basis size = 5 (2 loops overlapping gives 5 small loops
|
|
626
|
-
# E
|
|
627
|
-
# / \ Note: A-F = 10-15
|
|
628
|
-
# 1-2-3-4-5
|
|
629
|
-
# / | | \ cyc1=012DAB -- left
|
|
630
|
-
# 0 D F 6 cyc2=234E -- top
|
|
631
|
-
# \ | | / cyc3=45678F -- right
|
|
632
|
-
# B-A-9-8-7 cyc4=89AC -- bottom
|
|
633
|
-
# \ / cyc5=234F89AD -- middle
|
|
634
|
-
# C
|
|
635
|
-
#
|
|
636
|
-
# combinations of 5 basis elements: 2^5 - 1 (one includes no cycles)
|
|
637
|
-
#
|
|
638
|
-
# disjoint combs: (11 total) not simple cycles
|
|
639
|
-
# Any pair not including cyc5 => choose(4, 2) = 6
|
|
640
|
-
# Any triple not including cyc5 => choose(4, 3) = 4
|
|
641
|
-
# Any quad not including cyc5 => choose(4, 4) = 1
|
|
642
|
-
#
|
|
643
|
-
# we expect 31 - 11 = 20 simple cycles
|
|
644
|
-
#
|
|
645
|
-
testG = nx.cycle_graph(12)
|
|
646
|
-
testG.update(nx.cycle_graph([12, 10, 13, 2, 14, 4, 15, 8]).edges)
|
|
647
|
-
expected = (2**5 - 1) - 11 # 11 disjoint combinations
|
|
648
|
-
self.check_cycle_algorithm(testG, expected)
|
|
649
|
-
|
|
650
|
-
def test_simple_cycles_bounded(self):
|
|
651
|
-
# iteratively construct a cluster of nested cycles running in the same direction
|
|
652
|
-
# there should be one cycle of every length
|
|
653
|
-
d = nx.DiGraph()
|
|
654
|
-
expected = []
|
|
655
|
-
for n in range(10):
|
|
656
|
-
nx.add_cycle(d, range(n))
|
|
657
|
-
expected.append(n)
|
|
658
|
-
for k, e in enumerate(expected):
|
|
659
|
-
self.check_cycle_algorithm(d, e, length_bound=k)
|
|
660
|
-
|
|
661
|
-
# iteratively construct a path of undirected cycles, connected at articulation
|
|
662
|
-
# points. there should be one cycle of every length except 2: no digons
|
|
663
|
-
g = nx.Graph()
|
|
664
|
-
top = 0
|
|
665
|
-
expected = []
|
|
666
|
-
for n in range(10):
|
|
667
|
-
expected.append(n if n < 2 else n - 1)
|
|
668
|
-
if n == 2:
|
|
669
|
-
# no digons in undirected graphs
|
|
670
|
-
continue
|
|
671
|
-
nx.add_cycle(g, range(top, top + n))
|
|
672
|
-
top += n
|
|
673
|
-
for k, e in enumerate(expected):
|
|
674
|
-
self.check_cycle_algorithm(g, e, length_bound=k)
|
|
675
|
-
|
|
676
|
-
def test_simple_cycles_bound_corner_cases(self):
|
|
677
|
-
G = nx.cycle_graph(4)
|
|
678
|
-
DG = nx.cycle_graph(4, create_using=nx.DiGraph)
|
|
679
|
-
assert list(nx.simple_cycles(G, length_bound=0)) == []
|
|
680
|
-
assert list(nx.simple_cycles(DG, length_bound=0)) == []
|
|
681
|
-
assert list(nx.chordless_cycles(G, length_bound=0)) == []
|
|
682
|
-
assert list(nx.chordless_cycles(DG, length_bound=0)) == []
|
|
683
|
-
|
|
684
|
-
def test_simple_cycles_bound_error(self):
|
|
685
|
-
with pytest.raises(ValueError):
|
|
686
|
-
G = nx.DiGraph()
|
|
687
|
-
for c in nx.simple_cycles(G, -1):
|
|
688
|
-
assert False
|
|
689
|
-
|
|
690
|
-
with pytest.raises(ValueError):
|
|
691
|
-
G = nx.Graph()
|
|
692
|
-
for c in nx.simple_cycles(G, -1):
|
|
693
|
-
assert False
|
|
694
|
-
|
|
695
|
-
with pytest.raises(ValueError):
|
|
696
|
-
G = nx.Graph()
|
|
697
|
-
for c in nx.chordless_cycles(G, -1):
|
|
698
|
-
assert False
|
|
699
|
-
|
|
700
|
-
with pytest.raises(ValueError):
|
|
701
|
-
G = nx.DiGraph()
|
|
702
|
-
for c in nx.chordless_cycles(G, -1):
|
|
703
|
-
assert False
|
|
704
|
-
|
|
705
|
-
def test_chordless_cycles_clique(self):
|
|
706
|
-
g_family = [self.K(n) for n in range(2, 15)]
|
|
707
|
-
expected = [0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364]
|
|
708
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
709
|
-
g_family, expected, chordless=True
|
|
710
|
-
)
|
|
711
|
-
|
|
712
|
-
# directed cliques have as many digons as undirected graphs have edges
|
|
713
|
-
expected = [(n * n - n) // 2 for n in range(15)]
|
|
714
|
-
g_family = [self.D(n) for n in range(15)]
|
|
715
|
-
self.check_cycle_enumeration_integer_sequence(
|
|
716
|
-
g_family, expected, chordless=True
|
|
717
|
-
)
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
# These tests might fail with hash randomization since they depend on
|
|
721
|
-
# edge_dfs. For more information, see the comments in:
|
|
722
|
-
# networkx/algorithms/traversal/tests/test_edgedfs.py
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
class TestFindCycle:
|
|
726
|
-
@classmethod
|
|
727
|
-
def setup_class(cls):
|
|
728
|
-
cls.nodes = [0, 1, 2, 3]
|
|
729
|
-
cls.edges = [(-1, 0), (0, 1), (1, 0), (1, 0), (2, 1), (3, 1)]
|
|
730
|
-
|
|
731
|
-
def test_graph_nocycle(self):
|
|
732
|
-
G = nx.Graph(self.edges)
|
|
733
|
-
pytest.raises(nx.exception.NetworkXNoCycle, nx.find_cycle, G, self.nodes)
|
|
734
|
-
|
|
735
|
-
def test_graph_cycle(self):
|
|
736
|
-
G = nx.Graph(self.edges)
|
|
737
|
-
G.add_edge(2, 0)
|
|
738
|
-
x = list(nx.find_cycle(G, self.nodes))
|
|
739
|
-
x_ = [(0, 1), (1, 2), (2, 0)]
|
|
740
|
-
assert x == x_
|
|
741
|
-
|
|
742
|
-
def test_graph_orientation_none(self):
|
|
743
|
-
G = nx.Graph(self.edges)
|
|
744
|
-
G.add_edge(2, 0)
|
|
745
|
-
x = list(nx.find_cycle(G, self.nodes, orientation=None))
|
|
746
|
-
x_ = [(0, 1), (1, 2), (2, 0)]
|
|
747
|
-
assert x == x_
|
|
748
|
-
|
|
749
|
-
def test_graph_orientation_original(self):
|
|
750
|
-
G = nx.Graph(self.edges)
|
|
751
|
-
G.add_edge(2, 0)
|
|
752
|
-
x = list(nx.find_cycle(G, self.nodes, orientation="original"))
|
|
753
|
-
x_ = [(0, 1, FORWARD), (1, 2, FORWARD), (2, 0, FORWARD)]
|
|
754
|
-
assert x == x_
|
|
755
|
-
|
|
756
|
-
def test_digraph(self):
|
|
757
|
-
G = nx.DiGraph(self.edges)
|
|
758
|
-
x = list(nx.find_cycle(G, self.nodes))
|
|
759
|
-
x_ = [(0, 1), (1, 0)]
|
|
760
|
-
assert x == x_
|
|
761
|
-
|
|
762
|
-
def test_digraph_orientation_none(self):
|
|
763
|
-
G = nx.DiGraph(self.edges)
|
|
764
|
-
x = list(nx.find_cycle(G, self.nodes, orientation=None))
|
|
765
|
-
x_ = [(0, 1), (1, 0)]
|
|
766
|
-
assert x == x_
|
|
767
|
-
|
|
768
|
-
def test_digraph_orientation_original(self):
|
|
769
|
-
G = nx.DiGraph(self.edges)
|
|
770
|
-
x = list(nx.find_cycle(G, self.nodes, orientation="original"))
|
|
771
|
-
x_ = [(0, 1, FORWARD), (1, 0, FORWARD)]
|
|
772
|
-
assert x == x_
|
|
773
|
-
|
|
774
|
-
def test_multigraph(self):
|
|
775
|
-
G = nx.MultiGraph(self.edges)
|
|
776
|
-
x = list(nx.find_cycle(G, self.nodes))
|
|
777
|
-
x_ = [(0, 1, 0), (1, 0, 1)] # or (1, 0, 2)
|
|
778
|
-
# Hash randomization...could be any edge.
|
|
779
|
-
assert x[0] == x_[0]
|
|
780
|
-
assert x[1][:2] == x_[1][:2]
|
|
781
|
-
|
|
782
|
-
def test_multidigraph(self):
|
|
783
|
-
G = nx.MultiDiGraph(self.edges)
|
|
784
|
-
x = list(nx.find_cycle(G, self.nodes))
|
|
785
|
-
x_ = [(0, 1, 0), (1, 0, 0)] # (1, 0, 1)
|
|
786
|
-
assert x[0] == x_[0]
|
|
787
|
-
assert x[1][:2] == x_[1][:2]
|
|
788
|
-
|
|
789
|
-
def test_digraph_ignore(self):
|
|
790
|
-
G = nx.DiGraph(self.edges)
|
|
791
|
-
x = list(nx.find_cycle(G, self.nodes, orientation="ignore"))
|
|
792
|
-
x_ = [(0, 1, FORWARD), (1, 0, FORWARD)]
|
|
793
|
-
assert x == x_
|
|
794
|
-
|
|
795
|
-
def test_digraph_reverse(self):
|
|
796
|
-
G = nx.DiGraph(self.edges)
|
|
797
|
-
x = list(nx.find_cycle(G, self.nodes, orientation="reverse"))
|
|
798
|
-
x_ = [(1, 0, REVERSE), (0, 1, REVERSE)]
|
|
799
|
-
assert x == x_
|
|
800
|
-
|
|
801
|
-
def test_multidigraph_ignore(self):
|
|
802
|
-
G = nx.MultiDiGraph(self.edges)
|
|
803
|
-
x = list(nx.find_cycle(G, self.nodes, orientation="ignore"))
|
|
804
|
-
x_ = [(0, 1, 0, FORWARD), (1, 0, 0, FORWARD)] # or (1, 0, 1, 1)
|
|
805
|
-
assert x[0] == x_[0]
|
|
806
|
-
assert x[1][:2] == x_[1][:2]
|
|
807
|
-
assert x[1][3] == x_[1][3]
|
|
808
|
-
|
|
809
|
-
def test_multidigraph_ignore2(self):
|
|
810
|
-
# Loop traversed an edge while ignoring its orientation.
|
|
811
|
-
G = nx.MultiDiGraph([(0, 1), (1, 2), (1, 2)])
|
|
812
|
-
x = list(nx.find_cycle(G, [0, 1, 2], orientation="ignore"))
|
|
813
|
-
x_ = [(1, 2, 0, FORWARD), (1, 2, 1, REVERSE)]
|
|
814
|
-
assert x == x_
|
|
815
|
-
|
|
816
|
-
def test_multidigraph_original(self):
|
|
817
|
-
# Node 2 doesn't need to be searched again from visited from 4.
|
|
818
|
-
# The goal here is to cover the case when 2 to be researched from 4,
|
|
819
|
-
# when 4 is visited from the first time (so we must make sure that 4
|
|
820
|
-
# is not visited from 2, and hence, we respect the edge orientation).
|
|
821
|
-
G = nx.MultiDiGraph([(0, 1), (1, 2), (2, 3), (4, 2)])
|
|
822
|
-
pytest.raises(
|
|
823
|
-
nx.exception.NetworkXNoCycle,
|
|
824
|
-
nx.find_cycle,
|
|
825
|
-
G,
|
|
826
|
-
[0, 1, 2, 3, 4],
|
|
827
|
-
orientation="original",
|
|
828
|
-
)
|
|
829
|
-
|
|
830
|
-
def test_dag(self):
|
|
831
|
-
G = nx.DiGraph([(0, 1), (0, 2), (1, 2)])
|
|
832
|
-
pytest.raises(
|
|
833
|
-
nx.exception.NetworkXNoCycle, nx.find_cycle, G, orientation="original"
|
|
834
|
-
)
|
|
835
|
-
x = list(nx.find_cycle(G, orientation="ignore"))
|
|
836
|
-
assert x == [(0, 1, FORWARD), (1, 2, FORWARD), (0, 2, REVERSE)]
|
|
837
|
-
|
|
838
|
-
def test_prev_explored(self):
|
|
839
|
-
# https://github.com/networkx/networkx/issues/2323
|
|
840
|
-
|
|
841
|
-
G = nx.DiGraph()
|
|
842
|
-
G.add_edges_from([(1, 0), (2, 0), (1, 2), (2, 1)])
|
|
843
|
-
pytest.raises(nx.NetworkXNoCycle, nx.find_cycle, G, source=0)
|
|
844
|
-
x = list(nx.find_cycle(G, 1))
|
|
845
|
-
x_ = [(1, 2), (2, 1)]
|
|
846
|
-
assert x == x_
|
|
847
|
-
|
|
848
|
-
x = list(nx.find_cycle(G, 2))
|
|
849
|
-
x_ = [(2, 1), (1, 2)]
|
|
850
|
-
assert x == x_
|
|
851
|
-
|
|
852
|
-
x = list(nx.find_cycle(G))
|
|
853
|
-
x_ = [(1, 2), (2, 1)]
|
|
854
|
-
assert x == x_
|
|
855
|
-
|
|
856
|
-
def test_no_cycle(self):
|
|
857
|
-
# https://github.com/networkx/networkx/issues/2439
|
|
858
|
-
|
|
859
|
-
G = nx.DiGraph()
|
|
860
|
-
G.add_edges_from([(1, 2), (2, 0), (3, 1), (3, 2)])
|
|
861
|
-
pytest.raises(nx.NetworkXNoCycle, nx.find_cycle, G, source=0)
|
|
862
|
-
pytest.raises(nx.NetworkXNoCycle, nx.find_cycle, G)
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
def assert_basis_equal(a, b):
|
|
866
|
-
assert sorted(a) == sorted(b)
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
class TestMinimumCycleBasis:
|
|
870
|
-
@classmethod
|
|
871
|
-
def setup_class(cls):
|
|
872
|
-
T = nx.Graph()
|
|
873
|
-
nx.add_cycle(T, [1, 2, 3, 4], weight=1)
|
|
874
|
-
T.add_edge(2, 4, weight=5)
|
|
875
|
-
cls.diamond_graph = T
|
|
876
|
-
|
|
877
|
-
def test_unweighted_diamond(self):
|
|
878
|
-
mcb = nx.minimum_cycle_basis(self.diamond_graph)
|
|
879
|
-
assert_basis_equal(mcb, [[2, 4, 1], [3, 4, 2]])
|
|
880
|
-
|
|
881
|
-
def test_weighted_diamond(self):
|
|
882
|
-
mcb = nx.minimum_cycle_basis(self.diamond_graph, weight="weight")
|
|
883
|
-
assert_basis_equal(mcb, [[2, 4, 1], [4, 3, 2, 1]])
|
|
884
|
-
|
|
885
|
-
def test_dimensionality(self):
|
|
886
|
-
# checks |MCB|=|E|-|V|+|NC|
|
|
887
|
-
ntrial = 10
|
|
888
|
-
for seed in range(1234, 1234 + ntrial):
|
|
889
|
-
rg = nx.erdos_renyi_graph(10, 0.3, seed=seed)
|
|
890
|
-
nnodes = rg.number_of_nodes()
|
|
891
|
-
nedges = rg.number_of_edges()
|
|
892
|
-
ncomp = nx.number_connected_components(rg)
|
|
893
|
-
|
|
894
|
-
mcb = nx.minimum_cycle_basis(rg)
|
|
895
|
-
assert len(mcb) == nedges - nnodes + ncomp
|
|
896
|
-
check_independent(mcb)
|
|
897
|
-
|
|
898
|
-
def test_complete_graph(self):
|
|
899
|
-
cg = nx.complete_graph(5)
|
|
900
|
-
mcb = nx.minimum_cycle_basis(cg)
|
|
901
|
-
assert all(len(cycle) == 3 for cycle in mcb)
|
|
902
|
-
check_independent(mcb)
|
|
903
|
-
|
|
904
|
-
def test_tree_graph(self):
|
|
905
|
-
tg = nx.balanced_tree(3, 3)
|
|
906
|
-
assert not nx.minimum_cycle_basis(tg)
|
|
907
|
-
|
|
908
|
-
def test_petersen_graph(self):
|
|
909
|
-
G = nx.petersen_graph()
|
|
910
|
-
mcb = list(nx.minimum_cycle_basis(G))
|
|
911
|
-
expected = [
|
|
912
|
-
[4, 9, 7, 5, 0],
|
|
913
|
-
[1, 2, 3, 4, 0],
|
|
914
|
-
[1, 6, 8, 5, 0],
|
|
915
|
-
[4, 3, 8, 5, 0],
|
|
916
|
-
[1, 6, 9, 4, 0],
|
|
917
|
-
[1, 2, 7, 5, 0],
|
|
918
|
-
]
|
|
919
|
-
assert len(mcb) == len(expected)
|
|
920
|
-
assert all(c in expected for c in mcb)
|
|
921
|
-
|
|
922
|
-
# check that order of the nodes is a path
|
|
923
|
-
for c in mcb:
|
|
924
|
-
assert all(G.has_edge(u, v) for u, v in nx.utils.pairwise(c, cyclic=True))
|
|
925
|
-
# check independence of the basis
|
|
926
|
-
check_independent(mcb)
|
|
927
|
-
|
|
928
|
-
def test_gh6787_variable_weighted_complete_graph(self):
|
|
929
|
-
N = 8
|
|
930
|
-
cg = nx.complete_graph(N)
|
|
931
|
-
cg.add_weighted_edges_from([(u, v, 9) for u, v in cg.edges])
|
|
932
|
-
cg.add_weighted_edges_from([(u, v, 1) for u, v in nx.cycle_graph(N).edges])
|
|
933
|
-
mcb = nx.minimum_cycle_basis(cg, weight="weight")
|
|
934
|
-
check_independent(mcb)
|
|
935
|
-
|
|
936
|
-
def test_gh6787_and_edge_attribute_names(self):
|
|
937
|
-
G = nx.cycle_graph(4)
|
|
938
|
-
G.add_weighted_edges_from([(0, 2, 10), (1, 3, 10)], weight="dist")
|
|
939
|
-
expected = [[1, 3, 0], [3, 2, 1, 0], [1, 2, 0]]
|
|
940
|
-
mcb = list(nx.minimum_cycle_basis(G, weight="dist"))
|
|
941
|
-
assert len(mcb) == len(expected)
|
|
942
|
-
assert all(c in expected for c in mcb)
|
|
943
|
-
|
|
944
|
-
# test not using a weight with weight attributes
|
|
945
|
-
expected = [[1, 3, 0], [1, 2, 0], [3, 2, 0]]
|
|
946
|
-
mcb = list(nx.minimum_cycle_basis(G))
|
|
947
|
-
assert len(mcb) == len(expected)
|
|
948
|
-
assert all(c in expected for c in mcb)
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
class TestGirth:
|
|
952
|
-
@pytest.mark.parametrize(
|
|
953
|
-
("G", "expected"),
|
|
954
|
-
(
|
|
955
|
-
(nx.chvatal_graph(), 4),
|
|
956
|
-
(nx.tutte_graph(), 4),
|
|
957
|
-
(nx.petersen_graph(), 5),
|
|
958
|
-
(nx.heawood_graph(), 6),
|
|
959
|
-
(nx.pappus_graph(), 6),
|
|
960
|
-
(nx.random_labeled_tree(10, seed=42), inf),
|
|
961
|
-
(nx.empty_graph(10), inf),
|
|
962
|
-
(nx.Graph(chain(cycle_edges(range(5)), cycle_edges(range(6, 10)))), 4),
|
|
963
|
-
(
|
|
964
|
-
nx.Graph(
|
|
965
|
-
[
|
|
966
|
-
(0, 6),
|
|
967
|
-
(0, 8),
|
|
968
|
-
(0, 9),
|
|
969
|
-
(1, 8),
|
|
970
|
-
(2, 8),
|
|
971
|
-
(2, 9),
|
|
972
|
-
(4, 9),
|
|
973
|
-
(5, 9),
|
|
974
|
-
(6, 8),
|
|
975
|
-
(6, 9),
|
|
976
|
-
(7, 8),
|
|
977
|
-
]
|
|
978
|
-
),
|
|
979
|
-
3,
|
|
980
|
-
),
|
|
981
|
-
),
|
|
982
|
-
)
|
|
983
|
-
def test_girth(self, G, expected):
|
|
984
|
-
assert nx.girth(G) == expected
|