networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturns
sample_spanning_tree(G, lambda_key, seed=None)

The edge weights are multiplicative, so the probability of each tree is proportional to the product of edge weights.

The algorithm itself uses algorithm A8 in .

We 'shuffle' the edges in the graph, and then probabilistically determine weather to add the edge conditioned on all of the previous edges which where added to the tree. Probabilities are calculated using Kirchhoff's Matrix Tree Theorem and a weighted Laplacian matrix.

At each iteration, we contract the edges we have decided to include in the sampled tree and delete those which we have decided not to include.

Parameters

G : nx.Graph

An undirected version of the original graph.

lambda_key : string

The edge key for the edge attribute holding edge weight.

seed : integer, random_state, or None (default)

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

Returns

nx.Graph

A spanning tree using the distribution defined by :None:None:`gamma`.

Sample a spanning tree using the edges weights of the graph.

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/approximation/traveling_salesman.py#944
type: <class 'function'>
Commit: