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

Function barbell_graph

python/graphscope/nx/generators/classic.py:103–126  ·  view source on GitHub ↗
(m1, m2, create_using=None)

Source from the content-addressed store, hash-verified

101
102@patch_docstring(nxa.barbell_graph)
103def barbell_graph(m1, m2, create_using=None):
104 if m1 < 2:
105 raise NetworkXError("Invalid graph description, m1 should be >=2")
106 if m2 < 0:
107 raise NetworkXError("Invalid graph description, m2 should be >=0")
108
109 # left barbell
110 G = complete_graph(m1, create_using)
111 if G.is_directed():
112 raise NetworkXError("Directed Graph not supported")
113
114 # connecting path
115 G.add_nodes_from(range(m1, m1 + m2 - 1))
116 if m2 > 1:
117 G.add_edges_from(pairwise(range(m1, m1 + m2)))
118 # right barbell
119 G.add_edges_from(
120 (u, v) for u in range(m1 + m2, 2 * m1 + m2) for v in range(u + 1, 2 * m1 + m2)
121 )
122 # connect it up
123 G.add_edge(m1 - 1, m1)
124 if m2 > 0:
125 G.add_edge(m1 + m2 - 1, m1 + m2)
126 return G
127
128
129@patch_docstring(nxa.binomial_tree)

Callers

nothing calls this directly

Calls 5

complete_graphFunction · 0.85
add_nodes_fromMethod · 0.80
add_edges_fromMethod · 0.80
is_directedMethod · 0.45
add_edgeMethod · 0.45

Tested by

no test coverage detected