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

Function _try_creation

python/graphscope/nx/generators/random_graphs.py:307–334  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

305 return False
306
307 def _try_creation():
308 # Attempt to create an edge set
309
310 edges = set()
311 stubs = list(range(n)) * d
312
313 while stubs:
314 potential_edges = defaultdict(lambda: 0)
315 seed.shuffle(stubs)
316 stubiter = iter(stubs)
317 for s1, s2 in zip(stubiter, stubiter):
318 if s1 > s2:
319 s1, s2 = s2, s1
320 if s1 != s2 and ((s1, s2) not in edges):
321 edges.add((s1, s2))
322 else:
323 potential_edges[s1] += 1
324 potential_edges[s2] += 1
325
326 if not _suitable(edges, potential_edges):
327 return None # failed to find suitable edge set
328
329 stubs = [
330 node
331 for node, potential in potential_edges.items()
332 for _ in range(potential)
333 ]
334 return edges
335
336 # Even though a suitable edge set exists,
337 # the generation of such a set is not guaranteed.

Callers 1

random_regular_graphFunction · 0.85

Calls 4

_suitableFunction · 0.85
itemsMethod · 0.80
addMethod · 0.65
shuffleMethod · 0.45

Tested by

no test coverage detected