networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersRaisesReturns
connected_double_edge_swap(G, nswap=1, _window_threshold=3, seed=None)

A double-edge swap removes two randomly chosen edges :None:None:`(u, v)` and :None:None:`(x, y)` and creates the new edges :None:None:`(u, x)` and :None:None:`(v, y)`:

u--v            u  v
       becomes  |  |
x--y            x  y

If either :None:None:`(u, x)` or :None:None:`(v, y)` already exist, then no swap is performed so the actual number of swapped edges is always at most :None:None:`nswap`.

Notes

The initial graph G must be connected, and the resulting graph is connected. The graph G is modified in place.

Parameters

G : graph

An undirected graph

nswap : integer (optional, default=1)

Number of double-edge swaps to perform

_window_threshold : integer

The window size below which connectedness of the graph will be checked after each swap.

The "window" in this function is a dynamically updated integer that represents the number of swap attempts to make before checking if the graph remains connected. It is an optimization used to decrease the running time of the algorithm in exchange for increased complexity of implementation.

If the window size is below this threshold, then the algorithm checks after each swap if the graph remains connected by checking if there is a path joining the two nodes whose edge was just removed. If the window size is above this threshold, then the algorithm performs do all the swaps in the window and only then check if the graph is still connected.

seed : integer, random_state, or None (default)

Indicator of random number generation state. See Randomness<randomness> .

Raises

NetworkXError

If the input graph is not connected, or if the graph has fewer than four nodes.

Returns

int

The number of successful swaps

Attempts the specified number of double-edge swaps in the graph G.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/swap.py#96
type: <class 'function'>
Commit: