Ticket #12155: trac_12155.patch

File trac_12155.patch, 3.9 KB (added by ncohen, 9 years ago)
  • sage/graphs/graph_generators.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1324072706 -3600
    # Node ID ed261dd6a8f2ed57827057d5a61de136631a96a6
    # Parent  bf75326898107a067024ed03bf0e8a100cb4e35f
    trac 12155 -- Bug when taking complement of bipartite graph
    
    diff --git a/sage/graphs/graph_generators.py b/sage/graphs/graph_generators.py
    a b  
    42474247            ...
    42484248            sage: G = sage.plot.plot.GraphicsArray(j)
    42494249            sage: G.show() # long time
     4250
     4251        Trac ticket #12155::
     4252
     4253            sage: graphs.CompleteBipartiteGraph(5,6).complement()
     4254            complement(Complete bipartite graph): Graph on 11 vertices
    42504255        """
    42514256        pos_dict = {}
    42524257        c1 = 1 # scaling factor for top row
     
    42724277            y = 0
    42734278            pos_dict[i] = (x,y)
    42744279        import networkx
    4275         import sage.graphs.bipartite_graph as bipartite_graph
     4280        from sage.graphs.graph import Graph
    42764281        G = networkx.complete_bipartite_graph(n1,n2)
    4277         return bipartite_graph.BipartiteGraph(G, pos=pos_dict, name="Complete bipartite graph")
     4282        return Graph(G, pos=pos_dict, name="Complete bipartite graph")
    42784283
    42794284    def CompleteMultipartiteGraph(self, l):
    42804285        r"""
     
    51665171            Traceback (most recent call last):
    51675172            ...
    51685173            ValueError: Parameter p is a probability, and so should be a real value between 0 and 1
    5169 
     5174         
     5175        Trac ticket #12155::
     5176
     5177            sage: graphs.RandomBipartite(5,6,.2).complement()
     5178            complement(Random bipartite graph of size 5+6 with edge probability 0.200000000000000): Graph on 11 vertices
    51705179        """
    51715180        if not (p>=0 and p<=1):
    51725181            raise ValueError, "Parameter p is a probability, and so should be a real value between 0 and 1"
     
    51745183            raise ValueError, "n1 and n2 should be integers strictly greater than 0"
    51755184
    51765185        from numpy.random import uniform
    5177         import sage.graphs.bipartite_graph as bipartite_graph
    51785186        from sage.graphs.all import Graph
    51795187
    5180         g=Graph()
     5188        g=Graph(name="Random bipartite graph of size "+str(n1) +"+"+str(n2)+" with edge probability "+str(p))
    51815189
    51825190        S1=[(0,i) for i in range(n1)]
    51835191        S2=[(1,i) for i in range(n2)]
    51845192        g.add_vertices(S1)
    51855193        g.add_vertices(S2)
    5186         [g.add_edge((0,v),(1,w)) for v in range(n1) for w in range(n2) if uniform()<=p]
    5187 
    5188         return bipartite_graph.BipartiteGraph(g,[S1,S2],name="Random bipartite graph of size "+str(n1) +"+"+str(n2)+" with edge probability "+str(p))           
     5194
     5195        for w in range(n2):
     5196            for v in range(n1):
     5197                if uniform()<=p :
     5198                    g.add_edge((0,v),(1,w))
     5199
     5200        pos = {}
     5201        for i in range(n1):
     5202            pos[(0,i)] = (0, i/(n1-1.0))
     5203        for i in range(n2):
     5204            pos[(1,i)] = (1, i/(n2-1.0))
     5205
     5206        g.set_pos(pos)
     5207           
     5208        return g
    51895209
    51905210    def RandomGNM(self, n, m, dense=False, seed=None):
    51915211        """
     
    62596279            Traceback (most recent call last):
    62606280            ...
    62616281            ValueError: There exists no bipartite graph corresponding to the given degree sequences
     6282
     6283        TESTS:
     6284
     6285        Trac ticket #12155::
     6286
     6287            sage: graphs.DegreeSequenceBipartite([2,2,2,2,2],[5,5]).complement()
     6288            complement(): Graph on 7 vertices
    62626289        """
    62636290       
    62646291        from sage.combinat.integer_vector import gale_ryser_theorem
     6292        from sage.graphs.graph import Graph
    62656293        from sage.graphs.bipartite_graph import BipartiteGraph
    62666294
    62676295        s1 = sorted(s1, reverse = True)
     
    62726300        if m is False:
    62736301            raise ValueError("There exists no bipartite graph corresponding to the given degree sequences")
    62746302        else:
    6275             return BipartiteGraph(m)
     6303            return Graph(BipartiteGraph(m))
    62766304
    62776305    def DegreeSequenceConfigurationModel(self, deg_sequence, seed=None):
    62786306        """