-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain_streets.py
48 lines (40 loc) · 1.51 KB
/
main_streets.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
from search.Problems import StreetProblem
from search.strategies import *
from search.TreeSearch import TreeSearch
from search.GraphSearch import GraphSearch
from search.Environments import streets, streets_coords, Roads
import math
# model and load the environment
map = Roads(streets, streets_coords)
# formulate the problem
initial_state = 'Andria'
goal_state = 'Bari'
map_problem = StreetProblem(environment=map,
initial_state=initial_state,
goal_state=goal_state)
# search strategy (for the search tree, we do not include DepthFirst because it will cause infinite loop.
# You can try by yourself)
strategies = [AStar(map_problem), Greedy(map_problem), Random(), BreadthFirst(), DepthLimitedSearch(limit=5), UniformCost()]
# search algorithm (Tree Search / Graph Search)
for strategy in strategies:
search = TreeSearch(problem=map_problem, strategy=strategy)
result, node = search.run()
print(f'{strategy}, {search}')
print(result)
try:
print(node.path())
print(node.cost)
except AttributeError:
pass
print("---------")
strategies = [AStar(map_problem), Greedy(map_problem), Random(), BreadthFirst(), DepthFirst(), DepthLimitedSearch(limit=5), UniformCost()]
for strategy in strategies:
search = GraphSearch(problem=map_problem, strategy=strategy)
result, node = search.run()
print(f'{strategy}, {search}')
print(result)
try:
print(node.path())
print(node.cost)
except AttributeError:
pass