-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_func.py
81 lines (66 loc) · 1.4 KB
/
time_func.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
import time
from ucs import *
from a_star import *
depth_0_test = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 0]
]
depth_2_test = [
[1, 2, 3],
[4, 5, 6],
[0, 7, 8]
]
depth_4_test = [
[1, 2, 3],
[5, 0, 6],
[4, 7, 8]
]
depth_8_test = [
[1, 3, 6],
[5, 0, 2],
[4, 7, 8]
]
depth_12_test = [
[1, 3, 6],
[5, 0, 7],
[4, 8, 2]
]
depth_16_test = [
[1, 6, 7],
[5, 0, 3],
[4, 8, 2]
]
depth_20_test = [
[7, 1, 2],
[4, 8, 5],
[6, 3, 0]
]
depth_24_test = [
[0, 7, 2],
[4, 6, 1],
[3, 5, 8]
]
# Time each algorithm
ucs_times = []
tests = [depth_0_test, depth_2_test, depth_4_test, depth_8_test, depth_12_test, depth_16_test, depth_20_test, depth_24_test]
for puzzle in tests:
start = time.time()
ucs(puzzle, timing=True)
end = time.time()
ucs_times.append(end-start)
a_star_misplaced_times = []
for puzzle in tests:
start = time.time()
a_star(puzzle, misplaced_heuristic, timing=True)
end = time.time()
a_star_misplaced_times.append(end-start)
a_star_manhattan_times = []
for puzzle in tests:
start = time.time()
a_star(puzzle, manhattan_heuristic, timing=True)
end = time.time()
a_star_manhattan_times.append(end-start)
print('UCS Times: ' + str(ucs_times))
print('A* Times (Misplaced Heuristic): ' + str(a_star_misplaced_times))
print('A* Times (Manhattan Heuristic): ' + str(a_star_manhattan_times))