-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutomatingTests.py
90 lines (74 loc) · 2.61 KB
/
AutomatingTests.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
import sys
from time import perf_counter as time
from Graph import Graph, compute_mst_and_cost
from LazyNaivePrims import prims_mst as lazy_naive_prims
from EagerNaivePrims import prims_mst as eager_naive_prims
from BinaryHeapPrims import prims_mst as binary_heap_prims
from FibHeapPrims import prims_mst as fib_heap_prims
from VisualizeMst import visualize
import pandas as pd
choices = {"l": "lazy_naive_prims",
"e": "eager_naive_prims",
"b": "binary_heap_prims",
"f": "fib_heap_prims"}
representation_for_choice = {lazy_naive_prims: "matrix",
eager_naive_prims: "matrix",
binary_heap_prims: "lists",
fib_heap_prims: "lists"}
def read_graph(grf, fname):
try:
with open(fname) as input_file:
grf.read_from_file(input_file)
except OSError:
print("File not found. \nNote: For paths, use forward slash and enclose in double quotes.")
exit()
def generate_tests():
from GraphGeneration import automated_tests
limit = 999
for density in [1, 2, 3]:
lowest_nfverts = 2100
highest_nfverts = 3500
step = 100
for nfverts in range(lowest_nfverts, highest_nfverts + 1, step):
automated_tests(nfverts, density, limit)
print(f"Completed {nfverts, density, limit}.")
def implement(implementation_choice, grf):
duration = {'l': None, 'e': None, 'b': None, 'f': None}
for choice in implementation_choice:
prims_str = choices[choice]
prims = eval(prims_str)
if representation_for_choice[prims] == 'lists':
grf.matrix_to_lists()
else:
grf.lists_to_matrix()
start = time()
precursor = prims(grf)
end = time()
duration[choice] = int((end - start) * 10**(9))
return duration
def run_all_prims(fname):
grf = Graph(representation = "matrix")
read_graph(grf, fname)
duration = implement("bf", grf)
return duration
def time_tests():
limit = 999
for density in [1, 2, 3]:
mylist = []
for lowest_nfverts, highest_nfverts, step in [(10, 200, 10)]:
for nfverts in range(lowest_nfverts, highest_nfverts + 1, step):
fname = f"Tests/Mode {density}/Graph Test ({nfverts}, {density}, {limit}).txt"
duration = run_all_prims(fname)
print(f"{fname} complete.")
mylist.append({'nfverts': nfverts,
'l_duration': duration['l'],
'e_duration': duration['e'],
'b_duration': duration['b'],
'f_duration': duration['f']})
df = pd.DataFrame(mylist, columns = ['nfverts', 'l_duration', 'e_duration', 'b_duration', 'f_duration'])
df.to_csv(f"Tests/Durations ((10, 200, 10), {density}, 999) (1).csv")
def foo():
fname = "Tests/Graph Test (10000, 3, 999).txt"
duration = run_all_prims(fname)
print(duration)
foo()