-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
69 lines (59 loc) · 2.24 KB
/
test.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
import time
from bfs import *
from dfs import *
from astar import *
from utils import *
RED = "\033[91m"
RESET = "\033[0m"
start_state = "762853014"
goal_state = "012345678"
if is_solvable(start_state):
start_time1 = time.time()
_, res, nodes_expanded, search_depth = bfs_solver(start_state, goal_state)
end_time1 = time.time()
cost = res[0]
path = res[1]
print(RED + "BFS" + RESET)
print("Cost:", cost)
print("Nodes expanded:", nodes_expanded)
print("Search depth:", search_depth)
print("Time taken:", (end_time1 - start_time1) * 1000, "ms")
print("-------------------------------------------")
# ---------------------------------------------------------------------------
start_time2 = time.time()
_, res, nodes_expanded, search_depth = dfs_solver(start_state, goal_state)
end_time2 = time.time()
cost = res[0]
path = res[1]
print(RED + "DFS" + RESET)
print("Cost:", cost)
print("Nodes expanded:", nodes_expanded)
print("Search depth:", search_depth)
print("Time taken:", (end_time2 - start_time2) * 1000, "ms")
print("-------------------------------------------")
# ---------------------------------------------------------------------------
start_time3 = time.time()
_, res, nodes_expanded, search_depth = astar(start_state, goal_state, "manhatan")
end_time3 = time.time()
cost = res[0]
path = res[1]
print(RED + "A* (Manhatan)" + RESET)
print("Cost:", cost)
print("Nodes expanded:", nodes_expanded)
print("Search depth:", search_depth)
print("Time taken:", (end_time3 - start_time3) * 1000, "ms")
print("-------------------------------------------")
# ---------------------------------------------------------------------------
start_time4 = time.time()
_, res, nodes_expanded, search_depth = astar(start_state, goal_state, "eucledian")
end_time4 = time.time()
cost = res[0]
path = res[1]
print(RED + "A* (Eucledian)" + RESET)
print("Cost:", cost)
print("Nodes expanded:", nodes_expanded)
print("Search depth:", search_depth)
print("Time taken:", (end_time4 - start_time4) * 1000, "ms")
print("-------------------------------------------")
else:
print(RED + "Not solvable" + RESET)