cs 2710, issp 2160

Post on 08-Jan-2016

28 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

CS 2710, ISSP 2160. Chapter 3, Part 2 Heuristic Search. Heuristic Search. Take advantage of information about the problem. Best-First-Search. An evaluation function f determines order of nodes on the fringe (there are variations, depending on the search algorithm). Best-First-Search. - PowerPoint PPT Presentation

TRANSCRIPT

1

CS 2710, ISSP 2160

Chapter 3, Part 2Heuristic Search

2

Heuristic Search

• Take advantage of information about the problem

3

Best-First-Search

• An evaluation function f determines order of nodes on the fringe (there are variations, depending on the search algorithm)

4

Best-First-Search

• In our framework: – treesearch or graphsearch, with nodes ordered on the fringe in

increasing order by an evaluation function, f(n).

5

def treesearch (qfun,fringe): while len(fringe) > 0: cur = fringe[0] fringe = fringe[1:] if goalp(cur): return cur fringe = qfun(makeNodes(cur,successors(cur)),fringe) return []

best-first search: qfun appends the liststogether and sorts them in increasing order by f-value

[In the more efficient version, a heap is used to maintain the queue in increasing order by f-value]

6

Heuristic Evaluation Function,

h(n)• F may involve “heuristic evaluation function”, h(n)

7

h(n)

• Metric on states. Estimate of shortest distance to some goal.• h : state estimate of distance to goal• h (goal) = 0 for all goal nodes

8

Greedy Best-First Search

• f (n) = h (n)• Greedy best-first search may switch its strategy mid-search.

For example, it may go depth-first for awhile, but then return to the shallow parts of the tree.

9

Greedy Example

• In the map domain, h(n) could be the straight line distance from a city to Bucharest

• Greedy search expands the node that currently appears to be closest to the goal

10

Go from Arad to BucharestOradea

Zerind

AradSibiu

Timisoara

Lugoj

Mehadia

Dobreta

Rimnicu Vilcea

Fagaras

Craiova

Pitesti

Giurgiu

Bucharest

Urziceni

Vaslui

Iasi

Neamt

Hirsova

Eforie

71

75

151

140

118

99

80

97

146

138

120

75

70

111101

90

211

85

366

329

374

380

253 176

0

193

160

244

241

11

Greedy Example

Arad 366

Sibiu 253Zerind 374 Timisoara 329

Arad 366 Oradea 380 Fagaras 178 Rimniciu 193

Bucharest 0Sibiu 253

12

Greedy Search

• Complete?– Nope

• Optimal?– Nope

• Time and Space?– It depends

13

Best of Both

• In an A* search we combine the best parts of Uniform-Cost and Best-First.

• [Simple example in lecture]• We want to use the cost so-far to allow optimality and

completeness, while at the same time using a heuristic to draw us toward a goal.

14

A*: f(n) = g(n) + h(n)

g(n): actual cost from start to nh(n): estimated distance from n.state to a

goalEven if h continuously returns good values

for states along a path, if no goal is reached, g will eventually dominate h and force backtracking to more shallow nodes.

Example

• Figure 3.24 shows the progress of A* on the Romanian route finding problem. The h-values it uses are in Figure 3.22

• The next slide shows the state space with both the edge costs and the h-values in one diagram; this will help you trace through Figure 3.24

15

16

Go from Arad to BucharestOradea

Zerind

AradSibiu

Timisoara

Lugoj

Mehadia

Dobreta

Rimnicu Vilcea

Fagaras

Craiova

Pitesti

Giurgiu

Bucharest

Urziceni

Vaslui

Iasi

Neamt

Hirsova

Eforie

71

75

151

140

118

99

80

97

146

138

120

75

70

111101

90

211

85

366

329

374

380

253 176

0

193

160

244

241

17

A*: f(n) = g(n) + h(n)

• If h(n) does not overestimate the real cost then the treesearch version of A* is optimal.

• An h function that does not overestimate is called admissible

18

A* with an admissible heuristic is optimal

• Let: g2 be a suboptimal goal on fringe and gO be an optimal goal, g(gO) = C*

• C* < g(g2) (since g2 is suboptimal)• h(g2) = 0 (since g2 is a goal)• So f(g2) = g(g2) and • C* < f(g2)

19

Proof continued

• Let n be a node on the fringe that is on an optimal solution path

• Since h is admissible: f(n) = g(n) + h(n) <= C*

• For g2 to be the first goal found, it would need to be first on the fringe

• But f(n) <= C* < f(g2)

20

A* is complete

• Even if the heuristic is not admissible • (As long as all edgecosts exceed some finite e and that the

branching factor, b, is finite. The wrap-up notes mention these details)

21

A* and Memory• Does A* solve the memory problems with BrFS and Uniform

Cost?– A* has same or smaller memory requirement than BrFS or Uniform

Cost – How is A* related to BrFS And UC?– BrFS = A* with edgecost(n1,n2) = c, h(n) = 0 (for some positive c)– UC = A* with h(n) = 0– But it might not be sufficiently better to make A* practically

feasible

22

Note

• Placement of goalp test (and return if successful) in algorithm is critical.

• Optimality guarantee lost if nodes are tested when they are generated [elaboration and example]

• True for uniform-cost search too

23

Note for A*

• Assuming f-costs are nondecreasing along any path:– Can draw contours in the state space– Inside a contour labeled 300 are all nodes

with f(n) less than or equal to 300– A* fans out from start, expanding nodes in

bands of increasing f-cost.– h(n) = 0 and edgecosts equal: contours are

round– With better heuristics, the bands narrow and

stretch toward the goal node

24

EG Admissible Heuristics

The 8-puzzle (a small version of the 15 puzzle).

Sample heuristicsH1: Number of misplaced tilesH2: Manhattan distance

25

8 Puzzle Example

• H1(S) = 7• H2(S) = 2+3+3+2+4+2+0+2 = 18Which heuristic is better?

26

Informedness

• Let h1 and h2 be admissible heuristics. If h1(n) <= h2(n) for all n, then h2 is more informed than h1 and

• Fewer nodes will be expanded, on average, with h2 than with h1

• The larger values the better (without going over)

27

A* is often not feasible

• Still a memory hog• What can we do?• Use an iterative deepening style strategy!

28

IDA*

• Like iterative deepening, but search to f-contours rather than fixed depths.

• Each iteration expands all nodes within a particular f-value range.

29

Def fLimSearch(fringe,fLim): nextF = INFINITY while fringe: cur = fringe[0] fringe = fringe[1:] curF = cur.gval + h(cur) if curF <= fLim: if goalp(cur): return(cur,curF) succNodes = makeNodes(cur,successors(cur)) for s in succNodes: fVal = s.gval + h(s) if fVal > fLim and fVal < nextF: nextF = fVal fringe = succNodes + fringe return ([],nextF)

30

def IDAstar(start): result = [] startNode = Node(start) fLim = h(startNode) while not result: result, FLim = fLimSearch([startNode],fLim) return result

31

IDA*• Worst case, space is O(bd) (if edgecosts are all equal and the

heuristic is admissible; we aren’t analyzing other cases)• Optimal, if h is admissible • The number of iterations grows as the number of possible f

values grow. Let x = average # nodes with the same f-value. The lower x is, the fewer new nodes, on average, are expanded on each iteration.

• Practical if x above is not too low – avoids the overhead of maintaining a sorted queue, and realizes the space savings of depth-first search

32

Beam Search

• Cheap, unpredictable search• For problems with many solutions, it may be worthwhile to

discard unpromising paths• Greedy best first search that keeps a fixed number of nodes on

the fringe

33

Beam Search

def beamSearch(fringe,beamwidth): while len(fringe) > 0: cur = fringe[0] fringe = fringe[1:] if goalp(cur): return cur newnodes = makeNodes(cur, successors(cur)) for s in newnodes: fringe = insertByH(s, fringe) fringe = fringe[:beamwidth]return []

34

Beam Search

• Optimal? Complete?• Hardly!• Space?• O(b) (generates the successors)• Often useful

35

General Notes before Continuing

36

Search strategies differ along many dimensions

• Basic strategy: depth-first, breadth-first, least-actual-cost (g(n)), best first (h(n)), or a mixture?

• Is the algorithm iterative, starting by looking at a small part of the state space and then successively looking at larger parts of it? (e.g., iterative deepening and IDA*)

37

Search strategies differ along many dimensions

• Does it pay attention to cycles? (i.e., our treesearch vs. graphsearch)

• Can it backtrack? Or are parts of the search tree/graph irrevocably pruned? (e.g., beam search)

• Does it only look ahead toward goal (h), or does it also consider how far it has come so far? (g)

38

A note on optimality• It might be desirable to be greedy (e.g., greedy best-first vs.

A*)• Simon: people are often “satisficers”: often, they stop as soon

as they find a satisfactory solution• Consider choosing a line at the grocery store, or finding a

parking space

Creating Heuristics

39

40

Combining Heuristics

• If you have lots of heuristics and none dominates the others and all are admissible…

• Use them all!• h(n) = max(h1(n), …, hm(n))

Relaxed Heuristic• Relaxed problem

A problem with fewer restrictions on the actions

The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem.

41

42

Relaxed Problems• Exact solutions to different (relaxed) problems• H1 (# of misplaced tiles) is perfectly accurate if a tile could

move to any square• H2 (sum of Manhattan distances) is perfectly accurate if a tile

could move 1 square in any direction

43

Relaxed Problems• If problem is defined formally as a set of constraints, relaxed

problems can be generated automatically• Absolver (Prieditis, 1993)

– Discovered a better heuristic for 8 puzzle and the first useful heuristic for Rubik’s cube

• Next slide: formal definition of a problem that will allow us to relax it in order to automatically generate heuristics

• This looks forward to the planning section of the course

Systematic Relaxation

• Precondition List– A conjunction of predicates that must hold true before

the action can be applied• Add List

– A list of predicates that are to be added to the description of the world-state as a result of applying the action

• Delete List– A list of predicates that are no longer true once the

action is applied and should, therefore, be deleted from the state description

• Primitive Predicates– ON(x, y) :tile x is on cell y– CLEAR(y) :cell y is clear of tiles– ADJ(y, z) :cell y is adjacent to cell z

44

Here is the full definition of s move for the n-puzzle

Move(x, y, z):precondition list ON(x, y), CLEAR(z), ADJ(y, z)add list ON(x, z), CLEAR(y)delete list ON(x, y), CLEAR(z)

45

(1) Removing CLEAR(z) and ADJ(y, z) gives “# tiles out of place”.

Misplaced distance is 1+1=2 moves

1 2 34 5 6 78 9 10 11

12 13 14 15

15 1 2 34 5 6 78 9 10 11

13 14 12

46

(2) Removing CLEAR(z) gives “Manhattan distance”.

Manhattan distance is 6+3=9 moves

1 2 34 5 6 78 9 10 11

12 13 14 15

15 1 2 34 5 6 78 9 10 11

13 14 12

47

Pattern Database Heuristics

The idea behind pattern database heuristics is to The idea behind pattern database heuristics is to store exact solution costs for every possible store exact solution costs for every possible sub-problem instance.sub-problem instance.

48

Solve part of the problem, ignoring the other tiles

37

1112 13 14 15

14 73

15 1211 13

37

1112 13 14 15

7 1312

15 311 14

37

1112 13 14 15

12 117 14

13 315 49

50

Pattern Databases• optimal solution cost of the subproblem <= optimal solution

cost of the full problem. • Run exhaustive search to find optimal solutions for every

possible configuration of 3, 7, 11, 12, 13, 14, 15, and store the resulting path costs

• Do the same for the other tiles and space (maybe in two subsets)

• Do this once before any problem solving is performed. Expensive, but can be worth it, if the search will be applied to many problem instances (deployed)

Pattern Databases

• In our example, we have three subproblems (subsets of 7, 4, and 4 tiles)

• State S has specific configurations of those subsets• h(s)?

51

• h(s)?• Look up the exact costs for s’s configurations of the 7, 4, and 4

subsets of tiles in the database• Take the max! • The max of a set of admissible heuristics is admissible• What if it isn’t feasible to have entries for all possibilities? ….

52

• What if it isn’t feasible to have entries for all possibilities? ….• Take the max of:

– The exact costs we do have, and the Manhattan distance for those we don’t have

53

Sums of admissible heurstics

• We would like to take the sum rather than the max, since the result is more informed

• In general, adding two admissible heuristics might not be admissible

• For example, moves that solve one subproblem might help another subproblem

• But we can choose patterns that are disjoint, so we can sum them

54

Disjoint Pattern Database Heuristics

Patterns that have no tiles in common. (As in our example) When calculating costs Patterns that have no tiles in common. (As in our example) When calculating costs

for a pattern, only count moves of the tiles in the patternfor a pattern, only count moves of the tiles in the pattern

Add together the heuristic values for the individual patterns.Add together the heuristic values for the individual patterns.

The sum is admissible and more informed than taking the maxThe sum is admissible and more informed than taking the max

55

Examples for Disjoint Pattern Database Heuristics

1 2 3

4 5 6 7

8 9 10 11

12 13 14 15

5 10 14 7

8 3 6 1

15 12 9

2 11 4 1320 moves needed to solve red tiles25 moves needed to solve blue tiles

Overall heuristic is sum, or 20+25=45 moves

56

1 2 34 5 6 78 9 10 11

12 13 14 15

5 10 14 78 3 6 1

15 12 92 11 4 13

Overall heuristic is sum of the Manhattan Distance of each tile which is 39 moves.

A trivial example of disjoint pattern database heuristics is Manhattan Distance in A trivial example of disjoint pattern database heuristics is Manhattan Distance in the case that we view every tile as a single pattern databasethe case that we view every tile as a single pattern database

57

58

Other Sources of Heuristics

• Ad-hoc, informal, rules of thumb (guesswork)• Approximate solutions to problems (algorithms

course)• Learn from experience (solving lots of 8-

puzzles) (later in this course)

Wrap Up• The material in these notes is covered in R&N 3.5-6• The exam will be concerned only with the treesearch, not the

graphsearch, versions of the heuristic search algorithms; any question concerning the graphsearch versions will be about the uninformed algorithms

• Detail to bring out: we assumed in these and the previous notes that all edge costs exceed some finite positive value e; that b (the branching factor) and h-values are finite; and f values are nondecreasing along any path.

• IDA* is optimal in terms of solution time and space for admissible heuristic tree searches. Further reading (not required): R.E. Korf, Depth-First Iterative-Deepening: An Optimal Admissible Tree Search

• A* time and space complexity: Order roughly the number of nodes with f(n) smaller than the cost of the optimal path

59

top related