NetworkX

Previous topic

networkx.algorithms.cycles.simple_cycles

Next topic

networkx.algorithms.cycles.simple_cycles

networkx.algorithms.cycles.cycle_basis

networkx.algorithms.cycles.cycle_basis(G, root=None)

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

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.

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. :

See also

simple_cycles

Notes

This is adapted from algorithm CACM 491 [R114].

References

[R114](1, 2) Paton, K. An algorithm for finding a fundamental set of cycles of a graph. Comm. ACM 12, 9 (Sept 1969), 514-518.

Examples

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