Guest User

Untitled

a guest
Jan 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. def my_astar():
  2. p_queue = util.PriorityQueue()
  3. start = problem.getStartState()
  4. path = [(start, "", 0)]
  5. p_queue.push(path, heuristic(start, problem))
  6. closed_list = []
  7. while True:
  8. present_path = p_queue.pop()
  9. cost = present_path[-1][2]
  10. present_state = present_path[len(present_path) - 1][0]
  11.  
  12. if problem.isGoalState(present_state):
  13. return present_path
  14.  
  15. if present_state in closed_list: continue
  16.  
  17. closed_list.append(present_state)
  18. successors = problem.getSuccessors(present_state)
  19. #print 'successors', successors
  20. #r = raw_input()
  21.  
  22. for state in successors:
  23. #s = (state[0], state[1], cost + problem.getCostOfActions(
  24. s = (state[0], state[1], cost + state[2])
  25. p_queue.push(present_path +[s], cost + heuristic(state[0], problem))
Add Comment
Please, Sign In to add comment