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,227 @@
|
|
|
1
|
+
"""Lukes Algorithm for exact optimal weighted tree partitioning."""
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from functools import lru_cache
|
|
5
|
+
from random import choice
|
|
6
|
+
|
|
7
|
+
import networkx as nx
|
|
8
|
+
from networkx.utils import not_implemented_for
|
|
9
|
+
|
|
10
|
+
__all__ = ["lukes_partitioning"]
|
|
11
|
+
|
|
12
|
+
D_EDGE_W = "weight"
|
|
13
|
+
D_EDGE_VALUE = 1.0
|
|
14
|
+
D_NODE_W = "weight"
|
|
15
|
+
D_NODE_VALUE = 1
|
|
16
|
+
PKEY = "partitions"
|
|
17
|
+
CLUSTER_EVAL_CACHE_SIZE = 2048
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _split_n_from(n, min_size_of_first_part):
|
|
21
|
+
# splits j in two parts of which the first is at least
|
|
22
|
+
# the second argument
|
|
23
|
+
assert n >= min_size_of_first_part
|
|
24
|
+
for p1 in range(min_size_of_first_part, n + 1):
|
|
25
|
+
yield p1, n - p1
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@nx._dispatchable(node_attrs="node_weight", edge_attrs="edge_weight")
|
|
29
|
+
def lukes_partitioning(G, max_size, node_weight=None, edge_weight=None):
|
|
30
|
+
"""Optimal partitioning of a weighted tree using the Lukes algorithm.
|
|
31
|
+
|
|
32
|
+
This algorithm partitions a connected, acyclic graph featuring integer
|
|
33
|
+
node weights and float edge weights. The resulting clusters are such
|
|
34
|
+
that the total weight of the nodes in each cluster does not exceed
|
|
35
|
+
max_size and that the weight of the edges that are cut by the partition
|
|
36
|
+
is minimum. The algorithm is based on [1]_.
|
|
37
|
+
|
|
38
|
+
Parameters
|
|
39
|
+
----------
|
|
40
|
+
G : NetworkX graph
|
|
41
|
+
|
|
42
|
+
max_size : int
|
|
43
|
+
Maximum weight a partition can have in terms of sum of
|
|
44
|
+
node_weight for all nodes in the partition
|
|
45
|
+
|
|
46
|
+
edge_weight : key
|
|
47
|
+
Edge data key to use as weight. If None, the weights are all
|
|
48
|
+
set to one.
|
|
49
|
+
|
|
50
|
+
node_weight : key
|
|
51
|
+
Node data key to use as weight. If None, the weights are all
|
|
52
|
+
set to one. The data must be int.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
partition : list
|
|
57
|
+
A list of sets of nodes representing the clusters of the
|
|
58
|
+
partition.
|
|
59
|
+
|
|
60
|
+
Raises
|
|
61
|
+
------
|
|
62
|
+
NotATree
|
|
63
|
+
If G is not a tree.
|
|
64
|
+
TypeError
|
|
65
|
+
If any of the values of node_weight is not int.
|
|
66
|
+
|
|
67
|
+
References
|
|
68
|
+
----------
|
|
69
|
+
.. [1] Lukes, J. A. (1974).
|
|
70
|
+
"Efficient Algorithm for the Partitioning of Trees."
|
|
71
|
+
IBM Journal of Research and Development, 18(3), 217–224.
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
# First sanity check and tree preparation
|
|
75
|
+
if not nx.is_tree(G):
|
|
76
|
+
raise nx.NotATree("lukes_partitioning works only on trees")
|
|
77
|
+
else:
|
|
78
|
+
if nx.is_directed(G):
|
|
79
|
+
root = [n for n, d in G.in_degree() if d == 0]
|
|
80
|
+
assert len(root) == 1
|
|
81
|
+
root = root[0]
|
|
82
|
+
t_G = deepcopy(G)
|
|
83
|
+
else:
|
|
84
|
+
root = choice(list(G.nodes))
|
|
85
|
+
# this has the desirable side effect of not inheriting attributes
|
|
86
|
+
t_G = nx.dfs_tree(G, root)
|
|
87
|
+
|
|
88
|
+
# Since we do not want to screw up the original graph,
|
|
89
|
+
# if we have a blank attribute, we make a deepcopy
|
|
90
|
+
if edge_weight is None or node_weight is None:
|
|
91
|
+
safe_G = deepcopy(G)
|
|
92
|
+
if edge_weight is None:
|
|
93
|
+
nx.set_edge_attributes(safe_G, D_EDGE_VALUE, D_EDGE_W)
|
|
94
|
+
edge_weight = D_EDGE_W
|
|
95
|
+
if node_weight is None:
|
|
96
|
+
nx.set_node_attributes(safe_G, D_NODE_VALUE, D_NODE_W)
|
|
97
|
+
node_weight = D_NODE_W
|
|
98
|
+
else:
|
|
99
|
+
safe_G = G
|
|
100
|
+
|
|
101
|
+
# Second sanity check
|
|
102
|
+
# The values of node_weight MUST BE int.
|
|
103
|
+
# I cannot see any room for duck typing without incurring serious
|
|
104
|
+
# danger of subtle bugs.
|
|
105
|
+
all_n_attr = nx.get_node_attributes(safe_G, node_weight).values()
|
|
106
|
+
for x in all_n_attr:
|
|
107
|
+
if not isinstance(x, int):
|
|
108
|
+
raise TypeError(
|
|
109
|
+
"lukes_partitioning needs integer "
|
|
110
|
+
f"values for node_weight ({node_weight})"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# SUBROUTINES -----------------------
|
|
114
|
+
# these functions are defined here for two reasons:
|
|
115
|
+
# - brevity: we can leverage global "safe_G"
|
|
116
|
+
# - caching: signatures are hashable
|
|
117
|
+
|
|
118
|
+
@not_implemented_for("undirected")
|
|
119
|
+
# this is intended to be called only on t_G
|
|
120
|
+
def _leaves(gr):
|
|
121
|
+
for x in gr.nodes:
|
|
122
|
+
if not nx.descendants(gr, x):
|
|
123
|
+
yield x
|
|
124
|
+
|
|
125
|
+
@not_implemented_for("undirected")
|
|
126
|
+
def _a_parent_of_leaves_only(gr):
|
|
127
|
+
tleaves = set(_leaves(gr))
|
|
128
|
+
for n in set(gr.nodes) - tleaves:
|
|
129
|
+
if all(x in tleaves for x in nx.descendants(gr, n)):
|
|
130
|
+
return n
|
|
131
|
+
|
|
132
|
+
@lru_cache(CLUSTER_EVAL_CACHE_SIZE)
|
|
133
|
+
def _value_of_cluster(cluster):
|
|
134
|
+
valid_edges = [e for e in safe_G.edges if e[0] in cluster and e[1] in cluster]
|
|
135
|
+
return sum(safe_G.edges[e][edge_weight] for e in valid_edges)
|
|
136
|
+
|
|
137
|
+
def _value_of_partition(partition):
|
|
138
|
+
return sum(_value_of_cluster(frozenset(c)) for c in partition)
|
|
139
|
+
|
|
140
|
+
@lru_cache(CLUSTER_EVAL_CACHE_SIZE)
|
|
141
|
+
def _weight_of_cluster(cluster):
|
|
142
|
+
return sum(safe_G.nodes[n][node_weight] for n in cluster)
|
|
143
|
+
|
|
144
|
+
def _pivot(partition, node):
|
|
145
|
+
ccx = [c for c in partition if node in c]
|
|
146
|
+
assert len(ccx) == 1
|
|
147
|
+
return ccx[0]
|
|
148
|
+
|
|
149
|
+
def _concatenate_or_merge(partition_1, partition_2, x, i, ref_weight):
|
|
150
|
+
ccx = _pivot(partition_1, x)
|
|
151
|
+
cci = _pivot(partition_2, i)
|
|
152
|
+
merged_xi = ccx.union(cci)
|
|
153
|
+
|
|
154
|
+
# We first check if we can do the merge.
|
|
155
|
+
# If so, we do the actual calculations, otherwise we concatenate
|
|
156
|
+
if _weight_of_cluster(frozenset(merged_xi)) <= ref_weight:
|
|
157
|
+
cp1 = list(filter(lambda x: x != ccx, partition_1))
|
|
158
|
+
cp2 = list(filter(lambda x: x != cci, partition_2))
|
|
159
|
+
|
|
160
|
+
option_2 = [merged_xi] + cp1 + cp2
|
|
161
|
+
return option_2, _value_of_partition(option_2)
|
|
162
|
+
else:
|
|
163
|
+
option_1 = partition_1 + partition_2
|
|
164
|
+
return option_1, _value_of_partition(option_1)
|
|
165
|
+
|
|
166
|
+
# INITIALIZATION -----------------------
|
|
167
|
+
leaves = set(_leaves(t_G))
|
|
168
|
+
for lv in leaves:
|
|
169
|
+
t_G.nodes[lv][PKEY] = {}
|
|
170
|
+
slot = safe_G.nodes[lv][node_weight]
|
|
171
|
+
t_G.nodes[lv][PKEY][slot] = [{lv}]
|
|
172
|
+
t_G.nodes[lv][PKEY][0] = [{lv}]
|
|
173
|
+
|
|
174
|
+
for inner in [x for x in t_G.nodes if x not in leaves]:
|
|
175
|
+
t_G.nodes[inner][PKEY] = {}
|
|
176
|
+
slot = safe_G.nodes[inner][node_weight]
|
|
177
|
+
t_G.nodes[inner][PKEY][slot] = [{inner}]
|
|
178
|
+
nx._clear_cache(t_G)
|
|
179
|
+
|
|
180
|
+
# CORE ALGORITHM -----------------------
|
|
181
|
+
while True:
|
|
182
|
+
x_node = _a_parent_of_leaves_only(t_G)
|
|
183
|
+
weight_of_x = safe_G.nodes[x_node][node_weight]
|
|
184
|
+
best_value = 0
|
|
185
|
+
best_partition = None
|
|
186
|
+
bp_buffer = {}
|
|
187
|
+
x_descendants = nx.descendants(t_G, x_node)
|
|
188
|
+
for i_node in x_descendants:
|
|
189
|
+
for j in range(weight_of_x, max_size + 1):
|
|
190
|
+
for a, b in _split_n_from(j, weight_of_x):
|
|
191
|
+
if (
|
|
192
|
+
a not in t_G.nodes[x_node][PKEY]
|
|
193
|
+
or b not in t_G.nodes[i_node][PKEY]
|
|
194
|
+
):
|
|
195
|
+
# it's not possible to form this particular weight sum
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
part1 = t_G.nodes[x_node][PKEY][a]
|
|
199
|
+
part2 = t_G.nodes[i_node][PKEY][b]
|
|
200
|
+
part, value = _concatenate_or_merge(part1, part2, x_node, i_node, j)
|
|
201
|
+
|
|
202
|
+
if j not in bp_buffer or bp_buffer[j][1] < value:
|
|
203
|
+
# we annotate in the buffer the best partition for j
|
|
204
|
+
bp_buffer[j] = part, value
|
|
205
|
+
|
|
206
|
+
# we also keep track of the overall best partition
|
|
207
|
+
if best_value <= value:
|
|
208
|
+
best_value = value
|
|
209
|
+
best_partition = part
|
|
210
|
+
|
|
211
|
+
# as illustrated in Lukes, once we finished a child, we can
|
|
212
|
+
# discharge the partitions we found into the graph
|
|
213
|
+
# (the key phrase is make all x == x')
|
|
214
|
+
# so that they are used by the subsequent children
|
|
215
|
+
for w, (best_part_for_vl, vl) in bp_buffer.items():
|
|
216
|
+
t_G.nodes[x_node][PKEY][w] = best_part_for_vl
|
|
217
|
+
bp_buffer.clear()
|
|
218
|
+
|
|
219
|
+
# the absolute best partition for this node
|
|
220
|
+
# across all weights has to be stored at 0
|
|
221
|
+
t_G.nodes[x_node][PKEY][0] = best_partition
|
|
222
|
+
t_G.remove_nodes_from(x_descendants)
|
|
223
|
+
|
|
224
|
+
if x_node == root:
|
|
225
|
+
# the 0-labeled partition of root
|
|
226
|
+
# is the optimal one for the whole tree
|
|
227
|
+
return t_G.nodes[root][PKEY][0]
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
"""Functions for detecting communities based on modularity."""
|
|
2
|
+
|
|
3
|
+
import random
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
|
|
7
|
+
import networkx as nx
|
|
8
|
+
from networkx.algorithms.community.quality import modularity
|
|
9
|
+
from networkx.utils.mapped_queue import MappedQueue
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"greedy_modularity_communities",
|
|
13
|
+
"naive_greedy_modularity_communities",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _greedy_modularity_communities_generator(G, weight=None, resolution=1):
|
|
18
|
+
r"""Yield community partitions of G and the modularity change at each step.
|
|
19
|
+
|
|
20
|
+
This function performs Clauset-Newman-Moore greedy modularity maximization [2]_
|
|
21
|
+
At each step of the process it yields the change in modularity that will occur in
|
|
22
|
+
the next step followed by yielding the new community partition after that step.
|
|
23
|
+
|
|
24
|
+
Greedy modularity maximization begins with each node in its own community
|
|
25
|
+
and repeatedly joins the pair of communities that lead to the largest
|
|
26
|
+
modularity until one community contains all nodes (the partition has one set).
|
|
27
|
+
|
|
28
|
+
This function maximizes the generalized modularity, where `resolution`
|
|
29
|
+
is the resolution parameter, often expressed as $\gamma$.
|
|
30
|
+
See :func:`~networkx.algorithms.community.quality.modularity`.
|
|
31
|
+
|
|
32
|
+
Parameters
|
|
33
|
+
----------
|
|
34
|
+
G : NetworkX graph
|
|
35
|
+
|
|
36
|
+
weight : string or None, optional (default=None)
|
|
37
|
+
The name of an edge attribute that holds the numerical value used
|
|
38
|
+
as a weight. If None, then each edge has weight 1.
|
|
39
|
+
The degree is the sum of the edge weights adjacent to the node.
|
|
40
|
+
|
|
41
|
+
resolution : float (default=1)
|
|
42
|
+
If resolution is less than 1, modularity favors larger communities.
|
|
43
|
+
Greater than 1 favors smaller communities.
|
|
44
|
+
|
|
45
|
+
Yields
|
|
46
|
+
------
|
|
47
|
+
Alternating yield statements produce the following two objects:
|
|
48
|
+
|
|
49
|
+
communities: dict_values
|
|
50
|
+
A dict_values of frozensets of nodes, one for each community.
|
|
51
|
+
This represents a partition of the nodes of the graph into communities.
|
|
52
|
+
The first yield is the partition with each node in its own community.
|
|
53
|
+
|
|
54
|
+
dq: float
|
|
55
|
+
The change in modularity when merging the next two communities
|
|
56
|
+
that leads to the largest modularity.
|
|
57
|
+
|
|
58
|
+
See Also
|
|
59
|
+
--------
|
|
60
|
+
modularity
|
|
61
|
+
|
|
62
|
+
References
|
|
63
|
+
----------
|
|
64
|
+
.. [1] Newman, M. E. J. "Networks: An Introduction", page 224
|
|
65
|
+
Oxford University Press 2011.
|
|
66
|
+
.. [2] Clauset, A., Newman, M. E., & Moore, C.
|
|
67
|
+
"Finding community structure in very large networks."
|
|
68
|
+
Physical Review E 70(6), 2004.
|
|
69
|
+
.. [3] Reichardt and Bornholdt "Statistical Mechanics of Community
|
|
70
|
+
Detection" Phys. Rev. E74, 2006.
|
|
71
|
+
.. [4] Newman, M. E. J."Analysis of weighted networks"
|
|
72
|
+
Physical Review E 70(5 Pt 2):056131, 2004.
|
|
73
|
+
"""
|
|
74
|
+
directed = G.is_directed()
|
|
75
|
+
N = G.number_of_nodes()
|
|
76
|
+
|
|
77
|
+
# Count edges (or the sum of edge-weights for weighted graphs)
|
|
78
|
+
m = G.size(weight)
|
|
79
|
+
q0 = 1 / m
|
|
80
|
+
|
|
81
|
+
# Calculate degrees (notation from the papers)
|
|
82
|
+
# a : the fraction of (weighted) out-degree for each node
|
|
83
|
+
# b : the fraction of (weighted) in-degree for each node
|
|
84
|
+
if directed:
|
|
85
|
+
a = {node: deg_out * q0 for node, deg_out in G.out_degree(weight=weight)}
|
|
86
|
+
b = {node: deg_in * q0 for node, deg_in in G.in_degree(weight=weight)}
|
|
87
|
+
else:
|
|
88
|
+
a = b = {node: deg * q0 * 0.5 for node, deg in G.degree(weight=weight)}
|
|
89
|
+
|
|
90
|
+
# this preliminary step collects the edge weights for each node pair
|
|
91
|
+
# It handles multigraph and digraph and works fine for graph.
|
|
92
|
+
dq_dict = defaultdict(lambda: defaultdict(float))
|
|
93
|
+
for u, v, wt in G.edges(data=weight, default=1):
|
|
94
|
+
if u == v:
|
|
95
|
+
continue
|
|
96
|
+
dq_dict[u][v] += wt
|
|
97
|
+
dq_dict[v][u] += wt
|
|
98
|
+
|
|
99
|
+
# now scale and subtract the expected edge-weights term
|
|
100
|
+
for u, nbrdict in dq_dict.items():
|
|
101
|
+
for v, wt in nbrdict.items():
|
|
102
|
+
dq_dict[u][v] = q0 * wt - resolution * (a[u] * b[v] + b[u] * a[v])
|
|
103
|
+
|
|
104
|
+
# Use -dq to get a max_heap instead of a min_heap
|
|
105
|
+
# dq_heap holds a heap for each node's neighbors
|
|
106
|
+
dq_heap = {u: MappedQueue({(u, v): -dq for v, dq in dq_dict[u].items()}) for u in G}
|
|
107
|
+
# H -> all_dq_heap holds a heap with the best items for each node
|
|
108
|
+
H = MappedQueue([dq_heap[n].heap[0] for n in G if len(dq_heap[n]) > 0])
|
|
109
|
+
|
|
110
|
+
# Initialize single-node communities
|
|
111
|
+
communities = {n: frozenset([n]) for n in G}
|
|
112
|
+
yield communities.values()
|
|
113
|
+
|
|
114
|
+
# Merge the two communities that lead to the largest modularity
|
|
115
|
+
while len(H) > 1:
|
|
116
|
+
# Find best merge
|
|
117
|
+
# Remove from heap of row maxes
|
|
118
|
+
# Ties will be broken by choosing the pair with lowest min community id
|
|
119
|
+
try:
|
|
120
|
+
negdq, u, v = H.pop()
|
|
121
|
+
except IndexError:
|
|
122
|
+
break
|
|
123
|
+
dq = -negdq
|
|
124
|
+
yield dq
|
|
125
|
+
# Remove best merge from row u heap
|
|
126
|
+
dq_heap[u].pop()
|
|
127
|
+
# Push new row max onto H
|
|
128
|
+
if len(dq_heap[u]) > 0:
|
|
129
|
+
H.push(dq_heap[u].heap[0])
|
|
130
|
+
# If this element was also at the root of row v, we need to remove the
|
|
131
|
+
# duplicate entry from H
|
|
132
|
+
if dq_heap[v].heap[0] == (v, u):
|
|
133
|
+
H.remove((v, u))
|
|
134
|
+
# Remove best merge from row v heap
|
|
135
|
+
dq_heap[v].remove((v, u))
|
|
136
|
+
# Push new row max onto H
|
|
137
|
+
if len(dq_heap[v]) > 0:
|
|
138
|
+
H.push(dq_heap[v].heap[0])
|
|
139
|
+
else:
|
|
140
|
+
# Duplicate wasn't in H, just remove from row v heap
|
|
141
|
+
dq_heap[v].remove((v, u))
|
|
142
|
+
|
|
143
|
+
# Perform merge
|
|
144
|
+
communities[v] = frozenset(communities[u] | communities[v])
|
|
145
|
+
del communities[u]
|
|
146
|
+
|
|
147
|
+
# Get neighbor communities connected to the merged communities
|
|
148
|
+
u_nbrs = set(dq_dict[u])
|
|
149
|
+
v_nbrs = set(dq_dict[v])
|
|
150
|
+
all_nbrs = (u_nbrs | v_nbrs) - {u, v}
|
|
151
|
+
both_nbrs = u_nbrs & v_nbrs
|
|
152
|
+
# Update dq for merge of u into v
|
|
153
|
+
for w in all_nbrs:
|
|
154
|
+
# Calculate new dq value
|
|
155
|
+
if w in both_nbrs:
|
|
156
|
+
dq_vw = dq_dict[v][w] + dq_dict[u][w]
|
|
157
|
+
elif w in v_nbrs:
|
|
158
|
+
dq_vw = dq_dict[v][w] - resolution * (a[u] * b[w] + a[w] * b[u])
|
|
159
|
+
else: # w in u_nbrs
|
|
160
|
+
dq_vw = dq_dict[u][w] - resolution * (a[v] * b[w] + a[w] * b[v])
|
|
161
|
+
# Update rows v and w
|
|
162
|
+
for row, col in [(v, w), (w, v)]:
|
|
163
|
+
dq_heap_row = dq_heap[row]
|
|
164
|
+
# Update dict for v,w only (u is removed below)
|
|
165
|
+
dq_dict[row][col] = dq_vw
|
|
166
|
+
# Save old max of per-row heap
|
|
167
|
+
if len(dq_heap_row) > 0:
|
|
168
|
+
d_oldmax = dq_heap_row.heap[0]
|
|
169
|
+
else:
|
|
170
|
+
d_oldmax = None
|
|
171
|
+
# Add/update heaps
|
|
172
|
+
d = (row, col)
|
|
173
|
+
d_negdq = -dq_vw
|
|
174
|
+
# Save old value for finding heap index
|
|
175
|
+
if w in v_nbrs:
|
|
176
|
+
# Update existing element in per-row heap
|
|
177
|
+
dq_heap_row.update(d, d, priority=d_negdq)
|
|
178
|
+
else:
|
|
179
|
+
# We're creating a new nonzero element, add to heap
|
|
180
|
+
dq_heap_row.push(d, priority=d_negdq)
|
|
181
|
+
# Update heap of row maxes if necessary
|
|
182
|
+
if d_oldmax is None:
|
|
183
|
+
# No entries previously in this row, push new max
|
|
184
|
+
H.push(d, priority=d_negdq)
|
|
185
|
+
else:
|
|
186
|
+
# We've updated an entry in this row, has the max changed?
|
|
187
|
+
row_max = dq_heap_row.heap[0]
|
|
188
|
+
if d_oldmax != row_max or d_oldmax.priority != row_max.priority:
|
|
189
|
+
H.update(d_oldmax, row_max)
|
|
190
|
+
|
|
191
|
+
# Remove row/col u from dq_dict matrix
|
|
192
|
+
for w in dq_dict[u]:
|
|
193
|
+
# Remove from dict
|
|
194
|
+
dq_old = dq_dict[w][u]
|
|
195
|
+
del dq_dict[w][u]
|
|
196
|
+
# Remove from heaps if we haven't already
|
|
197
|
+
if w != v:
|
|
198
|
+
# Remove both row and column
|
|
199
|
+
for row, col in [(w, u), (u, w)]:
|
|
200
|
+
dq_heap_row = dq_heap[row]
|
|
201
|
+
# Check if replaced dq is row max
|
|
202
|
+
d_old = (row, col)
|
|
203
|
+
if dq_heap_row.heap[0] == d_old:
|
|
204
|
+
# Update per-row heap and heap of row maxes
|
|
205
|
+
dq_heap_row.remove(d_old)
|
|
206
|
+
H.remove(d_old)
|
|
207
|
+
# Update row max
|
|
208
|
+
if len(dq_heap_row) > 0:
|
|
209
|
+
H.push(dq_heap_row.heap[0])
|
|
210
|
+
else:
|
|
211
|
+
# Only update per-row heap
|
|
212
|
+
dq_heap_row.remove(d_old)
|
|
213
|
+
|
|
214
|
+
del dq_dict[u]
|
|
215
|
+
# Mark row u as deleted, but keep placeholder
|
|
216
|
+
dq_heap[u] = MappedQueue()
|
|
217
|
+
# Merge u into v and update a
|
|
218
|
+
a[v] += a[u]
|
|
219
|
+
a[u] = 0
|
|
220
|
+
if directed:
|
|
221
|
+
b[v] += b[u]
|
|
222
|
+
b[u] = 0
|
|
223
|
+
|
|
224
|
+
yield communities.values()
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
@nx._dispatchable(edge_attrs="weight")
|
|
228
|
+
def greedy_modularity_communities(
|
|
229
|
+
G,
|
|
230
|
+
weight=None,
|
|
231
|
+
resolution=1,
|
|
232
|
+
cutoff=1,
|
|
233
|
+
best_n=None,
|
|
234
|
+
):
|
|
235
|
+
r"""Find communities in G using greedy modularity maximization.
|
|
236
|
+
|
|
237
|
+
This function uses Clauset-Newman-Moore greedy modularity maximization [2]_
|
|
238
|
+
to find the community partition with the largest modularity.
|
|
239
|
+
|
|
240
|
+
Greedy modularity maximization begins with each node in its own community
|
|
241
|
+
and repeatedly joins the pair of communities that lead to the largest
|
|
242
|
+
modularity until no further increase in modularity is possible (a maximum).
|
|
243
|
+
Two keyword arguments adjust the stopping condition. `cutoff` is a lower
|
|
244
|
+
limit on the number of communities so you can stop the process before
|
|
245
|
+
reaching a maximum (used to save computation time). `best_n` is an upper
|
|
246
|
+
limit on the number of communities so you can make the process continue
|
|
247
|
+
until at most n communities remain even if the maximum modularity occurs
|
|
248
|
+
for more. To obtain exactly n communities, set both `cutoff` and `best_n` to n.
|
|
249
|
+
|
|
250
|
+
This function maximizes the generalized modularity, where `resolution`
|
|
251
|
+
is the resolution parameter, often expressed as $\gamma$.
|
|
252
|
+
See :func:`~networkx.algorithms.community.quality.modularity`.
|
|
253
|
+
|
|
254
|
+
Parameters
|
|
255
|
+
----------
|
|
256
|
+
G : NetworkX graph
|
|
257
|
+
|
|
258
|
+
weight : string or None, optional (default=None)
|
|
259
|
+
The name of an edge attribute that holds the numerical value used
|
|
260
|
+
as a weight. If None, then each edge has weight 1.
|
|
261
|
+
The degree is the sum of the edge weights adjacent to the node.
|
|
262
|
+
|
|
263
|
+
resolution : float, optional (default=1)
|
|
264
|
+
If resolution is less than 1, modularity favors larger communities.
|
|
265
|
+
Greater than 1 favors smaller communities.
|
|
266
|
+
|
|
267
|
+
cutoff : int, optional (default=1)
|
|
268
|
+
A minimum number of communities below which the merging process stops.
|
|
269
|
+
The process stops at this number of communities even if modularity
|
|
270
|
+
is not maximized. The goal is to let the user stop the process early.
|
|
271
|
+
The process stops before the cutoff if it finds a maximum of modularity.
|
|
272
|
+
|
|
273
|
+
best_n : int or None, optional (default=None)
|
|
274
|
+
A maximum number of communities above which the merging process will
|
|
275
|
+
not stop. This forces community merging to continue after modularity
|
|
276
|
+
starts to decrease until `best_n` communities remain.
|
|
277
|
+
If ``None``, don't force it to continue beyond a maximum.
|
|
278
|
+
|
|
279
|
+
Raises
|
|
280
|
+
------
|
|
281
|
+
ValueError : If the `cutoff` or `best_n` value is not in the range
|
|
282
|
+
``[1, G.number_of_nodes()]``, or if `best_n` < `cutoff`.
|
|
283
|
+
|
|
284
|
+
Returns
|
|
285
|
+
-------
|
|
286
|
+
communities: list
|
|
287
|
+
A list of frozensets of nodes, one for each community.
|
|
288
|
+
Sorted by length with largest communities first.
|
|
289
|
+
|
|
290
|
+
Examples
|
|
291
|
+
--------
|
|
292
|
+
>>> G = nx.karate_club_graph()
|
|
293
|
+
>>> c = nx.community.greedy_modularity_communities(G)
|
|
294
|
+
>>> sorted(c[0])
|
|
295
|
+
[8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
|
|
296
|
+
|
|
297
|
+
See Also
|
|
298
|
+
--------
|
|
299
|
+
modularity
|
|
300
|
+
|
|
301
|
+
References
|
|
302
|
+
----------
|
|
303
|
+
.. [1] Newman, M. E. J. "Networks: An Introduction", page 224
|
|
304
|
+
Oxford University Press 2011.
|
|
305
|
+
.. [2] Clauset, A., Newman, M. E., & Moore, C.
|
|
306
|
+
"Finding community structure in very large networks."
|
|
307
|
+
Physical Review E 70(6), 2004.
|
|
308
|
+
.. [3] Reichardt and Bornholdt "Statistical Mechanics of Community
|
|
309
|
+
Detection" Phys. Rev. E74, 2006.
|
|
310
|
+
.. [4] Newman, M. E. J."Analysis of weighted networks"
|
|
311
|
+
Physical Review E 70(5 Pt 2):056131, 2004.
|
|
312
|
+
"""
|
|
313
|
+
if not G.size():
|
|
314
|
+
return [{n} for n in G]
|
|
315
|
+
|
|
316
|
+
if (cutoff < 1) or (cutoff > G.number_of_nodes()):
|
|
317
|
+
raise ValueError(f"cutoff must be between 1 and {len(G)}. Got {cutoff}.")
|
|
318
|
+
if best_n is not None:
|
|
319
|
+
if (best_n < 1) or (best_n > G.number_of_nodes()):
|
|
320
|
+
raise ValueError(f"best_n must be between 1 and {len(G)}. Got {best_n}.")
|
|
321
|
+
if best_n < cutoff:
|
|
322
|
+
raise ValueError(f"Must have best_n >= cutoff. Got {best_n} < {cutoff}")
|
|
323
|
+
if best_n == 1:
|
|
324
|
+
return [set(G)]
|
|
325
|
+
else:
|
|
326
|
+
best_n = G.number_of_nodes()
|
|
327
|
+
|
|
328
|
+
# retrieve generator object to construct output
|
|
329
|
+
community_gen = _greedy_modularity_communities_generator(
|
|
330
|
+
G, weight=weight, resolution=resolution
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
# construct the first best community
|
|
334
|
+
communities = next(community_gen)
|
|
335
|
+
|
|
336
|
+
# continue merging communities until one of the breaking criteria is satisfied
|
|
337
|
+
while len(communities) > cutoff:
|
|
338
|
+
try:
|
|
339
|
+
dq = next(community_gen)
|
|
340
|
+
# StopIteration occurs when communities are the connected components
|
|
341
|
+
except StopIteration:
|
|
342
|
+
communities = sorted(communities, key=len, reverse=True)
|
|
343
|
+
# if best_n requires more merging, merge big sets for highest modularity
|
|
344
|
+
while len(communities) > best_n:
|
|
345
|
+
comm1, comm2, *rest = communities
|
|
346
|
+
communities = [comm1 ^ comm2]
|
|
347
|
+
communities.extend(rest)
|
|
348
|
+
return communities
|
|
349
|
+
|
|
350
|
+
# keep going unless max_mod is reached or best_n says to merge more
|
|
351
|
+
if dq < 0 and len(communities) <= best_n:
|
|
352
|
+
break
|
|
353
|
+
communities = next(community_gen)
|
|
354
|
+
|
|
355
|
+
return sorted(communities, key=len, reverse=True)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
@nx.utils.not_implemented_for("directed")
|
|
359
|
+
@nx.utils.not_implemented_for("multigraph")
|
|
360
|
+
@nx._dispatchable(edge_attrs="weight")
|
|
361
|
+
def naive_greedy_modularity_communities(G, resolution=1, weight=None):
|
|
362
|
+
r"""Find communities in G using greedy modularity maximization.
|
|
363
|
+
|
|
364
|
+
This implementation is O(n^4), much slower than alternatives, but it is
|
|
365
|
+
provided as an easy-to-understand reference implementation.
|
|
366
|
+
|
|
367
|
+
Greedy modularity maximization begins with each node in its own community
|
|
368
|
+
and joins the pair of communities that most increases modularity until no
|
|
369
|
+
such pair exists.
|
|
370
|
+
|
|
371
|
+
This function maximizes the generalized modularity, where `resolution`
|
|
372
|
+
is the resolution parameter, often expressed as $\gamma$.
|
|
373
|
+
See :func:`~networkx.algorithms.community.quality.modularity`.
|
|
374
|
+
|
|
375
|
+
Parameters
|
|
376
|
+
----------
|
|
377
|
+
G : NetworkX graph
|
|
378
|
+
Graph must be simple and undirected.
|
|
379
|
+
|
|
380
|
+
resolution : float (default=1)
|
|
381
|
+
If resolution is less than 1, modularity favors larger communities.
|
|
382
|
+
Greater than 1 favors smaller communities.
|
|
383
|
+
|
|
384
|
+
weight : string or None, optional (default=None)
|
|
385
|
+
The name of an edge attribute that holds the numerical value used
|
|
386
|
+
as a weight. If None, then each edge has weight 1.
|
|
387
|
+
The degree is the sum of the edge weights adjacent to the node.
|
|
388
|
+
|
|
389
|
+
Returns
|
|
390
|
+
-------
|
|
391
|
+
list
|
|
392
|
+
A list of sets of nodes, one for each community.
|
|
393
|
+
Sorted by length with largest communities first.
|
|
394
|
+
|
|
395
|
+
Examples
|
|
396
|
+
--------
|
|
397
|
+
>>> G = nx.karate_club_graph()
|
|
398
|
+
>>> c = nx.community.naive_greedy_modularity_communities(G)
|
|
399
|
+
>>> sorted(c[0])
|
|
400
|
+
[8, 14, 15, 18, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33]
|
|
401
|
+
|
|
402
|
+
See Also
|
|
403
|
+
--------
|
|
404
|
+
greedy_modularity_communities
|
|
405
|
+
modularity
|
|
406
|
+
"""
|
|
407
|
+
# First create one community for each node
|
|
408
|
+
communities = [frozenset([u]) for u in G.nodes()]
|
|
409
|
+
# Track merges
|
|
410
|
+
merges = []
|
|
411
|
+
# Greedily merge communities until no improvement is possible
|
|
412
|
+
old_modularity = None
|
|
413
|
+
new_modularity = modularity(G, communities, resolution=resolution, weight=weight)
|
|
414
|
+
while old_modularity is None or new_modularity > old_modularity:
|
|
415
|
+
# Save modularity for comparison
|
|
416
|
+
old_modularity = new_modularity
|
|
417
|
+
# Find best pair to merge
|
|
418
|
+
trial_communities = list(communities)
|
|
419
|
+
to_merge = None
|
|
420
|
+
for i, u in enumerate(communities):
|
|
421
|
+
for j, v in enumerate(communities):
|
|
422
|
+
# Skip i==j and empty communities
|
|
423
|
+
if j <= i or len(u) == 0 or len(v) == 0:
|
|
424
|
+
continue
|
|
425
|
+
# Merge communities u and v
|
|
426
|
+
trial_communities[j] = u | v
|
|
427
|
+
trial_communities[i] = frozenset([])
|
|
428
|
+
trial_modularity = modularity(
|
|
429
|
+
G, trial_communities, resolution=resolution, weight=weight
|
|
430
|
+
)
|
|
431
|
+
if trial_modularity >= new_modularity:
|
|
432
|
+
# Check if strictly better or tie
|
|
433
|
+
if trial_modularity > new_modularity:
|
|
434
|
+
# Found new best, save modularity and group indexes
|
|
435
|
+
new_modularity = trial_modularity
|
|
436
|
+
to_merge = (i, j, new_modularity - old_modularity)
|
|
437
|
+
elif to_merge and min(i, j) < min(to_merge[0], to_merge[1]):
|
|
438
|
+
# Break ties by choosing pair with lowest min id
|
|
439
|
+
new_modularity = trial_modularity
|
|
440
|
+
to_merge = (i, j, new_modularity - old_modularity)
|
|
441
|
+
# Un-merge
|
|
442
|
+
trial_communities[i] = u
|
|
443
|
+
trial_communities[j] = v
|
|
444
|
+
if to_merge is not None:
|
|
445
|
+
# If the best merge improves modularity, use it
|
|
446
|
+
merges.append(to_merge)
|
|
447
|
+
i, j, dq = to_merge
|
|
448
|
+
u, v = communities[i], communities[j]
|
|
449
|
+
communities[j] = u | v
|
|
450
|
+
communities[i] = frozenset([])
|
|
451
|
+
# Remove empty communities and sort
|
|
452
|
+
return sorted((c for c in communities if len(c) > 0), key=len, reverse=True)
|