UI logo
CS 440/ECE 448
Margaret Fleck

A* Search


Recap


Organize search using a priority queue.

Queue priority is f(x) = g(x) + h(x).

Search technique demo by Xueqiao Xu.


Data structures


Data structures


Algorithm outline


Search loop

When we revisit a state using a better path


A* gotchas


Don't try to empty the queue

Returning immediately only works for BFS/DFS

Use backpointer table to generate output path

Check for revisiting a state via a shorter path

To update a state's priority in the priority queue, just push a new copy of the state onto the queue.


Heuristics


Required properties for heuristic:


Maze:

Idea: simplify problem (e.g. ignore obstacles)


15-puzzle


Heuristics for the 8-puzzle or 15-puzzle


Why Admissibility?


Admissibility guarantees that the output solution is optimal.

When search stops:

"Suboptimal" search


Consistency


When we reach a state via a shorter path, is that state still in the queue?

Approach #1: Don't fuss, just push updated state into the queue regardless of whether it's already there or not.

Approach #2: Ensure that the heuristic is "consistent"


Suppose we can get from s to s' with cost c(s,s'). Heuristic h is consistent if

\( h(s) \le c(s,s') + h(s') \)

I.e. g(x)+h(x) stays constant or increases as we extend path.


UCS is consistent (h is always zero).

Straight-line distance is consistent (triangle inequality).

Non-consistent examples are typically contrived.


State design


An adventure game

Are these the same state?



Each state stored in the search queue must contain all information that might be relevant to extending your path towards the goal.


Reaching the goal might mean


Edit distance


Good problem representation matters

Edit Distance: find the best alignment between two strings

Best: fewest character edits (delete, add, substitute)


     A L G O R   I   T H M
     A L   T R U I S T I C
         D S   A   A   S S

D = delete character
A = add character
S = substitute

Domains


Naive method


A state is a string.

An action applies one edit operation

Each state has many successors: about \( 28^9 \) possible hanges to ALGORITHM

    LGORITHM, AGORITHM, ..., ALGORIHM, ...
    BLGORITHM, CLGORITHM, ....
    AAGORITHM, ....
    ...
    ALBORJTHM, ...
    ....

Better method


A state is an alignment of the initial sections (prefixes) of the two strings.

Start state is an alignment of two empty strings

End state is an alignment of the full strings.

An action extends the alignment by one character.



Nifty compact 2D table.

Memory efficient methods: