networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
cycle_basis(G, root=None)

A basis for cycles of a network is a minimal collection of cycles such that any cycle in the network can be written as a sum of cycles in the basis. Here summation of cycles is defined as "exclusive or" of the edges. Cycle bases are useful, e.g. when deriving equations for electric circuits using Kirchhoff's Laws.

Notes

This is adapted from algorithm CACM 491 .

Parameters

G : NetworkX Graph
root : node, optional

Specify starting node for basis.

Returns

A list of cycle lists. Each cycle list is a list of nodes
which forms a cycle (loop) in G.

Returns a list of cycles which form a basis for cycles of G.

See Also

simple_cycles

Examples

>>> G = nx.Graph()
... nx.add_cycle(G, [0, 1, 2, 3])
... nx.add_cycle(G, [0, 3, 4, 5])
... print(nx.cycle_basis(G, 0)) [[3, 4, 5, 0], [1, 2, 3, 0]]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.cycles.minimum_cycle_basis networkx.algorithms.cycles.recursive_simple_cycles networkx.algorithms.cycles.cycle_basis networkx.algorithms.cycles.simple_cycles

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/cycles.py#21
type: <class 'function'>
Commit: