a* algorithm algorithm.pdf> for the last node on each path have two costs! – (1) the real cost...

61
A*-1 © Gunnar Gotshalks A* Algorithm

Upload: others

Post on 25-Jan-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A* Algorithm algorithm.pdf> 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

A*-1 © Gunnar Gotshalks!

A* Algorithm!!!

Page 2: A* Algorithm algorithm.pdf> 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

A*-2 © 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?!

Page 3: A* Algorithm algorithm.pdf> 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

A*-3 © 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?!

Page 4: A* Algorithm algorithm.pdf> 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

A*-4 © 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

Page 5: A* Algorithm algorithm.pdf> 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

A*-5 © 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

Page 6: A* Algorithm algorithm.pdf> 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

A*-6 © 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)!

Page 7: A* Algorithm algorithm.pdf> 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

A*-7 © 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!

Page 8: A* Algorithm algorithm.pdf> 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

A*-8 © 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.!

Page 9: A* Algorithm algorithm.pdf> 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

A*-9 © Gunnar Gotshalks!

A* data structures – leaf node!

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

Lower case L!

Page 10: A* Algorithm algorithm.pdf> 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

A*-10 © 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!

Page 11: A* Algorithm algorithm.pdf> 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

A*-11 © 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!

Page 12: A* Algorithm algorithm.pdf> 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

A*-12 © 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)!

Page 13: A* Algorithm algorithm.pdf> 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

A*-13 © Gunnar Gotshalks!

A* data structures – tree!

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

Page 14: A* Algorithm algorithm.pdf> 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

A*-14 © Gunnar Gotshalks!

A* data structures – tree – 2!

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

Page 15: A* Algorithm algorithm.pdf> 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

A*-15 © 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!

Page 16: A* Algorithm algorithm.pdf> 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

A*-16 © 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 !

Page 17: A* Algorithm algorithm.pdf> 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

A*-17 © 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!

Page 18: A* Algorithm algorithm.pdf> 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

A*-18 © 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

Page 19: A* Algorithm algorithm.pdf> 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

A*-19 © 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

Page 20: A* Algorithm algorithm.pdf> 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

A*-20 © Gunnar Gotshalks!

After S and A have been expanded with bound 9 we have!!t ( S , 9 / 0 , [ l (E , 9 / 2) ] , t (A , 10 / 2 , [ t (B , 10/ 4 ) , [ I ( 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

Page 21: A* Algorithm algorithm.pdf> 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

A*-21 © Gunnar Gotshalks!

Generalization of f-value definition!

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

Page 22: A* Algorithm algorithm.pdf> 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

A*-22 © Gunnar Gotshalks!

Generalization of f-value definition – 2!

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

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

Page 23: A* Algorithm algorithm.pdf> 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

A*-23 © 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!

Page 24: A* Algorithm algorithm.pdf> 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

A*-24 © 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!

Page 25: A* Algorithm algorithm.pdf> 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

A*-25 © 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!

Page 26: A* Algorithm algorithm.pdf> 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

A*-26 © 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!

Page 27: A* Algorithm algorithm.pdf> 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

A*-27 © 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!

Page 28: A* Algorithm algorithm.pdf> 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

A*-28 © 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!

Page 29: A* Algorithm algorithm.pdf> 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

A*-29 © 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!

Page 30: A* Algorithm algorithm.pdf> 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

A*-30 © Gunnar Gotshalks!

Admissibility!

» What does admissible mean?!

Page 31: A* Algorithm algorithm.pdf> 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

A*-31 © Gunnar Gotshalks!

Admissibility – 2!

» What does admissible mean?!

> Acceptable or valid!

Page 32: A* Algorithm algorithm.pdf> 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

A*-32 © Gunnar Gotshalks!

Admissibility – 3!

» What does admissible mean?!

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

Page 33: A* Algorithm algorithm.pdf> 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

A*-33 © Gunnar Gotshalks!

Admissibility of a search algorithm!

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

Page 34: A* Algorithm algorithm.pdf> 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

A*-34 © 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!

Page 35: A* Algorithm algorithm.pdf> 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

A*-35 © Gunnar Gotshalks!

Admissibility of A*!

»  Is A* admissible?!

Page 36: A* Algorithm algorithm.pdf> 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

A*-36 © Gunnar Gotshalks!

Admissibility of A* – 2!

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

Page 37: A* Algorithm algorithm.pdf> 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

A*-37 © Gunnar Gotshalks!

Admissibility of A* – 3!

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

» What are those conditions?!

Page 38: A* Algorithm algorithm.pdf> 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

A*-38 © 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!

Page 39: A* Algorithm algorithm.pdf> 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

A*-39 © 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)?!

Page 40: A* Algorithm algorithm.pdf> 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

A*-40 © 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!

Page 41: A* Algorithm algorithm.pdf> 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

A*-41 © 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!

Page 42: A* Algorithm algorithm.pdf> 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

A*-42 © Gunnar Gotshalks!

Trivial Optimistic h(N)!

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

Page 43: A* Algorithm algorithm.pdf> 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

A*-43 © Gunnar Gotshalks!

Trivial optimistic h(N) – 2!

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

Page 44: A* Algorithm algorithm.pdf> 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

A*-44 © Gunnar Gotshalks!

Trivial optimistic h(N) – 3!

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

» What is the problem with this choice?!

Page 45: A* Algorithm algorithm.pdf> 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

A*-45 © 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!

Page 46: A* Algorithm algorithm.pdf> 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

A*-46 © 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”!

Page 47: A* Algorithm algorithm.pdf> 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

A*-47 © Gunnar Gotshalks!

Optimal optimistic h(N)!

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

Page 48: A* Algorithm algorithm.pdf> 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

A*-48 © Gunnar Gotshalks!

Optimal optimistic h(N) – 2!

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

Page 49: A* Algorithm algorithm.pdf> 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

A*-49 © 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)?!

Page 50: A* Algorithm algorithm.pdf> 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

A*-50 © 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!

Page 51: A* Algorithm algorithm.pdf> 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

A*-51 © 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!

Page 52: A* Algorithm algorithm.pdf> 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

A*-52 © Gunnar Gotshalks!

Distance between states!

◊  Many heuristics depend upon distance between states!

Page 53: A* Algorithm algorithm.pdf> 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

A*-53 © 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!

Page 54: A* Algorithm algorithm.pdf> 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

A*-54 © 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

Page 55: A* Algorithm algorithm.pdf> 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

A*-55 © Gunnar Gotshalks!

Common distance heuristics!

» What are two common distance heuristics?!

Page 56: A* Algorithm algorithm.pdf> 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

A*-56 © Gunnar Gotshalks!

Common distance heuristics – 2!

» What are two common distance heuristics?!

> Euclidean distance !

> Manhattan distance!

Page 57: A* Algorithm algorithm.pdf> 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

A*-57 © Gunnar Gotshalks!

Euclidean distance!

» What is Euclidean distance?!

Page 58: A* Algorithm algorithm.pdf> 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

A*-58 © 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

Page 59: A* Algorithm algorithm.pdf> 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

A*-59 © Gunnar Gotshalks!

Manhattan distance!

» What is Manhattan distance?!

Page 60: A* Algorithm algorithm.pdf> 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

A*-60 © 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)

Page 61: A* Algorithm algorithm.pdf> 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

A*-61 © 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!