okstra 0.107.2 → 0.109.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/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/prompts/lead/okstra-lead-contract.md +1 -1
- package/runtime/prompts/profiles/_common-contract.md +3 -2
- 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/session.py +44 -0
- package/runtime/python/okstra_project/__init__.py +2 -0
- package/runtime/python/okstra_project/state.py +36 -0
- package/runtime/python/okstra_token_usage/claude.py +15 -9
- package/runtime/python/okstra_token_usage/cli.py +23 -0
- package/runtime/python/okstra_token_usage/collect.py +163 -4
- 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/runtime/validators/forbidden_actions.py +8 -2
- package/runtime/validators/validate_session_conformance.py +26 -5
- 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,966 @@
|
|
|
1
|
+
from heapq import heappop, heappush
|
|
2
|
+
from itertools import count
|
|
3
|
+
|
|
4
|
+
import networkx as nx
|
|
5
|
+
from networkx.algorithms.shortest_paths.weighted import _weight_function
|
|
6
|
+
from networkx.utils import not_implemented_for, pairwise
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"all_simple_paths",
|
|
10
|
+
"is_simple_path",
|
|
11
|
+
"shortest_simple_paths",
|
|
12
|
+
"all_simple_edge_paths",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@nx._dispatchable
|
|
17
|
+
def is_simple_path(G, nodes):
|
|
18
|
+
"""Returns True if and only if `nodes` form a simple path in `G`.
|
|
19
|
+
|
|
20
|
+
A *simple path* in a graph is a nonempty sequence of nodes in which
|
|
21
|
+
no node appears more than once in the sequence, and each adjacent
|
|
22
|
+
pair of nodes in the sequence is adjacent in the graph.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
G : graph
|
|
27
|
+
A NetworkX graph.
|
|
28
|
+
nodes : list
|
|
29
|
+
A list of one or more nodes in the graph `G`.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
bool
|
|
34
|
+
Whether the given list of nodes represents a simple path in `G`.
|
|
35
|
+
|
|
36
|
+
Notes
|
|
37
|
+
-----
|
|
38
|
+
An empty list of nodes is not a path but a list of one node is a
|
|
39
|
+
path. Here's an explanation why.
|
|
40
|
+
|
|
41
|
+
This function operates on *node paths*. One could also consider
|
|
42
|
+
*edge paths*. There is a bijection between node paths and edge
|
|
43
|
+
paths.
|
|
44
|
+
|
|
45
|
+
The *length of a path* is the number of edges in the path, so a list
|
|
46
|
+
of nodes of length *n* corresponds to a path of length *n* - 1.
|
|
47
|
+
Thus the smallest edge path would be a list of zero edges, the empty
|
|
48
|
+
path. This corresponds to a list of one node.
|
|
49
|
+
|
|
50
|
+
To convert between a node path and an edge path, you can use code
|
|
51
|
+
like the following::
|
|
52
|
+
|
|
53
|
+
>>> from networkx.utils import pairwise
|
|
54
|
+
>>> nodes = [0, 1, 2, 3]
|
|
55
|
+
>>> edges = list(pairwise(nodes))
|
|
56
|
+
>>> edges
|
|
57
|
+
[(0, 1), (1, 2), (2, 3)]
|
|
58
|
+
>>> nodes = [edges[0][0]] + [v for u, v in edges]
|
|
59
|
+
>>> nodes
|
|
60
|
+
[0, 1, 2, 3]
|
|
61
|
+
|
|
62
|
+
Examples
|
|
63
|
+
--------
|
|
64
|
+
>>> G = nx.cycle_graph(4)
|
|
65
|
+
>>> nx.is_simple_path(G, [2, 3, 0])
|
|
66
|
+
True
|
|
67
|
+
>>> nx.is_simple_path(G, [0, 2])
|
|
68
|
+
False
|
|
69
|
+
|
|
70
|
+
"""
|
|
71
|
+
# The empty list is not a valid path. Could also return
|
|
72
|
+
# NetworkXPointlessConcept here.
|
|
73
|
+
if len(nodes) == 0:
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
# If the list is a single node, just check that the node is actually
|
|
77
|
+
# in the graph.
|
|
78
|
+
if len(nodes) == 1:
|
|
79
|
+
return nodes[0] in G
|
|
80
|
+
|
|
81
|
+
# check that all nodes in the list are in the graph, if at least one
|
|
82
|
+
# is not in the graph, then this is not a simple path
|
|
83
|
+
if not all(n in G for n in nodes):
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
# If the list contains repeated nodes, then it's not a simple path
|
|
87
|
+
if len(set(nodes)) != len(nodes):
|
|
88
|
+
return False
|
|
89
|
+
|
|
90
|
+
# Test that each adjacent pair of nodes is adjacent.
|
|
91
|
+
return all(v in G[u] for u, v in pairwise(nodes))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@nx._dispatchable
|
|
95
|
+
def all_simple_paths(G, source, target, cutoff=None):
|
|
96
|
+
"""Generate all simple paths in the graph G from source to target.
|
|
97
|
+
|
|
98
|
+
A simple path is a path with no repeated nodes.
|
|
99
|
+
|
|
100
|
+
Parameters
|
|
101
|
+
----------
|
|
102
|
+
G : NetworkX graph
|
|
103
|
+
|
|
104
|
+
source : node
|
|
105
|
+
Starting node for path
|
|
106
|
+
|
|
107
|
+
target : nodes
|
|
108
|
+
Single node or iterable of nodes at which to end path
|
|
109
|
+
|
|
110
|
+
cutoff : integer, optional
|
|
111
|
+
Depth to stop the search. Only paths with length <= `cutoff` are returned.
|
|
112
|
+
where the mathematical "length of a path" is `len(path) -1` (number of edges).
|
|
113
|
+
|
|
114
|
+
Returns
|
|
115
|
+
-------
|
|
116
|
+
path_generator: generator
|
|
117
|
+
A generator that produces lists of simple paths. If there are no paths
|
|
118
|
+
between the source and target within the given cutoff the generator
|
|
119
|
+
produces no output. If it is possible to traverse the same sequence of
|
|
120
|
+
nodes in multiple ways, namely through parallel edges, then it will be
|
|
121
|
+
returned multiple times (once for each viable edge combination).
|
|
122
|
+
|
|
123
|
+
Examples
|
|
124
|
+
--------
|
|
125
|
+
This iterator generates lists of nodes::
|
|
126
|
+
|
|
127
|
+
>>> G = nx.complete_graph(4)
|
|
128
|
+
>>> for path in nx.all_simple_paths(G, source=0, target=3):
|
|
129
|
+
... print(path)
|
|
130
|
+
...
|
|
131
|
+
[0, 1, 2, 3]
|
|
132
|
+
[0, 1, 3]
|
|
133
|
+
[0, 2, 1, 3]
|
|
134
|
+
[0, 2, 3]
|
|
135
|
+
[0, 3]
|
|
136
|
+
|
|
137
|
+
You can generate only those paths that are shorter than a certain
|
|
138
|
+
length by using the `cutoff` keyword argument::
|
|
139
|
+
|
|
140
|
+
>>> paths = nx.all_simple_paths(G, source=0, target=3, cutoff=2)
|
|
141
|
+
>>> print(list(paths))
|
|
142
|
+
[[0, 1, 3], [0, 2, 3], [0, 3]]
|
|
143
|
+
|
|
144
|
+
To get each path as the corresponding list of edges, you can use the
|
|
145
|
+
:func:`networkx.utils.pairwise` helper function::
|
|
146
|
+
|
|
147
|
+
>>> paths = nx.all_simple_paths(G, source=0, target=3)
|
|
148
|
+
>>> for path in map(nx.utils.pairwise, paths):
|
|
149
|
+
... print(list(path))
|
|
150
|
+
[(0, 1), (1, 2), (2, 3)]
|
|
151
|
+
[(0, 1), (1, 3)]
|
|
152
|
+
[(0, 2), (2, 1), (1, 3)]
|
|
153
|
+
[(0, 2), (2, 3)]
|
|
154
|
+
[(0, 3)]
|
|
155
|
+
|
|
156
|
+
Pass an iterable of nodes as target to generate all paths ending in any of several nodes::
|
|
157
|
+
|
|
158
|
+
>>> G = nx.complete_graph(4)
|
|
159
|
+
>>> for path in nx.all_simple_paths(G, source=0, target=[3, 2]):
|
|
160
|
+
... print(path)
|
|
161
|
+
...
|
|
162
|
+
[0, 1, 2]
|
|
163
|
+
[0, 1, 2, 3]
|
|
164
|
+
[0, 1, 3]
|
|
165
|
+
[0, 1, 3, 2]
|
|
166
|
+
[0, 2]
|
|
167
|
+
[0, 2, 1, 3]
|
|
168
|
+
[0, 2, 3]
|
|
169
|
+
[0, 3]
|
|
170
|
+
[0, 3, 1, 2]
|
|
171
|
+
[0, 3, 2]
|
|
172
|
+
|
|
173
|
+
The singleton path from ``source`` to itself is considered a simple path and is
|
|
174
|
+
included in the results:
|
|
175
|
+
|
|
176
|
+
>>> G = nx.empty_graph(5)
|
|
177
|
+
>>> list(nx.all_simple_paths(G, source=0, target=0))
|
|
178
|
+
[[0]]
|
|
179
|
+
|
|
180
|
+
>>> G = nx.path_graph(3)
|
|
181
|
+
>>> list(nx.all_simple_paths(G, source=0, target={0, 1, 2}))
|
|
182
|
+
[[0], [0, 1], [0, 1, 2]]
|
|
183
|
+
|
|
184
|
+
Iterate over each path from the root nodes to the leaf nodes in a
|
|
185
|
+
directed acyclic graph using a functional programming approach::
|
|
186
|
+
|
|
187
|
+
>>> from itertools import chain
|
|
188
|
+
>>> from itertools import product
|
|
189
|
+
>>> from itertools import starmap
|
|
190
|
+
>>> from functools import partial
|
|
191
|
+
>>>
|
|
192
|
+
>>> chaini = chain.from_iterable
|
|
193
|
+
>>>
|
|
194
|
+
>>> G = nx.DiGraph([(0, 1), (1, 2), (0, 3), (3, 2)])
|
|
195
|
+
>>> roots = (v for v, d in G.in_degree() if d == 0)
|
|
196
|
+
>>> leaves = (v for v, d in G.out_degree() if d == 0)
|
|
197
|
+
>>> all_paths = partial(nx.all_simple_paths, G)
|
|
198
|
+
>>> list(chaini(starmap(all_paths, product(roots, leaves))))
|
|
199
|
+
[[0, 1, 2], [0, 3, 2]]
|
|
200
|
+
|
|
201
|
+
The same list computed using an iterative approach::
|
|
202
|
+
|
|
203
|
+
>>> G = nx.DiGraph([(0, 1), (1, 2), (0, 3), (3, 2)])
|
|
204
|
+
>>> roots = (v for v, d in G.in_degree() if d == 0)
|
|
205
|
+
>>> leaves = (v for v, d in G.out_degree() if d == 0)
|
|
206
|
+
>>> all_paths = []
|
|
207
|
+
>>> for root in roots:
|
|
208
|
+
... for leaf in leaves:
|
|
209
|
+
... paths = nx.all_simple_paths(G, root, leaf)
|
|
210
|
+
... all_paths.extend(paths)
|
|
211
|
+
>>> all_paths
|
|
212
|
+
[[0, 1, 2], [0, 3, 2]]
|
|
213
|
+
|
|
214
|
+
Iterate over each path from the root nodes to the leaf nodes in a
|
|
215
|
+
directed acyclic graph passing all leaves together to avoid unnecessary
|
|
216
|
+
compute::
|
|
217
|
+
|
|
218
|
+
>>> G = nx.DiGraph([(0, 1), (2, 1), (1, 3), (1, 4)])
|
|
219
|
+
>>> roots = (v for v, d in G.in_degree() if d == 0)
|
|
220
|
+
>>> leaves = [v for v, d in G.out_degree() if d == 0]
|
|
221
|
+
>>> all_paths = []
|
|
222
|
+
>>> for root in roots:
|
|
223
|
+
... paths = nx.all_simple_paths(G, root, leaves)
|
|
224
|
+
... all_paths.extend(paths)
|
|
225
|
+
>>> all_paths
|
|
226
|
+
[[0, 1, 3], [0, 1, 4], [2, 1, 3], [2, 1, 4]]
|
|
227
|
+
|
|
228
|
+
If parallel edges offer multiple ways to traverse a given sequence of
|
|
229
|
+
nodes, this sequence of nodes will be returned multiple times:
|
|
230
|
+
|
|
231
|
+
>>> G = nx.MultiDiGraph([(0, 1), (0, 1), (1, 2)])
|
|
232
|
+
>>> list(nx.all_simple_paths(G, 0, 2))
|
|
233
|
+
[[0, 1, 2], [0, 1, 2]]
|
|
234
|
+
|
|
235
|
+
Notes
|
|
236
|
+
-----
|
|
237
|
+
This algorithm uses a modified depth-first search to generate the
|
|
238
|
+
paths [1]_. A single path can be found in $O(V+E)$ time but the
|
|
239
|
+
number of simple paths in a graph can be very large, e.g. $O(n!)$ in
|
|
240
|
+
the complete graph of order $n$.
|
|
241
|
+
|
|
242
|
+
This function does not check that a path exists between `source` and
|
|
243
|
+
`target`. For large graphs, this may result in very long runtimes.
|
|
244
|
+
Consider using `has_path` to check that a path exists between `source` and
|
|
245
|
+
`target` before calling this function on large graphs.
|
|
246
|
+
|
|
247
|
+
References
|
|
248
|
+
----------
|
|
249
|
+
.. [1] R. Sedgewick, "Algorithms in C, Part 5: Graph Algorithms",
|
|
250
|
+
Addison Wesley Professional, 3rd ed., 2001.
|
|
251
|
+
|
|
252
|
+
See Also
|
|
253
|
+
--------
|
|
254
|
+
all_shortest_paths, shortest_path, has_path
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
for edge_path in all_simple_edge_paths(G, source, target, cutoff):
|
|
258
|
+
yield [source] + [edge[1] for edge in edge_path]
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
@nx._dispatchable
|
|
262
|
+
def all_simple_edge_paths(G, source, target, cutoff=None):
|
|
263
|
+
"""Generate lists of edges for all simple paths in G from source to target.
|
|
264
|
+
|
|
265
|
+
A simple path is a path with no repeated nodes.
|
|
266
|
+
|
|
267
|
+
Parameters
|
|
268
|
+
----------
|
|
269
|
+
G : NetworkX graph
|
|
270
|
+
|
|
271
|
+
source : node
|
|
272
|
+
Starting node for path
|
|
273
|
+
|
|
274
|
+
target : nodes
|
|
275
|
+
Single node or iterable of nodes at which to end path
|
|
276
|
+
|
|
277
|
+
cutoff : integer, optional
|
|
278
|
+
Depth to stop the search. Only paths with length <= `cutoff` are returned.
|
|
279
|
+
Note that the length of an edge path is the number of edges.
|
|
280
|
+
|
|
281
|
+
Returns
|
|
282
|
+
-------
|
|
283
|
+
path_generator: generator
|
|
284
|
+
A generator that produces lists of simple paths. If there are no paths
|
|
285
|
+
between the source and target within the given cutoff the generator
|
|
286
|
+
produces no output.
|
|
287
|
+
For multigraphs, the list of edges have elements of the form `(u,v,k)`.
|
|
288
|
+
Where `k` corresponds to the edge key.
|
|
289
|
+
|
|
290
|
+
Examples
|
|
291
|
+
--------
|
|
292
|
+
|
|
293
|
+
Print the simple path edges of a Graph::
|
|
294
|
+
|
|
295
|
+
>>> g = nx.Graph([(1, 2), (2, 4), (1, 3), (3, 4)])
|
|
296
|
+
>>> for path in sorted(nx.all_simple_edge_paths(g, 1, 4)):
|
|
297
|
+
... print(path)
|
|
298
|
+
[(1, 2), (2, 4)]
|
|
299
|
+
[(1, 3), (3, 4)]
|
|
300
|
+
|
|
301
|
+
Print the simple path edges of a MultiGraph. Returned edges come with
|
|
302
|
+
their associated keys::
|
|
303
|
+
|
|
304
|
+
>>> mg = nx.MultiGraph()
|
|
305
|
+
>>> mg.add_edge(1, 2, key="k0")
|
|
306
|
+
'k0'
|
|
307
|
+
>>> mg.add_edge(1, 2, key="k1")
|
|
308
|
+
'k1'
|
|
309
|
+
>>> mg.add_edge(2, 3, key="k0")
|
|
310
|
+
'k0'
|
|
311
|
+
>>> for path in sorted(nx.all_simple_edge_paths(mg, 1, 3)):
|
|
312
|
+
... print(path)
|
|
313
|
+
[(1, 2, 'k0'), (2, 3, 'k0')]
|
|
314
|
+
[(1, 2, 'k1'), (2, 3, 'k0')]
|
|
315
|
+
|
|
316
|
+
When ``source`` is one of the targets, the empty path starting and ending at
|
|
317
|
+
``source`` without traversing any edge is considered a valid simple edge path
|
|
318
|
+
and is included in the results:
|
|
319
|
+
|
|
320
|
+
>>> G = nx.Graph()
|
|
321
|
+
>>> G.add_node(0)
|
|
322
|
+
>>> paths = list(nx.all_simple_edge_paths(G, 0, 0))
|
|
323
|
+
>>> for path in paths:
|
|
324
|
+
... print(path)
|
|
325
|
+
[]
|
|
326
|
+
>>> len(paths)
|
|
327
|
+
1
|
|
328
|
+
|
|
329
|
+
You can use the `cutoff` parameter to only generate paths that are
|
|
330
|
+
shorter than a certain length:
|
|
331
|
+
|
|
332
|
+
>>> g = nx.Graph([(1, 2), (2, 3), (3, 4), (4, 5), (1, 4), (1, 5)])
|
|
333
|
+
>>> for path in sorted(nx.all_simple_edge_paths(g, 1, 5)):
|
|
334
|
+
... print(path)
|
|
335
|
+
[(1, 2), (2, 3), (3, 4), (4, 5)]
|
|
336
|
+
[(1, 4), (4, 5)]
|
|
337
|
+
[(1, 5)]
|
|
338
|
+
>>> for path in sorted(nx.all_simple_edge_paths(g, 1, 5, cutoff=1)):
|
|
339
|
+
... print(path)
|
|
340
|
+
[(1, 5)]
|
|
341
|
+
>>> for path in sorted(nx.all_simple_edge_paths(g, 1, 5, cutoff=2)):
|
|
342
|
+
... print(path)
|
|
343
|
+
[(1, 4), (4, 5)]
|
|
344
|
+
[(1, 5)]
|
|
345
|
+
|
|
346
|
+
Notes
|
|
347
|
+
-----
|
|
348
|
+
This algorithm uses a modified depth-first search to generate the
|
|
349
|
+
paths [1]_. A single path can be found in $O(V+E)$ time but the
|
|
350
|
+
number of simple paths in a graph can be very large, e.g. $O(n!)$ in
|
|
351
|
+
the complete graph of order $n$.
|
|
352
|
+
|
|
353
|
+
References
|
|
354
|
+
----------
|
|
355
|
+
.. [1] R. Sedgewick, "Algorithms in C, Part 5: Graph Algorithms",
|
|
356
|
+
Addison Wesley Professional, 3rd ed., 2001.
|
|
357
|
+
|
|
358
|
+
See Also
|
|
359
|
+
--------
|
|
360
|
+
all_shortest_paths, shortest_path, all_simple_paths
|
|
361
|
+
|
|
362
|
+
"""
|
|
363
|
+
if source not in G:
|
|
364
|
+
raise nx.NodeNotFound(f"source node {source} not in graph")
|
|
365
|
+
|
|
366
|
+
if target in G:
|
|
367
|
+
targets = {target}
|
|
368
|
+
else:
|
|
369
|
+
try:
|
|
370
|
+
targets = set(target)
|
|
371
|
+
except TypeError as err:
|
|
372
|
+
raise nx.NodeNotFound(f"target node {target} not in graph") from err
|
|
373
|
+
|
|
374
|
+
cutoff = cutoff if cutoff is not None else len(G) - 1
|
|
375
|
+
|
|
376
|
+
if cutoff >= 0 and targets:
|
|
377
|
+
yield from _all_simple_edge_paths(G, source, targets, cutoff)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _all_simple_edge_paths(G, source, targets, cutoff):
|
|
381
|
+
# We simulate recursion with a stack, keeping the current path being explored
|
|
382
|
+
# and the outgoing edge iterators at each point in the stack.
|
|
383
|
+
# To avoid unnecessary checks, the loop is structured in a way such that a path
|
|
384
|
+
# is considered for yielding only after a new node/edge is added.
|
|
385
|
+
# We bootstrap the search by adding a dummy iterator to the stack that only yields
|
|
386
|
+
# a dummy edge to source (so that the trivial path has a chance of being included).
|
|
387
|
+
|
|
388
|
+
get_edges = (
|
|
389
|
+
(lambda node: G.edges(node, keys=True))
|
|
390
|
+
if G.is_multigraph()
|
|
391
|
+
else (lambda node: G.edges(node))
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
# The current_path is a dictionary that maps nodes in the path to the edge that was
|
|
395
|
+
# used to enter that node (instead of a list of edges) because we want both a fast
|
|
396
|
+
# membership test for nodes in the path and the preservation of insertion order.
|
|
397
|
+
current_path = {None: None}
|
|
398
|
+
stack = [iter([(None, source)])]
|
|
399
|
+
|
|
400
|
+
while stack:
|
|
401
|
+
# 1. Try to extend the current path.
|
|
402
|
+
next_edge = next((e for e in stack[-1] if e[1] not in current_path), None)
|
|
403
|
+
if next_edge is None:
|
|
404
|
+
# All edges of the last node in the current path have been explored.
|
|
405
|
+
stack.pop()
|
|
406
|
+
current_path.popitem()
|
|
407
|
+
continue
|
|
408
|
+
previous_node, next_node, *_ = next_edge
|
|
409
|
+
|
|
410
|
+
# 2. Check if we've reached a target.
|
|
411
|
+
if next_node in targets:
|
|
412
|
+
yield (list(current_path.values()) + [next_edge])[2:] # remove dummy edge
|
|
413
|
+
|
|
414
|
+
# 3. Only expand the search through the next node if it makes sense.
|
|
415
|
+
if len(current_path) - 1 < cutoff and (
|
|
416
|
+
targets - current_path.keys() - {next_node}
|
|
417
|
+
):
|
|
418
|
+
current_path[next_node] = next_edge
|
|
419
|
+
stack.append(iter(get_edges(next_node)))
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
@not_implemented_for("multigraph")
|
|
423
|
+
@nx._dispatchable(edge_attrs="weight")
|
|
424
|
+
def shortest_simple_paths(G, source, target, weight=None):
|
|
425
|
+
"""Generate all simple paths in the graph G from source to target,
|
|
426
|
+
starting from shortest ones.
|
|
427
|
+
|
|
428
|
+
A simple path is a path with no repeated nodes.
|
|
429
|
+
|
|
430
|
+
If a weighted shortest path search is to be used, no negative weights
|
|
431
|
+
are allowed.
|
|
432
|
+
|
|
433
|
+
Parameters
|
|
434
|
+
----------
|
|
435
|
+
G : NetworkX graph
|
|
436
|
+
|
|
437
|
+
source : node
|
|
438
|
+
Starting node for path
|
|
439
|
+
|
|
440
|
+
target : node
|
|
441
|
+
Ending node for path
|
|
442
|
+
|
|
443
|
+
weight : string or function
|
|
444
|
+
If it is a string, it is the name of the edge attribute to be
|
|
445
|
+
used as a weight.
|
|
446
|
+
|
|
447
|
+
If it is a function, the weight of an edge is the value returned
|
|
448
|
+
by the function. The function must accept exactly three positional
|
|
449
|
+
arguments: the two endpoints of an edge and the dictionary of edge
|
|
450
|
+
attributes for that edge. The function must return a number or None.
|
|
451
|
+
The weight function can be used to hide edges by returning None.
|
|
452
|
+
So ``weight = lambda u, v, d: 1 if d['color']=="red" else None``
|
|
453
|
+
will find the shortest red path.
|
|
454
|
+
|
|
455
|
+
If None all edges are considered to have unit weight. Default
|
|
456
|
+
value None.
|
|
457
|
+
|
|
458
|
+
Returns
|
|
459
|
+
-------
|
|
460
|
+
path_generator: generator
|
|
461
|
+
A generator that produces lists of simple paths, in order from
|
|
462
|
+
shortest to longest.
|
|
463
|
+
|
|
464
|
+
Raises
|
|
465
|
+
------
|
|
466
|
+
NetworkXNoPath
|
|
467
|
+
If no path exists between source and target.
|
|
468
|
+
|
|
469
|
+
NetworkXError
|
|
470
|
+
If source or target nodes are not in the input graph.
|
|
471
|
+
|
|
472
|
+
NetworkXNotImplemented
|
|
473
|
+
If the input graph is a Multi[Di]Graph.
|
|
474
|
+
|
|
475
|
+
Examples
|
|
476
|
+
--------
|
|
477
|
+
|
|
478
|
+
>>> G = nx.cycle_graph(7)
|
|
479
|
+
>>> paths = list(nx.shortest_simple_paths(G, 0, 3))
|
|
480
|
+
>>> print(paths)
|
|
481
|
+
[[0, 1, 2, 3], [0, 6, 5, 4, 3]]
|
|
482
|
+
|
|
483
|
+
You can use this function to efficiently compute the k shortest/best
|
|
484
|
+
paths between two nodes.
|
|
485
|
+
|
|
486
|
+
>>> from itertools import islice
|
|
487
|
+
>>> def k_shortest_paths(G, source, target, k, weight=None):
|
|
488
|
+
... return list(
|
|
489
|
+
... islice(nx.shortest_simple_paths(G, source, target, weight=weight), k)
|
|
490
|
+
... )
|
|
491
|
+
>>> for path in k_shortest_paths(G, 0, 3, 2):
|
|
492
|
+
... print(path)
|
|
493
|
+
[0, 1, 2, 3]
|
|
494
|
+
[0, 6, 5, 4, 3]
|
|
495
|
+
|
|
496
|
+
Notes
|
|
497
|
+
-----
|
|
498
|
+
This procedure is based on algorithm by Jin Y. Yen [1]_. Finding
|
|
499
|
+
the first $K$ paths requires $O(KN^3)$ operations.
|
|
500
|
+
|
|
501
|
+
See Also
|
|
502
|
+
--------
|
|
503
|
+
all_shortest_paths
|
|
504
|
+
shortest_path
|
|
505
|
+
all_simple_paths
|
|
506
|
+
|
|
507
|
+
References
|
|
508
|
+
----------
|
|
509
|
+
.. [1] Jin Y. Yen, "Finding the K Shortest Loopless Paths in a
|
|
510
|
+
Network", Management Science, Vol. 17, No. 11, Theory Series
|
|
511
|
+
(Jul., 1971), pp. 712-716.
|
|
512
|
+
|
|
513
|
+
"""
|
|
514
|
+
if source not in G:
|
|
515
|
+
raise nx.NodeNotFound(f"source node {source} not in graph")
|
|
516
|
+
|
|
517
|
+
if target not in G:
|
|
518
|
+
raise nx.NodeNotFound(f"target node {target} not in graph")
|
|
519
|
+
|
|
520
|
+
if weight is None:
|
|
521
|
+
length_func = len
|
|
522
|
+
shortest_path_func = _bidirectional_shortest_path
|
|
523
|
+
else:
|
|
524
|
+
wt = _weight_function(G, weight)
|
|
525
|
+
|
|
526
|
+
def length_func(path):
|
|
527
|
+
return sum(
|
|
528
|
+
wt(u, v, G.get_edge_data(u, v)) for (u, v) in zip(path, path[1:])
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
shortest_path_func = _bidirectional_dijkstra
|
|
532
|
+
|
|
533
|
+
listA = []
|
|
534
|
+
listB = PathBuffer()
|
|
535
|
+
prev_path = None
|
|
536
|
+
while True:
|
|
537
|
+
if not prev_path:
|
|
538
|
+
length, path = shortest_path_func(G, source, target, weight=weight)
|
|
539
|
+
listB.push(length, path)
|
|
540
|
+
else:
|
|
541
|
+
ignore_nodes = set()
|
|
542
|
+
ignore_edges = set()
|
|
543
|
+
for i in range(1, len(prev_path)):
|
|
544
|
+
root = prev_path[:i]
|
|
545
|
+
root_length = length_func(root)
|
|
546
|
+
for path in listA:
|
|
547
|
+
if path[:i] == root:
|
|
548
|
+
ignore_edges.add((path[i - 1], path[i]))
|
|
549
|
+
try:
|
|
550
|
+
length, spur = shortest_path_func(
|
|
551
|
+
G,
|
|
552
|
+
root[-1],
|
|
553
|
+
target,
|
|
554
|
+
ignore_nodes=ignore_nodes,
|
|
555
|
+
ignore_edges=ignore_edges,
|
|
556
|
+
weight=weight,
|
|
557
|
+
)
|
|
558
|
+
path = root[:-1] + spur
|
|
559
|
+
listB.push(root_length + length, path)
|
|
560
|
+
except nx.NetworkXNoPath:
|
|
561
|
+
pass
|
|
562
|
+
ignore_nodes.add(root[-1])
|
|
563
|
+
|
|
564
|
+
if listB:
|
|
565
|
+
path = listB.pop()
|
|
566
|
+
yield path
|
|
567
|
+
listA.append(path)
|
|
568
|
+
prev_path = path
|
|
569
|
+
else:
|
|
570
|
+
break
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
class PathBuffer:
|
|
574
|
+
def __init__(self):
|
|
575
|
+
self.paths = set()
|
|
576
|
+
self.sortedpaths = []
|
|
577
|
+
self.counter = count()
|
|
578
|
+
|
|
579
|
+
def __len__(self):
|
|
580
|
+
return len(self.sortedpaths)
|
|
581
|
+
|
|
582
|
+
def push(self, cost, path):
|
|
583
|
+
hashable_path = tuple(path)
|
|
584
|
+
if hashable_path not in self.paths:
|
|
585
|
+
heappush(self.sortedpaths, (cost, next(self.counter), path))
|
|
586
|
+
self.paths.add(hashable_path)
|
|
587
|
+
|
|
588
|
+
def pop(self):
|
|
589
|
+
(cost, num, path) = heappop(self.sortedpaths)
|
|
590
|
+
hashable_path = tuple(path)
|
|
591
|
+
self.paths.remove(hashable_path)
|
|
592
|
+
return path
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
def _bidirectional_shortest_path(
|
|
596
|
+
G, source, target, ignore_nodes=None, ignore_edges=None, weight=None
|
|
597
|
+
):
|
|
598
|
+
"""Returns the shortest path between source and target ignoring
|
|
599
|
+
nodes and edges in the containers ignore_nodes and ignore_edges.
|
|
600
|
+
|
|
601
|
+
This is a custom modification of the standard bidirectional shortest
|
|
602
|
+
path implementation at networkx.algorithms.unweighted
|
|
603
|
+
|
|
604
|
+
Parameters
|
|
605
|
+
----------
|
|
606
|
+
G : NetworkX graph
|
|
607
|
+
|
|
608
|
+
source : node
|
|
609
|
+
starting node for path
|
|
610
|
+
|
|
611
|
+
target : node
|
|
612
|
+
ending node for path
|
|
613
|
+
|
|
614
|
+
ignore_nodes : container of nodes
|
|
615
|
+
nodes to ignore, optional
|
|
616
|
+
|
|
617
|
+
ignore_edges : container of edges
|
|
618
|
+
edges to ignore, optional
|
|
619
|
+
|
|
620
|
+
weight : None
|
|
621
|
+
This function accepts a weight argument for convenience of
|
|
622
|
+
shortest_simple_paths function. It will be ignored.
|
|
623
|
+
|
|
624
|
+
Returns
|
|
625
|
+
-------
|
|
626
|
+
path: list
|
|
627
|
+
List of nodes in a path from source to target.
|
|
628
|
+
|
|
629
|
+
Raises
|
|
630
|
+
------
|
|
631
|
+
NetworkXNoPath
|
|
632
|
+
If no path exists between source and target.
|
|
633
|
+
|
|
634
|
+
See Also
|
|
635
|
+
--------
|
|
636
|
+
shortest_path
|
|
637
|
+
|
|
638
|
+
"""
|
|
639
|
+
# call helper to do the real work
|
|
640
|
+
results = _bidirectional_pred_succ(G, source, target, ignore_nodes, ignore_edges)
|
|
641
|
+
pred, succ, w = results
|
|
642
|
+
|
|
643
|
+
# build path from pred+w+succ
|
|
644
|
+
path = []
|
|
645
|
+
# from w to target
|
|
646
|
+
while w is not None:
|
|
647
|
+
path.append(w)
|
|
648
|
+
w = succ[w]
|
|
649
|
+
# from source to w
|
|
650
|
+
w = pred[path[0]]
|
|
651
|
+
while w is not None:
|
|
652
|
+
path.insert(0, w)
|
|
653
|
+
w = pred[w]
|
|
654
|
+
|
|
655
|
+
return len(path), path
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def _bidirectional_pred_succ(G, source, target, ignore_nodes=None, ignore_edges=None):
|
|
659
|
+
"""Bidirectional shortest path helper.
|
|
660
|
+
Returns (pred,succ,w) where
|
|
661
|
+
pred is a dictionary of predecessors from w to the source, and
|
|
662
|
+
succ is a dictionary of successors from w to the target.
|
|
663
|
+
"""
|
|
664
|
+
# does BFS from both source and target and meets in the middle
|
|
665
|
+
if ignore_nodes and (source in ignore_nodes or target in ignore_nodes):
|
|
666
|
+
raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
|
|
667
|
+
if target == source:
|
|
668
|
+
return ({target: None}, {source: None}, source)
|
|
669
|
+
|
|
670
|
+
# handle either directed or undirected
|
|
671
|
+
if G.is_directed():
|
|
672
|
+
Gpred = G.predecessors
|
|
673
|
+
Gsucc = G.successors
|
|
674
|
+
else:
|
|
675
|
+
Gpred = G.neighbors
|
|
676
|
+
Gsucc = G.neighbors
|
|
677
|
+
|
|
678
|
+
# support optional nodes filter
|
|
679
|
+
if ignore_nodes:
|
|
680
|
+
|
|
681
|
+
def filter_iter(nodes):
|
|
682
|
+
def iterate(v):
|
|
683
|
+
for w in nodes(v):
|
|
684
|
+
if w not in ignore_nodes:
|
|
685
|
+
yield w
|
|
686
|
+
|
|
687
|
+
return iterate
|
|
688
|
+
|
|
689
|
+
Gpred = filter_iter(Gpred)
|
|
690
|
+
Gsucc = filter_iter(Gsucc)
|
|
691
|
+
|
|
692
|
+
# support optional edges filter
|
|
693
|
+
if ignore_edges:
|
|
694
|
+
if G.is_directed():
|
|
695
|
+
|
|
696
|
+
def filter_pred_iter(pred_iter):
|
|
697
|
+
def iterate(v):
|
|
698
|
+
for w in pred_iter(v):
|
|
699
|
+
if (w, v) not in ignore_edges:
|
|
700
|
+
yield w
|
|
701
|
+
|
|
702
|
+
return iterate
|
|
703
|
+
|
|
704
|
+
def filter_succ_iter(succ_iter):
|
|
705
|
+
def iterate(v):
|
|
706
|
+
for w in succ_iter(v):
|
|
707
|
+
if (v, w) not in ignore_edges:
|
|
708
|
+
yield w
|
|
709
|
+
|
|
710
|
+
return iterate
|
|
711
|
+
|
|
712
|
+
Gpred = filter_pred_iter(Gpred)
|
|
713
|
+
Gsucc = filter_succ_iter(Gsucc)
|
|
714
|
+
|
|
715
|
+
else:
|
|
716
|
+
|
|
717
|
+
def filter_iter(nodes):
|
|
718
|
+
def iterate(v):
|
|
719
|
+
for w in nodes(v):
|
|
720
|
+
if (v, w) not in ignore_edges and (w, v) not in ignore_edges:
|
|
721
|
+
yield w
|
|
722
|
+
|
|
723
|
+
return iterate
|
|
724
|
+
|
|
725
|
+
Gpred = filter_iter(Gpred)
|
|
726
|
+
Gsucc = filter_iter(Gsucc)
|
|
727
|
+
|
|
728
|
+
# predecessor and successors in search
|
|
729
|
+
pred = {source: None}
|
|
730
|
+
succ = {target: None}
|
|
731
|
+
|
|
732
|
+
# initialize fringes, start with forward
|
|
733
|
+
forward_fringe = [source]
|
|
734
|
+
reverse_fringe = [target]
|
|
735
|
+
|
|
736
|
+
while forward_fringe and reverse_fringe:
|
|
737
|
+
if len(forward_fringe) <= len(reverse_fringe):
|
|
738
|
+
this_level = forward_fringe
|
|
739
|
+
forward_fringe = []
|
|
740
|
+
for v in this_level:
|
|
741
|
+
for w in Gsucc(v):
|
|
742
|
+
if w not in pred:
|
|
743
|
+
forward_fringe.append(w)
|
|
744
|
+
pred[w] = v
|
|
745
|
+
if w in succ:
|
|
746
|
+
# found path
|
|
747
|
+
return pred, succ, w
|
|
748
|
+
else:
|
|
749
|
+
this_level = reverse_fringe
|
|
750
|
+
reverse_fringe = []
|
|
751
|
+
for v in this_level:
|
|
752
|
+
for w in Gpred(v):
|
|
753
|
+
if w not in succ:
|
|
754
|
+
succ[w] = v
|
|
755
|
+
reverse_fringe.append(w)
|
|
756
|
+
if w in pred:
|
|
757
|
+
# found path
|
|
758
|
+
return pred, succ, w
|
|
759
|
+
|
|
760
|
+
raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
def _bidirectional_dijkstra(
|
|
764
|
+
G, source, target, weight="weight", ignore_nodes=None, ignore_edges=None
|
|
765
|
+
):
|
|
766
|
+
"""Dijkstra's algorithm for shortest paths using bidirectional search.
|
|
767
|
+
|
|
768
|
+
This function returns the shortest path between source and target
|
|
769
|
+
ignoring nodes and edges in the containers ignore_nodes and
|
|
770
|
+
ignore_edges.
|
|
771
|
+
|
|
772
|
+
This is a custom modification of the standard Dijkstra bidirectional
|
|
773
|
+
shortest path implementation at networkx.algorithms.weighted
|
|
774
|
+
|
|
775
|
+
Parameters
|
|
776
|
+
----------
|
|
777
|
+
G : NetworkX graph
|
|
778
|
+
|
|
779
|
+
source : node
|
|
780
|
+
Starting node.
|
|
781
|
+
|
|
782
|
+
target : node
|
|
783
|
+
Ending node.
|
|
784
|
+
|
|
785
|
+
weight: string, function, optional (default='weight')
|
|
786
|
+
Edge data key or weight function corresponding to the edge weight
|
|
787
|
+
If this is a function, the weight of an edge is the value
|
|
788
|
+
returned by the function. The function must accept exactly three
|
|
789
|
+
positional arguments: the two endpoints of an edge and the
|
|
790
|
+
dictionary of edge attributes for that edge. The function must
|
|
791
|
+
return a number or None to indicate a hidden edge.
|
|
792
|
+
|
|
793
|
+
ignore_nodes : container of nodes
|
|
794
|
+
nodes to ignore, optional
|
|
795
|
+
|
|
796
|
+
ignore_edges : container of edges
|
|
797
|
+
edges to ignore, optional
|
|
798
|
+
|
|
799
|
+
Returns
|
|
800
|
+
-------
|
|
801
|
+
length : number
|
|
802
|
+
Shortest path length.
|
|
803
|
+
|
|
804
|
+
Returns a tuple of two dictionaries keyed by node.
|
|
805
|
+
The first dictionary stores distance from the source.
|
|
806
|
+
The second stores the path from the source to that node.
|
|
807
|
+
|
|
808
|
+
Raises
|
|
809
|
+
------
|
|
810
|
+
NetworkXNoPath
|
|
811
|
+
If no path exists between source and target.
|
|
812
|
+
|
|
813
|
+
Notes
|
|
814
|
+
-----
|
|
815
|
+
Edge weight attributes must be numerical.
|
|
816
|
+
Distances are calculated as sums of weighted edges traversed.
|
|
817
|
+
|
|
818
|
+
The weight function can be used to hide edges by returning None.
|
|
819
|
+
So ``weight = lambda u, v, d: 1 if d['color']=="red" else None``
|
|
820
|
+
will find the shortest red path.
|
|
821
|
+
|
|
822
|
+
In practice bidirectional Dijkstra is much more than twice as fast as
|
|
823
|
+
ordinary Dijkstra.
|
|
824
|
+
|
|
825
|
+
Ordinary Dijkstra expands nodes in a sphere-like manner from the
|
|
826
|
+
source. The radius of this sphere will eventually be the length
|
|
827
|
+
of the shortest path. Bidirectional Dijkstra will expand nodes
|
|
828
|
+
from both the source and the target, making two spheres of half
|
|
829
|
+
this radius. Volume of the first sphere is pi*r*r while the
|
|
830
|
+
others are 2*pi*r/2*r/2, making up half the volume.
|
|
831
|
+
|
|
832
|
+
This algorithm is not guaranteed to work if edge weights
|
|
833
|
+
are negative or are floating point numbers
|
|
834
|
+
(overflows and roundoff errors can cause problems).
|
|
835
|
+
|
|
836
|
+
See Also
|
|
837
|
+
--------
|
|
838
|
+
shortest_path
|
|
839
|
+
shortest_path_length
|
|
840
|
+
"""
|
|
841
|
+
if ignore_nodes and (source in ignore_nodes or target in ignore_nodes):
|
|
842
|
+
raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
|
|
843
|
+
if source == target:
|
|
844
|
+
if source not in G:
|
|
845
|
+
raise nx.NodeNotFound(f"Node {source} not in graph")
|
|
846
|
+
return (0, [source])
|
|
847
|
+
|
|
848
|
+
# handle either directed or undirected
|
|
849
|
+
if G.is_directed():
|
|
850
|
+
Gpred = G.predecessors
|
|
851
|
+
Gsucc = G.successors
|
|
852
|
+
else:
|
|
853
|
+
Gpred = G.neighbors
|
|
854
|
+
Gsucc = G.neighbors
|
|
855
|
+
|
|
856
|
+
# support optional nodes filter
|
|
857
|
+
if ignore_nodes:
|
|
858
|
+
|
|
859
|
+
def filter_iter(nodes):
|
|
860
|
+
def iterate(v):
|
|
861
|
+
for w in nodes(v):
|
|
862
|
+
if w not in ignore_nodes:
|
|
863
|
+
yield w
|
|
864
|
+
|
|
865
|
+
return iterate
|
|
866
|
+
|
|
867
|
+
Gpred = filter_iter(Gpred)
|
|
868
|
+
Gsucc = filter_iter(Gsucc)
|
|
869
|
+
|
|
870
|
+
# support optional edges filter
|
|
871
|
+
if ignore_edges:
|
|
872
|
+
if G.is_directed():
|
|
873
|
+
|
|
874
|
+
def filter_pred_iter(pred_iter):
|
|
875
|
+
def iterate(v):
|
|
876
|
+
for w in pred_iter(v):
|
|
877
|
+
if (w, v) not in ignore_edges:
|
|
878
|
+
yield w
|
|
879
|
+
|
|
880
|
+
return iterate
|
|
881
|
+
|
|
882
|
+
def filter_succ_iter(succ_iter):
|
|
883
|
+
def iterate(v):
|
|
884
|
+
for w in succ_iter(v):
|
|
885
|
+
if (v, w) not in ignore_edges:
|
|
886
|
+
yield w
|
|
887
|
+
|
|
888
|
+
return iterate
|
|
889
|
+
|
|
890
|
+
Gpred = filter_pred_iter(Gpred)
|
|
891
|
+
Gsucc = filter_succ_iter(Gsucc)
|
|
892
|
+
|
|
893
|
+
else:
|
|
894
|
+
|
|
895
|
+
def filter_iter(nodes):
|
|
896
|
+
def iterate(v):
|
|
897
|
+
for w in nodes(v):
|
|
898
|
+
if (v, w) not in ignore_edges and (w, v) not in ignore_edges:
|
|
899
|
+
yield w
|
|
900
|
+
|
|
901
|
+
return iterate
|
|
902
|
+
|
|
903
|
+
Gpred = filter_iter(Gpred)
|
|
904
|
+
Gsucc = filter_iter(Gsucc)
|
|
905
|
+
|
|
906
|
+
wt = _weight_function(G, weight)
|
|
907
|
+
# Init: Forward Backward
|
|
908
|
+
dists = [{}, {}] # dictionary of final distances
|
|
909
|
+
paths = [{source: [source]}, {target: [target]}] # dictionary of paths
|
|
910
|
+
fringe = [[], []] # heap of (distance, node) tuples for
|
|
911
|
+
# extracting next node to expand
|
|
912
|
+
seen = [{source: 0}, {target: 0}] # dictionary of distances to
|
|
913
|
+
# nodes seen
|
|
914
|
+
c = count()
|
|
915
|
+
# initialize fringe heap
|
|
916
|
+
heappush(fringe[0], (0, next(c), source))
|
|
917
|
+
heappush(fringe[1], (0, next(c), target))
|
|
918
|
+
# neighs for extracting correct neighbor information
|
|
919
|
+
neighs = [Gsucc, Gpred]
|
|
920
|
+
# variables to hold shortest discovered path
|
|
921
|
+
# finaldist = 1e30000
|
|
922
|
+
finalpath = []
|
|
923
|
+
dir = 1
|
|
924
|
+
while fringe[0] and fringe[1]:
|
|
925
|
+
# choose direction
|
|
926
|
+
# dir == 0 is forward direction and dir == 1 is back
|
|
927
|
+
dir = 1 - dir
|
|
928
|
+
# extract closest to expand
|
|
929
|
+
(dist, _, v) = heappop(fringe[dir])
|
|
930
|
+
if v in dists[dir]:
|
|
931
|
+
# Shortest path to v has already been found
|
|
932
|
+
continue
|
|
933
|
+
# update distance
|
|
934
|
+
dists[dir][v] = dist # equal to seen[dir][v]
|
|
935
|
+
if v in dists[1 - dir]:
|
|
936
|
+
# if we have scanned v in both directions we are done
|
|
937
|
+
# we have now discovered the shortest path
|
|
938
|
+
return (finaldist, finalpath)
|
|
939
|
+
|
|
940
|
+
for w in neighs[dir](v):
|
|
941
|
+
if dir == 0: # forward
|
|
942
|
+
minweight = wt(v, w, G.get_edge_data(v, w))
|
|
943
|
+
else: # back, must remember to change v,w->w,v
|
|
944
|
+
minweight = wt(w, v, G.get_edge_data(w, v))
|
|
945
|
+
if minweight is None:
|
|
946
|
+
continue
|
|
947
|
+
vwLength = dists[dir][v] + minweight
|
|
948
|
+
|
|
949
|
+
if w in dists[dir]:
|
|
950
|
+
if vwLength < dists[dir][w]:
|
|
951
|
+
raise ValueError("Contradictory paths found: negative weights?")
|
|
952
|
+
elif w not in seen[dir] or vwLength < seen[dir][w]:
|
|
953
|
+
# relaxing
|
|
954
|
+
seen[dir][w] = vwLength
|
|
955
|
+
heappush(fringe[dir], (vwLength, next(c), w))
|
|
956
|
+
paths[dir][w] = paths[dir][v] + [w]
|
|
957
|
+
if w in seen[0] and w in seen[1]:
|
|
958
|
+
# see if this path is better than the already
|
|
959
|
+
# discovered shortest path
|
|
960
|
+
totaldist = seen[0][w] + seen[1][w]
|
|
961
|
+
if finalpath == [] or finaldist > totaldist:
|
|
962
|
+
finaldist = totaldist
|
|
963
|
+
revpath = paths[1][w][:]
|
|
964
|
+
revpath.reverse()
|
|
965
|
+
finalpath = paths[0][w] + revpath[1:]
|
|
966
|
+
raise nx.NetworkXNoPath(f"No path between {source} and {target}.")
|