-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atlas.py
112 lines (76 loc) · 3.19 KB
/
Atlas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import matplotlib.pyplot as plt
import networkx as nx
#BARABASI ALBERT GRAPH
n = 20 # 20 nodes
m = 2 # 2 edges for each added
seed = 20160 # seed random number generators for reproducibility
# Use seed for reproducibility
G = nx.barabasi_albert_graph(n, m, seed=None, initial_graph=G)#istanza di barabasi_albert_graph(n, m, seed=None, initial_graph=None)
#nelle vecchie versione di networkx non va initial_graph
# some properties
print("node degree clustering")
for v in nx.nodes(G):
print(f"{v} {nx.degree(G, v)} {nx.clustering(G_1, v)}")
#coefficiente di clustering=N_collegamenti_fra_vicini/N_collegamenti_possibili_fra_vicini
print()
pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout
nx.draw(G, pos=pos)
nx.draw_networkx(G, pos=pos, arrows=True, with_labels=True)
plt.show()
n = 10 # 10 nodes
p = 0.2 # 20 edges
seed = 20160 # seed random number generators for reproducibility
#BINOMIAL GRAPH
# Use seed for reproducibility
G = nx.binomial_graph(n, p, seed=seed)#istanza di binomial_graph(n, p, seed=None, directed=False)
#binomial_graph() and erdos_renyi_graph() are aliases for gnp_random_graph()
# some properties
print("node degree clustering")
for v in nx.nodes(G):
print(f"{v} {nx.degree(G, v)} {nx.clustering(G, v)}")
#coefficiente di clustering=N_collegamenti_fra_vicini/N_collegamenti_possibili_fra_vicini
print()
pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout
nx.draw(G, pos=pos)
nx.draw_networkx(G, pos=pos, arrows=True, with_labels=True)
plt.show()
#create G(N,M) GRAPH (n nodes and m edges)
n = 10 # 10 nodes
m = 20 # 20 edges
seed = 20160 # seed random number generators for reproducibility
# Use seed for reproducibility
G = nx.gnm_random_graph(n, m, seed=seed)
# some properties
print("node degree clustering")
for v in nx.nodes(G):
print(f"{v} {nx.degree(G, v)} {nx.clustering(G, v)}")
#coefficiente di clustering=N_collegamenti_fra_vicini/N_collegamenti_possibili_fra_vicini
print()
pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout, spring_layout per farlo posizionare in automatico
nx.draw(G, pos=pos)
nx.draw_networkx(G, pos=pos, arrows=True, with_labels=True) #istanza di draw_networkx(G[, pos, arrows, with_labels]),disegna frecce direzionali e dà i nomi ai nodi
plt.show()
#GEOMETRIC GRAPH
#create G(N,M) GRAPH (n nodes and m edges)
n = 10 # 10 nodes
m = 20 # 20 edges
seed = 20160 # seed random number generators for reproducibility
# Use seed for reproducibility
G = nx.gnm_random_graph(n, m, seed=seed)
# some properties
print("node degree clustering")
for v in nx.nodes(G):
print(f"{v} {nx.degree(G, v)} {nx.clustering(G, v)}")
#coefficiente di clustering=N_collegamenti_fra_vicini/N_collegamenti_possibili_fra_vicini
print()
pos = nx.spring_layout(G, seed=seed) # Seed for reproducible layout, spring_layout per farlo posizionare in automatico
nx.draw(G, pos=pos)
nx.draw_networkx(G, pos=pos, arrows=True, with_labels=True) #istanza di draw_networkx(G[, pos, arrows, with_labels]),disegna frecce direzionali e dà i nomi ai nodi
plt.show()
#zackary karate club
G = nx.karate_club_graph()
print("Node Degree")
for v in G:
print(f"{v:4} {G.degree(v):6}")
nx.draw_circular(G, with_labels=True)
plt.show()