def duplication_divergence_graph(n, p, seed=None):
 if ((p > 1) or (p < 0)):
  msg = 'NetworkXError p={0} is not in [0,1].'.format(p)
  raise nx.NetworkXError(msg)
 if (n < 2):
  msg = 'n must be greater than or equal to 2'
  raise nx.NetworkXError(msg)
 if (seed is not None):
  random.seed(seed)
 G = nx.Graph()
 G.name = 'duplication_divergence_graph({}, {})'.format(n, p)
 G.add_edge(0, 1)
 i = 2
 while (i < n):
  random_node = random.choice(list(G))
  G.add_node(i)
  flag = False
  for nbr in G.neighbors(random_node):
   if (random.random() < p):
    G.add_edge(i, nbr)
    flag = True
  if (not flag):
   G.remove_node(i)
  else:
   i += 1
 return G

def duplication_divergence_graph ( n , p , seed = None ) : if ( ( p > 1 ) or ( p < 0 ) ) : msg = 'NetworkXError p={0} is not in [0,1].' . format ( p ) raise nx . NetworkXError ( msg ) if ( n < 2 ) : msg = 'n must be greater than or equal to 2' raise nx . NetworkXError ( msg ) if ( seed is not None ) : random . seed ( seed ) G = nx . Graph ( ) G . name = 'duplication_divergence_graph({}, {})' . format ( n , p ) G . add_edge ( 0 , 1 ) i = 2 while ( i < n ) : random_node = random . choice ( list ( G ) ) G . add_node ( i ) flag = False for nbr in G . neighbors ( random_node ) : if ( random . random ( ) < p ) : G . add_edge ( i , nbr ) flag = True if ( not flag ) : G . remove_node ( i ) else : i += 1 return G
returns an undirected graph using the duplication-divergence model .