Best-First Search: The A* Algorithm

Best-First Search: The A* Algorithm
Keith L. Downing
August 20, 2014
Keith L. Downing
Best-First Search: The A* Algorithm
Search is..
A (preferably methodical) process for finding something.
Searching for:
pre-existing entities (information, objects, etc.)
strategies for creating/designing entities.
Examples:
Web search (for just about anything)
AI search - creates something, doesn’t just find it.
Web search for AI search algorithms.
Uninformed -vs - Informed: Do points in the search space give
information that helps the searcher to determine the next step?
Partial -vs- Complete solutions (i.e., attempts): Could the current state
of search always be considered a complete solution, though not
necessarily good or optimal? Or is it often a partial state that must be
incrementally enhanced to become a solution?
E.g. 2 approaches to origami.
Closed-loop -vs- Open-loop control
Keith L. Downing
Best-First Search: The A* Algorithm
Incremental -vs- Local Search
Incremental
Local
The problem-solver works with partial -vs- complete solutions.
Keith L. Downing
Best-First Search: The A* Algorithm
8 Puzzle: An AI Classic
Goal State
1 2 3
8
Current State
4
7 6 5
1 5 3
4 6
2 8 7
Move Left
Move Up
Move
Down
1 5
4 6 3
2 8 7
1 5 3
4
1 5 3
6
2 8 7
4 6 7
2 8
For this puzzle, a complete solution is a sequence of moves that achieves the
goal configuration. Typically, this is solved using incremental methods that
add one move at a time to a partial sequence.
Keith L. Downing
Best-First Search: The A* Algorithm
The Horizon of a Search Graph
Root Node Contains Starting Search State
Expansion = Generating Child Nodes
Open, Unexpanded
Closed, Expanded
Expansion
Keith L. Downing
Best-First Search: The A* Algorithm
3 Common Incremental Search Algorithms
General
General
Breadth-First
Depth-First
Problem-Specific
"Intelligent"
Best-First
Keith L. Downing
Best-First Search: The A* Algorithm
Stacks, Queues and Agendas
The key decision that differentiates depth-first, breadth-first and
best-first search is: these algorithms: What node on the OPEN
list should be expanded next?
Depth-First: OPEN = a stack (LIFO - Last in, first out)
Breadth-First: OPEN = a queue (FIFO - First in, first out)
Best-First: OPEN = a sorted list known as the agenda,
where sorting is based on the node’s evaluation, which
reflects the algorithm’s knowledge about that search state
and its potential to be extended into an optimal solution.
Keith L. Downing
Best-First Search: The A* Algorithm
Shakey the Robot: Stanford Research Institute, 1960’s
Needed a good route-planning algorithm.
Hart, Nilsson, Raphael (1968), A formal basis for the heuristic
determination of minimum cost paths, in IEEE Transactions System
Science and Cybernetics
Still used by the vehicle-navigation industry.
Keith L. Downing
Best-First Search: The A* Algorithm
The Evaluation Function in Best-First Search
g(x)
f(x) = g(x) + h(x)
x
Concrete
Estimate
h(x)
Goal
State
Keith L. Downing
Best-First Search: The A* Algorithm
The Heuristic Function: h(X)
Current State
Goal State
1 5 3
Distance ??
1 2 3
4 6
8
2 8 7
7 6 5
Euclidiean Distance
4
Manhattan Distance
1 5 3
1 5 3
8
8
The heuristic function estimates the distance (typically in terms of the number
of moves) from the current state to the goal.
Keith L. Downing
Best-First Search: The A* Algorithm
The A* Algorithm
DEFINE best-first-search()
1
CLOSED ← 0;
/ OPEN ← 0/
2
Generate the initial node, n0, for the start state.
3
g(n0) ← 0; Calculate h(n0)
4
f(n0) ← g(n0) + h(n0);
5
Push n0 onto OPEN.
6
Do Agenda Loop
Keith L. Downing
Best-First Search: The A* Algorithm
The Agenda Loop (Open List = Agenda)
If OPEN = 0/ return FAIL
X ← pop(OPEN)
push(X,CLOSED)
If X is a solution, return (X, SUCCEED)
SUCC ← generate-all-successors(X)
For each S ∈ SUCC do:
If node S* has previously been created, and if state(S*) =
state(S), then S ← S*.
push(S,kids(X))
If not(S ∈ OPEN) and not(S ∈ CLOSED) do:
attach-and-eval(S,X)
insert(S,OPEN) ;; OPEN is sorted by ascending f value.
else if g(X) + arc-cost(X,S) < g(S) then (found cheaper path
to S):
attach-and-eval(S,X)
If S ∈ CLOSED then propagate-path-improvements(S)
Keith L. Downing
Best-First Search: The A* Algorithm
Node Expansion in A*
A
(10)
A
(10)
1
1
1
C(9)
B(9)
1
2
E
(10)
D(8)
1
C(9)
B(9)
1
Expand D
2
D(8)
2
F(7)
E(10)
1
1
G(7)
H(8)
D
C
B
E
A
Agenda
Closed Nodes
(Open Nodes)
Keith L. Downing
G
C
H
D
F
B
E
A
Agenda
Closed Nodes
(OpenSearch:
Nodes)The A* Algorithm
Best-First
Updating g values in A*
P1
g=4
h = 20
P2
g=2
h = 22
Before
After
C1
g=5
C1
h = 19
g=3
h = 19
C2
g=6
C2
h = 18
g=4
Keith L. Downing
h = 18
Best-First Search: The A* Algorithm
Admissable Heuristics for A*
An admissable heuristic NEVER overestimates distance to the goal.
1
2
f(x) ≤ 2 + 2
1
X
Y
1
f(z) = 4 + 0
1
Z
V
2
f(v) ≤ 3 + 2
f(w) = 5 + 0
f(y) ≤ 3 + 1
1
W
Agenda
V
X
Y
W
W
Z
X
W
Time
Keith L. Downing
Best-First Search: The A* Algorithm
Rush Hour
Scenario
Specification
4
3
Exit
0
5
0, 2, 2, 2
0, 0, 4, 3
0, 3, 4, 2
0, 4, 1, 2
1
2
1, 2, 0, 2
1, 4, 2, 2
What is g?
Find an admissible h.
Keith L. Downing
Best-First Search: The A* Algorithm
Missionaries and Cannibals: A Classic AI Puzzle
M C
M
C C
M
3 x (M,C) => Boat holds 2
(4 or 5) x (M,C) => Boat holds 3
(6 or more) x (M,C) => Boat holds 4
What is g?
Find an admissible h.
Keith L. Downing
Best-First Search: The A* Algorithm
The Switchboard Puzzle
Start
End
Visit every peg from start to end. Neighbor distance is D, but
each turn requires an extra amount, W, for wrapping.
What is g?
Find an admissible h.
Keith L. Downing
Best-First Search: The A* Algorithm
Example Demos
Missionaries and Cannibals
Rush Hour
Navigation
Keith L. Downing
Best-First Search: The A* Algorithm