Date post: | 17-Dec-2015 |
Category: |
Documents |
Upload: | norma-stevenson |
View: | 215 times |
Download: | 0 times |
Heuristic State Space Seach
Henry Kautz
Assignment
Kinds of State-Space Search Problems
• The goal is fully specified. Only the path to it needs to be found and returned.– Route planning
• Can test if a state is a goal, but we do not know what it will be in advance. The path to the goal is not needed.– Crossword puzzles
• Goal test only, path matters.– General STRIPS planning
Dijkstra’s Algorithm: One-to-All Shortest Paths in a Weighted Graph
for each node do node.dist = ; end;start.dist := 0;insert(start, 0, heap);while (! empty(heap)) do
node := deleteMin(heap);for each edge <node, length, child> do
if (node.dist + length < child.dist) thenchild.dist = node.dist + length;if (child is in the heap) then
decreaseKey(child, child.dist, heap);else insert(child, child.dist, heap);
endend
Recording the Pathsfor each node do node.dist = ; end;start.dist := 0;insert(start, 0, heap);while (! empty(heap)) do
node := deleteMin(heap);for each edge <node, length, child> do
if (node.dist + length < child.dist) thenchild.dist = node.dist + length;child.prev = node;if (child is in the heap) then
decreaseKey(child, child.dist, heap);else insert(child, child.dist, heap);
endend
Shortest Paths to a Goalfor each node do node.dist = ; end;start.dist := 0;insert(start, 0, heap);while (! empty(heap)) do
node := deleteMin(heap);if GoalTest(node) then return node;for each edge <node, length, child> do
if (node.dist + length < child.dist) thenchild.dist = node.dist + length;child.prev = node;if (child is in the heap) then
decreaseKey(child, child.dist, heap);else insert(child, child.dist, heap);
endendreturn FAIL;
Generating Nodes on the Flystart.dist := 0;insert(start, 0, heap);while (! empty(heap)) do
node := deleteMin(heap);if GoalTest(node) then return node;for each edge <node, length, child> do
if (child is new or node.dist + length < child.dist) thenchild.dist = node.dist + length;child.prev = node;if (child is in the heap) then
decreaseKey(child, child.dist, heap);else insert(child, child.dist, heap);
endendreturn FAIL;
Problem: Large Graphs
• It is expensive to find optimal paths in large graphs, using BFS, IDFS, or Dijkstra’s algorithm
• How can we search large graphs efficiently by using “commonsense” about which direction looks most promising?
Example
52nd St
51st St
50th St
10th A
ve
9th A
ve
8th A
ve
7th A
ve
6th A
ve
5th A
ve
4th A
ve
3rd A
ve
2nd A
ve
S
G
53nd St
Plan a route from 9th & 50th to 3rd & 51st
Example
52nd St
51st St
50th St
10th A
ve
9th A
ve
8th A
ve
7th A
ve
6th A
ve
5th A
ve
4th A
ve
3rd A
ve
2nd A
ve
S
G
53nd St
Plan a route from 9th & 50th to 3rd & 51st
Best-First Search
• The Manhattan distance ( x+ y) is an estimate of the distance to the goal
–It is a heuristic h(state)
• Best-First Search–Order nodes in priority to minimize
estimated distance to the goal
• Compare: BFS / Dijkstra–Order nodes in priority to minimize distance
from the start
Best-First Searchstart.dist := 0;insert(start, h(start), heap);while (! empty(heap)) do
node := deleteMin(heap);if GoalTest(node) then return node;for each edge <node, length, child> do
if (child is new or node.dist + length < child.dist) thenchild.dist = node.dist + length;child.prev = node;if (child is in the heap) then
decreaseKey(child, h(child), heap);else insert(child, h(child), heap);
endendreturn FAIL;
Non-Optimality of Best-First Search
52nd St
51st St
50th St
10th A
ve
9th A
ve
8th A
ve
7th A
ve
6th A
ve
5th A
ve
4th A
ve
3rd A
ve
2nd A
ve
S G
53nd St
Path found by Best-first
Shortest Path
Improving Best-First
• Best-first is usually much faster than BFS/Dijkstra, but might stop with a non-optimal solution
• How can it be modified to be guaranteed to find optimal solutions?
• A* (Hart, Nilsson, Raphael 1968)–One of the first significant algorithms
developed in AI–Widely used in many applications
A*
Criteria for the priority queue:minimize (distance from start) +
(estimated distance to goal)
priority f(n) = g(n) + h(n)f(n) = priority of a nodeg(n) = true distance from starth(n) = heuristic distance to goal
Optimality of A*
• Suppose the estimated distance is always less than or equal to the true distance to the goal
–Heuristic is a lower bound–Heuristic is admissible
• Then: when the goal is removed from the priority queue, we are guaranteed to have found a shortest path
–Note: same is true for Dijkstra
A* in Action
52nd St
51st St
50th St
10th A
ve
9th A
ve
8th A
ve
7th A
ve
6th A
ve
5th A
ve
4th A
ve
3rd A
ve
2nd A
ve
S G
53nd St
f=6+2
f=1+7
f=7+3
A* Searchstart.dist := 0;insert(start, h(start), heap);while (! empty(heap)) do
node := deleteMin(heap);if GoalTest(node) then return node;for each edge <node, length, child> do
if (child is new or node.dist + length < child.dist) thenchild.dist = node.dist + length;child.prev = node;if (child is in the heap) then
decreaseKey(child, child.dist+h(child), heap);
else insert(child, child.dist+h(child), heap);end
endreturn FAIL;
Maze Runner
Observations on A*• Perfect heuristic: If h(n) = h*(n) (true distance)
for all n, then only the nodes on the optimal solution path will be expanded.
• Null heuristic: If h(n) = 0 for all n, then this is an admissible heuristic and A* acts like BFS/Dijkstra.
• Comparing heuristics: If h1(n) < h2(n) h*(n) for all non-goal nodes, then h2 is a better heuristic than h1 – Every node expanded by A* using h2 is also
expanded by A* using h1– h2 is stronger than h1
Memory Use in A*
• A*’s main disadvantage is memory consumption– Once a node is generated, it is always kept in
memory
• Memory-bounded A*– Limits amount of memory used– Tradeoff: sometimes will re-generate parts of
the search tree– Tricky part: guaranteeing optimality
Search Heuristics
• “Optimistic guess” at distance to a solution
• Some heuristics are domain specific– Manhattan distance for grid-like graphs– Euclidean distance for general road maps– Rubik’s Cube
• Admissible, but weak: # cubits out of place / 8• Better:
MAX( Sum( Manhattan distance edge cubits )/4, Sum( Manhattan distance corner cubits )/4 )
Planning Heuristics
• Good general heuristics for planning can be created by relaxing the operators– Eliminate preconditions– Eliminate negative preconditions & effects
• Use the length of the solution to the relaxed problem as a heuristic for the length of the solution to the original problem
Length of Precondition-free Solution?
Other General Techniques
• Plan for each goal separately (recursively), take MAX of sub-solution lengths– Admissible, but weak
• Plan for each goal separately (recursively), take SUM of sub-solution lengths– Non-admissible, but often useful
• Recursively compute set of facts which can be pairwise achieved– Admissible, polynomial time– FF (Hoffmann 2002), winner, 3rd International Planning
Competition (STRIPS Track)
Search and Reasoning
• State-space search can be viewed as a special kind of logical reasoning
• Explicitly representing problems logically, however, has many advantages:– Clarifies thinking– Increased expressivity– Tap into rich set of algorithms for logical
inference
Reasoning and Search
• Logical reasoning can be viewed as a special kind of state space search– State = agent’s explicit beliefs– Operator = making a logical deduction
• Thinking in terms of state space search will help us understand how to create practical inference algorithms