Heuristic Search Heuristic Search Best-First Search Best-First Example

2 downloads 258 Views 31KB Size Report
-Example: Straight-line distance from current location to the goal location in a road navigation problem. •Many search
Heuristic Search •Heuristic or informed search exploits additional knowledge about the problem that helps direct search to more promising paths.

•A heuristic function, h(n), provides an estimate of the cost of the path from a given node to the closest goal state. Must be zero if node represents a goal state.

-Example: Straight-line distance from current location to the goal location in a road navigation problem.

Heuristic Search

•Many search problems are NP-complete so in the worst case still have exponential time complexity; however a good heuristic can:

-Find a solution for an average problem efficiently. -Find a reasonably good but not optimal solution efficiently.

1

2

Best-First Search

Best-First Example

•At each step, best-first search sorts the queue according to a heuristic function.

Arad h=366 Arad

function BEST-FIRST-SEARCH( problem, EVAL-FN) returns a solution sequence inputs: problem, a problem Eval-Fn, an evaluation function

Sibiu h=253

Timisoara h=329

Zerind h=374 Arad

Queueing-Fn a function that orders nodes by EVAL-FN return GENERAL-SEARCH( problem, Queueing-Fn)

Sibiu

Timisoara h=329

Arad Fagaras Oradea h=366 h=178 h=380

Zerind h=374 Arad

Rimnicu h=193 Sibiu

Timisoara h=329

Oradea

71

Neamt Zerind

87

151

75

Iasi Arad

140 Sibiu

92 99

Fagaras

118

Vaslui

80 Rimnicu Vilcea

Timisoara

111

Lugoj

142

211

Pitesti

97

70

98 Mehadia

75 Dobreta

146

85

101

Hirsova

Urziceni

86

138

Bucharest

120 Craiova

90 Giurgiu

3

Eforie

Straight−line distance to Bucharest Arad 366 Bucharest 0 Craiova 160 Dobreta 242 Eforie 161 Fagaras 178 Giurgiu 77 Hirsova 151 Iasi 226 Lugoj 244 Mehadia 241 Neamt 234 Oradea 380 Pitesti 98 Rimnicu Vilcea 193 Sibiu 253 Timisoara 329 Urziceni 80 Vaslui 199 Zerind 374

Arad Fagaras h=366 Sibiu h=253

Zerind h=374

Oradea Rimnicu h=380 h=193 Bucharest h=0

•Does not find shortest path to goal (through Rimnicu) since it is only focused on the cost remaining rather than the total cost.

4

Best-First Properties

Beam Search •Space and time complexity of storing and sorting the complete

•Not complete, may follow infinite path if heuristic rates each state on such a path as the best option. Most reasonable heuristics will not cause this problem however.

queue can be too inefficient.

•Beam search trims queue to the best n options (n is called the beam width) at each point.

•Focuses search more but may eliminate solution even for finite •Worst case time complexity is still O(bm) where m is the maximum depth.

seach graphs

•Example for n=2. Arad h=366 Arad

•Since must maintain a queue of all unexpanded states, m

space-complexity is also O(b ).

Sibiu h=253

Timisoara h=329

Zerind h=374 Arad

Sibiu

•However, a good heuristic will avoid this worst-case behavior for most problems.

Timisoara

Zerind

h=329 Arad Fagaras Oradea h=366 h=178 h=380

h=374 Arad

Rimnicu h=193 Sibiu

Timisoara h=329

Arad Fagaras h=366 Sibiu h=253

Zerind h=374

Oradea Rimnicu h=380 h=193 Bucharest h=0

5

6

Hill-Climbing

Minimizing Total Path Cost: A* Search

•Beam search with a beam-width of 1 is called hillclimbing.

•A* combines features of uniform cost search (complete,

•Pursues locally best option at each point, i.e. the best

optimal, inefficient) with best-first (incomplete, non-optimal, efficient).

successor to the current best node.

•Subject to local maxima, plateaux, and ridges.

•Sort queue by estimated total cost of the completion of a path. f(n) = g(n) + h(n)

evaluation

•If the heuristic function always underestimates the distance to the goal, it is said to be admissible.

•If h is admissible, then f(n) never overestimates the actual cost of the best solution through n.

current state

7

8

A* Example Arad f=0+366 =366 Sibiu f=140+253 =393

Optimality of A* •If h is admissible, A* will always find a least cost path to the

Arad

goal. Timisoara f=118+329 =447

Zerind f=75+374 =449 Sibiu

Arad

Timisoara f=118+329 =447

Zerind

•Proof by contradiction:

f=75+374 =449

Arad Fagaras Oradea Rimnicu f=220+193 f=146+380 f=239+178 f=280+366 =413 =526 =417 =646

Arad

Sibiu

Timisoara Zerind f=118+329 f=75+374 =447 =449 Arad Fagaras Oradea Rimnicu f=280+366 f=239+178 f=146+380 =646 =417 =526 Craiova Pitesti Sibiu f=366+160 f=317+98 f=300+253 =526 =415 =553

Let G be an optimal goal state with a path cost f* Let G2 be a suboptimal goal state supposedly found by A* Let n be a current leaf node on an optimal path to G Since h is admissible: f* >= f(n) If G2 is chosen for expansion over n then: f(n) >= f(G2)

•Finds the optimal path to Bucharest through Rimnicu and Pitesti

Therefore: f* >= f(G2) Since G2 is a goal state, h(G2)=0, therefore f(G2) = g(G2) f* >= g(G2) Therefore G2 is optimal. Contradiction. Q.E.D.

9

10

Other Properties of A*

Heuristic Functions

•A* is complete as long as -Branching factor is always finite -Every operator adds cost at least δ > 0

•8-puzzle search space -Typical solution length: 20 steps -Average branching factor: 3 -Exhaustive search: 320=3.5 x 109 -Bound on unique states: 9! = 362,880

•Time and space complexity still O(bm) in the worst case since must maintain and sort complete queue of unexplored options.

•However, with a good heuristic can find optimal solutions for many problems in reasonable time.

•Again, space complexity is a worse problem than time.

5

4

5 1

6

1

88

6 8

7

3

22

7

6

•Admissible Heuristics: -Number of tiles out of place (h1): 7 -City-block (Manhattan) distance (h2):

12

3 84

Goal State

Start State

2+3+3+2+4+2+0+2=18

11

4 2

25

Heuristic Performance

Quality of Heuristics

•Experiments on sample problems can determine the number of nodes searched and CPU time for different strategies.

•ISince A* expands all nodes whose f value is less than that

•One other useful measure is effective branching factor: If a method expands N nodes to find solution of depth d, and a uniform tree of depth d would require a branching factor of b* to contain N nodes, the effective branching factor is b*

of an optimal solution, it is always better to use a heuristic with a higher value as long as it does not over-estimate.

•Therefore h2 is uniformly better than h1, or h2 dominates h1 .

N = 1 + b* + (b*)2 + ...+ (b*)d

•Experimental Results on 8-puzzle problems •A heuristic should also be easy to compute, otherwise the Search Cost

Effective Branching Factor

d

IDS

A*(h1 )

A*(h2 )

IDS

A*(h1 )

A*(h2 )

2 4 6 8 10 12 14 16 18 20 22 24

10 112 680 6384 47127 364404 3473941 – – – – –

6 13 20 39 93 227 539 1301 3056 7276 18094 39135

6 12 18 25 39 73 113 211 363 676 1219 1641

2.45 2.87 2.73 2.80 2.79 2.78 2.83 – – – – –

1.79 1.48 1.34 1.33 1.38 1.42 1.44 1.45 1.46 1.47 1.48 1.48

1.79 1.45 1.30 1.24 1.22 1.24 1.23 1.25 1.26 1.27 1.28 1.26

13

Inventing Heuristics

•Many good heuristics can be invented by considering relaxed versions of the problem (abstractions).

•For 8-puzzle: A tile can move from square A to B if A is adjacent to B and B is blank (a) A tile can move from square A to B if A is adjacent to B. (b) A tile can move from square A to B if B is blank. (c) A tile can move from square A to B.

•If there are a number of features that indicate a promising or unpromising state, a weighted sum of these features can be useful. Learning methods can be used to set weights.

15

overhead of computing the heuristic could outweigh the time saved by reducing search (e.g. using full breadth-first search to estimate distance wouldn’t help).

14