2018-12-20 18:25:33 +00:00
|
|
|
from networkx import Graph
|
|
|
|
import networkx as nx
|
|
|
|
|
|
|
|
def mygenerator(n=5, n_edges=5):
|
|
|
|
'''
|
|
|
|
Just a simple generator that creates a network with n nodes and
|
|
|
|
n_edges edges. Edges are assigned randomly, only avoiding self loops.
|
|
|
|
'''
|
|
|
|
G = nx.Graph()
|
|
|
|
|
|
|
|
for i in range(n):
|
|
|
|
G.add_node(i)
|
|
|
|
|
|
|
|
for i in range(n_edges):
|
|
|
|
nodes = list(G.nodes)
|
2022-10-06 13:49:10 +00:00
|
|
|
n_in = self.random.choice(nodes)
|
2018-12-20 18:25:33 +00:00
|
|
|
nodes.remove(n_in) # Avoid loops
|
2022-10-06 13:49:10 +00:00
|
|
|
n_out = self.random.choice(nodes)
|
2018-12-20 18:25:33 +00:00
|
|
|
G.add_edge(n_in, n_out)
|
|
|
|
return G
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-10-06 13:49:10 +00:00
|
|
|
|