Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dfs(root, final_state_number, h=None, h_type=None):
- stack = collections.deque()
- stack.appendleft(root)
- visited = []
- steps = 0
- while len(stack) != 0:
- curr_state = stack.popleft()
- steps += 1
- if curr_state.is_final(final_state_number):
- return curr_state.path, curr_state.profit + curr_state.capacity, steps
- visited.append(curr_state)
- children = curr_state.get_children()
- for state in list(reversed(children)):
- if state not in visited:
- stack.appendleft(state)
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement