| 3811 | def edge_disjoint_paths(self, s, t): |
| 3812 | r""" |
| 3813 | Returns a list of edge-disjoint paths between two |
| 3814 | vertices as given by Menger's theorem. |
| 3815 | |
| 3816 | The edge version of Menger's theorem asserts that the size |
| 3817 | of the minimum edge cut between two vertices `s` and`t` |
| 3818 | (the minimum number of edges whose removal disconnects `s` |
| 3819 | and `t`) is equal to the maximum number of pairwise |
| 3820 | edge-independent paths from `s` to `t`. |
| 3821 | |
| 3822 | This function returns a list of such paths. |
| 3823 | |
| 3824 | NOTE: |
| 3825 | |
| 3826 | This function is topological : it does not take the eventual |
| 3827 | weights of the edges into account. |
| 3828 | |
| 3829 | EXAMPLE: |
| 3830 | |
| 3831 | In a complete bipartite graph :: |
| 3832 | |
| 3833 | sage: g = graphs.CompleteBipartiteGraph(2,3) |
| 3834 | sage: g.edge_disjoint_paths(0,1) # optional - requires GLPK or CBC |
| 3835 | [[0, 2, 1], [0, 3, 1], [0, 4, 1]] |
| 3836 | """ |
| 3837 | |
| 3838 | [obj, flow_graph] = self.flow(s,t,value_only=False, integer=True, use_edge_labels=False) |
| 3839 | |
| 3840 | paths = [] |
| 3841 | |
| 3842 | while True: |
| 3843 | path = flow_graph.shortest_path(s,t) |
| 3844 | if not path: |
| 3845 | break |
| 3846 | v = s |
| 3847 | edges = [] |
| 3848 | for w in path: |
| 3849 | edges.append((v,w)) |
| 3850 | v=w |
| 3851 | flow_graph.delete_edges(edges) |
| 3852 | paths.append(path) |
| 3853 | |
| 3854 | return paths |
| 3855 | |
| 3856 | def vertex_disjoint_paths(self, s, t): |
| 3857 | r""" |
| 3858 | Returns a list of vertex-disjoint paths between two |
| 3859 | vertices as given by Menger's theorem. |
| 3860 | |
| 3861 | The vertex version of Menger's theorem asserts that the size |
| 3862 | of the minimum vertex cut between two vertices `s` and`t` |
| 3863 | (the minimum number of vertices whose removal disconnects `s` |
| 3864 | and `t`) is equal to the maximum number of pairwise |
| 3865 | vertex-independent paths from `s` to `t`. |
| 3866 | |
| 3867 | This function returns a list of such paths. |
| 3868 | |
| 3869 | EXAMPLE: |
| 3870 | |
| 3871 | In a complete bipartite graph :: |
| 3872 | |
| 3873 | sage: g = graphs.CompleteBipartiteGraph(2,3) |
| 3874 | sage: g.vertex_disjoint_paths(0,1) # optional - requires GLPK or CBC |
| 3875 | [[0, 2, 1], [0, 3, 1], [0, 4, 1]] |
| 3876 | """ |
| 3877 | |
| 3878 | [obj, flow_graph] = self.flow(s,t,value_only=False, integer=True, use_edge_labels=False, vertex_bound=True) |
| 3879 | |
| 3880 | paths = [] |
| 3881 | |
| 3882 | while True: |
| 3883 | path = flow_graph.shortest_path(s,t) |
| 3884 | if not path: |
| 3885 | break |
| 3886 | flow_graph.delete_vertices(path[1:-1]) |
| 3887 | paths.append(path) |
| 3888 | |
| 3889 | return paths |
| 3890 | |
| 3891 | |