-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.py
37 lines (31 loc) · 1.27 KB
/
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
33
34
35
36
37
from Search import city
class Search:
def __init__(self, source_city, destination_city):
self.source = source_city
self.destination = destination_city
def goal_check(self, current_city):
if current_city.name == self.destination:
return True
else:
return False
def find_next_city(self, current_city, visited_nodes):
next_city = []
file = open("distance.csv", 'r')
for line in file:
line_array = line.split(',')
if current_city.name in line_array:
index = line_array.index(current_city.name)
if index == 0 and line_array[1] not in visited_nodes:
next_city.append(city.City(line_array[1], current_city))
else:
if line_array[0] not in visited_nodes:
next_city.append(city.City(line_array[0], current_city))
file.close()
return next_city
def find_parent(self, current_city):
return current_city.parent
def calculate_distance(self, current_node, child_node):
file = open("distance.csv", 'r')
for line in file:
if current_node.name in line and child_node.name in line:
return int(line.split(',')[2])