Ask Your Question

Revision history [back]

You can use the subgraph_search_iterator method:

sage: G = Graph([[0,1], [1,2], [2,3], [3,1], [2,4], [3,4], [4,5]]) 
sage: H = Graph([[0,1], [1,2], [2,3], [3,1]]) 
sage: list(G.subgraph_search_iterator(H))
[[0, 1, 2, 3],
 [0, 1, 3, 2],
 [1, 2, 3, 4],
 [1, 2, 4, 3],
 [1, 3, 2, 4],
 [1, 3, 4, 2],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1],
 [5, 4, 2, 3],
 [5, 4, 3, 2]]

Note that the order of the returned vertices is important.

Regarding cycles, you can have a look at the cycle_basis method, which gives you a compact representation of cycles:

sage: G.cycle_basis()
[[2, 3, 1], [2, 4, 3]]