Top Banner
Heuristic State Space Seach Henry Kautz
27

Heuristic State Space Seach Henry Kautz. Assignment.

Dec 17, 2015

Download

Documents

Norma Stevenson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Heuristic State Space Seach Henry Kautz. Assignment.

Heuristic State Space Seach

Henry Kautz

Page 2: Heuristic State Space Seach Henry Kautz. Assignment.

Assignment

Page 3: 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

Page 4: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 5: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 6: Heuristic State Space Seach Henry Kautz. Assignment.

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;

Page 7: Heuristic State Space Seach Henry Kautz. Assignment.

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;

Page 8: Heuristic State Space Seach Henry Kautz. Assignment.

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?

Page 9: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 10: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 11: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 12: Heuristic State Space Seach Henry Kautz. Assignment.

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;

Page 13: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 14: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 15: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 16: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 17: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 18: Heuristic State Space Seach Henry Kautz. Assignment.

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;

Page 19: Heuristic State Space Seach Henry Kautz. Assignment.

Maze Runner

Page 20: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 21: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 22: Heuristic State Space Seach Henry Kautz. Assignment.

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 )

Page 23: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 24: Heuristic State Space Seach Henry Kautz. Assignment.

Length of Precondition-free Solution?

Page 25: Heuristic State Space Seach Henry Kautz. Assignment.

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)

Page 26: Heuristic State Space Seach Henry Kautz. Assignment.

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

Page 27: Heuristic State Space Seach Henry Kautz. Assignment.

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