Organize search using a priority queue.
Queue priority is f(x) = g(x) + h(x).
Search technique demo by Xueqiao Xu.
Data structures
Search loop
When we revisit a state using a better path
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.
Required properties for heuristic:
Maze:
Idea: simplify problem (e.g. ignore obstacles)
15-puzzle
Heuristics for the 8-puzzle or 15-puzzle
Admissibility guarantees that the output solution is optimal.
When search stops:
"Suboptimal" search
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.
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
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
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, ... ....
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: