project1_search/search/search.py
def aStarSearch(problem, heuristic=nullHeuristic):
    """Search the node that has the lowest combined cost and heuristic first."""
    fringe = util.PriorityQueue()
    start = [problem.getStartState(), 0, []]
    p = 0
    fringe.push(start, p)
    closed = []
    while not fringe.isEmpty():
        [node, cost, path] = fringe.pop()
        if problem.isGoalState(node):
            return path
        if not node in closed:
            closed.append(node)
            for child_node, child_action, child_cost in problem.getSuccessors(
                    node):
                new_cost = cost + child_cost
                new_path = path + [child_action]
                fringe.update(
                    [child_node, new_cost, new_path], new_cost + heuristic(
                        child_node, problem))  #pay attention to the priority!
    util.raiseNotDefined()
Search the node that has the lowest combined cost and heuristic first.
Search the node that has the lowest combined cost and heuristic first.
Search the node that has the lowest combined cost and heuristic first .
def aStarSearch(problem, heuristic=nullHeuristic):
    fringe = util.PriorityQueue()
    start = [problem.getStartState(), 0, []]
    p = 0
    fringe.push(start, p)
    closed = []
    while not fringe.isEmpty():
        [node, cost, path] = fringe.pop()
        if problem.isGoalState(node):
            return path
        if not node in closed:
            closed.append(node)
            for child_node, child_action, child_cost in problem.getSuccessors(
                    node):
                new_cost = cost + child_cost
                new_path = path + [child_action]
                fringe.update(
                    [child_node, new_cost, new_path], new_cost + heuristic(
                        child_node, problem))  
    util.raiseNotDefined()
def aStarSearch ( problem , heuristic = nullHeuristic ) : fringe = util . PriorityQueue ( ) start = [ problem . getStartState ( ) , 0 , [ ] ] p = 0 fringe . push ( start , p ) closed = [ ] while not fringe . isEmpty ( ) : [ node , cost , path ] = fringe . pop ( ) if problem . isGoalState ( node ) : return path if not node in closed : closed . append ( node ) for child_node , child_action , child_cost in problem . getSuccessors ( node ) : new_cost = cost + child_cost new_path = path + [ child_action ] fringe . update ( [ child_node , new_cost , new_path ] , new_cost + heuristic ( child_node , problem ) ) util . raiseNotDefined ( )
Search the node that has the lowest combined cost and heuristic first.
Search the node that has the lowest combined cost and heuristic first .
"""Search the node that has the lowest combined cost and heuristic first.""" #pay attention to the priority!
problem
heuristic