def relaxed_caveman_graph(l, k, p, seed=None):
 if (not (seed is None)):
  random.seed(seed)
 G = nx.caveman_graph(l, k)
 nodes = list(G)
 G.name = ('relaxed_caveman_graph (%s,%s,%s)' % (l, k, p))
 for (u, v) in G.edges():
  if (random.random() < p):
   x = random.choice(nodes)
   if G.has_edge(u, x):
    continue
   G.remove_edge(u, v)
   G.add_edge(u, x)
 return G

def relaxed_caveman_graph ( l , k , p , seed = None ) : if ( not ( seed is None ) ) : random . seed ( seed ) G = nx . caveman_graph ( l , k ) nodes = list ( G ) G . name = ( 'relaxed_caveman_graph (%s,%s,%s)' % ( l , k , p ) ) for ( u , v ) in G . edges ( ) : if ( random . random ( ) < p ) : x = random . choice ( nodes ) if G . has_edge ( u , x ) : continue G . remove_edge ( u , v ) G . add_edge ( u , x ) return G
return a relaxed caveman graph .