# HG changeset patch
# User Nathann Cohen
# Date 1260888265 -3600
# Node ID 12e224b8b44dc3d7de154c2d4127fe80eb295842
# Parent 1d7f8f66bbd069169b8f3d4f5083e06b64336ee5
edge_disjoint and vertex_disjoint paths
diff -r 1d7f8f66bbd0 -r 12e224b8b44d sage/graphs/graph.py
--- a/sage/graphs/graph.py Wed Dec 16 01:46:31 2009 +0100
+++ b/sage/graphs/graph.py Tue Dec 15 15:44:25 2009 +0100
@@ -3428,6 +3428,85 @@
return [obj,flow_graph]
+ def edge_disjoint_paths(self, s, t):
+ r"""
+ Returns a list of edge-disjoint paths between two
+ vertices as given by Menger's theorem.
+
+ The edge version of Menger's theorem asserts that the size
+ of the minimum edge cut between two vertices `s` and`t`
+ (the minimum number of edges whose removal disconnects `s`
+ and `t`) is equal to the maximum number of pairwise
+ edge-independent paths from `s` to `t`.
+
+ This function returns a list of such paths.
+
+ NOTE:
+
+ This function is topological : it does not take the eventual
+ weights of the edges into account.
+
+ EXAMPLE:
+
+ In a complete bipartite graph ::
+
+ sage: g = graphs.CompleteBipartiteGraph(2,3)
+ sage: g.edge_disjoint_paths(0,1) # optional - requires GLPK or CBC
+ [[0, 2, 1], [0, 3, 1], [0, 4, 1]]
+ """
+
+ [obj, flow_graph] = self.flow(s,t,value_only=False, integer=True, use_edge_labels=False)
+
+ paths = []
+
+ while True:
+ path = flow_graph.shortest_path(s,t)
+ if not path:
+ break
+ v = s
+ edges = []
+ for w in path:
+ edges.append((v,w))
+ v=w
+ flow_graph.delete_edges(edges)
+ paths.append(path)
+
+ return paths
+
+ def vertex_disjoint_paths(self, s, t):
+ r"""
+ Returns a list of vertex-disjoint paths between two
+ vertices as given by Menger's theorem.
+
+ The vertex version of Menger's theorem asserts that the size
+ of the minimum vertex cut between two vertices `s` and`t`
+ (the minimum number of vertices whose removal disconnects `s`
+ and `t`) is equal to the maximum number of pairwise
+ vertex-independent paths from `s` to `t`.
+
+ This function returns a list of such paths.
+
+ EXAMPLE:
+
+ In a complete bipartite graph ::
+
+ sage: g = graphs.CompleteBipartiteGraph(2,3)
+ sage: g.vertex_disjoint_paths(0,1) # optional - requires GLPK or CBC
+ [[0, 2, 1], [0, 3, 1], [0, 4, 1]]
+ """
+
+ [obj, flow_graph] = self.flow(s,t,value_only=False, integer=True, use_edge_labels=False, vertex_bound=True)
+
+ paths = []
+
+ while True:
+ path = flow_graph.shortest_path(s,t)
+ if not path:
+ break
+ flow_graph.delete_vertices(path[1:-1])
+ paths.append(path)
+
+ return paths
### Vertex handlers