Heuristic Search Heuristic Search Best-First A * Heuristic - - PowerPoint PPT Presentation

heuristic search heuristic search
SMART_READER_LITE
LIVE PREVIEW

Heuristic Search Heuristic Search Best-First A * Heuristic - - PowerPoint PPT Presentation

RN, Chapter 4.1 4.2 Heuristic Search Heuristic Search Best-First A * Heuristic Functions Some material from: D Lin, J You, JC Latombe 1 Search Overview Introduction to Search Blind Search Techniques Heuristic


slide-1
SLIDE 1

1

Heuristic Search Heuristic Search

RN, Chapter 4.1 – 4.2

Some material from: D Lin, J You, JC Latombe

Best-First A* Heuristic Functions

slide-2
SLIDE 2

2

Search Overview

Introduction to Search Blind Search Techniques

Heuristic Search Techniques

Best-First A* Heuristic Functions

Stochastic Algorithms Game Playing search Constraint Satisfaction Problems

slide-3
SLIDE 3

3

Heuristic Search

“Blind” methods only know Goal / NonGoal Often ∃ other problem-specific knowledge

that can guide search:

Heuristic fn

h(n): Nodes →ℜ

estimate of distance from n to a goal

Eg: straight line on map,

  • r “Manhattan distance”,
  • r …

Use: Given list of nodes to expand,

choose node n with min'l h(.)

4 3 2 1 3 2 4 3 4 2 1 5

slide-4
SLIDE 4

4

Heuristic Function Heuristic Function

h(n) estimates cost of cheapest path

from node n to goal node

Example: 8-puzzle

n

goal h1(n) = number of misplaced tiles = 6 5 8 4 2 1 7 3 6 1 2 3 4 5 6 7 8 5 8 4 2 1 7 3 6

slide-5
SLIDE 5

5

Heuristic Function Heuristic Function

h(n) estimates cost of cheapest path

from node n to goal node

Example: 8-puzzle

n

goal h1(n) = number of misplaced tiles = 6 h2 (n) = sum of the distances of every tile to its goal position = 3 + 1 5 8 4 2 1 7 3 6 1 2 3 4 5 6 7 8 1 2

+ 3 + 0 + 2 + 1 + 0 + 3

= 13

slide-6
SLIDE 6

6

Greedy Best Greedy Best-

  • First Search

First Search

BestF_Search( start, operations, is_goal ): path L := makeList( start ) loop n := arg minni∈L h(ni)

;; “most promising” node in L according to h(.)

if [ is_goal( n ) ] return( n ) S := successors( n, operators ) L := insert( S, L ) until L is empty return( failure ) Idea: choose frontier node with smallest h-value ie, “closest to goal" Can also return “path from start to n” . . . by identifying each node with path

slide-7
SLIDE 7

7

Robot Navigation Robot Navigation

slide-8
SLIDE 8

9

Robot Navigation Robot Navigation

2 1 1 5 8 7 7 3 4 7 6 7 6 3 2 8 6 4 5 2 3 3 3 6 5 2 4 4 3 5 5 4 6 5 6 4 5 h(n) = Manhattan distance to the goal 7 Edmonton

slide-9
SLIDE 9

10

Heuristic Function – Bulgaria

hSLD (n) is straight-line distance from n to goal (Bucharest)

slide-10
SLIDE 10

11

Best First

slide-11
SLIDE 11

12

Best First

slide-12
SLIDE 12

14

BestFirst is SubOptimal

hSLD finds path:

Arad → Sibiu → Fagaras → Bucharest

(Cost = 140 + 99 + 211 = 450)

Not optimal!

C( Arad → Sibiu → Rimnicu → Pitesti → Bucharest ) = 140 + 80 + 97 + 101 = 418 < hSLD 's solution!

BestFirst is greedy:

takes BIGGEST step each time…

slide-13
SLIDE 13

15

BestFirst can Loop

Consider: Iasi → Fagaras

hSLD suggests: Iasi → Neamt

Worse: Unless search alg detects repeated

states, BestFirst will oscillate: Iasi → Neamt

Iasi → Neamt

→ …

Loops are a real problem…

? ?

slide-14
SLIDE 14

16

Properties of Greedy Best-First Search

If state space is finite and

we avoid repeated states, THEN Best-First search is complete, but in general is not optimal

If state space is finite and

we do not avoid repeated states, THEN Best-First search is not complete.

If the state space is infinite,

THEN Best-First search is not complete.

slide-15
SLIDE 15

17

Analysis of Greedy BestFirst

Complete? Optimal? Time: Space: Worst of both worlds

≈DFS: too greedy! ≈BFS: too much space!

No

…can go down ∞-path (oscillate)

No

… may not find shortest path

O(bm) O(bm)

(if h(.)≡ 0, could examine entire space)

slide-16
SLIDE 16

18

A* Search

Find cheapest path, quickly

  • Consider both:

Path from start to n:

g(n) = cost of path found to n

Path from n to goal (est.):

h(n) = estimate of cost from n to a goal

f(n) = g(n)+h(n)

est of cost of path from start to goal, via n

Start n Goal g(n) h(n) f(n)

slide-17
SLIDE 17

19

A* Search, con’t

A* selects node with min'l f(n)

…ie, node with lowest estimated distance from start to goal, constrained to go via that node

  • … mix of { } searches!

lowest-cost-first best-first (so far) (to go)

slide-18
SLIDE 18

21

Example

  • f A*

Note: Finds Optimal Path!

A* expands

Rimnicu (f = (140+80)+193 = 413)

  • ver

Faragas (f = (140+99)+178 = 417)

Why?

Fagaras is closer to Bucharest (than Rimnicu) but path taken to get to Fargaras is not as efficient at getting close to Bucharest … as Rimnicu

slide-19
SLIDE 19

22

Robot Navigation Robot Navigation

f(n) = g(n)+h(n), with h(n) = Manhattan distance to goal 2 1 1 5 8 7 7 3 4 7 6 7 6 3 2 8 6 4 5 2 3 3 3 6 5 2 4 4 3 5 5 4 6 5 6 4 5 7+0 6+1 6+1 8+1 7+0 7+2 6+1 7+2 6+1 8+1 7+2 8+3 7+2 6+3 6+3 5+4 5+4 4+5 4+5 3+6 3+6 2+7 8+3 7+4 7+4 6+5 5+6 6+3 5+6 2+7 3+8 4+7 5+6 4+7 3+8 4+7 3+8 3+8 2+9 2+9 3+10 2+9 3+8 2+9 1+10

1+10 0+11

3+8 4+9 Edmonton

slide-20
SLIDE 20

23

How A* Searches

Contour-lines of “equal-f values” A* expands nodes with increasing f(n)

values

If use h(.)≡ 0 (UniformCost)

get Circles ⇒ more nodes expanded (in general)!

slide-21
SLIDE 21

24

Admissible heuristic Admissible heuristic

h*(n) = cost of optimal path

from n to a goal node

Heuristic h(n) is admissible if:

0 ≤ h(n) ≤ h*(n)

Admissible heuristic is always optimistic True for

Straight Line [map traversal] Manhattan distances [8-puzzle] Number of attacking queens [n-queens]

[place all queens, then move]

⇒ f(.) is under-estimate

slide-22
SLIDE 22

25

Heuristics for 8 Heuristics for 8-

  • Puzzle

Puzzle

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 n goal

  • h1

(n) = number of misplaced tiles …

= 6

  • h2

(n) = sum of distances of each tile to goal posn

… = 13

  • h3

(n) = h1 (n) + 3 x h2 (n) …

= 45

  • h4

(n) ≡ 0 … = 0

  • h5

(n) = min{ h1 (n) , h2 (n) } …

= 6

Admissible??

+ + – + +

slide-23
SLIDE 23

26

f(n) is monotonic

f (n) ≤ f (n’) , as

from-S-to-E-via-n is less constrained than from-S-to-E-via-n-n’

S E n

g(n) h(n) ≤ h*(n)

n’

slide-24
SLIDE 24

27

Monotonic f(.)

f(.) is “monotonic" ≡

f( Successor(n) ) ≥ f(n)

Always true if

| h(n) – h(m) | ≤ d(n,m) … d(n,m) is distance from n to m

If true:

first path that A* finds to node, is always shortest

If f (.) not monotonic,

can modify to be:

Eg, n’ ∈ Successor(n) f(n) = g(n)+h(n) = 3+4 = 7 f(n’) = g(n’)+h(n’) = 4+2 = 6

  • But… any path through n’ is also path

through n, so f(n) must be ≥ 7 ⇒ should reset f(n’) = 7 ⇒ use

f(n’) = max{ f(n), g(n’)+h(n’) }

Called “path-max equation” … ignores misleading numbers in heuristic

slide-25
SLIDE 25

28

A* is OPTIMAL

Thrm: A* always returns optimal solution if

∃ solution h(n) is under-estimate

PROOF: Let G be optimal goal, with f(G) = g(G) = f G2 be suboptimal goal, with f(G2) = g(G2 ) > f If A* returns G2 ⇒ G2 is chosen over n, where n is node on optimal path to G This only happens if f(G2 ) ≤ f(n) As f is monotonically increasing along every path, ⇒ f = f(G) ≥ f(n) Hence, f ≥ f(G2 ) … ie, if g(G) ≥ g(G2) … contradicting claim that G2 is suboptimal! []

slide-26
SLIDE 26

29

Properties of A*

A* is Optimally Efficient

Given the information in h(.), no other optimal search method can expand fewer nodes. Non-trivial and quite remarkable!

A* is Complete

… unless there are ∞ nodes w/ f(n) < f *

A* is Complete

if branching factor is finite & arc costs bounded above zero (∃ε > 0 s.t. c(ai)≥ε )

Time/ Space Complexity:

Still exponential as ≈breadth-first. … unless |h(n) – h(n*)| ≤ O( log(h(n*) ) h(n*) = true cost of getting from n to goal

slide-27
SLIDE 27

30

8 8-

  • Puzzle

Puzzle

0+4 1+5 1+5 1+3 3+3 3+4 3+4 3+2 4+1 5+2 5+0 2+3 2+4 2+3

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles goal

slide-28
SLIDE 28

31

Robot navigation Robot navigation

Cost of one horizontal/vertical step = 1 Cost of one diagonal step = √2

f(n) = g(n) + h(n), with h(n) = straight-line distance from n to goal

slide-29
SLIDE 29

32

A* Topics

Which heuristic? Avoiding Loops Iterative Deepening A*

slide-30
SLIDE 30

34

Heuristics for 8 Heuristics for 8-

  • Puzzle

Puzzle

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 n goal

  • h1

(n) = number of misplaced tiles …

= 6

  • h2

(n) = sum of distances of each tile to goal posn

…= 13

  • h3

(n) = h1 (n) + 3 x h2 (n)

… = 45

  • h4

(n) == 0 … = 0 Admissible??

+ + – + Many admissible heuristics … which to use??

slide-31
SLIDE 31

35

Importance of h(.)

A*( hi ) expands all nodes with

f(n) = g(n)+hi (n) < f* … ie, with hi(n) < f* - g(n)

h1(n) < h2(n)

⇒ If A*(h2) expands n, then A*(h1) expands n! . . . but not vice versa A*(h2 ) might expand FEWER nodes

So LARGER hi() means fewer n's expanded!

f* - g(n) h1 (n) h2 (n) n

slide-32
SLIDE 32

36

Importance of h(.)

LARGER hi() means

fewer n's expanded!

As hC ≤ hM ≤ h*,

prefer hM !

Gen'l:

Want largest h() that is under-estimate

f* - g(n) h1 (n) h2 (n)

slide-33
SLIDE 33

37

Effect of Different Heuristic Functions

“Effective Branching Factor” b is solution to

N = 1+(b*)+(b*)2 +(b*)3 + …+(b*)d where N is # of nodes searched d is solution depth

slide-34
SLIDE 34

38

About Heuristics About Heuristics

  • Heuristics are intended to
  • rient the search along promising paths
  • Time spent evaluating heuristic function must

be recovered by a better search

  • “Perfect heuristic function” would mean NO search!
  • Deciding which node to expand ≡

“meta-reasoning”

  • Heuristics…
  • may not always look like numbers
  • may involve large amount of knowledge
slide-35
SLIDE 35

39

Inventing Heuristics

Solve problem, then compute backwards... If {h1, … hk} all underestimates,

use hmax(n) = max { hi(n) } (Still an under-estimate, but larger … )

Relaxation:

Consider SIMPLER version of problem. As heuristic, use

“exact answer to approx problem"

slide-36
SLIDE 36

40

5 8 4 2 1 7 3 6

Inventing Heuristics

Original: Relaxed version#1:

Ie, can TELEPORT tile to blank

⇒ # of misplaced tiles hC

Relaxed version#2:

Ie, can walk over non-blank tile

⇒ Manhattan distance hM

Can move tile from sq A to sq B if … A is adjacent to B and B is blank.

5 8 4 2 1 7 3 6 5 8 4 2 1 7 3 6 1 2

Can move tile from sq A to sq B if … A is adjacent to B and B is blank. Can move tile from sq A to sq B if … A is adjacent to B and B is blank.

slide-37
SLIDE 37

41

Other Tricks

Patterns Databases Learning from part experiences

slide-38
SLIDE 38

42

Avoiding Repeated States in A* Avoiding Repeated States in A*

If the heuristic h(.) is monotonic, then:

Let CLOSED be the list of states

associated with expanded nodes

When a new node n is generated:

If its state is in CLOSED, then discard n If it has the same state as another node in

the fringe, then discard the node with the largest f(.)

slide-39
SLIDE 39

43

Complexity of Consistent A* Complexity of Consistent A*

s =|S|

size of the state space

r = |A|

max number of states that can be reached

by applying any operator, from any state

Assume test if state s ∈ CLOSED is O(1)

⇒ Time complexity of A*: O(sr log s)

slide-40
SLIDE 40

44

I terative Deepening A* I terative Deepening A* (I DA* ) (I DA* )

Use f(n) = g(n) + h(n)

with admissible, consistent h(.)

Each iteration is depth-first with cutoff

  • n the value of f(n) of expanded nodes

A I x p l

  • r

a t

  • r

i u m h t t p : / / w w w . c s . u a l b e r t a . c a / ~ a i x p l

  • r

e

slide-41
SLIDE 41

45

8 8-

  • Puzzle

Puzzle

4 6

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles Cutoff=4

slide-42
SLIDE 42

46

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=4

6

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-43
SLIDE 43

47

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=4

6 5

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-44
SLIDE 44

48

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=4

6 5 5

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-45
SLIDE 45

49

4

8 8-

  • Puzzle

Puzzle

4 6

Cutoff=4

6 5 5 6

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

No more nodes to expand with Cutoff =4 Now consider Cutoff = 5

slide-46
SLIDE 46

50

8 8-

  • Puzzle

Puzzle

4 6

Cutoff=5 f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-47
SLIDE 47

51

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=5

6

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-48
SLIDE 48

52

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=5

6 5

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-49
SLIDE 49

53

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=5

6 5 7

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-50
SLIDE 50

54

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=5

6 5 7 5

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-51
SLIDE 51

55

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=5

6 5 7 5 5

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-52
SLIDE 52

56

8 8-

  • Puzzle

Puzzle

4 4 6

Cutoff=5

6 5 7 5 5

f(n) = g(n) + h(n) with h(n) = number of misplaced tiles

slide-53
SLIDE 53

57

Summary Summary

Heuristic function Greedy Best-first search Admissible heuristic A* is complete and optimal

Optimally efficient !

Consistent heuristic and repeated states Inventing Heuristics IDA*