-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_plot.py
113 lines (95 loc) · 3.37 KB
/
build_plot.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
113
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def column(matrix, i):
return [row[i] for row in matrix]
action = ["insert", "search", "rmin", "xmin"]
for x in action:
filepath=[]
if x=="insert":
filepath.append("avl_insert.txt")
filepath.append("rb_insert.txt")
filepath.append("binomial_insert.txt")
elif x=="search":
filepath.append("avl_search.txt")
filepath.append("rb_search.txt")
filepath.append("binomial_search.txt")
elif x=="rmin":
filepath.append("avl_rmin.txt")
filepath.append("rb_rmin.txt")
filepath.append("binomial_rmin.txt")
elif x=="xmin":
filepath.append("avl_xmin.txt")
filepath.append("rb_xmin.txt")
filepath.append("binomial_xmin.txt")
avl_list = []
with open(filepath[0]) as f:
for line in f:
inner_list = [int(elt.strip()) for elt in line.split(' ')]
avl_list.append(inner_list)
rb_list = []
with open(filepath[1]) as f:
for line in f:
inner_list = [int(elt.strip()) for elt in line.split(' ')]
rb_list.append(inner_list)
binomial_list = []
with open(filepath[2]) as f:
for line in f:
inner_list = [int(elt.strip()) for elt in line.split(' ')]
binomial_list.append(inner_list)
avl_list.pop()
binomial_list.pop()
avl_X = column(avl_list, 0)
avl_Y = column(avl_list, 1)
bin_X = column(binomial_list, 0)
bin_Y = column(binomial_list, 1)
rb_X = column(rb_list, 0)
rb_Y = column(rb_list, 1)
avl_Y[:] = [x / 1000 for x in avl_Y]
bin_Y[:] = [x / 1000 for x in bin_Y]
rb_Y[:] = [x / 1000 for x in rb_Y]
plt.scatter(avl_X,avl_Y, c='b', marker='o', label='avl tree')
plt.scatter(bin_X, bin_Y, c='r', marker='s', label='binomial heap')
plt.scatter(rb_X, rb_Y, c='y', marker='^', label='red-black tree')
plt.xlabel('size of input')
plt.ylabel('time taken (milli sec)')
plt.legend(loc='upper left')
if x=="insert":
plt.title('Insertion')
elif x=="search":
plt.title("Search")
elif x=="rmin":
plt.title("Retrieve Minimum")
elif x=="xmin":
plt.title("Extract Minimum")
plt.show()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
binomial_mst = []
with open('binomial_mst.txt') as f:
for line in f:
binomial_list = [int(elt.strip()) for elt in line.split(' ')]
binomial_mst.append(binomial_list)
bmstX = column(binomial_mst, 0)
bmstY = column(binomial_mst, 1)
bmstZ = column(binomial_mst, 2)
bmstZ[:] = [x / 1000 for x in bmstZ]
avl_mst = []
with open('avl_mst.txt') as f:
for line in f:
avl_list = [int(elt.strip()) for elt in line.split(' ')]
avl_mst.append(avl_list)
amstX = column(avl_mst, 0)
amstY = column(avl_mst, 1)
amstZ = column(avl_mst, 2)
amstZ[:] = [x / 1000 for x in amstZ]
for c, m, t in [('r', 'o', 'avl'), ('b', '^', 'binomial')]:
if t=='avl':
ax.scatter(amstX, amstY, amstZ, c=c, marker=m, label='avl tree')
elif t=='binomial':
ax.scatter(bmstX, bmstY, bmstZ, c=c, marker=m, label='binomial heap')
ax.set_xlabel('vertex count')
ax.set_ylabel('edge count')
ax.set_zlabel('time taken (milli seconds)')
plt.title("Minimum Spanning Tree Comparision")
plt.legend(loc='upper left')
plt.show()