-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
91 lines (78 loc) · 2.94 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
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
82
83
84
85
86
87
88
89
90
91
# Search Algorithms: bfsTree, bfsGraph, dfsTree, dfsGraph,
# treeSearch, graphSearch
from search_algorithms import *
# select the problem you wish to solve
# by importing a specific "Problem" class defined in a separate python file
# e.g., "from <problem filename> import Problem"
from problem_maze import Problem
# ########################################################
# ########################################################
# Main Function
# ########################################################
# ########################################################
if __name__ == '__main__':
#define an object of the problem class
problem = Problem()
# ----------------------
# Run BFS (tree version)
# ----------------------
print("** Using BFS - Tree **")
(bfsSolution, bfsStats) = bfsTree(problem)
if bfsSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("bfsTree", bfsSolution, bfsStats.data)
# -----------------------
# Run BFS (graph version)
# -----------------------
print("** Using BFS - Graph **")
(bfsSolution, bfsStats) = bfsGraph(problem)
if bfsSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("bfsGraph", bfsSolution, bfsStats.data)
# -----------------------
# Run DFS (graph version)
# -----------------------
print("** Using DFS - Graph **")
(dfsSolution, dfsStats) = dfsGraph(problem)
if dfsSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("dfsGraph",dfsSolution,dfsStats.data)
# ----------------------
# Run UCS (tree version)
# ----------------------
print("** Using UCS - Tree **")
(ucsSolution, ucsStats) = ucsTree(problem)
if ucsSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("ucsTree", ucsSolution, ucsStats.data)
# ----------------------
# Run UCS (graph version)
# ----------------------
print("** Using UCS - Graph **")
(ucsSolution, ucsStats) = ucsGraph(problem)
if ucsSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("ucsGraph", ucsSolution, ucsStats.data)
# ------------------------
# Run GBFS (graph version)
# ------------------------
print("** Using GBFS - Graph **")
(gbfsSolution, gbfsStats) = gbfsGraph(problem)
if gbfsSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("gbfsGraph", gbfsSolution, gbfsStats.data)
# ----------------------
# Run A* (graph version)
# ----------------------
print("** Using A* - Graph **")
(aStarSolution, aStarStats) = aStarGraph(problem)
if aStarSolution == None:
print("Sorry, I can't find a solution!!")
else:
problem.drawSolution("AStarGraph", aStarSolution, aStarStats.data)