`A^star`-algorithm, Python




CS156

Chris Pollett

Sep 6, 2017

Outline

Introduction

Informed Search Strategies

Example Heuristic Functions

`A^star`-search

`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 = heuristic's 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

In-Class Exercise

Python

Getting Started

Running Python

Python as Calculator; Programs in Files

Variables and Arithmetic Expressions

Conditionals