okstra 0.108.0 → 0.110.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/README.kr.md +1 -1
- package/README.md +1 -1
- package/docs/kr/architecture.md +3 -3
- package/docs/kr/cli.md +2 -2
- package/docs/project-structure-overview.md +3 -3
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/prompts/profiles/_common-contract.md +1 -1
- package/runtime/python/okstra_ctl/graphify_cmd.py +225 -0
- package/runtime/python/okstra_ctl/resolve_task_key.py +15 -9
- package/runtime/python/okstra_ctl/worktree.py +14 -13
- package/runtime/python/okstra_project/__init__.py +2 -0
- package/runtime/python/okstra_project/state.py +36 -0
- package/runtime/python/okstra_vendor/__init__.py +41 -0
- package/runtime/python/okstra_vendor/graphify/.vendored-version +1 -0
- package/runtime/python/okstra_vendor/graphify/__init__.py +28 -0
- package/runtime/python/okstra_vendor/graphify/__main__.py +1371 -0
- package/runtime/python/okstra_vendor/graphify/analyze.py +540 -0
- package/runtime/python/okstra_vendor/graphify/benchmark.py +129 -0
- package/runtime/python/okstra_vendor/graphify/build.py +107 -0
- package/runtime/python/okstra_vendor/graphify/cache.py +169 -0
- package/runtime/python/okstra_vendor/graphify/cluster.py +137 -0
- package/runtime/python/okstra_vendor/graphify/detect.py +510 -0
- package/runtime/python/okstra_vendor/graphify/export.py +1014 -0
- package/runtime/python/okstra_vendor/graphify/extract.py +3277 -0
- package/runtime/python/okstra_vendor/graphify/hooks.py +220 -0
- package/runtime/python/okstra_vendor/graphify/ingest.py +297 -0
- package/runtime/python/okstra_vendor/graphify/manifest.py +4 -0
- package/runtime/python/okstra_vendor/graphify/report.py +175 -0
- package/runtime/python/okstra_vendor/graphify/security.py +203 -0
- package/runtime/python/okstra_vendor/graphify/serve.py +373 -0
- package/runtime/python/okstra_vendor/graphify/skill-aider.md +1184 -0
- package/runtime/python/okstra_vendor/graphify/skill-claw.md +1184 -0
- package/runtime/python/okstra_vendor/graphify/skill-codex.md +1242 -0
- package/runtime/python/okstra_vendor/graphify/skill-copilot.md +1268 -0
- package/runtime/python/okstra_vendor/graphify/skill-droid.md +1239 -0
- package/runtime/python/okstra_vendor/graphify/skill-kiro.md +1183 -0
- package/runtime/python/okstra_vendor/graphify/skill-opencode.md +1238 -0
- package/runtime/python/okstra_vendor/graphify/skill-trae.md +1208 -0
- package/runtime/python/okstra_vendor/graphify/skill-vscode.md +253 -0
- package/runtime/python/okstra_vendor/graphify/skill-windows.md +1245 -0
- package/runtime/python/okstra_vendor/graphify/skill.md +1319 -0
- package/runtime/python/okstra_vendor/graphify/transcribe.py +182 -0
- package/runtime/python/okstra_vendor/graphify/validate.py +72 -0
- package/runtime/python/okstra_vendor/graphify/watch.py +188 -0
- package/runtime/python/okstra_vendor/graphify/wiki.py +214 -0
- package/runtime/python/okstra_vendor/networkx/__init__.py +62 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +134 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +26 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +259 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +71 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +412 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +396 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +150 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +149 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +369 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +44 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +143 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +53 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +265 -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 +41 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_clique.py +112 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_connectivity.py +199 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_density.py +146 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_distance_measures.py +59 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_dominating_set.py +78 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_kcomponents.py +303 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_matching.py +8 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_maxcut.py +94 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_ramsey.py +31 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_steinertree.py +306 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_traveling_salesman.py +1014 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_treewidth.py +274 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/tests/test_vertex_cover.py +68 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +1508 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +255 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +83 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +5 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +122 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +302 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +255 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +160 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +127 -0
- 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 +81 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_connectivity.py +143 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_correlation.py +122 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_mixing.py +174 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_neighbor_degree.py +107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/tests/test_pairs.py +87 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +164 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +322 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +290 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +289 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +57 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +360 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +105 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +603 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +316 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +590 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +232 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +526 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +112 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +69 -0
- 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 +125 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_centrality.py +192 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_cluster.py +84 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_covering.py +33 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_edgelist.py +240 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_extendability.py +334 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_generators.py +407 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_link_analysis.py +218 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matching.py +327 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_matrix.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_project.py +409 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_redundancy.py +35 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/tests/test_spectral_bipartivity.py +80 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +168 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +205 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +164 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +20 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +591 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +236 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +282 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +364 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +227 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +96 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +150 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +357 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +130 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +787 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +331 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +150 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +200 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +128 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +209 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +141 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +361 -0
- 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 +923 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_betweenness_centrality_subset.py +354 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_closeness_centrality.py +274 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality.py +259 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_betweenness_centrality_subset.py +147 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_current_flow_closeness.py +43 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_degree_centrality.py +144 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_dispersion.py +73 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_eigenvector_centrality.py +186 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_group.py +277 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_harmonic_centrality.py +122 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_katz_centrality.py +345 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_laplacian_centrality.py +220 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_load_centrality.py +344 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_percolation_centrality.py +87 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_reaching.py +140 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_second_order_centrality.py +82 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_subgraph.py +110 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_trophic.py +302 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/tests/test_voterank.py +64 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +181 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +95 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +172 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +443 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +818 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +732 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +4 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +505 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +565 -0
- 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 +863 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +163 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +28 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +153 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +354 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +171 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +30 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +216 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +79 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +338 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +162 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +220 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +384 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +227 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +452 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +347 -0
- 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 +147 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_bipartitions.py +157 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_centrality.py +85 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_divisive.py +106 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_kclique.py +91 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_label_propagation.py +241 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_leiden.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_local.py +76 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_louvain.py +264 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_lukes.py +152 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_modularity_max.py +340 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_quality.py +139 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/community/tests/test_utils.py +26 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +6 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +115 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +394 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +282 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +71 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +359 -0
- 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 +70 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_biconnected.py +248 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_connected.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_semiconnected.py +55 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_strongly_connected.py +193 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/tests/test_weakly_connected.py +96 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +196 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +11 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +811 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +616 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +408 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +1270 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +592 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +220 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +235 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +152 -0
- 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 +421 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_cuts.py +309 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_disjoint_paths.py +249 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_augmentation.py +502 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_edge_kcomponents.py +488 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcomponents.py +323 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_kcutsets.py +280 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/tests/test_stoer_wagner.py +102 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/core.py +588 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +142 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +416 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +1234 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +677 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +1392 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +1095 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +272 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +142 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +268 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +167 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +470 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +11 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +370 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +407 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +238 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +241 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +178 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +611 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +356 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +662 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +425 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +300 -0
- 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 +128 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow.py +573 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_maxflow_large_graph.py +155 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_mincost.py +475 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/test_networksimplex.py +481 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/tests/wlm3.gpickle.bz2 +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +194 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +435 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +483 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +57 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +196 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +7 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +1306 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +336 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +1262 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +352 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +308 -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 +719 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphism.py +103 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_isomorphvf2.py +490 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_match_helpers.py +64 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_temporalisomorphvf2.py +212 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_tree_isomorphism.py +202 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp.py +1655 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py +3118 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tests/test_vf2userfunc.py +196 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +264 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +1102 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +192 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +2 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +337 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +498 -0
- 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 +77 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/tests/test_pagerank.py +213 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +687 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +280 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +1148 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +27 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +738 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/tests/test_contraction.py +544 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +78 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +59 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +219 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +155 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +4 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +324 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +468 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +633 -0
- 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 +328 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_binary.py +451 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_product.py +491 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/tests/test_unary.py +55 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +77 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +73 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +464 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +1463 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +306 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +98 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +167 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +5 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +239 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +264 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +716 -0
- 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 +254 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense.py +212 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_dense_numpy.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_generic.py +511 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_unweighted.py +149 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/tests/test_weighted.py +983 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +625 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +2542 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +2107 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +966 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +404 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +30 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +296 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +374 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +564 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +406 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_asteroidal.py +23 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_boundary.py +154 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_bridges.py +144 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_broadcasting.py +109 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chains.py +136 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_chordal.py +129 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_clique.py +300 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cluster.py +678 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_communicability.py +80 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_core.py +266 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_covering.py +85 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cuts.py +171 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_cycles.py +984 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_d_separation.py +340 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dag.py +835 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_measures.py +831 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_distance_regular.py +85 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominance.py +299 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_dominating.py +115 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_efficiency.py +58 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_euler.py +314 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graph_hashing.py +872 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_graphical.py +163 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hierarchy.py +46 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_hybrid.py +24 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_isolate.py +26 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_link_prediction.py +615 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_lowest_common_ancestors.py +459 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_matching.py +556 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_max_weight_clique.py +179 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_mis.py +62 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_moral.py +15 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_node_classification.py +140 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_non_randomness.py +60 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_perfect_graph.py +27 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planar_drawing.py +274 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_planarity.py +556 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_polynomials.py +57 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_reciprocity.py +37 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_regular.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_richclub.py +149 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_similarity.py +1158 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_simple_paths.py +803 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smallworld.py +76 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_smetric.py +8 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_sparsifiers.py +138 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_structuralholes.py +191 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_summarization.py +642 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_swap.py +179 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_threshold.py +270 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_time_dependent.py +431 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_tournament.py +161 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_triads.py +248 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_vitality.py +41 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_voronoi.py +103 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_walks.py +54 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tests/test_wiener.py +157 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +981 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +142 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +406 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +5 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +90 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +576 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +529 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +185 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +182 -0
- 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 +25 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_bfs.py +203 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_dfs.py +307 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgebfs.py +147 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/tests/test_edgedfs.py +131 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +7 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +1042 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +413 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +88 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +219 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +1281 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +106 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +273 -0
- 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 +624 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_coding.py +114 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_decomposition.py +79 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_distance_measures.py +99 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_mst.py +934 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_operations.py +53 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/tests/test_recognition.py +174 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +500 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +76 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +86 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +77 -0
- package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +278 -0
- package/runtime/python/okstra_vendor/networkx/classes/__init__.py +13 -0
- package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +435 -0
- package/runtime/python/okstra_vendor/networkx/classes/digraph.py +1363 -0
- package/runtime/python/okstra_vendor/networkx/classes/filters.py +95 -0
- package/runtime/python/okstra_vendor/networkx/classes/function.py +1549 -0
- package/runtime/python/okstra_vendor/networkx/classes/graph.py +2082 -0
- package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +269 -0
- package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +977 -0
- package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +1294 -0
- package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +1447 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/dispatch_interface.py +192 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/historical_tests.py +476 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_coreviews.py +362 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph.py +331 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_digraph_historical.py +110 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_filters.py +177 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_function.py +1045 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph.py +950 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graph_historical.py +12 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_graphviews.py +349 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_multidigraph.py +459 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_multigraph.py +528 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_reportviews.py +1421 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_special.py +131 -0
- package/runtime/python/okstra_vendor/networkx/classes/tests/test_subgraphviews.py +371 -0
- package/runtime/python/okstra_vendor/networkx/conftest.py +261 -0
- package/runtime/python/okstra_vendor/networkx/convert.py +502 -0
- package/runtime/python/okstra_vendor/networkx/convert_matrix.py +1314 -0
- package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +7 -0
- package/runtime/python/okstra_vendor/networkx/drawing/layout.py +2036 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +470 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +570 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +361 -0
- package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +2978 -0
- 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 +237 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_image_comparison_pylab_mpl.py +229 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_latex.py +285 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_layout.py +631 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pydot.py +146 -0
- package/runtime/python/okstra_vendor/networkx/drawing/tests/test_pylab.py +1582 -0
- package/runtime/python/okstra_vendor/networkx/exception.py +131 -0
- package/runtime/python/okstra_vendor/networkx/generators/__init__.py +34 -0
- package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
- package/runtime/python/okstra_vendor/networkx/generators/atlas.py +227 -0
- package/runtime/python/okstra_vendor/networkx/generators/classic.py +1091 -0
- package/runtime/python/okstra_vendor/networkx/generators/cographs.py +68 -0
- package/runtime/python/okstra_vendor/networkx/generators/community.py +1070 -0
- package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +886 -0
- package/runtime/python/okstra_vendor/networkx/generators/directed.py +572 -0
- package/runtime/python/okstra_vendor/networkx/generators/duplication.py +174 -0
- package/runtime/python/okstra_vendor/networkx/generators/ego.py +66 -0
- package/runtime/python/okstra_vendor/networkx/generators/expanders.py +499 -0
- package/runtime/python/okstra_vendor/networkx/generators/geometric.py +1037 -0
- package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +163 -0
- package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +443 -0
- package/runtime/python/okstra_vendor/networkx/generators/intersection.py +125 -0
- package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +70 -0
- package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +664 -0
- package/runtime/python/okstra_vendor/networkx/generators/lattice.py +405 -0
- package/runtime/python/okstra_vendor/networkx/generators/line.py +501 -0
- package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +110 -0
- package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +259 -0
- package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +117 -0
- package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +1416 -0
- package/runtime/python/okstra_vendor/networkx/generators/small.py +1070 -0
- package/runtime/python/okstra_vendor/networkx/generators/social.py +554 -0
- package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +120 -0
- package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +54 -0
- package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +131 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_atlas.py +75 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_classic.py +642 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_cographs.py +20 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_community.py +362 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_degree_seq.py +224 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_directed.py +189 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_duplication.py +103 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_ego.py +39 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_expanders.py +182 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_geometric.py +488 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_harary_graph.py +133 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_internet_as_graphs.py +221 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_intersection.py +28 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_interval_graph.py +144 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_joint_degree_seq.py +125 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_lattice.py +264 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_line.py +316 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_mycielski.py +30 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_nonisomorphic_trees.py +82 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_clustered.py +33 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_random_graphs.py +495 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_small.py +220 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_spectral_graph_forge.py +49 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_stochastic.py +72 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_sudoku.py +92 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_time_series.py +64 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_trees.py +195 -0
- package/runtime/python/okstra_vendor/networkx/generators/tests/test_triads.py +15 -0
- package/runtime/python/okstra_vendor/networkx/generators/time_series.py +74 -0
- package/runtime/python/okstra_vendor/networkx/generators/trees.py +1070 -0
- package/runtime/python/okstra_vendor/networkx/generators/triads.py +94 -0
- package/runtime/python/okstra_vendor/networkx/lazy_imports.py +188 -0
- package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +13 -0
- package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +650 -0
- package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +466 -0
- package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +77 -0
- package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +168 -0
- package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +512 -0
- package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +166 -0
- package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +186 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_algebraic_connectivity.py +400 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_attrmatrix.py +108 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_bethehessian.py +40 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_graphmatrix.py +275 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_laplacian.py +334 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_modularity.py +86 -0
- package/runtime/python/okstra_vendor/networkx/linalg/tests/test_spectrum.py +70 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +17 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +330 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +489 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +1084 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +879 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +427 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +1053 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +19 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +156 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +190 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +261 -0
- 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 +78 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_cytoscape.py +78 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_node_link.py +109 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tests/test_tree.py +48 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +137 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +108 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +393 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +113 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +286 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +379 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_adjlist.py +354 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_edgelist.py +318 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gexf.py +612 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_gml.py +744 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graph6.py +181 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_graphml.py +1531 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_leda.py +30 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_p2g.py +63 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_pajek.py +128 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_sparse6.py +166 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/tests/test_text.py +1742 -0
- package/runtime/python/okstra_vendor/networkx/readwrite/text.py +851 -0
- package/runtime/python/okstra_vendor/networkx/relabel.py +285 -0
- package/runtime/python/okstra_vendor/networkx/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_all_random_functions.py +248 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert.py +321 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_numpy.py +531 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_pandas.py +349 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_convert_scipy.py +281 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_exceptions.py +40 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_import.py +11 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_lazy_imports.py +96 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_relabel.py +349 -0
- package/runtime/python/okstra_vendor/networkx/tests/test_removed_functions_exception_messages.py +8 -0
- package/runtime/python/okstra_vendor/networkx/utils/__init__.py +8 -0
- package/runtime/python/okstra_vendor/networkx/utils/backends.py +2171 -0
- package/runtime/python/okstra_vendor/networkx/utils/configs.py +396 -0
- package/runtime/python/okstra_vendor/networkx/utils/decorators.py +1233 -0
- package/runtime/python/okstra_vendor/networkx/utils/heaps.py +338 -0
- package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +297 -0
- package/runtime/python/okstra_vendor/networkx/utils/misc.py +703 -0
- package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +198 -0
- package/runtime/python/okstra_vendor/networkx/utils/rcm.py +159 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/__init__.py +0 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test__init.py +11 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_backends.py +225 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_config.py +263 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_decorators.py +510 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_heaps.py +131 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_mapped_queue.py +268 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_misc.py +393 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_random_sequence.py +53 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_rcm.py +63 -0
- package/runtime/python/okstra_vendor/networkx/utils/tests/test_unionfind.py +55 -0
- package/runtime/python/okstra_vendor/networkx/utils/union_find.py +106 -0
- package/runtime/skills/okstra-graphify/SKILL.md +161 -0
- package/runtime/skills/okstra-inspect/SKILL.md +17 -9
- package/runtime/templates/reports/settings.template.json +4 -0
- package/src/cli-registry.mjs +7 -0
- package/src/commands/graphify.mjs +32 -0
- package/src/commands/lifecycle/doctor.mjs +9 -0
- package/src/lib/skill-catalog.mjs +1 -0
|
@@ -0,0 +1,1281 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Algorithms for calculating min/max spanning trees/forests.
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from heapq import heappop, heappush
|
|
9
|
+
from itertools import count
|
|
10
|
+
from math import isnan
|
|
11
|
+
from operator import itemgetter
|
|
12
|
+
from queue import PriorityQueue
|
|
13
|
+
|
|
14
|
+
import networkx as nx
|
|
15
|
+
from networkx.utils import UnionFind, not_implemented_for, py_random_state
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"minimum_spanning_edges",
|
|
19
|
+
"maximum_spanning_edges",
|
|
20
|
+
"minimum_spanning_tree",
|
|
21
|
+
"maximum_spanning_tree",
|
|
22
|
+
"number_of_spanning_trees",
|
|
23
|
+
"random_spanning_tree",
|
|
24
|
+
"partition_spanning_tree",
|
|
25
|
+
"EdgePartition",
|
|
26
|
+
"SpanningTreeIterator",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class EdgePartition(Enum):
|
|
31
|
+
"""
|
|
32
|
+
An enum to store the state of an edge partition. The enum is written to the
|
|
33
|
+
edges of a graph before being pasted to `kruskal_mst_edges`. Options are:
|
|
34
|
+
|
|
35
|
+
- EdgePartition.OPEN
|
|
36
|
+
- EdgePartition.INCLUDED
|
|
37
|
+
- EdgePartition.EXCLUDED
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
OPEN = 0
|
|
41
|
+
INCLUDED = 1
|
|
42
|
+
EXCLUDED = 2
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@not_implemented_for("multigraph")
|
|
46
|
+
@nx._dispatchable(edge_attrs="weight", preserve_edge_attrs="data")
|
|
47
|
+
def boruvka_mst_edges(
|
|
48
|
+
G, minimum=True, weight="weight", keys=False, data=True, ignore_nan=False
|
|
49
|
+
):
|
|
50
|
+
"""Iterate over edges of a Borůvka's algorithm min/max spanning tree.
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
G : NetworkX Graph
|
|
55
|
+
The edges of `G` must have distinct weights,
|
|
56
|
+
otherwise the edges may not form a tree.
|
|
57
|
+
|
|
58
|
+
minimum : bool (default: True)
|
|
59
|
+
Find the minimum (True) or maximum (False) spanning tree.
|
|
60
|
+
|
|
61
|
+
weight : string (default: 'weight')
|
|
62
|
+
The name of the edge attribute holding the edge weights.
|
|
63
|
+
|
|
64
|
+
keys : bool (default: True)
|
|
65
|
+
This argument is ignored since this function is not
|
|
66
|
+
implemented for multigraphs; it exists only for consistency
|
|
67
|
+
with the other minimum spanning tree functions.
|
|
68
|
+
|
|
69
|
+
data : bool (default: True)
|
|
70
|
+
Flag for whether to yield edge attribute dicts.
|
|
71
|
+
If True, yield edges `(u, v, d)`, where `d` is the attribute dict.
|
|
72
|
+
If False, yield edges `(u, v)`.
|
|
73
|
+
|
|
74
|
+
ignore_nan : bool (default: False)
|
|
75
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
76
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
# Initialize a forest, assuming initially that it is the discrete
|
|
80
|
+
# partition of the nodes of the graph.
|
|
81
|
+
forest = UnionFind(G)
|
|
82
|
+
|
|
83
|
+
def best_edge(component):
|
|
84
|
+
"""Returns the optimum (minimum or maximum) edge on the edge
|
|
85
|
+
boundary of the given set of nodes.
|
|
86
|
+
|
|
87
|
+
A return value of ``None`` indicates an empty boundary.
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
sign = 1 if minimum else -1
|
|
91
|
+
minwt = float("inf")
|
|
92
|
+
boundary = None
|
|
93
|
+
for e in nx.edge_boundary(G, component, data=True):
|
|
94
|
+
wt = e[-1].get(weight, 1) * sign
|
|
95
|
+
if isnan(wt):
|
|
96
|
+
if ignore_nan:
|
|
97
|
+
continue
|
|
98
|
+
msg = f"NaN found as an edge weight. Edge {e}"
|
|
99
|
+
raise ValueError(msg)
|
|
100
|
+
if wt < minwt:
|
|
101
|
+
minwt = wt
|
|
102
|
+
boundary = e
|
|
103
|
+
return boundary
|
|
104
|
+
|
|
105
|
+
# Determine the optimum edge in the edge boundary of each component
|
|
106
|
+
# in the forest.
|
|
107
|
+
best_edges = (best_edge(component) for component in forest.to_sets())
|
|
108
|
+
best_edges = [edge for edge in best_edges if edge is not None]
|
|
109
|
+
# If each entry was ``None``, that means the graph was disconnected,
|
|
110
|
+
# so we are done generating the forest.
|
|
111
|
+
while best_edges:
|
|
112
|
+
# Determine the optimum edge in the edge boundary of each
|
|
113
|
+
# component in the forest.
|
|
114
|
+
#
|
|
115
|
+
# This must be a sequence, not an iterator. In this list, the
|
|
116
|
+
# same edge may appear twice, in different orientations (but
|
|
117
|
+
# that's okay, since a union operation will be called on the
|
|
118
|
+
# endpoints the first time it is seen, but not the second time).
|
|
119
|
+
#
|
|
120
|
+
# Any ``None`` indicates that the edge boundary for that
|
|
121
|
+
# component was empty, so that part of the forest has been
|
|
122
|
+
# completed.
|
|
123
|
+
#
|
|
124
|
+
# TODO This can be parallelized, both in the outer loop over
|
|
125
|
+
# each component in the forest and in the computation of the
|
|
126
|
+
# minimum. (Same goes for the identical lines outside the loop.)
|
|
127
|
+
best_edges = (best_edge(component) for component in forest.to_sets())
|
|
128
|
+
best_edges = [edge for edge in best_edges if edge is not None]
|
|
129
|
+
# Join trees in the forest using the best edges, and yield that
|
|
130
|
+
# edge, since it is part of the spanning tree.
|
|
131
|
+
#
|
|
132
|
+
# TODO This loop can be parallelized, to an extent (the union
|
|
133
|
+
# operation must be atomic).
|
|
134
|
+
for u, v, d in best_edges:
|
|
135
|
+
if forest[u] != forest[v]:
|
|
136
|
+
if data:
|
|
137
|
+
yield u, v, d
|
|
138
|
+
else:
|
|
139
|
+
yield u, v
|
|
140
|
+
forest.union(u, v)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
@nx._dispatchable(
|
|
144
|
+
edge_attrs={"weight": None, "partition": None}, preserve_edge_attrs="data"
|
|
145
|
+
)
|
|
146
|
+
def kruskal_mst_edges(
|
|
147
|
+
G, minimum, weight="weight", keys=True, data=True, ignore_nan=False, partition=None
|
|
148
|
+
):
|
|
149
|
+
"""
|
|
150
|
+
Iterate over edge of a Kruskal's algorithm min/max spanning tree.
|
|
151
|
+
|
|
152
|
+
Parameters
|
|
153
|
+
----------
|
|
154
|
+
G : NetworkX Graph
|
|
155
|
+
The graph holding the tree of interest.
|
|
156
|
+
|
|
157
|
+
minimum : bool (default: True)
|
|
158
|
+
Find the minimum (True) or maximum (False) spanning tree.
|
|
159
|
+
|
|
160
|
+
weight : string (default: 'weight')
|
|
161
|
+
The name of the edge attribute holding the edge weights.
|
|
162
|
+
|
|
163
|
+
keys : bool (default: True)
|
|
164
|
+
If `G` is a multigraph, `keys` controls whether edge keys ar yielded.
|
|
165
|
+
Otherwise `keys` is ignored.
|
|
166
|
+
|
|
167
|
+
data : bool (default: True)
|
|
168
|
+
Flag for whether to yield edge attribute dicts.
|
|
169
|
+
If True, yield edges `(u, v, d)`, where `d` is the attribute dict.
|
|
170
|
+
If False, yield edges `(u, v)`.
|
|
171
|
+
|
|
172
|
+
ignore_nan : bool (default: False)
|
|
173
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
174
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
175
|
+
|
|
176
|
+
partition : string (default: None)
|
|
177
|
+
The name of the edge attribute holding the partition data, if it exists.
|
|
178
|
+
Partition data is written to the edges using the `EdgePartition` enum.
|
|
179
|
+
If a partition exists, all included edges and none of the excluded edges
|
|
180
|
+
will appear in the final tree. Open edges may or may not be used.
|
|
181
|
+
|
|
182
|
+
Yields
|
|
183
|
+
------
|
|
184
|
+
edge tuple
|
|
185
|
+
The edges as discovered by Kruskal's method. Each edge can
|
|
186
|
+
take the following forms: `(u, v)`, `(u, v, d)` or `(u, v, k, d)`
|
|
187
|
+
depending on the `key` and `data` parameters
|
|
188
|
+
"""
|
|
189
|
+
subtrees = UnionFind()
|
|
190
|
+
if G.is_multigraph():
|
|
191
|
+
edges = G.edges(keys=True, data=True)
|
|
192
|
+
else:
|
|
193
|
+
edges = G.edges(data=True)
|
|
194
|
+
|
|
195
|
+
# Sort the edges of the graph with respect to the partition data.
|
|
196
|
+
# Edges are returned in the following order:
|
|
197
|
+
|
|
198
|
+
# * Included edges
|
|
199
|
+
# * Open edges from smallest to largest weight
|
|
200
|
+
# * Excluded edges
|
|
201
|
+
included_edges = []
|
|
202
|
+
open_edges = []
|
|
203
|
+
for e in edges:
|
|
204
|
+
d = e[-1]
|
|
205
|
+
wt = d.get(weight, 1)
|
|
206
|
+
if isnan(wt):
|
|
207
|
+
if ignore_nan:
|
|
208
|
+
continue
|
|
209
|
+
raise ValueError(f"NaN found as an edge weight. Edge {e}")
|
|
210
|
+
|
|
211
|
+
edge = (wt,) + e
|
|
212
|
+
if d.get(partition) == EdgePartition.INCLUDED:
|
|
213
|
+
included_edges.append(edge)
|
|
214
|
+
elif d.get(partition) == EdgePartition.EXCLUDED:
|
|
215
|
+
continue
|
|
216
|
+
else:
|
|
217
|
+
open_edges.append(edge)
|
|
218
|
+
|
|
219
|
+
if minimum:
|
|
220
|
+
sorted_open_edges = sorted(open_edges, key=itemgetter(0))
|
|
221
|
+
else:
|
|
222
|
+
sorted_open_edges = sorted(open_edges, key=itemgetter(0), reverse=True)
|
|
223
|
+
|
|
224
|
+
# Condense the lists into one
|
|
225
|
+
included_edges.extend(sorted_open_edges)
|
|
226
|
+
sorted_edges = included_edges
|
|
227
|
+
del open_edges, sorted_open_edges, included_edges
|
|
228
|
+
|
|
229
|
+
# Multigraphs need to handle edge keys in addition to edge data.
|
|
230
|
+
if G.is_multigraph():
|
|
231
|
+
for wt, u, v, k, d in sorted_edges:
|
|
232
|
+
if subtrees[u] != subtrees[v]:
|
|
233
|
+
if keys:
|
|
234
|
+
if data:
|
|
235
|
+
yield u, v, k, d
|
|
236
|
+
else:
|
|
237
|
+
yield u, v, k
|
|
238
|
+
else:
|
|
239
|
+
if data:
|
|
240
|
+
yield u, v, d
|
|
241
|
+
else:
|
|
242
|
+
yield u, v
|
|
243
|
+
subtrees.union(u, v)
|
|
244
|
+
else:
|
|
245
|
+
for wt, u, v, d in sorted_edges:
|
|
246
|
+
if subtrees[u] != subtrees[v]:
|
|
247
|
+
if data:
|
|
248
|
+
yield u, v, d
|
|
249
|
+
else:
|
|
250
|
+
yield u, v
|
|
251
|
+
subtrees.union(u, v)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@nx._dispatchable(edge_attrs="weight", preserve_edge_attrs="data")
|
|
255
|
+
def prim_mst_edges(G, minimum, weight="weight", keys=True, data=True, ignore_nan=False):
|
|
256
|
+
"""Iterate over edges of Prim's algorithm min/max spanning tree.
|
|
257
|
+
|
|
258
|
+
Parameters
|
|
259
|
+
----------
|
|
260
|
+
G : NetworkX Graph
|
|
261
|
+
The graph holding the tree of interest.
|
|
262
|
+
|
|
263
|
+
minimum : bool (default: True)
|
|
264
|
+
Find the minimum (True) or maximum (False) spanning tree.
|
|
265
|
+
|
|
266
|
+
weight : string (default: 'weight')
|
|
267
|
+
The name of the edge attribute holding the edge weights.
|
|
268
|
+
|
|
269
|
+
keys : bool (default: True)
|
|
270
|
+
If `G` is a multigraph, `keys` controls whether edge keys ar yielded.
|
|
271
|
+
Otherwise `keys` is ignored.
|
|
272
|
+
|
|
273
|
+
data : bool (default: True)
|
|
274
|
+
Flag for whether to yield edge attribute dicts.
|
|
275
|
+
If True, yield edges `(u, v, d)`, where `d` is the attribute dict.
|
|
276
|
+
If False, yield edges `(u, v)`.
|
|
277
|
+
|
|
278
|
+
ignore_nan : bool (default: False)
|
|
279
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
280
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
281
|
+
|
|
282
|
+
"""
|
|
283
|
+
is_multigraph = G.is_multigraph()
|
|
284
|
+
|
|
285
|
+
nodes = set(G)
|
|
286
|
+
c = count()
|
|
287
|
+
|
|
288
|
+
sign = 1 if minimum else -1
|
|
289
|
+
|
|
290
|
+
while nodes:
|
|
291
|
+
u = nodes.pop()
|
|
292
|
+
frontier = []
|
|
293
|
+
visited = {u}
|
|
294
|
+
if is_multigraph:
|
|
295
|
+
for v, keydict in G.adj[u].items():
|
|
296
|
+
for k, d in keydict.items():
|
|
297
|
+
wt = d.get(weight, 1) * sign
|
|
298
|
+
if isnan(wt):
|
|
299
|
+
if ignore_nan:
|
|
300
|
+
continue
|
|
301
|
+
msg = f"NaN found as an edge weight. Edge {(u, v, k, d)}"
|
|
302
|
+
raise ValueError(msg)
|
|
303
|
+
heappush(frontier, (wt, next(c), u, v, k, d))
|
|
304
|
+
else:
|
|
305
|
+
for v, d in G.adj[u].items():
|
|
306
|
+
wt = d.get(weight, 1) * sign
|
|
307
|
+
if isnan(wt):
|
|
308
|
+
if ignore_nan:
|
|
309
|
+
continue
|
|
310
|
+
msg = f"NaN found as an edge weight. Edge {(u, v, d)}"
|
|
311
|
+
raise ValueError(msg)
|
|
312
|
+
heappush(frontier, (wt, next(c), u, v, d))
|
|
313
|
+
while nodes and frontier:
|
|
314
|
+
if is_multigraph:
|
|
315
|
+
W, _, u, v, k, d = heappop(frontier)
|
|
316
|
+
else:
|
|
317
|
+
W, _, u, v, d = heappop(frontier)
|
|
318
|
+
if v in visited or v not in nodes:
|
|
319
|
+
continue
|
|
320
|
+
# Multigraphs need to handle edge keys in addition to edge data.
|
|
321
|
+
if is_multigraph and keys:
|
|
322
|
+
if data:
|
|
323
|
+
yield u, v, k, d
|
|
324
|
+
else:
|
|
325
|
+
yield u, v, k
|
|
326
|
+
else:
|
|
327
|
+
if data:
|
|
328
|
+
yield u, v, d
|
|
329
|
+
else:
|
|
330
|
+
yield u, v
|
|
331
|
+
# update frontier
|
|
332
|
+
visited.add(v)
|
|
333
|
+
nodes.discard(v)
|
|
334
|
+
if is_multigraph:
|
|
335
|
+
for w, keydict in G.adj[v].items():
|
|
336
|
+
if w in visited:
|
|
337
|
+
continue
|
|
338
|
+
for k2, d2 in keydict.items():
|
|
339
|
+
new_weight = d2.get(weight, 1) * sign
|
|
340
|
+
if isnan(new_weight):
|
|
341
|
+
if ignore_nan:
|
|
342
|
+
continue
|
|
343
|
+
msg = f"NaN found as an edge weight. Edge {(v, w, k2, d2)}"
|
|
344
|
+
raise ValueError(msg)
|
|
345
|
+
heappush(frontier, (new_weight, next(c), v, w, k2, d2))
|
|
346
|
+
else:
|
|
347
|
+
for w, d2 in G.adj[v].items():
|
|
348
|
+
if w in visited:
|
|
349
|
+
continue
|
|
350
|
+
new_weight = d2.get(weight, 1) * sign
|
|
351
|
+
if isnan(new_weight):
|
|
352
|
+
if ignore_nan:
|
|
353
|
+
continue
|
|
354
|
+
msg = f"NaN found as an edge weight. Edge {(v, w, d2)}"
|
|
355
|
+
raise ValueError(msg)
|
|
356
|
+
heappush(frontier, (new_weight, next(c), v, w, d2))
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
ALGORITHMS = {
|
|
360
|
+
"boruvka": boruvka_mst_edges,
|
|
361
|
+
"borůvka": boruvka_mst_edges,
|
|
362
|
+
"kruskal": kruskal_mst_edges,
|
|
363
|
+
"prim": prim_mst_edges,
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
@not_implemented_for("directed")
|
|
368
|
+
@nx._dispatchable(edge_attrs="weight", preserve_edge_attrs="data")
|
|
369
|
+
def minimum_spanning_edges(
|
|
370
|
+
G, algorithm="kruskal", weight="weight", keys=True, data=True, ignore_nan=False
|
|
371
|
+
):
|
|
372
|
+
"""Generate edges in a minimum spanning forest of an undirected
|
|
373
|
+
weighted graph.
|
|
374
|
+
|
|
375
|
+
A minimum spanning tree is a subgraph of the graph (a tree)
|
|
376
|
+
with the minimum sum of edge weights. A spanning forest is a
|
|
377
|
+
union of the spanning trees for each connected component of the graph.
|
|
378
|
+
|
|
379
|
+
Parameters
|
|
380
|
+
----------
|
|
381
|
+
G : undirected Graph
|
|
382
|
+
An undirected graph. If `G` is connected, then the algorithm finds a
|
|
383
|
+
spanning tree. Otherwise, a spanning forest is found.
|
|
384
|
+
|
|
385
|
+
algorithm : string
|
|
386
|
+
The algorithm to use when finding a minimum spanning tree. Valid
|
|
387
|
+
choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'.
|
|
388
|
+
|
|
389
|
+
weight : string
|
|
390
|
+
Edge data key to use for weight (default 'weight').
|
|
391
|
+
|
|
392
|
+
keys : bool
|
|
393
|
+
Whether to yield edge key in multigraphs in addition to the edge.
|
|
394
|
+
If `G` is not a multigraph, this is ignored.
|
|
395
|
+
|
|
396
|
+
data : bool, optional
|
|
397
|
+
If True yield the edge data along with the edge.
|
|
398
|
+
|
|
399
|
+
ignore_nan : bool (default: False)
|
|
400
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
401
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
402
|
+
|
|
403
|
+
Returns
|
|
404
|
+
-------
|
|
405
|
+
edges : iterator
|
|
406
|
+
An iterator over edges in a maximum spanning tree of `G`.
|
|
407
|
+
Edges connecting nodes `u` and `v` are represented as tuples:
|
|
408
|
+
`(u, v, k, d)` or `(u, v, k)` or `(u, v, d)` or `(u, v)`
|
|
409
|
+
|
|
410
|
+
If `G` is a multigraph, `keys` indicates whether the edge key `k` will
|
|
411
|
+
be reported in the third position in the edge tuple. `data` indicates
|
|
412
|
+
whether the edge datadict `d` will appear at the end of the edge tuple.
|
|
413
|
+
|
|
414
|
+
If `G` is not a multigraph, the tuples are `(u, v, d)` if `data` is True
|
|
415
|
+
or `(u, v)` if `data` is False.
|
|
416
|
+
|
|
417
|
+
Examples
|
|
418
|
+
--------
|
|
419
|
+
>>> from networkx.algorithms import tree
|
|
420
|
+
|
|
421
|
+
Find minimum spanning edges by Kruskal's algorithm
|
|
422
|
+
|
|
423
|
+
>>> G = nx.cycle_graph(4)
|
|
424
|
+
>>> G.add_edge(0, 3, weight=2)
|
|
425
|
+
>>> mst = tree.minimum_spanning_edges(G, algorithm="kruskal", data=False)
|
|
426
|
+
>>> edgelist = list(mst)
|
|
427
|
+
>>> sorted(sorted(e) for e in edgelist)
|
|
428
|
+
[[0, 1], [1, 2], [2, 3]]
|
|
429
|
+
|
|
430
|
+
Find minimum spanning edges by Prim's algorithm
|
|
431
|
+
|
|
432
|
+
>>> G = nx.cycle_graph(4)
|
|
433
|
+
>>> G.add_edge(0, 3, weight=2)
|
|
434
|
+
>>> mst = tree.minimum_spanning_edges(G, algorithm="prim", data=False)
|
|
435
|
+
>>> edgelist = list(mst)
|
|
436
|
+
>>> sorted(sorted(e) for e in edgelist)
|
|
437
|
+
[[0, 1], [1, 2], [2, 3]]
|
|
438
|
+
|
|
439
|
+
Notes
|
|
440
|
+
-----
|
|
441
|
+
For Borůvka's algorithm, each edge must have a weight attribute, and
|
|
442
|
+
each edge weight must be distinct.
|
|
443
|
+
|
|
444
|
+
For the other algorithms, if the graph edges do not have a weight
|
|
445
|
+
attribute a default weight of 1 will be used.
|
|
446
|
+
|
|
447
|
+
Modified code from David Eppstein, April 2006
|
|
448
|
+
http://www.ics.uci.edu/~eppstein/PADS/
|
|
449
|
+
|
|
450
|
+
"""
|
|
451
|
+
try:
|
|
452
|
+
algo = ALGORITHMS[algorithm]
|
|
453
|
+
except KeyError as err:
|
|
454
|
+
msg = f"{algorithm} is not a valid choice for an algorithm."
|
|
455
|
+
raise ValueError(msg) from err
|
|
456
|
+
|
|
457
|
+
return algo(
|
|
458
|
+
G, minimum=True, weight=weight, keys=keys, data=data, ignore_nan=ignore_nan
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
@not_implemented_for("directed")
|
|
463
|
+
@nx._dispatchable(edge_attrs="weight", preserve_edge_attrs="data")
|
|
464
|
+
def maximum_spanning_edges(
|
|
465
|
+
G, algorithm="kruskal", weight="weight", keys=True, data=True, ignore_nan=False
|
|
466
|
+
):
|
|
467
|
+
"""Generate edges in a maximum spanning forest of an undirected
|
|
468
|
+
weighted graph.
|
|
469
|
+
|
|
470
|
+
A maximum spanning tree is a subgraph of the graph (a tree)
|
|
471
|
+
with the maximum possible sum of edge weights. A spanning forest is a
|
|
472
|
+
union of the spanning trees for each connected component of the graph.
|
|
473
|
+
|
|
474
|
+
Parameters
|
|
475
|
+
----------
|
|
476
|
+
G : undirected Graph
|
|
477
|
+
An undirected graph. If `G` is connected, then the algorithm finds a
|
|
478
|
+
spanning tree. Otherwise, a spanning forest is found.
|
|
479
|
+
|
|
480
|
+
algorithm : string
|
|
481
|
+
The algorithm to use when finding a maximum spanning tree. Valid
|
|
482
|
+
choices are 'kruskal', 'prim', or 'boruvka'. The default is 'kruskal'.
|
|
483
|
+
|
|
484
|
+
weight : string
|
|
485
|
+
Edge data key to use for weight (default 'weight').
|
|
486
|
+
|
|
487
|
+
keys : bool
|
|
488
|
+
Whether to yield edge key in multigraphs in addition to the edge.
|
|
489
|
+
If `G` is not a multigraph, this is ignored.
|
|
490
|
+
|
|
491
|
+
data : bool, optional
|
|
492
|
+
If True yield the edge data along with the edge.
|
|
493
|
+
|
|
494
|
+
ignore_nan : bool (default: False)
|
|
495
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
496
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
497
|
+
|
|
498
|
+
Returns
|
|
499
|
+
-------
|
|
500
|
+
edges : iterator
|
|
501
|
+
An iterator over edges in a maximum spanning tree of `G`.
|
|
502
|
+
Edges connecting nodes `u` and `v` are represented as tuples:
|
|
503
|
+
`(u, v, k, d)` or `(u, v, k)` or `(u, v, d)` or `(u, v)`
|
|
504
|
+
|
|
505
|
+
If `G` is a multigraph, `keys` indicates whether the edge key `k` will
|
|
506
|
+
be reported in the third position in the edge tuple. `data` indicates
|
|
507
|
+
whether the edge datadict `d` will appear at the end of the edge tuple.
|
|
508
|
+
|
|
509
|
+
If `G` is not a multigraph, the tuples are `(u, v, d)` if `data` is True
|
|
510
|
+
or `(u, v)` if `data` is False.
|
|
511
|
+
|
|
512
|
+
Examples
|
|
513
|
+
--------
|
|
514
|
+
>>> from networkx.algorithms import tree
|
|
515
|
+
|
|
516
|
+
Find maximum spanning edges by Kruskal's algorithm
|
|
517
|
+
|
|
518
|
+
>>> G = nx.cycle_graph(4)
|
|
519
|
+
>>> G.add_edge(0, 3, weight=2)
|
|
520
|
+
>>> mst = tree.maximum_spanning_edges(G, algorithm="kruskal", data=False)
|
|
521
|
+
>>> edgelist = list(mst)
|
|
522
|
+
>>> sorted(sorted(e) for e in edgelist)
|
|
523
|
+
[[0, 1], [0, 3], [1, 2]]
|
|
524
|
+
|
|
525
|
+
Find maximum spanning edges by Prim's algorithm
|
|
526
|
+
|
|
527
|
+
>>> G = nx.cycle_graph(4)
|
|
528
|
+
>>> G.add_edge(0, 3, weight=2) # assign weight 2 to edge 0-3
|
|
529
|
+
>>> mst = tree.maximum_spanning_edges(G, algorithm="prim", data=False)
|
|
530
|
+
>>> edgelist = list(mst)
|
|
531
|
+
>>> sorted(sorted(e) for e in edgelist)
|
|
532
|
+
[[0, 1], [0, 3], [2, 3]]
|
|
533
|
+
|
|
534
|
+
Notes
|
|
535
|
+
-----
|
|
536
|
+
For Borůvka's algorithm, each edge must have a weight attribute, and
|
|
537
|
+
each edge weight must be distinct.
|
|
538
|
+
|
|
539
|
+
For the other algorithms, if the graph edges do not have a weight
|
|
540
|
+
attribute a default weight of 1 will be used.
|
|
541
|
+
|
|
542
|
+
Modified code from David Eppstein, April 2006
|
|
543
|
+
http://www.ics.uci.edu/~eppstein/PADS/
|
|
544
|
+
"""
|
|
545
|
+
try:
|
|
546
|
+
algo = ALGORITHMS[algorithm]
|
|
547
|
+
except KeyError as err:
|
|
548
|
+
msg = f"{algorithm} is not a valid choice for an algorithm."
|
|
549
|
+
raise ValueError(msg) from err
|
|
550
|
+
|
|
551
|
+
return algo(
|
|
552
|
+
G, minimum=False, weight=weight, keys=keys, data=data, ignore_nan=ignore_nan
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
@nx._dispatchable(preserve_all_attrs=True, returns_graph=True)
|
|
557
|
+
def minimum_spanning_tree(G, weight="weight", algorithm="kruskal", ignore_nan=False):
|
|
558
|
+
"""Returns a minimum spanning tree or forest on an undirected graph `G`.
|
|
559
|
+
|
|
560
|
+
Parameters
|
|
561
|
+
----------
|
|
562
|
+
G : undirected graph
|
|
563
|
+
An undirected graph. If `G` is connected, then the algorithm finds a
|
|
564
|
+
spanning tree. Otherwise, a spanning forest is found.
|
|
565
|
+
|
|
566
|
+
weight : str
|
|
567
|
+
Data key to use for edge weights.
|
|
568
|
+
|
|
569
|
+
algorithm : string
|
|
570
|
+
The algorithm to use when finding a minimum spanning tree. Valid
|
|
571
|
+
choices are 'kruskal', 'prim', or 'boruvka'. The default is
|
|
572
|
+
'kruskal'.
|
|
573
|
+
|
|
574
|
+
ignore_nan : bool (default: False)
|
|
575
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
576
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
577
|
+
|
|
578
|
+
Returns
|
|
579
|
+
-------
|
|
580
|
+
G : NetworkX Graph
|
|
581
|
+
A minimum spanning tree or forest.
|
|
582
|
+
|
|
583
|
+
Examples
|
|
584
|
+
--------
|
|
585
|
+
>>> G = nx.cycle_graph(4)
|
|
586
|
+
>>> G.add_edge(0, 3, weight=2)
|
|
587
|
+
>>> T = nx.minimum_spanning_tree(G)
|
|
588
|
+
>>> sorted(T.edges(data=True))
|
|
589
|
+
[(0, 1, {}), (1, 2, {}), (2, 3, {})]
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
Notes
|
|
593
|
+
-----
|
|
594
|
+
For Borůvka's algorithm, each edge must have a weight attribute, and
|
|
595
|
+
each edge weight must be distinct.
|
|
596
|
+
|
|
597
|
+
For the other algorithms, if the graph edges do not have a weight
|
|
598
|
+
attribute a default weight of 1 will be used.
|
|
599
|
+
|
|
600
|
+
There may be more than one tree with the same minimum or maximum weight.
|
|
601
|
+
See :mod:`networkx.tree.recognition` for more detailed definitions.
|
|
602
|
+
|
|
603
|
+
Isolated nodes with self-loops are in the tree as edgeless isolated nodes.
|
|
604
|
+
|
|
605
|
+
"""
|
|
606
|
+
edges = minimum_spanning_edges(
|
|
607
|
+
G, algorithm, weight, keys=True, data=True, ignore_nan=ignore_nan
|
|
608
|
+
)
|
|
609
|
+
T = G.__class__() # Same graph class as G
|
|
610
|
+
T.graph.update(G.graph)
|
|
611
|
+
T.add_nodes_from(G.nodes.items())
|
|
612
|
+
T.add_edges_from(edges)
|
|
613
|
+
return T
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
@nx._dispatchable(preserve_all_attrs=True, returns_graph=True)
|
|
617
|
+
def partition_spanning_tree(
|
|
618
|
+
G, minimum=True, weight="weight", partition="partition", ignore_nan=False
|
|
619
|
+
):
|
|
620
|
+
"""
|
|
621
|
+
Find a spanning tree while respecting a partition of edges.
|
|
622
|
+
|
|
623
|
+
Edges can be flagged as either `INCLUDED` which are required to be in the
|
|
624
|
+
returned tree, `EXCLUDED`, which cannot be in the returned tree and `OPEN`.
|
|
625
|
+
|
|
626
|
+
This is used in the SpanningTreeIterator to create new partitions following
|
|
627
|
+
the algorithm of Sörensen and Janssens [1]_.
|
|
628
|
+
|
|
629
|
+
Parameters
|
|
630
|
+
----------
|
|
631
|
+
G : undirected graph
|
|
632
|
+
An undirected graph.
|
|
633
|
+
|
|
634
|
+
minimum : bool (default: True)
|
|
635
|
+
Determines whether the returned tree is the minimum spanning tree of
|
|
636
|
+
the partition of the maximum one.
|
|
637
|
+
|
|
638
|
+
weight : str
|
|
639
|
+
Data key to use for edge weights.
|
|
640
|
+
|
|
641
|
+
partition : str
|
|
642
|
+
The key for the edge attribute containing the partition
|
|
643
|
+
data on the graph. Edges can be included, excluded or open using the
|
|
644
|
+
`EdgePartition` enum.
|
|
645
|
+
|
|
646
|
+
ignore_nan : bool (default: False)
|
|
647
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
648
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
Returns
|
|
652
|
+
-------
|
|
653
|
+
G : NetworkX Graph
|
|
654
|
+
A minimum spanning tree using all of the included edges in the graph and
|
|
655
|
+
none of the excluded edges.
|
|
656
|
+
|
|
657
|
+
References
|
|
658
|
+
----------
|
|
659
|
+
.. [1] G.K. Janssens, K. Sörensen, An algorithm to generate all spanning
|
|
660
|
+
trees in order of increasing cost, Pesquisa Operacional, 2005-08,
|
|
661
|
+
Vol. 25 (2), p. 219-229,
|
|
662
|
+
https://www.scielo.br/j/pope/a/XHswBwRwJyrfL88dmMwYNWp/?lang=en
|
|
663
|
+
"""
|
|
664
|
+
edges = kruskal_mst_edges(
|
|
665
|
+
G,
|
|
666
|
+
minimum,
|
|
667
|
+
weight,
|
|
668
|
+
keys=True,
|
|
669
|
+
data=True,
|
|
670
|
+
ignore_nan=ignore_nan,
|
|
671
|
+
partition=partition,
|
|
672
|
+
)
|
|
673
|
+
T = G.__class__() # Same graph class as G
|
|
674
|
+
T.graph.update(G.graph)
|
|
675
|
+
T.add_nodes_from(G.nodes.items())
|
|
676
|
+
T.add_edges_from(edges)
|
|
677
|
+
return T
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
@nx._dispatchable(preserve_all_attrs=True, returns_graph=True)
|
|
681
|
+
def maximum_spanning_tree(G, weight="weight", algorithm="kruskal", ignore_nan=False):
|
|
682
|
+
"""Returns a maximum spanning tree or forest on an undirected graph `G`.
|
|
683
|
+
|
|
684
|
+
Parameters
|
|
685
|
+
----------
|
|
686
|
+
G : undirected graph
|
|
687
|
+
An undirected graph. If `G` is connected, then the algorithm finds a
|
|
688
|
+
spanning tree. Otherwise, a spanning forest is found.
|
|
689
|
+
|
|
690
|
+
weight : str
|
|
691
|
+
Data key to use for edge weights.
|
|
692
|
+
|
|
693
|
+
algorithm : string
|
|
694
|
+
The algorithm to use when finding a maximum spanning tree. Valid
|
|
695
|
+
choices are 'kruskal', 'prim', or 'boruvka'. The default is
|
|
696
|
+
'kruskal'.
|
|
697
|
+
|
|
698
|
+
ignore_nan : bool (default: False)
|
|
699
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
700
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
Returns
|
|
704
|
+
-------
|
|
705
|
+
G : NetworkX Graph
|
|
706
|
+
A maximum spanning tree or forest.
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
Examples
|
|
710
|
+
--------
|
|
711
|
+
>>> G = nx.cycle_graph(4)
|
|
712
|
+
>>> G.add_edge(0, 3, weight=2)
|
|
713
|
+
>>> T = nx.maximum_spanning_tree(G)
|
|
714
|
+
>>> sorted(T.edges(data=True))
|
|
715
|
+
[(0, 1, {}), (0, 3, {'weight': 2}), (1, 2, {})]
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
Notes
|
|
719
|
+
-----
|
|
720
|
+
For Borůvka's algorithm, each edge must have a weight attribute, and
|
|
721
|
+
each edge weight must be distinct.
|
|
722
|
+
|
|
723
|
+
For the other algorithms, if the graph edges do not have a weight
|
|
724
|
+
attribute a default weight of 1 will be used.
|
|
725
|
+
|
|
726
|
+
There may be more than one tree with the same minimum or maximum weight.
|
|
727
|
+
See :mod:`networkx.tree.recognition` for more detailed definitions.
|
|
728
|
+
|
|
729
|
+
Isolated nodes with self-loops are in the tree as edgeless isolated nodes.
|
|
730
|
+
|
|
731
|
+
"""
|
|
732
|
+
edges = maximum_spanning_edges(
|
|
733
|
+
G, algorithm, weight, keys=True, data=True, ignore_nan=ignore_nan
|
|
734
|
+
)
|
|
735
|
+
edges = list(edges)
|
|
736
|
+
T = G.__class__() # Same graph class as G
|
|
737
|
+
T.graph.update(G.graph)
|
|
738
|
+
T.add_nodes_from(G.nodes.items())
|
|
739
|
+
T.add_edges_from(edges)
|
|
740
|
+
return T
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
@py_random_state(3)
|
|
744
|
+
@nx._dispatchable(preserve_edge_attrs=True, returns_graph=True)
|
|
745
|
+
def random_spanning_tree(G, weight=None, *, multiplicative=True, seed=None):
|
|
746
|
+
"""
|
|
747
|
+
Sample a random spanning tree using the edges weights of `G`.
|
|
748
|
+
|
|
749
|
+
This function supports two different methods for determining the
|
|
750
|
+
probability of the graph. If ``multiplicative=True``, the probability
|
|
751
|
+
is based on the product of edge weights, and if ``multiplicative=False``
|
|
752
|
+
it is based on the sum of the edge weight. However, since it is
|
|
753
|
+
easier to determine the total weight of all spanning trees for the
|
|
754
|
+
multiplicative version, that is significantly faster and should be used if
|
|
755
|
+
possible. Additionally, setting `weight` to `None` will cause a spanning tree
|
|
756
|
+
to be selected with uniform probability.
|
|
757
|
+
|
|
758
|
+
The function uses algorithm A8 in [1]_ .
|
|
759
|
+
|
|
760
|
+
Parameters
|
|
761
|
+
----------
|
|
762
|
+
G : nx.Graph
|
|
763
|
+
An undirected version of the original graph.
|
|
764
|
+
|
|
765
|
+
weight : string
|
|
766
|
+
The edge key for the edge attribute holding edge weight.
|
|
767
|
+
|
|
768
|
+
multiplicative : bool, default=True
|
|
769
|
+
If `True`, the probability of each tree is the product of its edge weight
|
|
770
|
+
over the sum of the product of all the spanning trees in the graph. If
|
|
771
|
+
`False`, the probability is the sum of its edge weight over the sum of
|
|
772
|
+
the sum of weights for all spanning trees in the graph.
|
|
773
|
+
|
|
774
|
+
seed : integer, random_state, or None (default)
|
|
775
|
+
Indicator of random number generation state.
|
|
776
|
+
See :ref:`Randomness<randomness>`.
|
|
777
|
+
|
|
778
|
+
Returns
|
|
779
|
+
-------
|
|
780
|
+
nx.Graph
|
|
781
|
+
A spanning tree using the distribution defined by the weight of the tree.
|
|
782
|
+
|
|
783
|
+
References
|
|
784
|
+
----------
|
|
785
|
+
.. [1] V. Kulkarni, Generating random combinatorial objects, Journal of
|
|
786
|
+
Algorithms, 11 (1990), pp. 185–207
|
|
787
|
+
"""
|
|
788
|
+
|
|
789
|
+
def find_node(merged_nodes, node):
|
|
790
|
+
"""
|
|
791
|
+
We can think of clusters of contracted nodes as having one
|
|
792
|
+
representative in the graph. Each node which is not in merged_nodes
|
|
793
|
+
is still its own representative. Since a representative can be later
|
|
794
|
+
contracted, we need to recursively search though the dict to find
|
|
795
|
+
the final representative, but once we know it we can use path
|
|
796
|
+
compression to speed up the access of the representative for next time.
|
|
797
|
+
|
|
798
|
+
This cannot be replaced by the standard NetworkX union_find since that
|
|
799
|
+
data structure will merge nodes with less representing nodes into the
|
|
800
|
+
one with more representing nodes but this function requires we merge
|
|
801
|
+
them using the order that contract_edges contracts using.
|
|
802
|
+
|
|
803
|
+
Parameters
|
|
804
|
+
----------
|
|
805
|
+
merged_nodes : dict
|
|
806
|
+
The dict storing the mapping from node to representative
|
|
807
|
+
node
|
|
808
|
+
The node whose representative we seek
|
|
809
|
+
|
|
810
|
+
Returns
|
|
811
|
+
-------
|
|
812
|
+
The representative of the `node`
|
|
813
|
+
"""
|
|
814
|
+
if node not in merged_nodes:
|
|
815
|
+
return node
|
|
816
|
+
else:
|
|
817
|
+
rep = find_node(merged_nodes, merged_nodes[node])
|
|
818
|
+
merged_nodes[node] = rep
|
|
819
|
+
return rep
|
|
820
|
+
|
|
821
|
+
def prepare_graph():
|
|
822
|
+
"""
|
|
823
|
+
For the graph `G`, remove all edges not in the set `V` and then
|
|
824
|
+
contract all edges in the set `U`.
|
|
825
|
+
|
|
826
|
+
Returns
|
|
827
|
+
-------
|
|
828
|
+
A copy of `G` which has had all edges not in `V` removed and all edges
|
|
829
|
+
in `U` contracted.
|
|
830
|
+
"""
|
|
831
|
+
|
|
832
|
+
# The result is a MultiGraph version of G so that parallel edges are
|
|
833
|
+
# allowed during edge contraction
|
|
834
|
+
result = nx.MultiGraph(incoming_graph_data=G)
|
|
835
|
+
|
|
836
|
+
# Remove all edges not in V
|
|
837
|
+
edges_to_remove = set(result.edges()).difference(V)
|
|
838
|
+
result.remove_edges_from(edges_to_remove)
|
|
839
|
+
|
|
840
|
+
# Contract all edges in U
|
|
841
|
+
#
|
|
842
|
+
# Imagine that you have two edges to contract and they share an
|
|
843
|
+
# endpoint like this:
|
|
844
|
+
# [0] ----- [1] ----- [2]
|
|
845
|
+
# If we contract (0, 1) first, the contraction function will always
|
|
846
|
+
# delete the second node it is passed so the resulting graph would be
|
|
847
|
+
# [0] ----- [2]
|
|
848
|
+
# and edge (1, 2) no longer exists but (0, 2) would need to be contracted
|
|
849
|
+
# in its place now. That is why I use the below dict as a merge-find
|
|
850
|
+
# data structure with path compression to track how the nodes are merged.
|
|
851
|
+
merged_nodes = {}
|
|
852
|
+
|
|
853
|
+
for u, v in U:
|
|
854
|
+
u_rep = find_node(merged_nodes, u)
|
|
855
|
+
v_rep = find_node(merged_nodes, v)
|
|
856
|
+
# We cannot contract a node with itself
|
|
857
|
+
if u_rep == v_rep:
|
|
858
|
+
continue
|
|
859
|
+
nx.contracted_nodes(result, u_rep, v_rep, self_loops=False, copy=False)
|
|
860
|
+
merged_nodes[v_rep] = u_rep
|
|
861
|
+
|
|
862
|
+
return merged_nodes, result
|
|
863
|
+
|
|
864
|
+
def spanning_tree_total_weight(G, weight):
|
|
865
|
+
"""
|
|
866
|
+
Find the sum of weights of the spanning trees of `G` using the
|
|
867
|
+
appropriate `method`.
|
|
868
|
+
|
|
869
|
+
This is easy if the chosen method is 'multiplicative', since we can
|
|
870
|
+
use Kirchhoff's Tree Matrix Theorem directly. However, with the
|
|
871
|
+
'additive' method, this process is slightly more complex and less
|
|
872
|
+
computationally efficient as we have to find the number of spanning
|
|
873
|
+
trees which contain each possible edge in the graph.
|
|
874
|
+
|
|
875
|
+
Parameters
|
|
876
|
+
----------
|
|
877
|
+
G : NetworkX Graph
|
|
878
|
+
The graph to find the total weight of all spanning trees on.
|
|
879
|
+
|
|
880
|
+
weight : string
|
|
881
|
+
The key for the weight edge attribute of the graph.
|
|
882
|
+
|
|
883
|
+
Returns
|
|
884
|
+
-------
|
|
885
|
+
float
|
|
886
|
+
The sum of either the multiplicative or additive weight for all
|
|
887
|
+
spanning trees in the graph.
|
|
888
|
+
"""
|
|
889
|
+
if multiplicative:
|
|
890
|
+
return number_of_spanning_trees(G, weight=weight)
|
|
891
|
+
else:
|
|
892
|
+
# There are two cases for the total spanning tree additive weight.
|
|
893
|
+
# 1. There is one edge in the graph. Then the only spanning tree is
|
|
894
|
+
# that edge itself, which will have a total weight of that edge
|
|
895
|
+
# itself.
|
|
896
|
+
if G.number_of_edges() == 1:
|
|
897
|
+
return G.edges(data=weight).__iter__().__next__()[2]
|
|
898
|
+
# 2. There are no edges or two or more edges in the graph. Then, we find the
|
|
899
|
+
# total weight of the spanning trees using the formula in the
|
|
900
|
+
# reference paper: take the weight of each edge and multiply it by
|
|
901
|
+
# the number of spanning trees which include that edge. This
|
|
902
|
+
# can be accomplished by contracting the edge and finding the
|
|
903
|
+
# multiplicative total spanning tree weight if the weight of each edge
|
|
904
|
+
# is assumed to be 1, which is conveniently built into networkx already,
|
|
905
|
+
# by calling number_of_spanning_trees with weight=None.
|
|
906
|
+
# Note that with no edges the returned value is just zero.
|
|
907
|
+
else:
|
|
908
|
+
total = 0
|
|
909
|
+
for u, v, w in G.edges(data=weight):
|
|
910
|
+
total += w * nx.number_of_spanning_trees(
|
|
911
|
+
nx.contracted_edge(G, edge=(u, v), self_loops=False),
|
|
912
|
+
weight=None,
|
|
913
|
+
)
|
|
914
|
+
return total
|
|
915
|
+
|
|
916
|
+
if G.number_of_nodes() < 2:
|
|
917
|
+
# no edges in the spanning tree
|
|
918
|
+
return nx.empty_graph(G.nodes)
|
|
919
|
+
|
|
920
|
+
U = set()
|
|
921
|
+
st_cached_value = 0
|
|
922
|
+
V = set(G.edges())
|
|
923
|
+
shuffled_edges = list(G.edges())
|
|
924
|
+
seed.shuffle(shuffled_edges)
|
|
925
|
+
|
|
926
|
+
for u, v in shuffled_edges:
|
|
927
|
+
e_weight = G[u][v][weight] if weight is not None else 1
|
|
928
|
+
node_map, prepared_G = prepare_graph()
|
|
929
|
+
G_total_tree_weight = spanning_tree_total_weight(prepared_G, weight)
|
|
930
|
+
# Add the edge to U so that we can compute the total tree weight
|
|
931
|
+
# assuming we include that edge
|
|
932
|
+
# Now, if (u, v) cannot exist in G because it is fully contracted out
|
|
933
|
+
# of existence, then it by definition cannot influence G_e's Kirchhoff
|
|
934
|
+
# value. But, we also cannot pick it.
|
|
935
|
+
rep_edge = (find_node(node_map, u), find_node(node_map, v))
|
|
936
|
+
# Check to see if the 'representative edge' for the current edge is
|
|
937
|
+
# in prepared_G. If so, then we can pick it.
|
|
938
|
+
if rep_edge in prepared_G.edges:
|
|
939
|
+
prepared_G_e = nx.contracted_edge(
|
|
940
|
+
prepared_G, edge=rep_edge, self_loops=False
|
|
941
|
+
)
|
|
942
|
+
G_e_total_tree_weight = spanning_tree_total_weight(prepared_G_e, weight)
|
|
943
|
+
if multiplicative:
|
|
944
|
+
threshold = e_weight * G_e_total_tree_weight / G_total_tree_weight
|
|
945
|
+
else:
|
|
946
|
+
numerator = (st_cached_value + e_weight) * nx.number_of_spanning_trees(
|
|
947
|
+
prepared_G_e
|
|
948
|
+
) + G_e_total_tree_weight
|
|
949
|
+
denominator = (
|
|
950
|
+
st_cached_value * nx.number_of_spanning_trees(prepared_G)
|
|
951
|
+
+ G_total_tree_weight
|
|
952
|
+
)
|
|
953
|
+
threshold = numerator / denominator
|
|
954
|
+
else:
|
|
955
|
+
threshold = 0.0
|
|
956
|
+
z = seed.uniform(0.0, 1.0)
|
|
957
|
+
if z > threshold:
|
|
958
|
+
# Remove the edge from V since we did not pick it.
|
|
959
|
+
V.remove((u, v))
|
|
960
|
+
else:
|
|
961
|
+
# Add the edge to U since we picked it.
|
|
962
|
+
st_cached_value += e_weight
|
|
963
|
+
U.add((u, v))
|
|
964
|
+
# If we decide to keep an edge, it may complete the spanning tree.
|
|
965
|
+
if len(U) == G.number_of_nodes() - 1:
|
|
966
|
+
spanning_tree = nx.Graph()
|
|
967
|
+
spanning_tree.add_edges_from(U)
|
|
968
|
+
return spanning_tree
|
|
969
|
+
raise Exception(f"Something went wrong! Only {len(U)} edges in the spanning tree!")
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
class SpanningTreeIterator:
|
|
973
|
+
"""
|
|
974
|
+
Iterate over all spanning trees of a graph in either increasing or
|
|
975
|
+
decreasing cost.
|
|
976
|
+
|
|
977
|
+
Notes
|
|
978
|
+
-----
|
|
979
|
+
This iterator uses the partition scheme from [1]_ (included edges,
|
|
980
|
+
excluded edges and open edges) as well as a modified Kruskal's Algorithm
|
|
981
|
+
to generate minimum spanning trees which respect the partition of edges.
|
|
982
|
+
For spanning trees with the same weight, ties are broken arbitrarily.
|
|
983
|
+
|
|
984
|
+
References
|
|
985
|
+
----------
|
|
986
|
+
.. [1] G.K. Janssens, K. Sörensen, An algorithm to generate all spanning
|
|
987
|
+
trees in order of increasing cost, Pesquisa Operacional, 2005-08,
|
|
988
|
+
Vol. 25 (2), p. 219-229,
|
|
989
|
+
https://www.scielo.br/j/pope/a/XHswBwRwJyrfL88dmMwYNWp/?lang=en
|
|
990
|
+
"""
|
|
991
|
+
|
|
992
|
+
@dataclass(order=True)
|
|
993
|
+
class Partition:
|
|
994
|
+
"""
|
|
995
|
+
This dataclass represents a partition and stores a dict with the edge
|
|
996
|
+
data and the weight of the minimum spanning tree of the partition dict.
|
|
997
|
+
"""
|
|
998
|
+
|
|
999
|
+
mst_weight: float
|
|
1000
|
+
partition_dict: dict = field(compare=False)
|
|
1001
|
+
|
|
1002
|
+
def __copy__(self):
|
|
1003
|
+
return SpanningTreeIterator.Partition(
|
|
1004
|
+
self.mst_weight, self.partition_dict.copy()
|
|
1005
|
+
)
|
|
1006
|
+
|
|
1007
|
+
def __init__(self, G, weight="weight", minimum=True, ignore_nan=False):
|
|
1008
|
+
"""
|
|
1009
|
+
Initialize the iterator
|
|
1010
|
+
|
|
1011
|
+
Parameters
|
|
1012
|
+
----------
|
|
1013
|
+
G : nx.Graph
|
|
1014
|
+
The directed graph which we need to iterate trees over
|
|
1015
|
+
|
|
1016
|
+
weight : String, default = "weight"
|
|
1017
|
+
The edge attribute used to store the weight of the edge
|
|
1018
|
+
|
|
1019
|
+
minimum : bool, default = True
|
|
1020
|
+
Return the trees in increasing order while true and decreasing order
|
|
1021
|
+
while false.
|
|
1022
|
+
|
|
1023
|
+
ignore_nan : bool, default = False
|
|
1024
|
+
If a NaN is found as an edge weight normally an exception is raised.
|
|
1025
|
+
If `ignore_nan is True` then that edge is ignored instead.
|
|
1026
|
+
"""
|
|
1027
|
+
self.G = G.copy()
|
|
1028
|
+
self.G.__networkx_cache__ = None # Disable caching
|
|
1029
|
+
self.weight = weight
|
|
1030
|
+
self.minimum = minimum
|
|
1031
|
+
self.ignore_nan = ignore_nan
|
|
1032
|
+
# Randomly create a key for an edge attribute to hold the partition data
|
|
1033
|
+
self.partition_key = (
|
|
1034
|
+
"SpanningTreeIterators super secret partition attribute name"
|
|
1035
|
+
)
|
|
1036
|
+
|
|
1037
|
+
def __iter__(self):
|
|
1038
|
+
"""
|
|
1039
|
+
Returns
|
|
1040
|
+
-------
|
|
1041
|
+
SpanningTreeIterator
|
|
1042
|
+
The iterator object for this graph
|
|
1043
|
+
"""
|
|
1044
|
+
self.partition_queue = PriorityQueue()
|
|
1045
|
+
self._clear_partition(self.G)
|
|
1046
|
+
mst_weight = partition_spanning_tree(
|
|
1047
|
+
self.G, self.minimum, self.weight, self.partition_key, self.ignore_nan
|
|
1048
|
+
).size(weight=self.weight)
|
|
1049
|
+
|
|
1050
|
+
self.partition_queue.put(
|
|
1051
|
+
self.Partition(mst_weight if self.minimum else -mst_weight, {})
|
|
1052
|
+
)
|
|
1053
|
+
|
|
1054
|
+
return self
|
|
1055
|
+
|
|
1056
|
+
def __next__(self):
|
|
1057
|
+
"""
|
|
1058
|
+
Returns
|
|
1059
|
+
-------
|
|
1060
|
+
(multi)Graph
|
|
1061
|
+
The spanning tree of next greatest weight, which ties broken
|
|
1062
|
+
arbitrarily.
|
|
1063
|
+
"""
|
|
1064
|
+
if self.partition_queue.empty():
|
|
1065
|
+
del self.G, self.partition_queue
|
|
1066
|
+
raise StopIteration
|
|
1067
|
+
|
|
1068
|
+
partition = self.partition_queue.get()
|
|
1069
|
+
self._write_partition(partition)
|
|
1070
|
+
next_tree = partition_spanning_tree(
|
|
1071
|
+
self.G, self.minimum, self.weight, self.partition_key, self.ignore_nan
|
|
1072
|
+
)
|
|
1073
|
+
self._partition(partition, next_tree)
|
|
1074
|
+
|
|
1075
|
+
self._clear_partition(next_tree)
|
|
1076
|
+
return next_tree
|
|
1077
|
+
|
|
1078
|
+
def _partition(self, partition, partition_tree):
|
|
1079
|
+
"""
|
|
1080
|
+
Create new partitions based of the minimum spanning tree of the
|
|
1081
|
+
current minimum partition.
|
|
1082
|
+
|
|
1083
|
+
Parameters
|
|
1084
|
+
----------
|
|
1085
|
+
partition : Partition
|
|
1086
|
+
The Partition instance used to generate the current minimum spanning
|
|
1087
|
+
tree.
|
|
1088
|
+
partition_tree : nx.Graph
|
|
1089
|
+
The minimum spanning tree of the input partition.
|
|
1090
|
+
"""
|
|
1091
|
+
# create two new partitions with the data from the input partition dict
|
|
1092
|
+
p1 = self.Partition(0, partition.partition_dict.copy())
|
|
1093
|
+
p2 = self.Partition(0, partition.partition_dict.copy())
|
|
1094
|
+
for e in partition_tree.edges:
|
|
1095
|
+
# determine if the edge was open or included
|
|
1096
|
+
if e not in partition.partition_dict:
|
|
1097
|
+
# This is an open edge
|
|
1098
|
+
p1.partition_dict[e] = EdgePartition.EXCLUDED
|
|
1099
|
+
p2.partition_dict[e] = EdgePartition.INCLUDED
|
|
1100
|
+
|
|
1101
|
+
self._write_partition(p1)
|
|
1102
|
+
p1_mst = partition_spanning_tree(
|
|
1103
|
+
self.G,
|
|
1104
|
+
self.minimum,
|
|
1105
|
+
self.weight,
|
|
1106
|
+
self.partition_key,
|
|
1107
|
+
self.ignore_nan,
|
|
1108
|
+
)
|
|
1109
|
+
p1_mst_weight = p1_mst.size(weight=self.weight)
|
|
1110
|
+
if nx.is_connected(p1_mst):
|
|
1111
|
+
p1.mst_weight = p1_mst_weight if self.minimum else -p1_mst_weight
|
|
1112
|
+
self.partition_queue.put(p1.__copy__())
|
|
1113
|
+
p1.partition_dict = p2.partition_dict.copy()
|
|
1114
|
+
|
|
1115
|
+
def _write_partition(self, partition):
|
|
1116
|
+
"""
|
|
1117
|
+
Writes the desired partition into the graph to calculate the minimum
|
|
1118
|
+
spanning tree.
|
|
1119
|
+
|
|
1120
|
+
Parameters
|
|
1121
|
+
----------
|
|
1122
|
+
partition : Partition
|
|
1123
|
+
A Partition dataclass describing a partition on the edges of the
|
|
1124
|
+
graph.
|
|
1125
|
+
"""
|
|
1126
|
+
|
|
1127
|
+
partition_dict = partition.partition_dict
|
|
1128
|
+
partition_key = self.partition_key
|
|
1129
|
+
G = self.G
|
|
1130
|
+
|
|
1131
|
+
edges = (
|
|
1132
|
+
G.edges(keys=True, data=True) if G.is_multigraph() else G.edges(data=True)
|
|
1133
|
+
)
|
|
1134
|
+
for *e, d in edges:
|
|
1135
|
+
d[partition_key] = partition_dict.get(tuple(e), EdgePartition.OPEN)
|
|
1136
|
+
|
|
1137
|
+
def _clear_partition(self, G):
|
|
1138
|
+
"""
|
|
1139
|
+
Removes partition data from the graph
|
|
1140
|
+
"""
|
|
1141
|
+
partition_key = self.partition_key
|
|
1142
|
+
edges = (
|
|
1143
|
+
G.edges(keys=True, data=True) if G.is_multigraph() else G.edges(data=True)
|
|
1144
|
+
)
|
|
1145
|
+
for *e, d in edges:
|
|
1146
|
+
if partition_key in d:
|
|
1147
|
+
del d[partition_key]
|
|
1148
|
+
|
|
1149
|
+
|
|
1150
|
+
@nx._dispatchable(edge_attrs="weight")
|
|
1151
|
+
def number_of_spanning_trees(G, *, root=None, weight=None):
|
|
1152
|
+
"""Returns the number of spanning trees in `G`.
|
|
1153
|
+
|
|
1154
|
+
A spanning tree for an undirected graph is a tree that connects
|
|
1155
|
+
all nodes in the graph. For a directed graph, the analog of a
|
|
1156
|
+
spanning tree is called a (spanning) arborescence. The arborescence
|
|
1157
|
+
includes a unique directed path from the `root` node to each other node.
|
|
1158
|
+
The graph must be weakly connected, and the root must be a node
|
|
1159
|
+
that includes all nodes as successors [3]_. Note that to avoid
|
|
1160
|
+
discussing sink-roots and reverse-arborescences, we have reversed
|
|
1161
|
+
the edge orientation from [3]_ and use the in-degree laplacian.
|
|
1162
|
+
|
|
1163
|
+
This function (when `weight` is `None`) returns the number of
|
|
1164
|
+
spanning trees for an undirected graph and the number of
|
|
1165
|
+
arborescences from a single root node for a directed graph.
|
|
1166
|
+
When `weight` is the name of an edge attribute which holds the
|
|
1167
|
+
weight value of each edge, the function returns the sum over
|
|
1168
|
+
all trees of the multiplicative weight of each tree. That is,
|
|
1169
|
+
the weight of the tree is the product of its edge weights.
|
|
1170
|
+
|
|
1171
|
+
Kirchoff's Tree Matrix Theorem states that any cofactor of the
|
|
1172
|
+
Laplacian matrix of a graph is the number of spanning trees in the
|
|
1173
|
+
graph. (Here we use cofactors for a diagonal entry so that the
|
|
1174
|
+
cofactor becomes the determinant of the matrix with one row
|
|
1175
|
+
and its matching column removed.) For a weighted Laplacian matrix,
|
|
1176
|
+
the cofactor is the sum across all spanning trees of the
|
|
1177
|
+
multiplicative weight of each tree. That is, the weight of each
|
|
1178
|
+
tree is the product of its edge weights. The theorem is also
|
|
1179
|
+
known as Kirchhoff's theorem [1]_ and the Matrix-Tree theorem [2]_.
|
|
1180
|
+
|
|
1181
|
+
For directed graphs, a similar theorem (Tutte's Theorem) holds with
|
|
1182
|
+
the cofactor chosen to be the one with row and column removed that
|
|
1183
|
+
correspond to the root. The cofactor is the number of arborescences
|
|
1184
|
+
with the specified node as root. And the weighted version gives the
|
|
1185
|
+
sum of the arborescence weights with root `root`. The arborescence
|
|
1186
|
+
weight is the product of its edge weights.
|
|
1187
|
+
|
|
1188
|
+
Parameters
|
|
1189
|
+
----------
|
|
1190
|
+
G : NetworkX graph
|
|
1191
|
+
|
|
1192
|
+
root : node
|
|
1193
|
+
A node in the directed graph `G` that has all nodes as descendants.
|
|
1194
|
+
(This is ignored for undirected graphs.)
|
|
1195
|
+
|
|
1196
|
+
weight : string or None, optional (default=None)
|
|
1197
|
+
The name of the edge attribute holding the edge weight.
|
|
1198
|
+
If `None`, then each edge is assumed to have a weight of 1.
|
|
1199
|
+
|
|
1200
|
+
Returns
|
|
1201
|
+
-------
|
|
1202
|
+
Number
|
|
1203
|
+
Undirected graphs:
|
|
1204
|
+
The number of spanning trees of the graph `G`.
|
|
1205
|
+
Or the sum of all spanning tree weights of the graph `G`
|
|
1206
|
+
where the weight of a tree is the product of its edge weights.
|
|
1207
|
+
Directed graphs:
|
|
1208
|
+
The number of arborescences of `G` rooted at node `root`.
|
|
1209
|
+
Or the sum of all arborescence weights of the graph `G` with
|
|
1210
|
+
specified root where the weight of an arborescence is the product
|
|
1211
|
+
of its edge weights.
|
|
1212
|
+
|
|
1213
|
+
Raises
|
|
1214
|
+
------
|
|
1215
|
+
NetworkXPointlessConcept
|
|
1216
|
+
If `G` does not contain any nodes.
|
|
1217
|
+
|
|
1218
|
+
NetworkXError
|
|
1219
|
+
If the graph `G` is directed and the root node
|
|
1220
|
+
is not specified or is not in G.
|
|
1221
|
+
|
|
1222
|
+
Examples
|
|
1223
|
+
--------
|
|
1224
|
+
>>> G = nx.complete_graph(5)
|
|
1225
|
+
>>> round(nx.number_of_spanning_trees(G))
|
|
1226
|
+
125
|
|
1227
|
+
|
|
1228
|
+
>>> G = nx.Graph()
|
|
1229
|
+
>>> G.add_edge(1, 2, weight=2)
|
|
1230
|
+
>>> G.add_edge(1, 3, weight=1)
|
|
1231
|
+
>>> G.add_edge(2, 3, weight=1)
|
|
1232
|
+
>>> round(nx.number_of_spanning_trees(G, weight="weight"))
|
|
1233
|
+
5
|
|
1234
|
+
|
|
1235
|
+
Notes
|
|
1236
|
+
-----
|
|
1237
|
+
Self-loops are excluded. Multi-edges are contracted in one edge
|
|
1238
|
+
equal to the sum of the weights.
|
|
1239
|
+
|
|
1240
|
+
References
|
|
1241
|
+
----------
|
|
1242
|
+
.. [1] Wikipedia
|
|
1243
|
+
"Kirchhoff's theorem."
|
|
1244
|
+
https://en.wikipedia.org/wiki/Kirchhoff%27s_theorem
|
|
1245
|
+
.. [2] Kirchhoff, G. R.
|
|
1246
|
+
Über die Auflösung der Gleichungen, auf welche man
|
|
1247
|
+
bei der Untersuchung der linearen Vertheilung
|
|
1248
|
+
Galvanischer Ströme geführt wird
|
|
1249
|
+
Annalen der Physik und Chemie, vol. 72, pp. 497-508, 1847.
|
|
1250
|
+
.. [3] Margoliash, J.
|
|
1251
|
+
"Matrix-Tree Theorem for Directed Graphs"
|
|
1252
|
+
https://www.math.uchicago.edu/~may/VIGRE/VIGRE2010/REUPapers/Margoliash.pdf
|
|
1253
|
+
"""
|
|
1254
|
+
import numpy as np
|
|
1255
|
+
|
|
1256
|
+
if len(G) == 0:
|
|
1257
|
+
raise nx.NetworkXPointlessConcept("Graph G must contain at least one node.")
|
|
1258
|
+
|
|
1259
|
+
# undirected G
|
|
1260
|
+
if not nx.is_directed(G):
|
|
1261
|
+
if not nx.is_connected(G):
|
|
1262
|
+
return 0
|
|
1263
|
+
G_laplacian = nx.laplacian_matrix(G, weight=weight).toarray()
|
|
1264
|
+
return float(np.linalg.det(G_laplacian[1:, 1:]))
|
|
1265
|
+
|
|
1266
|
+
# directed G
|
|
1267
|
+
if root is None:
|
|
1268
|
+
raise nx.NetworkXError("Input `root` must be provided when G is directed")
|
|
1269
|
+
if root not in G:
|
|
1270
|
+
raise nx.NetworkXError("The node root is not in the graph G.")
|
|
1271
|
+
if not nx.is_weakly_connected(G):
|
|
1272
|
+
return 0
|
|
1273
|
+
|
|
1274
|
+
# Compute directed Laplacian matrix
|
|
1275
|
+
nodelist = [root] + [n for n in G if n != root]
|
|
1276
|
+
A = nx.adjacency_matrix(G, nodelist=nodelist, weight=weight)
|
|
1277
|
+
D = np.diag(A.sum(axis=0))
|
|
1278
|
+
G_laplacian = D - A
|
|
1279
|
+
|
|
1280
|
+
# Compute number of spanning trees
|
|
1281
|
+
return float(np.linalg.det(G_laplacian[1:, 1:]))
|