-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (34 loc) · 1.22 KB
/
main.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
import time
import sys, os
import genetic, least_constraining_value, minimum_remaining_values, power_heuristic
ACCURACY = 4
OMIT_OUTPUT = True
NO_OF_TESTS = 5
def main():
"""Run imported algorithms and show statistics."""
if OMIT_OUTPUT:
sys.stdout = open(os.devnull, 'w')
genetic_time, lcv_time, mrv_time, ph_time = [], [], [], []
for _ in range(NO_OF_TESTS):
now = time.time()
genetic.run()
genetic_time.append(time.time() - now)
now = time.time()
least_constraining_value.run()
lcv_time.append(time.time() - now)
now = time.time()
minimum_remaining_values.run()
mrv_time.append(time.time() - now)
now = time.time()
power_heuristic.run()
ph_time.append(time.time() - now)
if OMIT_OUTPUT:
sys.stdout = sys.__stdout__
algorithms = ['Genetic', 'Least constraining value',
'Minimum remaining values', 'Power heuristic']
stats = [genetic_time, lcv_time, mrv_time, ph_time]
for name, t in zip(algorithms, stats):
avg_time = round(sum(t) / NO_OF_TESTS * 1000, ACCURACY)
print(f"Statistics for {name} algorithm: {avg_time} ms.")
if __name__ == '__main__':
main()