# 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


4247  4247  ... 
4248  4248  sage: G = sage.plot.plot.GraphicsArray(j) 
4249  4249  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 
4250  4255  """ 
4251  4256  pos_dict = {} 
4252  4257  c1 = 1 # scaling factor for top row 
… 
… 

4272  4277  y = 0 
4273  4278  pos_dict[i] = (x,y) 
4274  4279  import networkx 
4275   import sage.graphs.bipartite_graph as bipartite_graph 
 4280  from sage.graphs.graph import Graph 
4276  4281  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") 
4278  4283  
4279  4284  def CompleteMultipartiteGraph(self, l): 
4280  4285  r""" 
… 
… 

5166  5171  Traceback (most recent call last): 
5167  5172  ... 
5168  5173  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 
5170  5179  """ 
5171  5180  if not (p>=0 and p<=1): 
5172  5181  raise ValueError, "Parameter p is a probability, and so should be a real value between 0 and 1" 
… 
… 

5174  5183  raise ValueError, "n1 and n2 should be integers strictly greater than 0" 
5175  5184  
5176  5185  from numpy.random import uniform 
5177   import sage.graphs.bipartite_graph as bipartite_graph 
5178  5186  from sage.graphs.all import Graph 
5179  5187  
5180   g=Graph() 
 5188  g=Graph(name="Random bipartite graph of size "+str(n1) +"+"+str(n2)+" with edge probability "+str(p)) 
5181  5189  
5182  5190  S1=[(0,i) for i in range(n1)] 
5183  5191  S2=[(1,i) for i in range(n2)] 
5184  5192  g.add_vertices(S1) 
5185  5193  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/(n11.0)) 
 5203  for i in range(n2): 
 5204  pos[(1,i)] = (1, i/(n21.0)) 
 5205  
 5206  g.set_pos(pos) 
 5207  
 5208  return g 
5189  5209  
5190  5210  def RandomGNM(self, n, m, dense=False, seed=None): 
5191  5211  """ 
… 
… 

6259  6279  Traceback (most recent call last): 
6260  6280  ... 
6261  6281  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 
6262  6289  """ 
6263  6290  
6264  6291  from sage.combinat.integer_vector import gale_ryser_theorem 
 6292  from sage.graphs.graph import Graph 
6265  6293  from sage.graphs.bipartite_graph import BipartiteGraph 
6266  6294  
6267  6295  s1 = sorted(s1, reverse = True) 
… 
… 

6272  6300  if m is False: 
6273  6301  raise ValueError("There exists no bipartite graph corresponding to the given degree sequences") 
6274  6302  else: 
6275   return BipartiteGraph(m) 
 6303  return Graph(BipartiteGraph(m)) 
6276  6304  
6277  6305  def DegreeSequenceConfigurationModel(self, deg_sequence, seed=None): 
6278  6306  """ 