chordless_cycles#
- graph_tool.structure.chordless_cycles(g, max_length=0)[git][source]#
Return an iterator over the chordless cycles of the graph.
- Parameters:
- g
Graph Graph to be used.
- max_length
int(optional, default:0) If positive, only cycles with at most this number of vertices are returned.
- g
- Returns:
- cycle_iteratoriterator over
numpy.ndarray The vertices of every chordless cycle, in order.
- cycle_iteratoriterator over
See also
all_circuitsAll cycles of a directed graph
cycle_basisBasis of the cycle space
is_chordalTest for chordal graphs
Notes
A chordless (or induced) cycle has no edge between two of its vertices other than the edges of the cycle itself. Every cycle is found from its vertex of smallest index \(s\), by extending paths over vertices with larger indices, where a new vertex must not be adjacent to any vertex of the path except the last one and \(s\); a vertex adjacent to \(s\) closes the cycle. For undirected graphs, every cycle is returned once. For directed graphs, the cycles follow the edge directions, and the adjacency for the chords ignores them, so that a reciprocal pair of edges is a cycle of length two, and a chord of any longer cycle. Self-loops and parallel edges are ignored. The number of chordless cycles can grow exponentially with the size of the graph, and the search may explore paths that do not close.
Examples
>>> g = gt.lattice([3, 3]) >>> for c in gt.chordless_cycles(g): ... print(c) [0 1 2 5 8 7 6 3] [0 1 4 3] [1 2 5 4] [3 4 7 6] [4 5 8 7]