Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def dfs(root, final_state_number, h=None, h_type=None):
  2. stack = collections.deque()
  3. stack.appendleft(root)
  4. visited = []
  5. steps = 0
  6.  
  7. while len(stack) != 0:
  8. curr_state = stack.popleft()
  9. steps += 1
  10.  
  11. if curr_state.is_final(final_state_number):
  12. return curr_state.path, curr_state.profit + curr_state.capacity, steps
  13.  
  14. visited.append(curr_state)
  15.  
  16. children = curr_state.get_children()
  17. for state in list(reversed(children)):
  18. if state not in visited:
  19. stack.appendleft(state)
  20.  
  21. return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement