MCPcopy Create free account
hub / github.com/alibaba/GraphScope / random_shell_graph

Function random_shell_graph

python/graphscope/nx/generators/random_graphs.py:646–677  ·  view source on GitHub ↗
(constructor, seed=None)

Source from the content-addressed store, hash-verified

644@patch_docstring(nxa.random_shell_graph)
645@py_random_state(1)
646def random_shell_graph(constructor, seed=None):
647 G = empty_graph(0)
648
649 glist = []
650 intra_edges = []
651 nnodes = 0
652 # create gnm graphs for each shell
653 for n, m, d in constructor:
654 inter_edges = int(m * d)
655 intra_edges.append(m - inter_edges)
656 g = nx.convert_node_labels_to_integers(
657 gnm_random_graph(n, inter_edges, seed=seed), first_label=nnodes
658 )
659 glist.append(g)
660 nnodes += n
661 G = nx.operators.union(G, g)
662
663 # connect the shells randomly
664 for gi in range(len(glist) - 1):
665 nlist1 = list(glist[gi])
666 nlist2 = list(glist[gi + 1])
667 total_edges = intra_edges[gi]
668 edge_count = 0
669 while edge_count < total_edges:
670 u = seed.choice(nlist1)
671 v = seed.choice(nlist2)
672 if u == v or G.has_edge(u, v):
673 continue
674 else:
675 G.add_edge(u, v)
676 edge_count = edge_count + 1
677 return G
678
679
680@patch_docstring(nxa.random_powerlaw_tree)

Callers 1

test_random_graphMethod · 0.90

Calls 6

empty_graphFunction · 0.90
gnm_random_graphFunction · 0.85
has_edgeMethod · 0.80
appendMethod · 0.65
unionMethod · 0.45
add_edgeMethod · 0.45

Tested by 1

test_random_graphMethod · 0.72