`A^star`-algorithm, Python




CS156

Chris Pollett

Sep 8, 2014

Outline

Introduction

`A^\star`-algorithm

function A-STAR-SEARCH(problem) returns a solution, or failure 
    node := a node with STATE = problem.INITIAL-STATE, PATH-COST = 0,
        H-COST = heuristics cost to solution
    frontier := a priority queue ordered by f=c+h, with node as
        the only element
    explored := an empty set
    loop do
        if EMPTY?(frontier) then return failure
        node := POP(frontier) /* lowest f=c+h-value in frontier 
            since priority-queue */
        if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
        add node.STATE to explored
        for each action in problem.ACTIONS(node.STATE) do
            child := CHILD-NODE(problem, node, action)
            if child.STATE is not in explored or frontier then
                frontier := INSERT(child, frontier)
            else if child.STATE is in frontier with higher f value
                replace that frontier node with child

`A^star`-Example Map

We will use the following road map of Romania to illustrate the `A^star`-algorithm:

Road map of Romania

`A^star`-Example Map

An example search for Bucharest

Quiz

Which of the following is true?

  1. A rational agent always has complete information about its environment.
  2. Iterative Deepening Depth First search is typically more memory efficient than Breadth-First search.
  3. Problem solving agents always use factored and not atomic representations of their environment.

Python

Getting Started

Running Python

Python as Calculator; Programs in Files

Variables and Arithmetic Expressions

Conditionals

File I/O

Strings