Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1.     def search(self, start, goal):
  2.         """Implement breadth-first search. Return the answer as a linked list of States
  3.        where the first node contains the goal stop code and each node is linked to the previous node in the path.
  4.        The last node in the list is the starting stop and its previous node is None.
  5.  
  6.        :param start: Code of the initial stop (str)
  7.        :param goal: Code of the last stop (str)
  8.        :returns (obj)
  9.        """
  10.  
  11.         node_list = []
  12.         visited = set()
  13.  
  14.         node_list.append(State(start))
  15.  
  16.         while len(node_list) > 0:
  17.             node = node_list[0]
  18.             del node_list[0]
  19.             if node.get_stop() not in visited:
  20.                 visited.add(node.get_stop())
  21.                 if node.get_stop() == goal:
  22.                     return node
  23.                 for neighbor in self.get_neighbors_codes(node.get_stop()):
  24.                     node_list.append(State(neighbor,node))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement