-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcc_tests.py
More file actions
74 lines (54 loc) · 2.21 KB
/
mcc_tests.py
File metadata and controls
74 lines (54 loc) · 2.21 KB
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
# MCC runtime testing with csv file writing
import csv
from timeit import default_timer as timer
from mcc_algos import *
def runtime(algo_type, V, low, high, runs):
times = []
for i in range(low, high + 1):
total = 0
for j in range(runs):
start = timer()
algo_type(V, i)
end = timer()
total += end - start
average = total / runs
times.append((i, average))
return times
def minimum(algo_type, V, low, high):
mins = []
for i in range(low, high + 1):
(min_change, min_count) = algo_type(V, i)
mins.append((i, min_count))
return mins
def get_data():
V1 = [1, 2, 6, 12, 24, 48, 60]
V2 = [1, 5, 10, 25, 50]
V3 = [1, 6, 13, 37, 150]
# Minimum coins for each A
write_data('alg1_V1_1-35.csv', minimum(changeslow, V1, 1, 35))
write_data('alg1_V2_1-35.csv', minimum(changeslow, V2, 1, 35))
write_data('alg1_V3_1-35.csv', minimum(changeslow, V3, 1, 35))
write_data('alg2_V1_1-50.csv', minimum(changegreedy, V1, 1, 50))
write_data('alg2_V2_1-50.csv', minimum(changegreedy, V2, 1, 50))
write_data('alg2_V3_1-50.csv', minimum(changegreedy, V3, 1, 50))
write_data('alg2_V1_2000-2200.csv', minimum(changegreedy, V1, 2000, 2200))
write_data('alg2_V2_2000-2200.csv', minimum(changegreedy, V2, 2000, 2200))
write_data('alg2_V3_2000-2200.csv', minimum(changegreedy, V3, 2000, 2200))
write_data('alg3_V1_1-50.csv', minimum(changedp, V1, 1, 50))
write_data('alg3_V2_1-50.csv', minimum(changedp, V2, 1, 50))
write_data('alg3_V3_1-50.csv', minimum(changedp, V3, 1, 50))
write_data('alg3_V1_2000-2200.csv', minimum(changedp, V1, 2000, 2200))
write_data('alg3_V2_2000-2200.csv', minimum(changedp, V2, 2000, 2200))
write_data('alg3_V3_2000-2200.csv', minimum(changedp, V3, 2000, 2200))
# Runtimes for each
write_data('alg1_V2_runtimes.csv', runtime(changeslow, V2, 1, 35, 1))
write_data('alg2_V2_runtimes.csv', runtime(changegreedy, V2, 1, 50, 5))
write_data('alg3_V2_runtimes.csv', runtime(changedp, V2, 1, 50, 5))
print('Wrote csv files...')
def write_data(filename, array):
with open(filename, 'wb') as output:
file_writer = csv.writer(output)
for row in array:
file_writer.writerow(row)
if __name__ == '__main__':
get_data()