-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperformance.py
86 lines (66 loc) · 3 KB
/
performance.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
from Graph_IncidenceList_prioritySearch import *
from Graph_IncidenceList_prioritySearch import buildGraph
from time import *
def performanceGraphIL(graph, version, d = None):
try:
assert d != None, "You must provide a 'd' for the D-Heap test!"
except AssertionError as myError:
print(myError)
return
binaryHeapVertices = open("performanceData/performancebinaryHeapVertices.txt", "a")
binaryHeapEdges = open("performanceData/performancebinaryHeapEdges.txt", "a")
binomialHeapVertices = open("performanceData/performancebinomialHeapVertices.txt", "a")
binomialHeapEdges = open("performanceData/performancebinomialHeapEdges.txt", "a")
dHeapVertices = open("performanceData/performancedHeapVertices.txt", "a")
dHeapEdges = open("performanceData/performancedHeapEdges.txt", "a")
nVertices = len(graph.getNodes())
nEdges = graph.numEdges()
start = time()
graph.prioritySearch_PQbinaryHeap()
tempo = time()-start
if version == 0:
binaryHeapVertices.write("{}\t{}\n".format(nVertices, tempo))
elif version == 1:
binaryHeapEdges.write("{}\t{}\n".format(nEdges, tempo))
start = time()
graph.prioritySearch_PQbinomialHeap()
tempo = time()-start
if version == 0:
binomialHeapVertices.write("{}\t{}\n".format(nVertices, tempo))
elif version == 1:
binomialHeapEdges.write("{}\t{}\n".format(nEdges, tempo))
start = time()
graph.prioritySearch_PQ_DHeap(d)
tempo = time()-start
if version == 0:
dHeapVertices.write("{}\t{}\n".format(nVertices, tempo))
elif version == 1:
dHeapEdges.write("{}\t{}\n".format(nEdges, tempo))
binaryHeapVertices.close()
binaryHeapEdges.close()
binomialHeapVertices.close()
binomialHeapEdges.close()
dHeapVertices.close()
dHeapEdges.close()
def dataVertices(maxV, d):
for vertices in range(10,maxV+1,10):
graph = buildGraph(vertices)
performanceGraphIL(graph, 0, d)
def dataEdges(nVertices, d):
graph = buildGraph(nVertices)
nEdges = graph.numEdges()
maxEdges = int((nVertices*(nVertices-1)))-nEdges
print("maxE = "+str(maxEdges))
for edges in range(100):
performanceGraphIL(graph, 1, d)
addEdges(graph, int(maxEdges/100))
def dataForGraphs(nVertices, maxV, d):
dataVertices(maxV, d)
dataEdges(nVertices, d)
def ereaseDataFromGraphs():
binaryHeapVertices = open("performanceData/performancebinaryHeapVertices.txt", "w+").close()
binaryHeapEdges = open("performanceData/performancebinaryHeapEdges.txt", "w+").close()
binomialHeapVertices = open("performanceData/performancebinomialHeapVertices.txt", "w+").close()
binomialHeapEdges = open("performanceData/performancebinomialHeapEdges.txt", "w+").close()
dHeapVertices = open("performanceData/performancedHeapVertices.txt", "w+").close()
dHeapEdges = open("performanceData/performancedHeapEdges.txt", "w+").close()