def barabasi_albert_graph(n, m, seed=None):
 if ((m < 1) or (m >= n)):
  raise nx.NetworkXError(('Barab\xc3\xa1si\xe2\x80\x93Albert network must have m >= 1 and m < n, m = %d, n = %d' % (m, n)))
 if (seed is not None):
  random.seed(seed)
 G = empty_graph(m)
 G.name = ('barabasi_albert_graph(%s,%s)' % (n, m))
 targets = list(range(m))
 repeated_nodes = []
 source = m
 while (source < n):
  G.add_edges_from(zip(([source] * m), targets))
  repeated_nodes.extend(targets)
  repeated_nodes.extend(([source] * m))
  targets = _random_subset(repeated_nodes, m)
  source += 1
 return G

def barabasi_albert_graph ( n , m , seed = None ) : if ( ( m < 1 ) or ( m >= n ) ) : raise nx . NetworkXError ( ( 'Barab\xc3\xa1si\xe2\x80\x93Albert network must have m >= 1 and m < n, m = %d, n = %d' % ( m , n ) ) ) if ( seed is not None ) : random . seed ( seed ) G = empty_graph ( m ) G . name = ( 'barabasi_albert_graph(%s,%s)' % ( n , m ) ) targets = list ( range ( m ) ) repeated_nodes = [ ] source = m while ( source < n ) : G . add_edges_from ( zip ( ( [ source ] * m ) , targets ) ) repeated_nodes . extend ( targets ) repeated_nodes . extend ( ( [ source ] * m ) ) targets = _random_subset ( repeated_nodes , m ) source += 1 return G
returns a random graph according to the barabási–albert preferential attachment model .