update with a ton of links
This commit is contained in:
@@ -17,10 +17,15 @@ def build_cluster(n):
|
||||
|
||||
return g
|
||||
|
||||
def build_network(n):
|
||||
g = build_cluster(0)
|
||||
def analyze_network(N_max):
|
||||
i = 0
|
||||
g = build_cluster(i)
|
||||
stats = []
|
||||
|
||||
for i in range(1, n):
|
||||
throw_dist = 4
|
||||
|
||||
while g.number_of_nodes() < N_max:
|
||||
i += 1
|
||||
c = build_cluster(i)
|
||||
g = nx.union(g, c)
|
||||
|
||||
@@ -31,10 +36,31 @@ def build_network(n):
|
||||
g.add_edge(nn(i, 'ld'), nn(i-1, 'ld'))
|
||||
g.add_edge(nn(i, 'ru'), nn(i-1, 'ru'))
|
||||
|
||||
#if not i % 2:
|
||||
|
||||
#elif i % 5 != 1:
|
||||
g.add_edge(nn(i, 'ls'), nn(i-1, 'rs'))
|
||||
g.add_edge(nn(i, 'rs'), nn(i-1, 'ls'))
|
||||
|
||||
return g
|
||||
if i >= 1 * throw_dist:
|
||||
g.add_edge(nn(i, 'rs'), nn(i-(1*throw_dist), 'ls'))
|
||||
g.add_edge(nn(i, 'ls'), nn(i-(1*throw_dist), 'rs'))
|
||||
|
||||
if i >= 2 * throw_dist:
|
||||
g.add_edge(nn(i, 'lu'), nn(i-(2*throw_dist), 'lu'))
|
||||
if i >= 3 * throw_dist:
|
||||
g.add_edge(nn(i, 'ld'), nn(i-(3*throw_dist), 'ld'))
|
||||
if i >= 4 * throw_dist:
|
||||
g.add_edge(nn(i, 'ru'), nn(i-(4*throw_dist), 'ru'))
|
||||
if i >= 5 * throw_dist:
|
||||
g.add_edge(nn(i, 'rd'), nn(i-(5*throw_dist), 'rd'))
|
||||
if i >= 7 * throw_dist:
|
||||
g.add_edge(nn(i, 'm'), nn(i-(7*throw_dist), 'm'))
|
||||
|
||||
stats.append(analyze(g))
|
||||
print(stats[-1])
|
||||
|
||||
return g, stats
|
||||
|
||||
def analyze(G: nx.Graph) -> dict:
|
||||
N = G.number_of_nodes()
|
||||
@@ -54,23 +80,14 @@ def analyze(G: nx.Graph) -> dict:
|
||||
'Середній діаметр': D_average,
|
||||
'Топологічний трафік': Q,
|
||||
'Вартість': C,
|
||||
'Graph': G.copy()
|
||||
}
|
||||
|
||||
def main():
|
||||
i = 0
|
||||
g, r = analyze_network(1000)
|
||||
|
||||
while True:
|
||||
i += 1
|
||||
g = build_network(i)
|
||||
|
||||
if g.number_of_nodes() > 1000:
|
||||
break
|
||||
|
||||
r = analyze(g)
|
||||
print(r)
|
||||
#nx.draw(g, with_labels = True)
|
||||
#plt.show()
|
||||
#print(r)
|
||||
nx.draw(g, with_labels = True)
|
||||
plt.show()
|
||||
|
||||
if __name__=="__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user