Ticket #7292: trac_7292.patch

File trac_7292.patch, 3.0 KB (added by ncohen, 11 years ago)
• sage/graphs/graph.py

```# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1260888265 -3600
# Node ID 12e224b8b44dc3d7de154c2d4127fe80eb295842
# Parent  1d7f8f66bbd069169b8f3d4f5083e06b64336ee5
edge_disjoint and vertex_disjoint paths

diff -r 1d7f8f66bbd0 -r 12e224b8b44d sage/graphs/graph.py```
 a 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