Ask Your Question

Revision history [back]

There seem not to be an existing method in Sage for doing that out of the box, so you should write your own algorithm. If you are lazy, you can still use the following slow brute force method, depending on the size of your graph:

sage: G = graphs.PetersenGraph()
sage: allp = G.all_paths(0,4)
sage: m = min(len(p) for p in allp) ; m
2
sage: [p for p in allp if len(p) == m]
[[0, 4]]

There seem not to be an existing method in Sage for doing that out of the box, so you should write your own algorithm. If you are lazy, you can still use the following slow brute force method, depending on the size of your graph:

sage: G = graphs.PetersenGraph()
graphs.GrotzschGraph()
sage: allp = G.all_paths(0,4)
G.all_paths(1,4)
sage: m = min(len(p) for p in allp) ; m
2
sage: [p for p in allp if len(p) == m]
[[0, [[1, 0, 4], [1, 10, 4]]

There seem not to be an existing method in Sage for doing that out of the box, so you should write your own algorithm. If you are lazy, you can still use the following slow brute force method, depending on the size of your graph:

sage: G = graphs.GrotzschGraph()
sage: allp = G.all_paths(1,4)
sage: m = min(len(p) for p in allp) ; m
2
3
sage: [p for p in allp if len(p) == m]
[[1, 0, 4], [1, 10, 4]]