okstra 0.130.4 → 0.131.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/docs/architecture.md +2 -2
- package/docs/cli.md +1 -1
- package/docs/for-ai/README.md +0 -2
- package/docs/for-ai/skills/okstra-run.md +13 -2
- package/docs/for-ai/skills/okstra-setup.md +4 -1
- package/docs/project-structure-overview.md +5 -4
- package/docs/task-process/implementation-planning.md +13 -0
- package/docs/task-process/implementation.md +17 -2
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/workers/report-writer-worker.md +7 -0
- package/runtime/bin/lib/okstra/usage.sh +4 -4
- package/runtime/prompts/lead/okstra-lead-contract.md +2 -2
- package/runtime/prompts/lead/plan-body-verification.md +26 -5
- package/runtime/prompts/lead/report-writer.md +6 -2
- package/runtime/prompts/profiles/_common-contract.md +2 -1
- package/runtime/prompts/profiles/_implementation-deliverable.md +6 -1
- package/runtime/prompts/profiles/_implementation-executor.md +2 -2
- package/runtime/prompts/profiles/_implementation-verifier.md +33 -10
- package/runtime/prompts/profiles/final-verification.md +21 -6
- package/runtime/prompts/profiles/implementation-planning.md +16 -4
- package/runtime/python/okstra_ctl/codex_dispatch.py +31 -0
- package/runtime/python/okstra_ctl/conformance.py +49 -11
- package/runtime/python/okstra_ctl/report_finalize.py +52 -1
- package/runtime/python/okstra_ctl/run.py +15 -3
- package/runtime/python/okstra_ctl/worker_prompt_contract.py +14 -6
- package/runtime/python/okstra_ctl/worker_prompt_policy.py +19 -1
- package/runtime/python/okstra_vendor/__init__.py +0 -44
- package/runtime/schemas/final-report-v1.0.schema.json +99 -5
- package/runtime/skills/okstra-run/SKILL.md +11 -4
- package/runtime/skills/okstra-setup/SKILL.md +3 -2
- package/runtime/skills/okstra-setup/references/project-config.md +16 -7
- package/runtime/templates/reports/final-report.template.md +15 -9
- package/runtime/templates/reports/i18n/en.json +1 -0
- package/runtime/templates/reports/i18n/ko.json +1 -0
- package/runtime/validators/lib/fixtures.sh +6 -0
- package/runtime/validators/validate-run.py +1722 -98
- package/src/cli-registry.mjs +0 -7
- package/src/commands/lifecycle/doctor.mjs +0 -9
- package/src/lib/skill-catalog.mjs +0 -1
- package/docs/for-ai/skills/okstra-graphify.md +0 -64
- package/runtime/python/okstra_ctl/graphify_cmd.py +0 -225
- package/runtime/python/okstra_vendor/graphify/.vendored-version +0 -1
- package/runtime/python/okstra_vendor/graphify/__init__.py +0 -28
- package/runtime/python/okstra_vendor/graphify/__main__.py +0 -1371
- package/runtime/python/okstra_vendor/graphify/analyze.py +0 -540
- package/runtime/python/okstra_vendor/graphify/benchmark.py +0 -129
- package/runtime/python/okstra_vendor/graphify/build.py +0 -107
- package/runtime/python/okstra_vendor/graphify/cache.py +0 -169
- package/runtime/python/okstra_vendor/graphify/cluster.py +0 -137
- package/runtime/python/okstra_vendor/graphify/detect.py +0 -510
- package/runtime/python/okstra_vendor/graphify/export.py +0 -1014
- package/runtime/python/okstra_vendor/graphify/extract.py +0 -3277
- package/runtime/python/okstra_vendor/graphify/hooks.py +0 -220
- package/runtime/python/okstra_vendor/graphify/ingest.py +0 -297
- package/runtime/python/okstra_vendor/graphify/manifest.py +0 -4
- package/runtime/python/okstra_vendor/graphify/report.py +0 -175
- package/runtime/python/okstra_vendor/graphify/security.py +0 -203
- package/runtime/python/okstra_vendor/graphify/serve.py +0 -373
- package/runtime/python/okstra_vendor/graphify/skill-aider.md +0 -1184
- package/runtime/python/okstra_vendor/graphify/skill-claw.md +0 -1184
- package/runtime/python/okstra_vendor/graphify/skill-codex.md +0 -1242
- package/runtime/python/okstra_vendor/graphify/skill-copilot.md +0 -1268
- package/runtime/python/okstra_vendor/graphify/skill-droid.md +0 -1239
- package/runtime/python/okstra_vendor/graphify/skill-kiro.md +0 -1183
- package/runtime/python/okstra_vendor/graphify/skill-opencode.md +0 -1238
- package/runtime/python/okstra_vendor/graphify/skill-trae.md +0 -1208
- package/runtime/python/okstra_vendor/graphify/skill-vscode.md +0 -253
- package/runtime/python/okstra_vendor/graphify/skill-windows.md +0 -1245
- package/runtime/python/okstra_vendor/graphify/skill.md +0 -1319
- package/runtime/python/okstra_vendor/graphify/transcribe.py +0 -182
- package/runtime/python/okstra_vendor/graphify/validate.py +0 -72
- package/runtime/python/okstra_vendor/graphify/watch.py +0 -188
- package/runtime/python/okstra_vendor/graphify/wiki.py +0 -214
- package/runtime/python/okstra_vendor/networkx/__init__.py +0 -62
- package/runtime/python/okstra_vendor/networkx/algorithms/__init__.py +0 -134
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/__init__.py +0 -26
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clique.py +0 -259
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/clustering_coefficient.py +0 -71
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/connectivity.py +0 -412
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/density.py +0 -396
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/distance_measures.py +0 -150
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/dominating_set.py +0 -149
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/kcomponents.py +0 -369
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/matching.py +0 -44
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/maxcut.py +0 -143
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/ramsey.py +0 -53
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/steinertree.py +0 -265
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/traveling_salesman.py +0 -1508
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/treewidth.py +0 -255
- package/runtime/python/okstra_vendor/networkx/algorithms/approximation/vertex_cover.py +0 -83
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/__init__.py +0 -5
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/connectivity.py +0 -122
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/correlation.py +0 -302
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/mixing.py +0 -255
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/neighbor_degree.py +0 -160
- package/runtime/python/okstra_vendor/networkx/algorithms/assortativity/pairs.py +0 -127
- package/runtime/python/okstra_vendor/networkx/algorithms/asteroidal.py +0 -164
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/__init__.py +0 -88
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/basic.py +0 -322
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/centrality.py +0 -290
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/cluster.py +0 -289
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/covering.py +0 -57
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/edgelist.py +0 -360
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/extendability.py +0 -105
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/generators.py +0 -603
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/link_analysis.py +0 -316
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matching.py +0 -590
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/matrix.py +0 -232
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/projection.py +0 -526
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/redundancy.py +0 -112
- package/runtime/python/okstra_vendor/networkx/algorithms/bipartite/spectral.py +0 -69
- package/runtime/python/okstra_vendor/networkx/algorithms/boundary.py +0 -168
- package/runtime/python/okstra_vendor/networkx/algorithms/bridges.py +0 -205
- package/runtime/python/okstra_vendor/networkx/algorithms/broadcasting.py +0 -164
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/__init__.py +0 -20
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness.py +0 -591
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/betweenness_subset.py +0 -236
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/closeness.py +0 -282
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness.py +0 -364
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_betweenness_subset.py +0 -227
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/current_flow_closeness.py +0 -96
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/degree_alg.py +0 -150
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/dispersion.py +0 -107
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/eigenvector.py +0 -357
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/flow_matrix.py +0 -130
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/group.py +0 -787
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/harmonic.py +0 -88
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/katz.py +0 -331
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/laplacian.py +0 -150
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/load.py +0 -200
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/percolation.py +0 -128
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/reaching.py +0 -209
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/second_order.py +0 -141
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/subgraph_alg.py +0 -361
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/trophic.py +0 -181
- package/runtime/python/okstra_vendor/networkx/algorithms/centrality/voterank_alg.py +0 -95
- package/runtime/python/okstra_vendor/networkx/algorithms/chains.py +0 -172
- package/runtime/python/okstra_vendor/networkx/algorithms/chordal.py +0 -443
- package/runtime/python/okstra_vendor/networkx/algorithms/clique.py +0 -818
- package/runtime/python/okstra_vendor/networkx/algorithms/cluster.py +0 -732
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/__init__.py +0 -4
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/equitable_coloring.py +0 -505
- package/runtime/python/okstra_vendor/networkx/algorithms/coloring/greedy_coloring.py +0 -565
- package/runtime/python/okstra_vendor/networkx/algorithms/communicability_alg.py +0 -163
- package/runtime/python/okstra_vendor/networkx/algorithms/community/__init__.py +0 -28
- package/runtime/python/okstra_vendor/networkx/algorithms/community/asyn_fluid.py +0 -153
- package/runtime/python/okstra_vendor/networkx/algorithms/community/bipartitions.py +0 -354
- package/runtime/python/okstra_vendor/networkx/algorithms/community/centrality.py +0 -171
- package/runtime/python/okstra_vendor/networkx/algorithms/community/community_utils.py +0 -30
- package/runtime/python/okstra_vendor/networkx/algorithms/community/divisive.py +0 -216
- package/runtime/python/okstra_vendor/networkx/algorithms/community/kclique.py +0 -79
- package/runtime/python/okstra_vendor/networkx/algorithms/community/label_propagation.py +0 -338
- package/runtime/python/okstra_vendor/networkx/algorithms/community/leiden.py +0 -162
- package/runtime/python/okstra_vendor/networkx/algorithms/community/local.py +0 -220
- package/runtime/python/okstra_vendor/networkx/algorithms/community/louvain.py +0 -384
- package/runtime/python/okstra_vendor/networkx/algorithms/community/lukes.py +0 -227
- package/runtime/python/okstra_vendor/networkx/algorithms/community/modularity_max.py +0 -452
- package/runtime/python/okstra_vendor/networkx/algorithms/community/quality.py +0 -347
- package/runtime/python/okstra_vendor/networkx/algorithms/components/__init__.py +0 -6
- package/runtime/python/okstra_vendor/networkx/algorithms/components/attracting.py +0 -115
- package/runtime/python/okstra_vendor/networkx/algorithms/components/biconnected.py +0 -394
- package/runtime/python/okstra_vendor/networkx/algorithms/components/connected.py +0 -282
- package/runtime/python/okstra_vendor/networkx/algorithms/components/semiconnected.py +0 -71
- package/runtime/python/okstra_vendor/networkx/algorithms/components/strongly_connected.py +0 -359
- package/runtime/python/okstra_vendor/networkx/algorithms/components/weakly_connected.py +0 -196
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/__init__.py +0 -11
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/connectivity.py +0 -811
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/cuts.py +0 -616
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/disjoint_paths.py +0 -408
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_augmentation.py +0 -1270
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/edge_kcomponents.py +0 -592
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcomponents.py +0 -220
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/kcutsets.py +0 -235
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/stoerwagner.py +0 -152
- package/runtime/python/okstra_vendor/networkx/algorithms/connectivity/utils.py +0 -88
- package/runtime/python/okstra_vendor/networkx/algorithms/core.py +0 -588
- package/runtime/python/okstra_vendor/networkx/algorithms/covering.py +0 -142
- package/runtime/python/okstra_vendor/networkx/algorithms/cuts.py +0 -416
- package/runtime/python/okstra_vendor/networkx/algorithms/cycles.py +0 -1234
- package/runtime/python/okstra_vendor/networkx/algorithms/d_separation.py +0 -677
- package/runtime/python/okstra_vendor/networkx/algorithms/dag.py +0 -1392
- package/runtime/python/okstra_vendor/networkx/algorithms/distance_measures.py +0 -1095
- package/runtime/python/okstra_vendor/networkx/algorithms/distance_regular.py +0 -272
- package/runtime/python/okstra_vendor/networkx/algorithms/dominance.py +0 -142
- package/runtime/python/okstra_vendor/networkx/algorithms/dominating.py +0 -268
- package/runtime/python/okstra_vendor/networkx/algorithms/efficiency_measures.py +0 -167
- package/runtime/python/okstra_vendor/networkx/algorithms/euler.py +0 -470
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/__init__.py +0 -11
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/boykovkolmogorov.py +0 -370
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/capacityscaling.py +0 -407
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/dinitz_alg.py +0 -238
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/edmondskarp.py +0 -241
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/gomory_hu.py +0 -178
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/maxflow.py +0 -611
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/mincost.py +0 -356
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/networksimplex.py +0 -662
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/preflowpush.py +0 -425
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/shortestaugmentingpath.py +0 -300
- package/runtime/python/okstra_vendor/networkx/algorithms/flow/utils.py +0 -194
- package/runtime/python/okstra_vendor/networkx/algorithms/graph_hashing.py +0 -435
- package/runtime/python/okstra_vendor/networkx/algorithms/graphical.py +0 -483
- package/runtime/python/okstra_vendor/networkx/algorithms/hierarchy.py +0 -57
- package/runtime/python/okstra_vendor/networkx/algorithms/hybrid.py +0 -196
- package/runtime/python/okstra_vendor/networkx/algorithms/isolate.py +0 -107
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/__init__.py +0 -7
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/ismags.py +0 -1306
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorph.py +0 -336
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/isomorphvf2.py +0 -1262
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/matchhelpers.py +0 -352
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/temporalisomorphvf2.py +0 -308
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/tree_isomorphism.py +0 -264
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2pp.py +0 -1102
- package/runtime/python/okstra_vendor/networkx/algorithms/isomorphism/vf2userfunc.py +0 -192
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/__init__.py +0 -2
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/hits_alg.py +0 -337
- package/runtime/python/okstra_vendor/networkx/algorithms/link_analysis/pagerank_alg.py +0 -498
- package/runtime/python/okstra_vendor/networkx/algorithms/link_prediction.py +0 -687
- package/runtime/python/okstra_vendor/networkx/algorithms/lowest_common_ancestors.py +0 -280
- package/runtime/python/okstra_vendor/networkx/algorithms/matching.py +0 -1148
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/__init__.py +0 -27
- package/runtime/python/okstra_vendor/networkx/algorithms/minors/contraction.py +0 -738
- package/runtime/python/okstra_vendor/networkx/algorithms/mis.py +0 -78
- package/runtime/python/okstra_vendor/networkx/algorithms/moral.py +0 -59
- package/runtime/python/okstra_vendor/networkx/algorithms/node_classification.py +0 -219
- package/runtime/python/okstra_vendor/networkx/algorithms/non_randomness.py +0 -155
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/__init__.py +0 -4
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/all.py +0 -324
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/binary.py +0 -468
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/product.py +0 -633
- package/runtime/python/okstra_vendor/networkx/algorithms/operators/unary.py +0 -77
- package/runtime/python/okstra_vendor/networkx/algorithms/perfect_graph.py +0 -73
- package/runtime/python/okstra_vendor/networkx/algorithms/planar_drawing.py +0 -464
- package/runtime/python/okstra_vendor/networkx/algorithms/planarity.py +0 -1463
- package/runtime/python/okstra_vendor/networkx/algorithms/polynomials.py +0 -306
- package/runtime/python/okstra_vendor/networkx/algorithms/reciprocity.py +0 -98
- package/runtime/python/okstra_vendor/networkx/algorithms/regular.py +0 -167
- package/runtime/python/okstra_vendor/networkx/algorithms/richclub.py +0 -138
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/__init__.py +0 -5
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/astar.py +0 -239
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/dense.py +0 -264
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/generic.py +0 -716
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/unweighted.py +0 -625
- package/runtime/python/okstra_vendor/networkx/algorithms/shortest_paths/weighted.py +0 -2542
- package/runtime/python/okstra_vendor/networkx/algorithms/similarity.py +0 -2107
- package/runtime/python/okstra_vendor/networkx/algorithms/simple_paths.py +0 -966
- package/runtime/python/okstra_vendor/networkx/algorithms/smallworld.py +0 -404
- package/runtime/python/okstra_vendor/networkx/algorithms/smetric.py +0 -30
- package/runtime/python/okstra_vendor/networkx/algorithms/sparsifiers.py +0 -296
- package/runtime/python/okstra_vendor/networkx/algorithms/structuralholes.py +0 -374
- package/runtime/python/okstra_vendor/networkx/algorithms/summarization.py +0 -564
- package/runtime/python/okstra_vendor/networkx/algorithms/swap.py +0 -406
- package/runtime/python/okstra_vendor/networkx/algorithms/threshold.py +0 -981
- package/runtime/python/okstra_vendor/networkx/algorithms/time_dependent.py +0 -142
- package/runtime/python/okstra_vendor/networkx/algorithms/tournament.py +0 -406
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/__init__.py +0 -5
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/beamsearch.py +0 -90
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/breadth_first_search.py +0 -576
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/depth_first_search.py +0 -529
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgebfs.py +0 -185
- package/runtime/python/okstra_vendor/networkx/algorithms/traversal/edgedfs.py +0 -182
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/__init__.py +0 -7
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/branchings.py +0 -1042
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/coding.py +0 -413
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/decomposition.py +0 -88
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/distance_measures.py +0 -219
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/mst.py +0 -1281
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/operations.py +0 -106
- package/runtime/python/okstra_vendor/networkx/algorithms/tree/recognition.py +0 -273
- package/runtime/python/okstra_vendor/networkx/algorithms/triads.py +0 -500
- package/runtime/python/okstra_vendor/networkx/algorithms/vitality.py +0 -76
- package/runtime/python/okstra_vendor/networkx/algorithms/voronoi.py +0 -86
- package/runtime/python/okstra_vendor/networkx/algorithms/walks.py +0 -77
- package/runtime/python/okstra_vendor/networkx/algorithms/wiener.py +0 -278
- package/runtime/python/okstra_vendor/networkx/classes/__init__.py +0 -13
- package/runtime/python/okstra_vendor/networkx/classes/coreviews.py +0 -435
- package/runtime/python/okstra_vendor/networkx/classes/digraph.py +0 -1363
- package/runtime/python/okstra_vendor/networkx/classes/filters.py +0 -95
- package/runtime/python/okstra_vendor/networkx/classes/function.py +0 -1549
- package/runtime/python/okstra_vendor/networkx/classes/graph.py +0 -2082
- package/runtime/python/okstra_vendor/networkx/classes/graphviews.py +0 -269
- package/runtime/python/okstra_vendor/networkx/classes/multidigraph.py +0 -977
- package/runtime/python/okstra_vendor/networkx/classes/multigraph.py +0 -1294
- package/runtime/python/okstra_vendor/networkx/classes/reportviews.py +0 -1447
- package/runtime/python/okstra_vendor/networkx/convert.py +0 -502
- package/runtime/python/okstra_vendor/networkx/convert_matrix.py +0 -1314
- package/runtime/python/okstra_vendor/networkx/drawing/__init__.py +0 -7
- package/runtime/python/okstra_vendor/networkx/drawing/layout.py +0 -2036
- package/runtime/python/okstra_vendor/networkx/drawing/nx_agraph.py +0 -470
- package/runtime/python/okstra_vendor/networkx/drawing/nx_latex.py +0 -570
- package/runtime/python/okstra_vendor/networkx/drawing/nx_pydot.py +0 -361
- package/runtime/python/okstra_vendor/networkx/drawing/nx_pylab.py +0 -2978
- package/runtime/python/okstra_vendor/networkx/exception.py +0 -131
- package/runtime/python/okstra_vendor/networkx/generators/__init__.py +0 -34
- package/runtime/python/okstra_vendor/networkx/generators/atlas.dat.gz +0 -0
- package/runtime/python/okstra_vendor/networkx/generators/atlas.py +0 -227
- package/runtime/python/okstra_vendor/networkx/generators/classic.py +0 -1091
- package/runtime/python/okstra_vendor/networkx/generators/cographs.py +0 -68
- package/runtime/python/okstra_vendor/networkx/generators/community.py +0 -1070
- package/runtime/python/okstra_vendor/networkx/generators/degree_seq.py +0 -886
- package/runtime/python/okstra_vendor/networkx/generators/directed.py +0 -572
- package/runtime/python/okstra_vendor/networkx/generators/duplication.py +0 -174
- package/runtime/python/okstra_vendor/networkx/generators/ego.py +0 -66
- package/runtime/python/okstra_vendor/networkx/generators/expanders.py +0 -499
- package/runtime/python/okstra_vendor/networkx/generators/geometric.py +0 -1037
- package/runtime/python/okstra_vendor/networkx/generators/harary_graph.py +0 -163
- package/runtime/python/okstra_vendor/networkx/generators/internet_as_graphs.py +0 -443
- package/runtime/python/okstra_vendor/networkx/generators/intersection.py +0 -125
- package/runtime/python/okstra_vendor/networkx/generators/interval_graph.py +0 -70
- package/runtime/python/okstra_vendor/networkx/generators/joint_degree_seq.py +0 -664
- package/runtime/python/okstra_vendor/networkx/generators/lattice.py +0 -405
- package/runtime/python/okstra_vendor/networkx/generators/line.py +0 -501
- package/runtime/python/okstra_vendor/networkx/generators/mycielski.py +0 -110
- package/runtime/python/okstra_vendor/networkx/generators/nonisomorphic_trees.py +0 -259
- package/runtime/python/okstra_vendor/networkx/generators/random_clustered.py +0 -117
- package/runtime/python/okstra_vendor/networkx/generators/random_graphs.py +0 -1416
- package/runtime/python/okstra_vendor/networkx/generators/small.py +0 -1070
- package/runtime/python/okstra_vendor/networkx/generators/social.py +0 -554
- package/runtime/python/okstra_vendor/networkx/generators/spectral_graph_forge.py +0 -120
- package/runtime/python/okstra_vendor/networkx/generators/stochastic.py +0 -54
- package/runtime/python/okstra_vendor/networkx/generators/sudoku.py +0 -131
- package/runtime/python/okstra_vendor/networkx/generators/time_series.py +0 -74
- package/runtime/python/okstra_vendor/networkx/generators/trees.py +0 -1070
- package/runtime/python/okstra_vendor/networkx/generators/triads.py +0 -94
- package/runtime/python/okstra_vendor/networkx/lazy_imports.py +0 -188
- package/runtime/python/okstra_vendor/networkx/linalg/__init__.py +0 -13
- package/runtime/python/okstra_vendor/networkx/linalg/algebraicconnectivity.py +0 -650
- package/runtime/python/okstra_vendor/networkx/linalg/attrmatrix.py +0 -466
- package/runtime/python/okstra_vendor/networkx/linalg/bethehessianmatrix.py +0 -77
- package/runtime/python/okstra_vendor/networkx/linalg/graphmatrix.py +0 -168
- package/runtime/python/okstra_vendor/networkx/linalg/laplacianmatrix.py +0 -512
- package/runtime/python/okstra_vendor/networkx/linalg/modularitymatrix.py +0 -166
- package/runtime/python/okstra_vendor/networkx/linalg/spectrum.py +0 -186
- package/runtime/python/okstra_vendor/networkx/readwrite/__init__.py +0 -17
- package/runtime/python/okstra_vendor/networkx/readwrite/adjlist.py +0 -330
- package/runtime/python/okstra_vendor/networkx/readwrite/edgelist.py +0 -489
- package/runtime/python/okstra_vendor/networkx/readwrite/gexf.py +0 -1084
- package/runtime/python/okstra_vendor/networkx/readwrite/gml.py +0 -879
- package/runtime/python/okstra_vendor/networkx/readwrite/graph6.py +0 -427
- package/runtime/python/okstra_vendor/networkx/readwrite/graphml.py +0 -1053
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/__init__.py +0 -19
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/adjacency.py +0 -156
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/cytoscape.py +0 -190
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/node_link.py +0 -261
- package/runtime/python/okstra_vendor/networkx/readwrite/json_graph/tree.py +0 -137
- package/runtime/python/okstra_vendor/networkx/readwrite/leda.py +0 -108
- package/runtime/python/okstra_vendor/networkx/readwrite/multiline_adjlist.py +0 -393
- package/runtime/python/okstra_vendor/networkx/readwrite/p2g.py +0 -113
- package/runtime/python/okstra_vendor/networkx/readwrite/pajek.py +0 -286
- package/runtime/python/okstra_vendor/networkx/readwrite/sparse6.py +0 -379
- package/runtime/python/okstra_vendor/networkx/readwrite/text.py +0 -851
- package/runtime/python/okstra_vendor/networkx/relabel.py +0 -285
- package/runtime/python/okstra_vendor/networkx/utils/__init__.py +0 -8
- package/runtime/python/okstra_vendor/networkx/utils/backends.py +0 -2171
- package/runtime/python/okstra_vendor/networkx/utils/configs.py +0 -396
- package/runtime/python/okstra_vendor/networkx/utils/decorators.py +0 -1233
- package/runtime/python/okstra_vendor/networkx/utils/heaps.py +0 -338
- package/runtime/python/okstra_vendor/networkx/utils/mapped_queue.py +0 -297
- package/runtime/python/okstra_vendor/networkx/utils/misc.py +0 -703
- package/runtime/python/okstra_vendor/networkx/utils/random_sequence.py +0 -198
- package/runtime/python/okstra_vendor/networkx/utils/rcm.py +0 -159
- package/runtime/python/okstra_vendor/networkx/utils/union_find.py +0 -106
- package/runtime/skills/okstra-graphify/SKILL.md +0 -169
- package/src/commands/graphify.mjs +0 -32
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
"""Swap edges in a graph."""
|
|
2
|
-
|
|
3
|
-
import math
|
|
4
|
-
|
|
5
|
-
import networkx as nx
|
|
6
|
-
from networkx.utils import py_random_state
|
|
7
|
-
|
|
8
|
-
__all__ = ["double_edge_swap", "connected_double_edge_swap", "directed_edge_swap"]
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
@nx.utils.not_implemented_for("undirected")
|
|
12
|
-
@py_random_state(3)
|
|
13
|
-
@nx._dispatchable(mutates_input=True, returns_graph=True)
|
|
14
|
-
def directed_edge_swap(G, *, nswap=1, max_tries=100, seed=None):
|
|
15
|
-
"""Swap three edges in a directed graph while keeping the node degrees fixed.
|
|
16
|
-
|
|
17
|
-
A directed edge swap swaps three edges such that a -> b -> c -> d becomes
|
|
18
|
-
a -> c -> b -> d. This pattern of swapping allows all possible states with the
|
|
19
|
-
same in- and out-degree distribution in a directed graph to be reached.
|
|
20
|
-
|
|
21
|
-
If the swap would create parallel edges (e.g. if a -> c already existed in the
|
|
22
|
-
previous example), another attempt is made to find a suitable trio of edges.
|
|
23
|
-
|
|
24
|
-
Parameters
|
|
25
|
-
----------
|
|
26
|
-
G : DiGraph
|
|
27
|
-
A directed graph
|
|
28
|
-
|
|
29
|
-
nswap : integer (optional, default=1)
|
|
30
|
-
Number of three-edge (directed) swaps to perform
|
|
31
|
-
|
|
32
|
-
max_tries : integer (optional, default=100)
|
|
33
|
-
Maximum number of attempts to swap edges
|
|
34
|
-
|
|
35
|
-
seed : integer, random_state, or None (default)
|
|
36
|
-
Indicator of random number generation state.
|
|
37
|
-
See :ref:`Randomness<randomness>`.
|
|
38
|
-
|
|
39
|
-
Returns
|
|
40
|
-
-------
|
|
41
|
-
G : DiGraph
|
|
42
|
-
The graph after the edges are swapped.
|
|
43
|
-
|
|
44
|
-
Raises
|
|
45
|
-
------
|
|
46
|
-
NetworkXError
|
|
47
|
-
If `G` is not directed, or
|
|
48
|
-
If nswap > max_tries, or
|
|
49
|
-
If there are fewer than 4 nodes or 3 edges in `G`.
|
|
50
|
-
NetworkXAlgorithmError
|
|
51
|
-
If the number of swap attempts exceeds `max_tries` before `nswap` swaps are made
|
|
52
|
-
|
|
53
|
-
Notes
|
|
54
|
-
-----
|
|
55
|
-
Does not enforce any connectivity constraints.
|
|
56
|
-
|
|
57
|
-
The graph G is modified in place.
|
|
58
|
-
|
|
59
|
-
A later swap is allowed to undo a previous swap.
|
|
60
|
-
|
|
61
|
-
References
|
|
62
|
-
----------
|
|
63
|
-
.. [1] Erdős, Péter L., et al. “A Simple Havel-Hakimi Type Algorithm to Realize
|
|
64
|
-
Graphical Degree Sequences of Directed Graphs.” ArXiv:0905.4913 [Math],
|
|
65
|
-
Jan. 2010. https://doi.org/10.48550/arXiv.0905.4913.
|
|
66
|
-
Published 2010 in Elec. J. Combinatorics (17(1)). R66.
|
|
67
|
-
http://www.combinatorics.org/Volume_17/PDF/v17i1r66.pdf
|
|
68
|
-
.. [2] “Combinatorics - Reaching All Possible Simple Directed Graphs with a given
|
|
69
|
-
Degree Sequence with 2-Edge Swaps.” Mathematics Stack Exchange,
|
|
70
|
-
https://math.stackexchange.com/questions/22272/. Accessed 30 May 2022.
|
|
71
|
-
"""
|
|
72
|
-
if nswap > max_tries:
|
|
73
|
-
raise nx.NetworkXError("Number of swaps > number of tries allowed.")
|
|
74
|
-
if len(G) < 4:
|
|
75
|
-
raise nx.NetworkXError("DiGraph has fewer than four nodes.")
|
|
76
|
-
if len(G.edges) < 3:
|
|
77
|
-
raise nx.NetworkXError("DiGraph has fewer than 3 edges")
|
|
78
|
-
|
|
79
|
-
# Instead of choosing uniformly at random from a generated edge list,
|
|
80
|
-
# this algorithm chooses nonuniformly from the set of nodes with
|
|
81
|
-
# probability weighted by degree.
|
|
82
|
-
tries = 0
|
|
83
|
-
swapcount = 0
|
|
84
|
-
keys, degrees = zip(*G.degree()) # keys, degree
|
|
85
|
-
cdf = nx.utils.cumulative_distribution(degrees) # cdf of degree
|
|
86
|
-
discrete_sequence = nx.utils.discrete_sequence
|
|
87
|
-
|
|
88
|
-
while swapcount < nswap:
|
|
89
|
-
# choose source node index from discrete distribution
|
|
90
|
-
start_index = discrete_sequence(1, cdistribution=cdf, seed=seed)[0]
|
|
91
|
-
start = keys[start_index]
|
|
92
|
-
tries += 1
|
|
93
|
-
|
|
94
|
-
if tries > max_tries:
|
|
95
|
-
msg = f"Maximum number of swap attempts ({tries}) exceeded before desired swaps achieved ({nswap})."
|
|
96
|
-
raise nx.NetworkXAlgorithmError(msg)
|
|
97
|
-
|
|
98
|
-
# If the given node doesn't have any out edges, then there isn't anything to swap
|
|
99
|
-
if G.out_degree(start) == 0:
|
|
100
|
-
continue
|
|
101
|
-
second = seed.choice(list(G.succ[start]))
|
|
102
|
-
if start == second:
|
|
103
|
-
continue
|
|
104
|
-
|
|
105
|
-
if G.out_degree(second) == 0:
|
|
106
|
-
continue
|
|
107
|
-
third = seed.choice(list(G.succ[second]))
|
|
108
|
-
if second == third:
|
|
109
|
-
continue
|
|
110
|
-
|
|
111
|
-
if G.out_degree(third) == 0:
|
|
112
|
-
continue
|
|
113
|
-
fourth = seed.choice(list(G.succ[third]))
|
|
114
|
-
if third == fourth:
|
|
115
|
-
continue
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
third not in G.succ[start]
|
|
119
|
-
and fourth not in G.succ[second]
|
|
120
|
-
and second not in G.succ[third]
|
|
121
|
-
):
|
|
122
|
-
# Swap nodes
|
|
123
|
-
G.add_edge(start, third)
|
|
124
|
-
G.add_edge(third, second)
|
|
125
|
-
G.add_edge(second, fourth)
|
|
126
|
-
G.remove_edge(start, second)
|
|
127
|
-
G.remove_edge(second, third)
|
|
128
|
-
G.remove_edge(third, fourth)
|
|
129
|
-
swapcount += 1
|
|
130
|
-
|
|
131
|
-
return G
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
@py_random_state(3)
|
|
135
|
-
@nx._dispatchable(mutates_input=True, returns_graph=True)
|
|
136
|
-
def double_edge_swap(G, nswap=1, max_tries=100, seed=None):
|
|
137
|
-
"""Swap two edges in the graph while keeping the node degrees fixed.
|
|
138
|
-
|
|
139
|
-
A double-edge swap removes two randomly chosen edges u-v and x-y
|
|
140
|
-
and creates the new edges u-x and v-y::
|
|
141
|
-
|
|
142
|
-
u--v u v
|
|
143
|
-
becomes | |
|
|
144
|
-
x--y x y
|
|
145
|
-
|
|
146
|
-
If either the edge u-x or v-y already exist no swap is performed
|
|
147
|
-
and another attempt is made to find a suitable edge pair.
|
|
148
|
-
|
|
149
|
-
Parameters
|
|
150
|
-
----------
|
|
151
|
-
G : graph
|
|
152
|
-
An undirected graph
|
|
153
|
-
|
|
154
|
-
nswap : integer (optional, default=1)
|
|
155
|
-
Number of double-edge swaps to perform
|
|
156
|
-
|
|
157
|
-
max_tries : integer (optional)
|
|
158
|
-
Maximum number of attempts to swap edges
|
|
159
|
-
|
|
160
|
-
seed : integer, random_state, or None (default)
|
|
161
|
-
Indicator of random number generation state.
|
|
162
|
-
See :ref:`Randomness<randomness>`.
|
|
163
|
-
|
|
164
|
-
Returns
|
|
165
|
-
-------
|
|
166
|
-
G : graph
|
|
167
|
-
The graph after double edge swaps.
|
|
168
|
-
|
|
169
|
-
Raises
|
|
170
|
-
------
|
|
171
|
-
NetworkXError
|
|
172
|
-
If `G` is directed, or
|
|
173
|
-
If `nswap` > `max_tries`, or
|
|
174
|
-
If there are fewer than 4 nodes or 2 edges in `G`.
|
|
175
|
-
NetworkXAlgorithmError
|
|
176
|
-
If the number of swap attempts exceeds `max_tries` before `nswap` swaps are made
|
|
177
|
-
|
|
178
|
-
Notes
|
|
179
|
-
-----
|
|
180
|
-
Does not enforce any connectivity constraints.
|
|
181
|
-
|
|
182
|
-
The graph G is modified in place.
|
|
183
|
-
"""
|
|
184
|
-
if G.is_directed():
|
|
185
|
-
raise nx.NetworkXError(
|
|
186
|
-
"double_edge_swap() not defined for directed graphs. Use directed_edge_swap instead."
|
|
187
|
-
)
|
|
188
|
-
if nswap > max_tries:
|
|
189
|
-
raise nx.NetworkXError("Number of swaps > number of tries allowed.")
|
|
190
|
-
if len(G) < 4:
|
|
191
|
-
raise nx.NetworkXError("Graph has fewer than four nodes.")
|
|
192
|
-
if len(G.edges) < 2:
|
|
193
|
-
raise nx.NetworkXError("Graph has fewer than 2 edges")
|
|
194
|
-
# Instead of choosing uniformly at random from a generated edge list,
|
|
195
|
-
# this algorithm chooses nonuniformly from the set of nodes with
|
|
196
|
-
# probability weighted by degree.
|
|
197
|
-
n = 0
|
|
198
|
-
swapcount = 0
|
|
199
|
-
keys, degrees = zip(*G.degree()) # keys, degree
|
|
200
|
-
cdf = nx.utils.cumulative_distribution(degrees) # cdf of degree
|
|
201
|
-
discrete_sequence = nx.utils.discrete_sequence
|
|
202
|
-
while swapcount < nswap:
|
|
203
|
-
# if random.random() < 0.5: continue # trick to avoid periodicities?
|
|
204
|
-
# pick two random edges without creating edge list
|
|
205
|
-
# choose source node indices from discrete distribution
|
|
206
|
-
(ui, xi) = discrete_sequence(2, cdistribution=cdf, seed=seed)
|
|
207
|
-
if ui == xi:
|
|
208
|
-
continue # same source, skip
|
|
209
|
-
u = keys[ui] # convert index to label
|
|
210
|
-
x = keys[xi]
|
|
211
|
-
# choose target uniformly from neighbors
|
|
212
|
-
v = seed.choice(list(G[u]))
|
|
213
|
-
y = seed.choice(list(G[x]))
|
|
214
|
-
if v == y:
|
|
215
|
-
continue # same target, skip
|
|
216
|
-
if (x not in G[u]) and (y not in G[v]): # don't create parallel edges
|
|
217
|
-
G.add_edge(u, x)
|
|
218
|
-
G.add_edge(v, y)
|
|
219
|
-
G.remove_edge(u, v)
|
|
220
|
-
G.remove_edge(x, y)
|
|
221
|
-
swapcount += 1
|
|
222
|
-
if n >= max_tries:
|
|
223
|
-
e = (
|
|
224
|
-
f"Maximum number of swap attempts ({n}) exceeded "
|
|
225
|
-
f"before desired swaps achieved ({nswap})."
|
|
226
|
-
)
|
|
227
|
-
raise nx.NetworkXAlgorithmError(e)
|
|
228
|
-
n += 1
|
|
229
|
-
return G
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
@py_random_state(3)
|
|
233
|
-
@nx._dispatchable(mutates_input=True)
|
|
234
|
-
def connected_double_edge_swap(G, nswap=1, _window_threshold=3, seed=None):
|
|
235
|
-
"""Attempts the specified number of double-edge swaps in the graph `G`.
|
|
236
|
-
|
|
237
|
-
A double-edge swap removes two randomly chosen edges `(u, v)` and `(x,
|
|
238
|
-
y)` and creates the new edges `(u, x)` and `(v, y)`::
|
|
239
|
-
|
|
240
|
-
u--v u v
|
|
241
|
-
becomes | |
|
|
242
|
-
x--y x y
|
|
243
|
-
|
|
244
|
-
If either `(u, x)` or `(v, y)` already exist, then no swap is performed
|
|
245
|
-
so the actual number of swapped edges is always *at most* `nswap`.
|
|
246
|
-
|
|
247
|
-
Parameters
|
|
248
|
-
----------
|
|
249
|
-
G : graph
|
|
250
|
-
An undirected graph
|
|
251
|
-
|
|
252
|
-
nswap : integer (optional, default=1)
|
|
253
|
-
Number of double-edge swaps to perform
|
|
254
|
-
|
|
255
|
-
_window_threshold : integer
|
|
256
|
-
|
|
257
|
-
The window size below which connectedness of the graph will be checked
|
|
258
|
-
after each swap.
|
|
259
|
-
|
|
260
|
-
The "window" in this function is a dynamically updated integer that
|
|
261
|
-
represents the number of swap attempts to make before checking if the
|
|
262
|
-
graph remains connected. It is an optimization used to decrease the
|
|
263
|
-
running time of the algorithm in exchange for increased complexity of
|
|
264
|
-
implementation.
|
|
265
|
-
|
|
266
|
-
If the window size is below this threshold, then the algorithm checks
|
|
267
|
-
after each swap if the graph remains connected by checking if there is a
|
|
268
|
-
path joining the two nodes whose edge was just removed. If the window
|
|
269
|
-
size is above this threshold, then the algorithm performs do all the
|
|
270
|
-
swaps in the window and only then check if the graph is still connected.
|
|
271
|
-
|
|
272
|
-
seed : integer, random_state, or None (default)
|
|
273
|
-
Indicator of random number generation state.
|
|
274
|
-
See :ref:`Randomness<randomness>`.
|
|
275
|
-
|
|
276
|
-
Returns
|
|
277
|
-
-------
|
|
278
|
-
int
|
|
279
|
-
The number of successful swaps
|
|
280
|
-
|
|
281
|
-
Raises
|
|
282
|
-
------
|
|
283
|
-
|
|
284
|
-
NetworkXError
|
|
285
|
-
|
|
286
|
-
If the input graph is not connected, or if the graph has fewer than four
|
|
287
|
-
nodes.
|
|
288
|
-
|
|
289
|
-
Notes
|
|
290
|
-
-----
|
|
291
|
-
|
|
292
|
-
The initial graph `G` must be connected, and the resulting graph is
|
|
293
|
-
connected. The graph `G` is modified in place.
|
|
294
|
-
|
|
295
|
-
References
|
|
296
|
-
----------
|
|
297
|
-
.. [1] C. Gkantsidis and M. Mihail and E. Zegura,
|
|
298
|
-
The Markov chain simulation method for generating connected
|
|
299
|
-
power law random graphs, 2003.
|
|
300
|
-
http://citeseer.ist.psu.edu/gkantsidis03markov.html
|
|
301
|
-
"""
|
|
302
|
-
if not nx.is_connected(G):
|
|
303
|
-
raise nx.NetworkXError("Graph not connected")
|
|
304
|
-
if len(G) < 4:
|
|
305
|
-
raise nx.NetworkXError("Graph has fewer than four nodes.")
|
|
306
|
-
n = 0
|
|
307
|
-
swapcount = 0
|
|
308
|
-
deg = G.degree()
|
|
309
|
-
# Label key for nodes
|
|
310
|
-
dk = [n for n, d in G.degree()]
|
|
311
|
-
cdf = nx.utils.cumulative_distribution([d for n, d in G.degree()])
|
|
312
|
-
discrete_sequence = nx.utils.discrete_sequence
|
|
313
|
-
window = 1
|
|
314
|
-
while n < nswap:
|
|
315
|
-
wcount = 0
|
|
316
|
-
swapped = []
|
|
317
|
-
# If the window is small, we just check each time whether the graph is
|
|
318
|
-
# connected by checking if the nodes that were just separated are still
|
|
319
|
-
# connected.
|
|
320
|
-
if window < _window_threshold:
|
|
321
|
-
# This Boolean keeps track of whether there was a failure or not.
|
|
322
|
-
fail = False
|
|
323
|
-
while wcount < window and n < nswap:
|
|
324
|
-
# Pick two random edges without creating the edge list. Choose
|
|
325
|
-
# source nodes from the discrete degree distribution.
|
|
326
|
-
(ui, xi) = discrete_sequence(2, cdistribution=cdf, seed=seed)
|
|
327
|
-
# If the source nodes are the same, skip this pair.
|
|
328
|
-
if ui == xi:
|
|
329
|
-
continue
|
|
330
|
-
# Convert an index to a node label.
|
|
331
|
-
u = dk[ui]
|
|
332
|
-
x = dk[xi]
|
|
333
|
-
# Choose targets uniformly from neighbors.
|
|
334
|
-
v = seed.choice(list(G.neighbors(u)))
|
|
335
|
-
y = seed.choice(list(G.neighbors(x)))
|
|
336
|
-
# If the target nodes are the same, skip this pair.
|
|
337
|
-
if v == y:
|
|
338
|
-
continue
|
|
339
|
-
if x not in G[u] and y not in G[v]:
|
|
340
|
-
G.remove_edge(u, v)
|
|
341
|
-
G.remove_edge(x, y)
|
|
342
|
-
G.add_edge(u, x)
|
|
343
|
-
G.add_edge(v, y)
|
|
344
|
-
swapped.append((u, v, x, y))
|
|
345
|
-
swapcount += 1
|
|
346
|
-
n += 1
|
|
347
|
-
# If G remains connected...
|
|
348
|
-
if nx.has_path(G, u, v):
|
|
349
|
-
wcount += 1
|
|
350
|
-
# Otherwise, undo the changes.
|
|
351
|
-
else:
|
|
352
|
-
G.add_edge(u, v)
|
|
353
|
-
G.add_edge(x, y)
|
|
354
|
-
G.remove_edge(u, x)
|
|
355
|
-
G.remove_edge(v, y)
|
|
356
|
-
swapcount -= 1
|
|
357
|
-
fail = True
|
|
358
|
-
# If one of the swaps failed, reduce the window size.
|
|
359
|
-
if fail:
|
|
360
|
-
window = math.ceil(window / 2)
|
|
361
|
-
else:
|
|
362
|
-
window += 1
|
|
363
|
-
# If the window is large, then there is a good chance that a bunch of
|
|
364
|
-
# swaps will work. It's quicker to do all those swaps first and then
|
|
365
|
-
# check if the graph remains connected.
|
|
366
|
-
else:
|
|
367
|
-
while wcount < window and n < nswap:
|
|
368
|
-
# Pick two random edges without creating the edge list. Choose
|
|
369
|
-
# source nodes from the discrete degree distribution.
|
|
370
|
-
(ui, xi) = discrete_sequence(2, cdistribution=cdf, seed=seed)
|
|
371
|
-
# If the source nodes are the same, skip this pair.
|
|
372
|
-
if ui == xi:
|
|
373
|
-
continue
|
|
374
|
-
# Convert an index to a node label.
|
|
375
|
-
u = dk[ui]
|
|
376
|
-
x = dk[xi]
|
|
377
|
-
# Choose targets uniformly from neighbors.
|
|
378
|
-
v = seed.choice(list(G.neighbors(u)))
|
|
379
|
-
y = seed.choice(list(G.neighbors(x)))
|
|
380
|
-
# If the target nodes are the same, skip this pair.
|
|
381
|
-
if v == y:
|
|
382
|
-
continue
|
|
383
|
-
if x not in G[u] and y not in G[v]:
|
|
384
|
-
G.remove_edge(u, v)
|
|
385
|
-
G.remove_edge(x, y)
|
|
386
|
-
G.add_edge(u, x)
|
|
387
|
-
G.add_edge(v, y)
|
|
388
|
-
swapped.append((u, v, x, y))
|
|
389
|
-
swapcount += 1
|
|
390
|
-
n += 1
|
|
391
|
-
wcount += 1
|
|
392
|
-
# If the graph remains connected, increase the window size.
|
|
393
|
-
if nx.is_connected(G):
|
|
394
|
-
window += 1
|
|
395
|
-
# Otherwise, undo the changes from the previous window and decrease
|
|
396
|
-
# the window size.
|
|
397
|
-
else:
|
|
398
|
-
while swapped:
|
|
399
|
-
(u, v, x, y) = swapped.pop()
|
|
400
|
-
G.add_edge(u, v)
|
|
401
|
-
G.add_edge(x, y)
|
|
402
|
-
G.remove_edge(u, x)
|
|
403
|
-
G.remove_edge(v, y)
|
|
404
|
-
swapcount -= 1
|
|
405
|
-
window = math.ceil(window / 2)
|
|
406
|
-
return swapcount
|