Ticket #7854: trac_7854.patch

File trac_7854.patch, 5.4 KB (added by ncohen, 11 years ago)
  • sage/graphs/generic_graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1263661219 -3600
    # Node ID 44726155b3d1b768675926d29b71c820717b6db3
    # Parent  9491c46f86b19b985e09d32609207845783fddba
    ticket #7854 : small modifications to edge_connectivity for graphs
    
    diff -r 9491c46f86b1 -r 44726155b3d1 sage/graphs/generic_graph.py
    a b  
    40384038            b=p.get_values(b)
    40394039            return [v for v in g.vertices() if b[v]==1]
    40404040
    4041     def edge_connectivity(self,value_only=True,use_edge_labels=True, vertices=False):
     4041    def edge_connectivity(self,value_only=True,use_edge_labels=False, vertices=False):
    40424042        r"""
    40434043        Returns the edge connectivity of the graph
    40444044        ( cf. http://en.wikipedia.org/wiki/Connectivity_(graph_theory) )
     
    40694069   
    40704070        EXAMPLE:
    40714071
    4072         A basic application on the PappusGraph()
     4072        A basic application on the PappusGraph::
    40734073       
    40744074           sage: g = graphs.PappusGraph()
    40754075           sage: g.edge_connectivity() # optional - requires Glpk or COIN-OR/CBC
     
    41064106           sage: tree.add_edges(g.min_spanning_tree())
    41074107           sage: for u,v in tree.edge_iterator(labels=None):
    41084108           ...        tree.set_edge_label(u,v,random())
    4109            sage: minimum = min([l for u,v,l in tree.edge_iterator()])                 # optional - requires Glpk or COIN-OR/CBC
    4110            sage: [value, [(u,v,l)]] = tree.edge_connectivity(value_only=False)        # optional - requires Glpk or COIN-OR/CBC
    4111            sage: l == minimum                                                         # optional - requires Glpk or COIN-OR/CBC
     4109           sage: minimum = min([l for u,v,l in tree.edge_iterator()])                                       # optional - requires Glpk or COIN-OR/CBC
     4110           sage: [value, [(u,v,l)]] = tree.edge_connectivity(value_only=False, use_edge_labels=True)        # optional - requires Glpk or COIN-OR/CBC
     4111           sage: l == minimum                                                                               # optional - requires Glpk or COIN-OR/CBC
    41124112           True
     4113
     4114        When ``value_only = True``, this function is optimized for small
     4115        connexity values and does not need to build a linear program.
     4116
     4117        It is the case for connected graphs which are not
     4118        connected ::
     4119       
     4120           sage: g = 2 * graphs.PetersenGraph()
     4121           sage: g.edge_connectivity()
     4122           0.0
     4123
     4124        Or if they are just 1-connected ::
     4125
     4126           sage: g = graphs.PathGraph(10)
     4127           sage: g.edge_connectivity()
     4128           1.0
     4129
     4130        For directed graphs, the strong connexity is tested
     4131        through the dedicated function ::
     4132
     4133           sage: g = digraphs.ButterflyGraph(3)
     4134           sage: g.edge_connectivity()
     4135           0.0
    41134136        """
    41144137        g=self
    41154138
     
    41214144        else:
    41224145            weight=lambda x: 1
    41234146
     4147
     4148        # Better methods for small connectivity tests,
     4149        # when one is not interested in cuts...
     4150        if value_only and not use_edge_labels:
     4151
     4152            if self.is_directed():
     4153                if not self.is_strongly_connected():
     4154                    return 0.0
     4155
     4156            else:
     4157                if not self.is_connected():
     4158                    return 0.0
     4159
     4160                h = self.strong_orientation()
     4161                if not h.is_strongly_connected():
     4162                    return 1.0
     4163
     4164
    41244165        if g.is_directed():
    41254166            reorder_edge = lambda x,y : (x,y)
    41264167        else:
     
    41604201        p.set_binary(in_set)
    41614202        p.set_binary(in_cut)
    41624203
    4163         p.set_objective(sum([weight(l ) * in_cut[reorder_edge(u,v)] for (u,v,l ) in g.edge_iterator()]))
     4204        p.set_objective(sum([weight(l ) * in_cut[reorder_edge(u,v)] for (u,v,l) in g.edge_iterator()]))
    41644205
    41654206        if value_only:
    41664207            return p.solve(objective_only=True)
     
    42364277           sage: [val, [cut_vertex]] = tree.vertex_connectivity(value_only=False) # optional - requires Glpk or COIN-OR/CBC
    42374278           sage: tree.degree(cut_vertex) > 1                                      # optional - requires Glpk or COIN-OR/CBC
    42384279           True
     4280
     4281        When ``value_only = True``, this function is optimized for small
     4282        connexity values and does not need to build a linear program.
     4283
     4284        It is the case for connected graphs which are not
     4285        connected ::
     4286       
     4287           sage: g = 2 * graphs.PetersenGraph()
     4288           sage: g.vertex_connectivity()
     4289           0.0
     4290
     4291        Or if they are just 1-connected ::
     4292
     4293           sage: g = graphs.PathGraph(10)
     4294           sage: g.vertex_connectivity()
     4295           1.0
     4296
     4297        For directed graphs, the strong connexity is tested
     4298        through the dedicated function ::
     4299
     4300           sage: g = digraphs.ButterflyGraph(3)
     4301           sage: g.vertex_connectivity()
     4302           0.0
     4303
    42394304        """
    42404305        g=self
    42414306
     
    42454310        if sets:
    42464311            value_only=False
    42474312
     4313        if value_only:
     4314            if self.is_directed():
     4315                if not self.is_strongly_connected():
     4316                    return 0.0
     4317
     4318            else:
     4319                if not self.is_connected():
     4320                    return 0.0
     4321
     4322                if len(self.blocks_and_cut_vertices()[0]) > 1:
     4323                    return 1.0
     4324               
     4325
    42484326        if g.is_directed():
    42494327            reorder_edge = lambda x,y : (x,y)
    42504328        else: