Heuristic Search - York University · 2014-03-09 · Why use heuristic search – 3! » Why is...

89
HS-1 © Gunnar Gotshalks Heuristic Search

Transcript of Heuristic Search - York University · 2014-03-09 · Why use heuristic search – 3! » Why is...

HS-1 © Gunnar Gotshalks!

Heuristic Search!!

HS-2 © Gunnar Gotshalks!

What is heuristic search!

» What is a heuristic search?!

HS-3 © Gunnar Gotshalks!

What is heuristic search – 2!

» What is a heuristic search?!

> Using problem domain information!

!

HS-4 © Gunnar Gotshalks!

Why use heuristic search!

» Why is heuristic search used?!

HS-5 © Gunnar Gotshalks!

Why use heuristic search – 2!

» Why is heuristic search used?!

> To make searching more efficient by concentrating on the most likely paths!–  Best first paths ���

HS-6 © Gunnar Gotshalks!

Why use heuristic search – 3!

» Why is heuristic search used?!

> To make searching more efficient by concentrating on the most likely paths!–  Best first paths ���

> As opposed to trying!–  All paths equally –  Random order

HS-7 © Gunnar Gotshalks!

Best-first search!

» Best-first search would be based on which basic search method?!

HS-8 © Gunnar Gotshalks!

Best-first search – 2!

» Best-first search would be based on which basic search method?!

> Breadth-first!

HS-9 © Gunnar Gotshalks!

Best-first search – 3!

» Best-first search would be based on which basic search method?!

> Breadth-first!

» Why?!

HS-10 © Gunnar Gotshalks!

Best-first search – 4!

» Best-first search would be based on which basic search method?!

> Breadth-first!

» Why?!> Need to have a set of paths from which to select

the best path to extend!

HS-11 © Gunnar Gotshalks!

Best-first search – 5!

» Best-first search would be based on which basic search method?!

> Breadth-first!

» Why?!> Need to have a set of paths from which to select

the best path to extend!

> Want to minimize work selecting paths to extend!

HS-12 © Gunnar Gotshalks!

Selecting a path!

◊  Given a set of paths P1 .. Pn!» What do you need to be able to select the best path

to extend? !

HS-13 © Gunnar Gotshalks!

Selecting a path – 2!

◊  Given a set of paths P1 .. Pn!» What do you need to be able to select the best path

to extend?!

> A cost is associated with each path!

HS-14 © Gunnar Gotshalks!

Selecting a path – 3!

◊  Given a set of paths P1 .. Pn!» What do you need to be able to select the best path

to extend?!

> A cost is associated with each path!

» How do you use the cost to select the best path?!

HS-15 © Gunnar Gotshalks!

Selecting a path – 4!

◊  Given a set of paths P1 .. Pn!» What do you need to be able to select the best path

to extend?!

> A cost is associated with each path!

» How do you use the cost to select the best path?!

> The path with the minimum cost would be the best one to extend !

HS-16 © Gunnar Gotshalks!

Path cost!

◊  Given a set of paths P1 .. Pn!» How is the cost of a path computed?!

HS-17 © Gunnar Gotshalks!

Path cost – 2!

◊  Given a set of paths P1 .. Pn!» How is the cost of a path computed?!

> Each edge has a cost associated with it.!

HS-18 © Gunnar Gotshalks!

Path cost – 3!

◊  Given a set of paths P1 .. Pn!» How is the cost of a path computed?!

> Each edge has a cost associated with it.!

> The cost of a path is the sum of the costs of the edges in the path!

HS-19 © Gunnar Gotshalks!

Path cost – 4!

◊  Given a set of paths P1 .. Pn!» How would the cost of a path computed?!

> Each edge has a cost associated with it.!> The cost of a path is the sum of the costs of the

edges in the path!

» What else?!

HS-20 © Gunnar Gotshalks!

Path cost – 5!

◊  Given a set of paths P1 .. Pn!» How would the cost of a path computed?!

> Each edge has a cost associated with it.!> The cost of a path is the sum of the costs of the

edges in the path!

» What else?!

S

Found paths

GOAL?

HS-21 © Gunnar Gotshalks!

Path cost – 6!

◊  Given a set of paths P1 .. Pn!» How would the cost of a path computed?!

> Each edge has a cost associated with it.!> The cost of a path is the sum of the costs of the

edges in the path!

» What else?!> An estimate of the cost to get to the goal from

the vertex at the end of the path!

HS-22 © Gunnar Gotshalks!

Types of heuristic searches!

»  In the textbook, what types of heuristic searches are discussed?!

HS-23 © Gunnar Gotshalks!

Types of heuristic searches – 2!

»  In the textbook, what types of heuristic searches are discussed?!

> A*!–  One of the best known algorithms in AI

HS-24 © Gunnar Gotshalks!

Types of heuristic searches – 3!

»  In the textbook, what types of heuristic searches are discussed?!

> A*!–  One of the best known algorithms in AI

>  IDA*!–  Iterative deepening A*

HS-25 © Gunnar Gotshalks!

Types of heuristic searches – 4!

»  In the textbook, what types of heuristic searches are discussed?!

> A*!–  One of the best known algorithms in AI

>  IDA*!–  Iterative deepening A*

> RBFS!–  Recursive Best First Search

HS-26 © Gunnar Gotshalks!

Types of heuristic searches – 5!

»  In the textbook, what types of heuristic searches are discussed?!

> A*!–  One of the best known algorithms in AI

>  IDA*!–  Iterative deepening A*

> RBFS!–  Recursive Best First Search

> RTA*!–  Real-time A*

HS-27 © Gunnar Gotshalks!

Difference between search methods!

» What is the major difference between the different heuristic search methods?!

HS-28 © Gunnar Gotshalks!

Difference between search methods – 2!

» What is the major differences between the different heuristic search methods?!

> Different ways of trading off space versus time!–  E.g. have linear space vs exponential space at a cost of

regenerating paths that were not saved

HS-29 © Gunnar Gotshalks!

Difference between search methods – 3!

» What is the major differences between the different heuristic search methods?!

> Different ways of trading off space versus time!–  E.g. have linear space vs exponential space at a cost of

regenerating paths that were not saved

> Trading off optimality vs time!–  Minimize computation time at the expense of quality of

solution

HS-30 © Gunnar Gotshalks!

Basics of A* algorithm!

◊  You are in the middle of a search and have a set of potential paths P1 .. Pn to explore.!» How do you select the best path to extend?!

HS-31 © Gunnar Gotshalks!

Basics of A* algorithm – 2!

◊  You are in the middle of a search and have a set of potential paths P1 .. Pn to explore.!» How do you select the best path to extend?!

> For the last node on each path have two costs!

» What are they?!

HS-32 © Gunnar Gotshalks!

Basics of A* algorithm – 3!

◊  You are in the middle of a search and have a set of potential paths P1 .. Pn to explore.!» How do you select the best path to extend?!

> For the last node on each path have two costs!

» What are they?!>  (1) the real cost of following the path!

•  g(n) where n is the last vertex in the path

HS-33 © Gunnar Gotshalks!

Basics of A* algorithm – 4!

◊  You are in the middle of a search and have a set of potential paths P1 .. Pn to explore.!» How do you select the best path to extend?!

> For the last node on each path have two costs!

» What are they?!>  (1) the real cost of following the path!

–  g(n) where n is the last vertex in the path ���

>  (2) a heuristic estimate of the cost of the optimal extension of the path to the goal vertex!

•  h(n) where n is the last vertex in the path

HS-34 © Gunnar Gotshalks!

Basics of A* algorithm – 5!

◊  You are in the middle of a search and have a set of potential paths P1 .. Pn to explore.!» How do you select the best path to extend?!

> For the last node on each path have two costs!–  (1) the real cost of following the path

•  g(n) where n is the last vertex in the path –  (2) a heuristic estimate of the cost of the optimal

extension of the path to the goal vertex •  h(n) where n is the last vertex in the path ���

» The estimated cost for the full path to the goal is!>  f(n) = g(n) + h(n)!

HS-35 © Gunnar Gotshalks!

Basics of A* algorithm – 3!

• • •S N G• • •

g(N)! h(N)!

S .. N is the known path! g(N) is its real cost!

S .. G is the solution path!total estimated cost is! f(N) = g(n) + h(N)!

N .. G is the path yet to be found! h(N) is its estimated cost!

HS-36 © Gunnar Gotshalks!

Bratko Figure 12.2!

h(n) in magentag(n) in cloverf(n) in mocha +=

F

S

E G

A B C D

T2

5 2 2

2

2 2 3

3

7 = 2 + 5 8 = 4 + 4 10 = 6 + 4 12 = 9 + 3

9 = 2 + 7 11 = 7 + 4 11 = 9 + 211 = 11 + 0

Put "write('Case1 '), S=[N|P], write(S), nl,” just before "goal”!in expand case 1 to see the sequence in which the path is expanded.!

HS-37 © Gunnar Gotshalks!

A* data structures – leaf node!

◊  A leaf is a single node tree – l ( N , F / G )!

Lower case L!

HS-38 © Gunnar Gotshalks!

A* data structures – leaf node – 2!

◊  A leaf is a single node tree – l ( N , F / G )!» N is a node in the state-space!

HS-39 © Gunnar Gotshalks!

A* data structures – leaf node – 3!

◊  A leaf is a single node tree – l ( N , F / G )!» N is a node in the state-space !

» G = g(n) is the cost of the path to N!

HS-40 © Gunnar Gotshalks!

A* data structures – leaf node – 4!

◊  A leaf is a single node tree – l ( N , F / G )!» N is a node in the state-space !

» G is the cost of the path to N!

» F is f(N) = G + h(N)!

HS-41 © Gunnar Gotshalks!

A* data structures – tree!

◊  A tree – t ( N , F / G , Sub-trees)!

HS-42 © Gunnar Gotshalks!

A* data structures – tree – 2!

◊  A tree – t ( N , F / G , Sub-trees)!» N is a node in the state-space !

HS-43 © Gunnar Gotshalks!

A* data structures – tree – 3!

◊  A tree – t ( N , F / G , Sub-trees)!» N is a node in the state-space !

» G = g(n) is the cost of the path to N!

HS-44 © Gunnar Gotshalks!

A* data structures – tree – 4!

◊  A tree – t ( N , F / G , Sub-trees)!» N is a node in the state-space !

» G = g(n) is the cost of the path to N!

» F is the updated value of f(N)!>  f-value of the most promising successor of N !

HS-45 © Gunnar Gotshalks!

A* data structures – tree – 5!

◊  A tree – t ( N , F / G , Sub-trees)!» N is a node in the state-space !

» G = g(n) is the cost of the path to N!

» F is the updated value of f(N)!>  f-value of the most promising successor of N !

» Sub-trees is a list of the sub-trees from N!

HS-46 © Gunnar Gotshalks!

Example for Figure 12.2!

When S is expanded, the existing tree is represented as !

!t ( S , 7 / 0 , [ l ( A , 7 / 2 ) , l ( E , 9 / 2 ) ] )!

h(n) in magentag(n) in cloverf(n) in mocha +=

F

S

E G

A B C D

T2

5 2 2

2

2 2 3

3

7 = 2 + 5 8 = 4 + 4 10 = 6 + 4 12 = 9 + 3

9 = 2 + 7 11 = 7 + 4 11 = 9 + 211 = 11 + 0

HS-47 © Gunnar Gotshalks!

Example for Figure 12.2 – 2!

t ( S , 7 / 0 , [ l ( A , 7 / 2 ) , l ( E , 9 / 2 ) ] )!!The most promising node to expand is A!

h(n) in magentag(n) in cloverf(n) in mocha +=

F

S

E G

A B C D

T2

5 2 2

2

2 2 3

3

7 = 2 + 5 8 = 4 + 4 10 = 6 + 4 12 = 9 + 3

9 = 2 + 7 11 = 7 + 4 11 = 9 + 211 = 11 + 0

HS-48 © Gunnar Gotshalks!

After S and A have been expanded we have!!t ( S , 9 / 0 , [ l (E , 9 / 2) ] , t (A , 10 / 2 , [ t (B , 10 / 4 , [ l ( C , 10 / 6) ] ) ] ) ] ) !!

Example for Figure 12.2 – 3!

Updated – E is the most promising successor!

h(n) in magentag(n) in cloverf(n) in mocha +=

F

S

E G

A B C D

T2

5 2 2

2

2 2 3

3

7 = 2 + 5 8 = 4 + 4 10 = 6 + 4 12 = 9 + 3

9 = 2 + 7 11 = 7 + 4 11 = 9 + 211 = 11 + 0

HS-49 © Gunnar Gotshalks!

Generalization of f-value definition!

◊  For a single node we have !»  f (N) = g (N) + h (N)!

HS-50 © Gunnar Gotshalks!

Generalization of f-value definition – 2!

◊  For a single node we have !»  f ( N ) = g ( N ) + h ( N )!

◊  For a tree with root node N we have, where the Sj are sub-trees of N !»  f ( T ) = min ( f ( Sj ) )!

HS-51 © Gunnar Gotshalks!

Expand parameter diagram!

Nodes at boundary of expansion have f > Bound!

Expansion

S

Tree

N

Path

Tree1 = Tree + Expansion!

Expand is the main routine!for the A* algorithm!

HS-52 © Gunnar Gotshalks!

Expand parameters for A*!

◊  Prolog implementation for A* with the main routine!» Expand ( Path, Tree, Bound, Tree1, Solved, Solution )!

◊  Where!» Path – between start and start of subtree Tree!

HS-53 © Gunnar Gotshalks!

Expand parameters for A* – 2!

◊  Prolog implementation for A* with the main routine!» Expand ( Path, Tree, Bound, Tree1, Solved, Solution )!

◊  Where!» Path – between start and start of subtree Tree!» Tree – subtree at the end of Path!

HS-54 © Gunnar Gotshalks!

Expand parameters for A* – 3!

◊  Prolog implementation for A* with the main routine!» Expand ( Path, Tree, Bound, Tree1, Solved, Solution )!

◊  Where!» Path – between start and start of subtree Tree!» Tree – subtree at the end of Path!» Bound – cost stops tree expansion!

HS-55 © Gunnar Gotshalks!

Expand parameters for A* – 4!

◊  Prolog implementation for A* with the main routine!» Expand ( Path, Tree, Bound, Tree1, Solved, Solution )!

◊  Where!» Path – between start and start of subtree Tree!» Tree – subtree at the end of Path!» Bound – cost stops tree expansion!» Tree1 – Tree expanded until f(N) > Bound!

HS-56 © Gunnar Gotshalks!

Expand parameters for A* – 5!

◊  Prolog implementation for A* with the main routine!» Expand ( Path, Tree, Bound, Tree1, Solved, Solution )!

◊  Where!» Path – between start and start of subtree Tree!» Tree – subtree at the end of Path!» Bound – cost stops tree expansion!» Tree1 – Tree expanded until f(N) > Bound!» Solved – “yes” when goal is found!

HS-57 © Gunnar Gotshalks!

Expand parameters for A* – 6!

◊  Prolog implementation for A* with the main routine!» Expand ( Path, Tree, Bound, Tree1, Solved, Solution )!

◊  Where!» Path – between start and start of subtree Tree!» Tree – subtree at the end of Path!» Bound – cost stops tree expansion!» Tree1 – Tree expanded until f(N) > Bound!» Solved – “yes” when goal is found!» Solution – path to goal when it is found!

HS-58 © Gunnar Gotshalks!

Admissibility!

» What does admissible mean?!

HS-59 © Gunnar Gotshalks!

Admissibility – 2!

» What does admissible mean?!

> Acceptable or valid!

HS-60 © Gunnar Gotshalks!

Admissibility – 3!

» What does admissible mean?!

> Acceptable or valid!–  Especially as evidence in a court of law

HS-61 © Gunnar Gotshalks!

Admissibility of a search algorithm!

» When would a search algorithm be considered to be admissible?!

HS-62 © Gunnar Gotshalks!

Admissibility of a search algorithm – 2!

» When would a search algorithm be considered to be admissible?!

>  If it is guaranteed to find an optimal solution!

HS-63 © Gunnar Gotshalks!

Admissibility of A*!

»  Is A* admissible?!

HS-64 © Gunnar Gotshalks!

Admissibility of A* – 2!

»  Is A* admissible?!> Yes, with necessary conditions!

HS-65 © Gunnar Gotshalks!

Admissibility of A* – 3!

»  Is A* admissible?!> Yes, with necessary conditions!

» What are those conditions?!

HS-66 © Gunnar Gotshalks!

Admissibility of A* – 4!

»  Is A* admissible?!> Yes, with necessary conditions!

» What are those conditions?!> h(N) ≤ h*(N) for all nodes in the state space!

HS-67 © Gunnar Gotshalks!

Admissibility of A* – 5!

»  Is A* admissible?!> Yes, with necessary conditions!

» What are those conditions?!> h(N) ≤ h*(N) for all nodes in the state space!

» What is h*(N)?!

HS-68 © Gunnar Gotshalks!

Admissibility of A* – 6!

»  Is A* admissible?!> Yes, with necessary conditions!

» What are those conditions?!> h(N) ≤ h*(N) for all nodes in the state space!

» What is h*(N)?!> The actual cost of the minimum cost path from

N to the goal!

HS-69 © Gunnar Gotshalks!

Admissibility of A* – 7!

»  Is A* admissible?!> Yes, with necessary conditions!

» What are those conditions?!> h(N) ≤ h*(N) for all nodes in the state space!

» What is h*(N)?!> The actual cost of the minimum cost path from

N to the goal!

Pick an h(N) that is optimistic!

HS-70 © Gunnar Gotshalks!

Trivial Optimistic h(N)!

» What is a trivial optimistic h(N)?!

HS-71 © Gunnar Gotshalks!

Trivial optimistic h(N) – 2!

» What is a trivial optimistic h(N)?!> h(N) = 0!

HS-72 © Gunnar Gotshalks!

Trivial optimistic h(N) – 3!

» What is a trivial optimistic h(N)?!> h(N) = 0!

» What is the problem with this choice?!

HS-73 © Gunnar Gotshalks!

Trivial optimistic h(N) – 4!

» What is a trivial optimistic h(N)?!> h(N) = 0!

» What is the problem with this choice?!> Gives poor guidance for a search!

HS-74 © Gunnar Gotshalks!

Trivial optimistic h(N) – 5!

» What is a trivial optimistic h(N)?!> h(N) = 0!

» What is the problem with this choice?!> Gives poor guidance for a search!

> All possible expansion nodes are equally “good”!

HS-75 © Gunnar Gotshalks!

Optimal optimistic h(N)!

» What would be an optimal optimistic h(N)?!

HS-76 © Gunnar Gotshalks!

Optimal optimistic h(N) – 2!

» What would be an optimal optimistic h(N)?!> h(N) = h*(N)!

HS-77 © Gunnar Gotshalks!

Optimal optimistic h(N) – 3!

» What would be an optimal optimistic h(N)?!> h(N) = h*(N)!

» What is the problem in getting the optimal h(N)?!

HS-78 © Gunnar Gotshalks!

Optimal optimistic h(N) – 3!

» What would be an optimal optimistic h(N)?!> h(N) = h*(N)!

» What is the problem in getting the optimal h(N)?!> Finding the optimal h(N) is the essence of the

difficulty in finding a solution to a problem!

HS-79 © Gunnar Gotshalks!

Optimal optimistic h(N) – 4!

» What would be an optimal optimistic h(N)?!> h(N) = h*(N)!

» What is the problem in getting the optimal h(N)?!> Finding the optimal h(N) is the essence of the

difficulty in finding a solution to a problem!

In practice finding h(N) that minimizes the space that is searched and is admissible is the main difficulty!

HS-80 © Gunnar Gotshalks!

Distance between states!

◊  Many heuristics depend upon distance between states!

HS-81 © Gunnar Gotshalks!

Distance between states – 2!

◊  Many heuristics depend upon distance between states!> For example in the travelling salesman problem

it is the distance between cities!

HS-82 © Gunnar Gotshalks!

Distance between states – 3!

◊  Many heuristics depend upon distance between states!> For example in the travelling salesman problem

it is the distance between cities!>  In the tile-puzzle it is the distance the tiles are

from the goal position!

!

L A T E

Y O U R

M I N D

P A R

HS-83 © Gunnar Gotshalks!

Common distance heuristics!

» What are two common distance heuristics?!

HS-84 © Gunnar Gotshalks!

Common distance heuristics – 2!

» What are two common distance heuristics?!

> Euclidean distance !

> Manhattan distance!

HS-85 © Gunnar Gotshalks!

Euclidean distance!

» What is Euclidean distance?!

HS-86 © Gunnar Gotshalks!

Euclidean distance – 2!

◊  The Euclidean distance between point (X1,Y1) and point (X2, Y2)!»  Is the straight line distance between the points

based on Euclidean geometry!

D = (X1− X2)2 + (Y1−Y 2)2

HS-87 © Gunnar Gotshalks!

Manhattan distance!

» What is Manhattan distance?!

HS-88 © Gunnar Gotshalks!

Manhattan distance – 2!

◊  The Manhattan distance between point (X1, Y2) and point (X2,Y2)!»  Is the sum of the horizontal and vertical distances

between the two points.!

D = abs(X1− X2)+ abs(Y1−Y 2)

HS-89 © Gunnar Gotshalks!

Manhattan distance – 3!

» Manhattan is one of the boroughs in New York with rectangular blocks. To travel between two points you can only move parallel to one or the other of the X or Y “axes” along the streets!

!L A T E

Y O U R

M I N D

P A R

The empty square can only!travel parallel to the axes!