Ticket #14856: trac_14856.patch

File trac_14856.patch, 5.7 KB (added by ncohen, 7 years ago)
  • sage/graphs/base/c_graph.pyx

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1373031296 -7200
    #      Fri Jul 05 15:34:56 2013 +0200
    # Node ID 0017dc3c4f4caa5f1507eb7f86518244f13b1976
    # Parent  3e59c8cb417f7fad8175b6f0a592abbe88eaeb58
    Bug in GenericGraph.vertex_connectivity when the digraph is a tournament
    
    diff --git a/sage/graphs/base/c_graph.pyx b/sage/graphs/base/c_graph.pyx
    a b  
    26532653           False
    26542654
    26552655        A graph with non-integer vertex labels::
     2656
    26562657            sage: Graph(graphs.CubeGraph(3), implementation='c_graph').is_connected()
    26572658            True
    26582659        """
    2659         cdef int v_int = 0
    2660         v_int = bitset_first((<CGraph>self._cg).active_vertices)
     2660        cdef int v_int
     2661        cdef CGraph cg = <CGraph> self._cg
     2662
     2663        if cg.num_edges() < cg.num_verts - 1:
     2664            return False
     2665
     2666        v_int = bitset_first(cg.active_vertices)
    26612667
    26622668        if v_int == -1:
    26632669            return True
    2664         v = vertex_label(v_int, self.vertex_ints, self.vertex_labels, self._cg)
    2665         return len(list(self.depth_first_search(v, ignore_direction=True))) == (<CGraph>self._cg).num_verts
     2670        v = vertex_label(v_int, self.vertex_ints, self.vertex_labels, cg)
     2671        return len(list(self.depth_first_search(v, ignore_direction=True))) == cg.num_verts
    26662672
    26672673    def is_strongly_connected(self):
    26682674        r"""
  • sage/graphs/generic_graph.py

    diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py
    a b  
    75467546              connected. In this case, no certificate can be given as there is
    75477547              no pair of vertices split by a cut of size `k-1`. For this reason,
    75487548              the certificates returned in this situation are empty.
    7549        
    7550         INPUT:
    7551    
     7549
     7550        INPUT:
     7551
    75527552        - ``value_only`` -- boolean (default: ``True``)
    75537553
    75547554          - When set to ``True`` (default), only the value is returned.
     
    75747574          verbosity. Set to 0 by default, which means quiet.
    75757575
    75767576        EXAMPLES:
    7577        
     7577
    75787578        A basic application on a ``PappusGraph``::
    7579        
     7579
    75807580           sage: g=graphs.PappusGraph()
    75817581           sage: g.vertex_connectivity()
    75827582           3
     
    75997599           sage: tree.degree(cut_vertex) > 1
    76007600           True
    76017601
    7602         When ``value_only = True``, this function is optimized for small 
     7602        When ``value_only = True``, this function is optimized for small
    76037603        connectivity values and does not need to build a linear program.
    76047604
    7605         It is the case for connected graphs which are not
    7606         connected::
    7607        
     7605        It is the case for connected graphs which are not connected::
     7606
    76087607           sage: g = 2 * graphs.PetersenGraph()
    76097608           sage: g.vertex_connectivity()
    7610            0.0
     7609           0
    76117610
    76127611        Or if they are just 1-connected::
    76137612
    76147613           sage: g = graphs.PathGraph(10)
    76157614           sage: g.vertex_connectivity()
    7616            1.0
     7615           1
    76177616
    76187617        For directed graphs, the strong connectivity is tested
    76197618        through the dedicated function::
    76207619
    76217620           sage: g = digraphs.ButterflyGraph(3)
    76227621           sage: g.vertex_connectivity()
    7623            0.0
     7622           0
    76247623
    76257624        A complete graph on `10` vertices is `9`-connected::
    76267625
    76277626           sage: g = graphs.CompleteGraph(10)
    76287627           sage: g.vertex_connectivity()
    76297628           9
     7629
     7630        A complete digraph on `10` vertices is `9`-connected::
     7631
     7632           sage: g = DiGraph(graphs.CompleteGraph(10))
     7633           sage: g.vertex_connectivity()
     7634           9
    76307635        """
    76317636        g=self
    76327637
    76337638        if sets:
    76347639            value_only=False
    76357640
    7636         if g.is_clique():
     7641        # When the graph is complete, the MILP below is infeasible.
     7642        if ((not g.is_directed() and g.is_clique())
     7643            or
     7644            (g.is_directed() and g.size() >= (g.order()-1)*g.order() and
     7645             ((not g.allows_loops() and not g.allows_multiple_edges())
     7646              or
     7647              all(g.has_edge(u,v) for u in g for v in g if v != u)))):
    76377648            if value_only:
    76387649                return g.order()-1
    76397650            elif not sets:
     
    76447655        if value_only:
    76457656            if self.is_directed():
    76467657                if not self.is_strongly_connected():
    7647                     return 0.0
     7658                    return 0
    76487659
    76497660            else:
    76507661                if not self.is_connected():
    7651                     return 0.0
     7662                    return 0
    76527663
    76537664                if len(self.blocks_and_cut_vertices()[0]) > 1:
    7654                     return 1.0
    7655                
     7665                    return 1
    76567666
    76577667        if g.is_directed():
    76587668            reorder_edge = lambda x,y : (x,y)
    76597669        else:
    7660             reorder_edge = lambda x,y : (x,y) if x<= y else (y,x)   
     7670            reorder_edge = lambda x,y : (x,y) if x<= y else (y,x)
    76617671
    76627672        from sage.numerical.mip import MixedIntegerLinearProgram
    76637673
     
    76847694
    76857695            # Two adjacent vertices are in different sets if and only if
    76867696            # the edge between them is in the cut
    7687    
     7697
    76887698            for (u,v) in g.edge_iterator(labels=None):
    76897699                p.add_constraint(in_set[0][u]+in_set[2][v],max=1)
    76907700                p.add_constraint(in_set[2][u]+in_set[0][v],max=1)
    76917701
    7692    
    76937702        p.set_binary(in_set)
    76947703
    76957704        p.set_objective(p.sum([in_set[1][v] for v in g]))
     
    77017710
    77027711            in_set = p.get_values(in_set)
    77037712
    7704            
    77057713            cut = []
    77067714            a = []
    77077715            b = []
     
    77137721                    cut.append(v)
    77147722                else:
    77157723                    b.append(v)
    7716            
    77177724
    77187725            val.append(cut)
    77197726
     
    77217728                val.append([a,b])
    77227729
    77237730            return val
    7724    
    77257731
    77267732    ### Vertex handlers
    77277733