diff r 684eea91ff22 r c0dc40a14607 sage/graphs/graph_generators.py
a

b


89  89  Random Graphs: 
90  90   RandomGNP 
91  91   RandomBarabasiAlbert 
 92   RandomBipartite 
92  93   RandomGNM 
93  94   RandomNewmanWattsStrogatz 
94  95   RandomHolmeKim 
… 
… 

207  208  Random Graphs: 
208  209   RandomGNP 
209  210   RandomBarabasiAlbert 
 211   RandomBipartite 
210  212   RandomGNM 
211  213   RandomNewmanWattsStrogatz 
212  214   RandomHolmeKim 
… 
… 

2620  2622  import networkx 
2621  2623  return graph.Graph(networkx.barabasi_albert_graph(n,m,seed)) 
2622  2624  
 2625  def RandomBipartite(self, n1,n2, p): 
 2626  r""" 
 2627  Returns a bipartite graph with `n1+n2` vertices 
 2628  such that each edge from `[n1]` to `[n2]` exists 
 2629  with probability `p` 
 2630  
 2631  INPUT: 
 2632  
 2633   ``n1,n2`` : Cardinalities of the two sets 
 2634   ``p`` : Probability for an edge to exist 
 2635  
 2636  
 2637  EXAMPLE: 
 2638  
 2639  sage: g=graphs.RandomBipartite(5,2,0.5) 
 2640  
 2641  """ 
 2642  from numpy.random import uniform 
 2643  import sage.graphs.bipartite_graph as bipartite_graph 
 2644  
 2645  pos_dict = {} 
 2646  c1 = 1 # scaling factor for top row 
 2647  c2 = 1 # scaling factor for bottom row 
 2648  c3 = 0 # pad to center if top row has 1 node 
 2649  c4 = 0 # pad to center if bottom row has 1 node 
 2650  if n1 > n2: 
 2651  if n2 == 1: 
 2652  c4 = (n11)/2 
 2653  else: 
 2654  c2 = ((n11)/(n21)) 
 2655  elif n2 > n1: 
 2656  if n1 == 1: 
 2657  c3 = (n21)/2 
 2658  else: 
 2659  c1 = ((n21)/(n11)) 
 2660  for i in range(n1): 
 2661  x = c1*i + c3 
 2662  y = 1 
 2663  pos_dict[i] = [x,y] 
 2664  for i in range(n1+n2)[n1:]: 
 2665  x = c2*(in1) + c4 
 2666  y = 0 
 2667  pos_dict[i] = [x,y] 
 2668  
 2669  g=graph.Graph() 
 2670  g.add_vertices(range(n1+n2)) 
 2671  
 2672  [g.add_edge(v,w+n1) for v in range(n1) for w in range(n2) if uniform()<=p] 
 2673  return bipartite_graph.BipartiteGraph(g, pos=pos_dict, name="Random bipartite graph") 
 2674  
 2675  
2623  2676  def RandomGNM(self, n, m, dense=False, seed=None): 
2624  2677  """ 
2625  2678  Returns a graph randomly picked out of all graphs on n vertices 