Skip to content

Commit e539513

Browse files
committed
initial public release
0 parents  commit e539513

10 files changed

+408
-0
lines changed

__init__.py

Whitespace-only changes.

gen.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import random
2+
import networkx as nx
3+
4+
5+
# generate a random graph with degree between a and b
6+
def generate_graph(degree_start=10, degree_end=15, size=5000):
7+
8+
z=[random.randint(degree_start, degree_end) for i in range(size)]
9+
10+
# if sum of degree sequence is odd, make it even
11+
if sum(z) % 2 != 0:
12+
z[random.randint(0, size)] += 1
13+
14+
G=nx.configuration_model(z)
15+
16+
# remove self-loops and parallel edges
17+
G=nx.Graph(G)
18+
G.remove_edges_from(G.selfloop_edges())
19+
20+
return G
21+
22+
23+
24+
def generate_graph_mean(degree_start=10, degree_end=15, size=5000):
25+
26+
z=[numpy.random.geometric(0.07) for i in range(size)]
27+
28+
print("Mean degree", numpy.mean(z))
29+
# if sum of degree sequence is odd, make it even
30+
if sum(z) % 2 != 0:
31+
z[random.randint(0, size)] += 1
32+
33+
G=nx.configuration_model(z)
34+
35+
# remove self-loops and parallel edges
36+
G=nx.Graph(G)
37+
G.remove_edges_from(G.selfloop_edges())
38+
39+
return G

plot_avg_23.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import csv
2+
import matplotlib
3+
import numpy as np
4+
5+
from mpl_toolkits.mplot3d import Axes3D
6+
import matplotlib.pyplot as plt
7+
8+
csv_read = csv.reader(open('log.txt'), delimiter=',')
9+
10+
avgd = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
11+
two3 = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
12+
for row in csv_read:
13+
#import ipdb ; ipdb.set_trace()
14+
for i, col in enumerate(row):
15+
16+
# 0 - <>
17+
# 1 - M
18+
# 2 - N
19+
# 3 - size
20+
# 4 - degree min
21+
# 5 - degree max
22+
# 6 - shortestpath
23+
# 7 - 2/3
24+
sz = int(row[3])
25+
avgd_rw = np.mean([int(row[4]), int(row[5])])
26+
two3_rw = float(row[7])
27+
28+
avgd[sz].append(avgd_rw)
29+
two3[sz].append(two3_rw)
30+
31+
32+
33+
fig = plt.figure()
34+
ax = fig.add_subplot(111)
35+
36+
ax.scatter(avgd[1000], two3[1000], c='r', marker='o', label='1000')
37+
ax.scatter(avgd[2000], two3[2000], c='g', marker='1', label='2000')
38+
ax.scatter(avgd[3000], two3[3000], c='b', marker='2', label='3000')
39+
ax.scatter(avgd[4000], two3[4000], c='y', marker='x', label='4000')
40+
ax.scatter(avgd[5000], two3[5000], c='c', marker='+', label='5000')
41+
42+
#ax.set_xscale('log')
43+
#ax.set_xticklabels([1,2,3,10,100])
44+
#ax.set_xticks([1,2,3,10,100])
45+
46+
ax.set_xlabel('Average degree')
47+
ax.set_ylabel('Hops to reach 2/3rds of nodes')
48+
49+
ax.legend()
50+
51+
plt.show()

plot_m_avgd_sp.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import csv
2+
import matplotlib
3+
import numpy as np
4+
5+
from mpl_toolkits.mplot3d import Axes3D
6+
import matplotlib.pyplot as plt
7+
8+
csv_read = csv.reader(open('log.txt'), delimiter=',')
9+
10+
m = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
11+
avgd = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
12+
sp = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
13+
for row in csv_read:
14+
#import ipdb ; ipdb.set_trace()
15+
for i, col in enumerate(row):
16+
17+
# 1 - M
18+
# 2 - N
19+
# 3 - size
20+
# 4 - degree min
21+
# 5 - degree max
22+
# 6 - shortestpath
23+
# 7 - 2/3
24+
sz = int(row[3])
25+
m_rw = int(row[1])
26+
avgd_rw = np.mean([int(row[4]), int(row[5])])
27+
sp_rw = float(row[6])
28+
29+
m[sz].append(m_rw)
30+
avgd[sz].append(avgd_rw)
31+
sp[sz].append(sp_rw)
32+
33+
34+
35+
36+
37+
38+
39+
fig = plt.figure()
40+
ax = fig.add_subplot(111, projection='3d')
41+
42+
ax.scatter(m[1000], avgd[1000], sp[1000], c='r', marker='x', label='1000')
43+
ax.scatter(m[2000], avgd[2000], sp[2000], c='g', marker='+', label='2000')
44+
ax.scatter(m[3000], avgd[3000], sp[3000], c='b', marker='1', label='3000')
45+
ax.scatter(m[4000], avgd[4000], sp[4000], c='purple', marker='2', label='4000')
46+
ax.scatter(m[5000], avgd[5000], sp[5000], c='c', marker='3', label='5000')
47+
48+
49+
ax.set_xlabel('M')
50+
ax.set_ylabel('Average degree')
51+
ax.set_zlabel('Shortest path time')
52+
53+
ax.legend()
54+
55+
plt.show()

plot_n_23.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import csv
2+
import matplotlib
3+
import numpy as np
4+
5+
from mpl_toolkits.mplot3d import Axes3D
6+
import matplotlib.pyplot as plt
7+
8+
csv_read = csv.reader(open('log.txt'), delimiter=',')
9+
10+
n = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
11+
two3 = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
12+
for row in csv_read:
13+
#import ipdb ; ipdb.set_trace()
14+
for i, col in enumerate(row):
15+
16+
# 0 - <>
17+
# 1 - M
18+
# 2 - N
19+
# 3 - size
20+
# 4 - degree min
21+
# 5 - degree max
22+
# 6 - shortestpath
23+
# 7 - 2/3
24+
sz = int(row[3])
25+
n_rw = int(row[2])
26+
two3_rw = float(row[7])
27+
28+
n[sz].append(n_rw)
29+
two3[sz].append(two3_rw)
30+
31+
32+
33+
fig = plt.figure()
34+
ax = fig.add_subplot(111)
35+
36+
ax.scatter(n[1000], two3[1000], c='r', marker='+', label='1000')
37+
ax.scatter(n[2000], two3[2000], c='g', marker='x', label='2000')
38+
ax.scatter(n[3000], two3[3000], c='b', marker='1', label='3000')
39+
ax.scatter(n[4000], two3[4000], c='purple', marker='2', label='4000')
40+
ax.scatter(n[5000], two3[5000], c='c', marker='3', label='5000')
41+
42+
ax.set_xscale('log')
43+
ax.set_xticklabels([1,2,3,10,100])
44+
ax.set_xticks([1,2,3,10,100])
45+
46+
ax.set_xlabel('N')
47+
ax.set_ylabel('Time to reach 2/3rds of nodes')
48+
49+
ax.legend()
50+
51+
plt.show()

plot_n_avg.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import csv
2+
import matplotlib
3+
import numpy as np
4+
5+
from mpl_toolkits.mplot3d import Axes3D
6+
import matplotlib.pyplot as plt
7+
8+
csv_read = csv.reader(open('log.txt'), delimiter=',')
9+
10+
n = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
11+
avgd = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
12+
for row in csv_read:
13+
#import ipdb ; ipdb.set_trace()
14+
for i, col in enumerate(row):
15+
16+
# 0 - <>
17+
# 1 - M
18+
# 2 - N
19+
# 3 - size
20+
# 4 - degree min
21+
# 5 - degree max
22+
# 6 - shortestpath
23+
# 7 - 2/3
24+
sz = int(row[3])
25+
n_rw = int(row[2])
26+
avgd_rw = np.mean([int(row[4]), int(row[5])])
27+
28+
n[sz].append(n_rw)
29+
avgd[sz].append(avgd_rw)
30+
31+
32+
33+
fig = plt.figure()
34+
ax = fig.add_subplot(111)
35+
36+
ax.scatter(n[1000], avgd[1000], c='r', marker='o', label='1000')
37+
ax.scatter(n[2000], avgd[2000], c='g', marker='o', label='2000')
38+
ax.scatter(n[3000], avgd[3000], c='b', marker='o', label='3000')
39+
ax.scatter(n[4000], avgd[4000], c='y', marker='o', label='4000')
40+
ax.scatter(n[5000], avgd[5000], c='c', marker='o', label='5000')
41+
42+
ax.set_xscale('log')
43+
ax.set_xticklabels([1,2,3,10,100])
44+
ax.set_xticks([1,2,3,10,100])
45+
46+
ax.set_xlabel('N')
47+
ax.set_ylabel('Average degree')
48+
49+
ax.legend()
50+
51+
plt.show()

plot_n_avgd_23.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import csv
2+
import matplotlib
3+
import numpy as np
4+
5+
from mpl_toolkits.mplot3d import Axes3D
6+
import matplotlib.pyplot as plt
7+
8+
csv_read = csv.reader(open('log.txt'), delimiter=',')
9+
10+
n = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
11+
avgd = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
12+
two3 = {1000:[], 2000:[], 3000:[], 4000:[], 5000:[]}
13+
for row in csv_read:
14+
#import ipdb ; ipdb.set_trace()
15+
for i, col in enumerate(row):
16+
17+
# 0 - <>
18+
# 1 - M
19+
# 2 - N
20+
# 3 - size
21+
# 4 - degree min
22+
# 5 - degree max
23+
# 6 - shortestpath
24+
# 7 - 2/3
25+
sz = int(row[3])
26+
n_rw = int(row[2])
27+
avgd_rw = np.mean([int(row[4]), int(row[5])])
28+
two3_rw = float(row[7])
29+
30+
n[sz].append(n_rw)
31+
avgd[sz].append(avgd_rw)
32+
two3[sz].append(two3_rw)
33+
34+
35+
36+
fig = plt.figure()
37+
ax = fig.add_subplot(111, projection='3d')
38+
39+
for i, j in enumerate(n[1000]):
40+
41+
print(n[1000][i], avgd[1000][i], two3[1000][i])
42+
43+
ax.scatter(n[1000], avgd[1000], two3[1000], c='r', marker='x', label='1000')
44+
ax.scatter(n[2000], avgd[2000], two3[2000], c='g', marker='+', label='2000')
45+
ax.scatter(n[3000], avgd[3000], two3[3000], c='b', marker='1', label='3000')
46+
ax.scatter(n[4000], avgd[4000], two3[4000], c='purple', marker='2', label='4000')
47+
ax.scatter(n[5000], avgd[5000], two3[5000], c='c', marker='3', label='5000')
48+
49+
#ax.set_xscale('log')
50+
#ax.set_xticklabels([1,2,3,10,100])
51+
#ax.set_xticks([1,2,3,10,100])
52+
53+
ax.set_xlabel('N')
54+
ax.set_ylabel('Average degree')
55+
ax.set_zlabel('Time to reach 2/3rds of nodes')
56+
57+
ax.legend()
58+
59+
plt.show()

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
numpy==1.13.3
2+
matplotlib==2.1.1
3+
networkx==1.11

run_experiment.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
for M in {2..5}
4+
do
5+
for N in 1 2 3 10 100
6+
do
7+
for degree in {5..10}
8+
do
9+
for size in `seq 1000 1000 5000`
10+
do
11+
time python sim.py $M $N $size $degree $(( $degree + 10 )) >> log.txt 2>&1
12+
done
13+
done
14+
done
15+
done

0 commit comments

Comments
 (0)