Ticket #7292: trac_7292-2.patch

File trac_7292-2.patch, 3.7 KB (added by ncohen, 11 years ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1263110446 -3600
    # Node ID c3476e402067cb921f152112f9d9d6dbb0129e74
    # Parent  8d74bf796c54840b797ad8dbab525af0a8c5ffe3
    edge/vertex-disjoint paths in Graphs
    
    diff -r 8d74bf796c54 -r c3476e402067 sage/graphs/generic_graph.py
    a b  
    20692069
    20702070        # All the edges from self are doubled in O
    20712071        # ( one in each direction )
     2072        from sage.graphs.digraph import DiGraph
    20722073        O = DiGraph(self)
    20732074
    20742075        # Builds the list of edges that should be removed
     
    34593460            3
    34603461            sage: (u,v,l) = cycle.edge_iterator().next()
    34613462            sage: u in feedback or v in feedback              # optional - requires GLPK or CBC
     3463            True
    34623464           
    34633465        For a circuit, the minimum feedback arc set is clearly `1` ::
    34643466
     
    38063808
    38073809        return [obj,flow_graph]
    38083810
     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
    38093892    def matching(self,value_only=False, use_edge_labels=True):
    38103893        r"""
    38113894        Returns a maximum weighted matching of the graph