Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def search(self, start, goal):
- """Implement breadth-first search. Return the answer as a linked list of States
- where the first node contains the goal stop code and each node is linked to the previous node in the path.
- The last node in the list is the starting stop and its previous node is None.
- :param start: Code of the initial stop (str)
- :param goal: Code of the last stop (str)
- :returns (obj)
- """
- node_list = []
- visited = set()
- node_list.append(State(start))
- while len(node_list) > 0:
- node = node_list[0]
- del node_list[0]
- if node.get_stop() not in visited:
- visited.add(node.get_stop())
- if node.get_stop() == goal:
- return node
- for neighbor in self.get_neighbors_codes(node.get_stop()):
- node_list.append(State(neighbor,node))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement