Skip to content

Commit b8b453a

Browse files
committed
Automate tests, collecting and plotting the data.
1 parent 3873db2 commit b8b453a

11 files changed

+561
-0
lines changed

AutomatingTests.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import sys
2+
from time import perf_counter as time
3+
from Graph import Graph, compute_mst_and_cost
4+
from LazyNaivePrims import prims_mst as lazy_naive_prims
5+
from EagerNaivePrims import prims_mst as eager_naive_prims
6+
from BinaryHeapPrims import prims_mst as binary_heap_prims
7+
from FibHeapPrims import prims_mst as fib_heap_prims
8+
from VisualizeMst import visualize
9+
import pandas as pd
10+
11+
choices = {"l": "lazy_naive_prims",
12+
"e": "eager_naive_prims",
13+
"b": "binary_heap_prims",
14+
"f": "fib_heap_prims"}
15+
16+
representation_for_choice = {lazy_naive_prims: "matrix",
17+
eager_naive_prims: "matrix",
18+
binary_heap_prims: "lists",
19+
fib_heap_prims: "lists"}
20+
21+
def read_graph(grf, fname):
22+
try:
23+
with open(fname) as input_file:
24+
grf.read_from_file(input_file)
25+
26+
except OSError:
27+
print("File not found. \nNote: For paths, use forward slash and enclose in double quotes.")
28+
exit()
29+
30+
def generate_tests():
31+
from GraphGeneration import automated_tests
32+
limit = 999
33+
for density in [1, 2, 3]:
34+
lowest_nfverts = 2100
35+
highest_nfverts = 3500
36+
step = 100
37+
for nfverts in range(lowest_nfverts, highest_nfverts + 1, step):
38+
automated_tests(nfverts, density, limit)
39+
print(f"Completed {nfverts, density, limit}.")
40+
41+
generate_tests()
42+
def implement(implementation_choice, grf):
43+
duration = {'l': None, 'e': None, 'b': None, 'f': None}
44+
45+
for choice in implementation_choice:
46+
prims_str = choices[choice]
47+
prims = eval(prims_str)
48+
49+
if representation_for_choice[prims] == 'lists':
50+
grf.matrix_to_lists()
51+
else:
52+
grf.lists_to_matrix()
53+
54+
start = time()
55+
precursor = prims(grf)
56+
end = time()
57+
58+
duration[choice] = int((end - start) * 10**(9))
59+
60+
return duration
61+
62+
def run_all_prims(fname):
63+
grf = Graph(representation = "matrix")
64+
read_graph(grf, fname)
65+
adj_mat = grf.graph
66+
duration = implement("ebf", grf)
67+
return duration
68+
69+
70+
def time_tests():
71+
limit = 999
72+
for density in [1, 2, 3]:
73+
mylist = []
74+
lowest_nfverts = 2100
75+
highest_nfverts = 3500
76+
step = 100
77+
for nfverts in range(lowest_nfverts, highest_nfverts + 1, step):
78+
fname = f"Tests/Mode {density}/Graph Test ({nfverts}, {density}, {limit}).txt"
79+
duration = run_all_prims(fname)
80+
print(f"{fname} complete.")
81+
mylist.append({'nfverts': nfverts,
82+
'l_duration': None,
83+
'e_duration': duration['e'],
84+
'b_duration': duration['b'],
85+
'f_duration': duration['f']})
86+
df = pd.DataFrame(mylist, columns = ['nfverts', 'l_duration', 'e_duration', 'b_duration', 'f_duration'])
87+
df.to_csv(f"Tests/Durations (({lowest_nfverts}, {highest_nfverts}, {step}), {density}, {limit}).csv")
88+
89+
90+
time_tests()
49.2 KB
Loading
51.3 KB
Loading
41.7 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
,nfverts,l_duration,e_duration,b_duration,f_duration
2+
0,10,145658,78553,178422,277896
3+
1,20,797769,267632,547108,815926
4+
2,30,2204621,637898,1675670,1610933
5+
3,40,5058194,864085,1411194,2196331
6+
4,50,13656415,1289219,1944487,2859098
7+
5,60,20441200,1500010,2250410,3298444
8+
6,70,32770105,1901461,2608834,3975818
9+
7,80,48051269,2527123,3222655,4627927
10+
8,90,98402290,3078574,3890555,5500303
11+
9,100,181722367,3637526,4637402,6110570
12+
10,110,175541534,4378057,4978062,7398212
13+
11,120,160771557,6207281,5739515,7906635
14+
12,130,168704247,6061228,6368731,10076914
15+
13,140,335479402,7029919,7125446,9919808
16+
14,150,267020089,8211769,8362165,11575742
17+
15,160,481793618,9155198,9067170,12198246
18+
16,170,672744211,10253758,10961527,18422107
19+
17,180,386227531,11476661,10665077,14004575
20+
18,190,628294547,14492868,11803111,16295643
21+
19,200,1007268737,14032996,12442195,16150379
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
,nfverts,l_duration,e_duration,b_duration,f_duration
2+
0,10,249080,117632,240000,399081
3+
1,20,1966988,723951,1818959,1697776
4+
2,30,4505557,659610,1078428,1758566
5+
3,40,12266536,1087113,1786592,2593834
6+
4,50,40316344,1361852,2010410,2930941
7+
5,60,105372604,7606239,8955853,4547796
8+
6,70,54839607,2561071,3444497,5331355
9+
7,80,114587802,3165416,3963975,5828332
10+
8,90,163829212,4076872,4746350,6503731
11+
9,100,300993362,4796086,5597408,7487027
12+
10,110,356011391,5773067,7315711,8836643
13+
11,120,501907185,7374526,8209402,10114415
14+
12,130,1141761684,7862819,8469139,12894173
15+
13,140,716249656,16355250,27914806,37878431
16+
14,150,587178855,10640997,10346127,13778783
17+
15,160,751355831,12265746,11621926,14878923
18+
16,170,1926223939,13603520,12854697,26434928
19+
17,180,1047325342,17551705,14941687,19891328
20+
18,190,1831116145,20982783,23384775,24782941
21+
19,200,2633791296,24302939,22195423,26117162
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
,nfverts,l_duration,e_duration,b_duration,f_duration
2+
0,10,280659,128289,252237,398292
3+
1,20,1584880,467766,666714,1109613
4+
2,30,11075606,921717,1218956,2010804
5+
3,40,20959492,1428563,1889618,2743046
6+
4,50,26030714,1893171,3002390,5141088
7+
5,60,78595436,2990152,3652921,5017931
8+
6,70,132971224,3586211,4821746,10051652
9+
7,80,144220122,5180562,5891489,8561114
10+
8,90,229810742,5957805,6999130,9484804
11+
9,100,338650739,7309395,8225191,11527978
12+
10,110,456077906,8581246,9733885,12884698
13+
11,120,749154764,10818630,13573914,20622779
14+
12,130,745431974,11821268,12643907,16382881
15+
13,140,826917695,13455885,13956416,19114875
16+
14,150,1258267527,16618540,16437354,20710413
17+
15,160,1296783859,18295790,18488028,23092272
18+
16,170,3598164066,19639484,19626852,36722238
19+
17,180,2095567271,24117411,21503445,26350848
20+
18,190,1861245837,24285175,23680829,28983366
21+
19,200,4732366879,44602033,26085977,31205751
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
,nfverts,l_duration,e_duration,b_duration,f_duration
2+
0,250,,21033705,18546844,22455952
3+
1,300,,30875749,22700690,28415731
4+
2,350,,42188200,29756661,38140143
5+
3,400,,54559737,36317235,44475322
6+
4,450,,69551950,62582820,52628275
7+
5,500,,85731541,51337871,61520972
8+
6,550,,105464974,60400306,74957121
9+
7,600,,125016431,69169843,83503630
10+
8,650,,143191825,77625956,93919626
11+
9,700,,170547681,89909861,104649441
12+
10,750,,192572182,99460193,118737306
13+
11,800,,220698570,113551610,136030062
14+
12,850,,250722867,123738658,149558187
15+
13,900,,275118570,138614424,155571651
16+
14,950,,312576604,150744774,177464309
17+
15,1000,,345818424,164671192,189878874
18+
16,1050,,387466224,222776481,201426589
19+
17,1100,,422204107,193040345,219016584
20+
18,1150,,450692472,211956269,235020121
21+
19,1200,,493136069,252538275,263293747
22+
20,1250,,545476973,253118937,278377147
23+
21,1300,,583939620,275472257,288650641
24+
22,1350,,650279968,276781214,301069153
25+
23,1400,,682932441,296391881,332001743
26+
24,1450,,719543760,329958966,342600900
27+
25,1500,,777485232,406493073,370985053
28+
26,1550,,855521718,499530457,472338813
29+
27,1600,,1106340507,464886522,505194971
30+
28,1650,,1161004850,519622314,516021102
31+
29,1700,,1279265311,511039488,565922516
32+
30,1750,,1281997304,566797260,635128674
33+
31,1800,,1346984879,562346568,607775583
34+
32,1850,,1464640598,636282104,692163035
35+
33,1900,,1523191154,647911135,693235938
36+
34,1950,,1698787952,670749197,697828339
37+
35,2000,,1684685876,707863017,750773985
38+
36,2100,,1911987652,777566152,950319641
39+
37,2200,,2177237334,848693905,981536840
40+
38,2300,,2246175860,879326495,989870585
41+
39,2400,,2460547148,1000699874,1014815765
42+
40,2500,,2677984773,1060905178,1208820064
43+
41,2600,,3008512166,1188408862,1189769925
44+
42,2700,,3162355648,1251118001,1277260428
45+
43,2800,,3366629494,1285765489,1434112616
46+
44,2900,,4006601231,1345739080,1735726114
47+
45,3000,,3794856936,1448438113,1680834795
48+
46,3100,,4738487317,1746961983,1812293772
49+
47,3200,,4376565883,1666263768,1788248599
50+
48,3300,,5004168450,1824610046,1872182101
51+
49,3400,,5010964289,1811409162,1908577496
52+
50,3500,,5387737015,1990566904,2128359877
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
,nfverts,l_duration,e_duration,b_duration,f_duration
2+
0,250,,29721926,26002687,40915165
3+
1,300,,66271663,32433787,43642816
4+
2,350,,56355802,42450702,57786339
5+
3,400,,149119237,54715659,64607440
6+
4,450,,93435282,65188891,75045938
7+
5,500,,115130176,76842003,101382576
8+
6,550,,139708247,91288291,109616056
9+
7,600,,168161480,106508271,123578395
10+
8,650,,197229716,141267075,148388179
11+
9,700,,240625031,221108704,179606563
12+
10,750,,299736905,187772543,257028044
13+
11,800,,302786664,182547373,230514562
14+
12,850,,338866662,207775187,236059077
15+
13,900,,421051468,245152695,269458002
16+
14,950,,474770409,251260897,270880644
17+
15,1000,,467761412,276104629,293225674
18+
16,1050,,515158596,302899955,317302822
19+
17,1100,,739056531,383118956,432161812
20+
18,1150,,733429518,423458196,841861750
21+
19,1200,,814026680,483388367,491597767
22+
20,1250,,895396347,506570640,529671202
23+
21,1300,,941333392,652379589,627486515
24+
22,1350,,1047104683,560471950,625098339
25+
23,1400,,1106492481,616935912,650733524
26+
24,1450,,1227894281,639385153,695545166
27+
25,1500,,1258661478,682764677,757414690
28+
26,1550,,1336459935,737095071,807806767
29+
27,1600,,1617376440,848722720,851983270
30+
28,1650,,1535105189,813159831,949526607
31+
29,1700,,1632682077,893621993,930348180
32+
30,1750,,1710236193,937781919,978060366
33+
31,1800,,1869986165,960711953,1076303182
34+
32,1850,,1922948784,1036906187,1101187969
35+
33,1900,,2126498679,1078651095,1235137753
36+
34,1950,,2160807873,1134403735,1262466767
37+
35,2000,,2223896357,1222826612,1311191067
38+
36,2100,,2957267059,1538369684,2028148888
39+
37,2200,,2911234095,1638260145,1699583352
40+
38,2300,,3080756636,1629559687,1650099177
41+
39,2400,,3512171205,2453414992,1895022135
42+
40,2500,,3701578760,1928025137,2055611717
43+
41,2600,,3993502583,2190301245,2244560979
44+
42,2700,,4576593120,2142474583,2206433862
45+
43,2800,,4579254850,2343826566,2393634821
46+
44,2900,,4980294200,2663341117,3071580517
47+
45,3000,,5328538693,2840276080,2818419738
48+
46,3100,,5945546052,3440876480,4321320087
49+
47,3200,,6283314155,2880470056,3070877485
50+
48,3300,,6462374399,3020393832,3206779260
51+
49,3400,,7165159484,3575153109,4236331841
52+
50,3500,,8054336314,4015214847,4079180441
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
,nfverts,l_duration,e_duration,b_duration,f_duration
2+
0,250,,40220028,30439168,35500519
3+
1,300,,50767077,41924514,48456667
4+
2,350,,67365092,54601975,62997692
5+
3,400,,98213211,68063781,83968633
6+
4,450,,111125540,83728632,98158736
7+
5,500,,142611952,101848368,114896094
8+
6,550,,167936873,143418800,140922467
9+
7,600,,198936965,146824221,186722140
10+
8,650,,233157345,173808231,211784954
11+
9,700,,281843750,224919522,214176680
12+
10,750,,335799141,222439768,243066495
13+
11,800,,361179718,300463227,337121124
14+
12,850,,503825224,326780523,377542468
15+
13,900,,555604810,387272803,808911249
16+
14,950,,625375447,464635861,449398514
17+
15,1000,,683909817,457019360,501935211
18+
16,1050,,833364583,574802579,554094535
19+
17,1100,,825729923,543921699,597710510
20+
18,1150,,987494251,595647995,640931743
21+
19,1200,,1012290219,646687048,685876411
22+
20,1250,,1066696008,882055330,801040534
23+
21,1300,,1164477770,735542954,820078434
24+
22,1350,,1244247163,1171944271,892571591
25+
23,1400,,1377261415,845738882,964742639
26+
24,1450,,1454386841,910525536,992253234
27+
25,1500,,1528432903,948807393,1050020625
28+
26,1550,,1665639291,1026769666,1142048660
29+
27,1600,,1742247214,1125884858,1254442893
30+
28,1650,,1858091078,1171354924,1257105018
31+
29,1700,,1970404786,1237103163,1390392035
32+
30,1750,,2113756482,1281041243,1457372652
33+
31,1800,,2257312256,1458573449,1456623041
34+
32,1850,,2365337118,1467848648,1530688840
35+
33,1900,,2512921607,1541925895,1621721341
36+
34,1950,,2703906542,1635337887,1836519738
37+
35,2000,,2752491103,1688314718,1825878344
38+
36,2100,,3311358437,1913346740,1942844848
39+
37,2200,,3532758065,2095255821,2139118507
40+
38,2300,,3606802154,2195488519,2486166940
41+
39,2400,,4021865816,2440196343,2535991378
42+
40,2500,,4277264374,2975164557,3021186468
43+
41,2600,,5054102627,2877830431,2976782594
44+
42,2700,,5209673491,3073317372,3241623327
45+
43,2800,,5557086662,3397759062,3481610064
46+
44,2900,,5963882107,3914277537,3767582791
47+
45,3000,,6386540165,3915230044,3959705760
48+
46,3100,,7113031343,4023274642,4174392841
49+
47,3200,,7096133721,4287284842,4596605633
50+
48,3300,,8110113033,5032243917,4777852735
51+
49,3400,,8232187469,5460330041,5644397952
52+
50,3500,,8647543632,5003400682,5644257031

0 commit comments

Comments
 (0)