mirror of
https://github.com/status-im/research.git
synced 2025-02-04 19:23:54 +00:00
Added random graph simulator
This commit is contained in:
parent
768e21e523
commit
29106975c0
39
random_graphs.py
Normal file
39
random_graphs.py
Normal file
@ -0,0 +1,39 @@
|
||||
import numpy, random
|
||||
|
||||
EXP_CONN = 2
|
||||
NODES = 10000
|
||||
|
||||
nodes = []
|
||||
|
||||
for i in range(NODES):
|
||||
n = []
|
||||
EDGES = numpy.random.poisson(EXP_CONN / 2.)
|
||||
for j in range(EDGES):
|
||||
n.append(random.randrange(NODES))
|
||||
nodes.append(n)
|
||||
|
||||
for i in range(NODES):
|
||||
for p in nodes[i]:
|
||||
if i not in nodes[p]:
|
||||
nodes[p].append(i)
|
||||
|
||||
print 'Total edges:', sum([len(s) for s in nodes])
|
||||
|
||||
components = []
|
||||
scanned = {}
|
||||
for i in range(NODES):
|
||||
if i in scanned:
|
||||
pass
|
||||
size = 0
|
||||
positions = [i]
|
||||
while len(positions):
|
||||
val = positions.pop()
|
||||
if val not in scanned:
|
||||
scanned[val] = True
|
||||
size += 1
|
||||
for p in nodes[val]:
|
||||
positions.append(p)
|
||||
# print 'Component:', size
|
||||
components.append(size)
|
||||
|
||||
print 'Biggest components:', sorted(components)[::-1][:10]
|
Loading…
x
Reference in New Issue
Block a user