-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_search.py
32 lines (26 loc) · 959 Bytes
/
main_search.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
from pathlib import Path
from input.roads import *
from search.problem import *
from search.strategies import *
from search.tree_search import TreeSearch
# load the environment
# streets = roads_small # for uninformed search (no cost)
streets = Roads(streets=roads_small, coordinates=roads_small_coords)
# formulate the problem
initial_state = 'Corato'
goal_state = 'Bari'
map_problem = StreetProblem(environment=streets,
initial_state=initial_state,
goal_state=goal_state)
# search strategy
strategies = [GraphRandom()]
# search algorithm (Tree Search / Graph Search)
for strategy in strategies:
search = TreeSearch(problem=map_problem, strategy=strategy)
# run algorithm
result, node = search.recursive_run()
# display the solutions
print("Result: " + result)
print("Goal: " + node.state)
print("Path: " + str(node.path()))
print("Path cost: " + str(node.cost))