Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def my_astar():
- p_queue = util.PriorityQueue()
- start = problem.getStartState()
- path = [(start, "", 0)]
- p_queue.push(path, heuristic(start, problem))
- closed_list = []
- while True:
- present_path = p_queue.pop()
- cost = present_path[-1][2]
- present_state = present_path[len(present_path) - 1][0]
- if problem.isGoalState(present_state):
- return present_path
- if present_state in closed_list: continue
- closed_list.append(present_state)
- successors = problem.getSuccessors(present_state)
- #print 'successors', successors
- #r = raw_input()
- for state in successors:
- #s = (state[0], state[1], cost + problem.getCostOfActions(
- s = (state[0], state[1], cost + state[2])
- p_queue.push(present_path +[s], cost + heuristic(state[0], problem))
Add Comment
Please, Sign In to add comment