First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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]]
click to hide/show revision 2
No.2 Revision

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]]
click to hide/show revision 3
No.3 Revision

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]]