29
Informed Search Heuristic functions Greedy Search A Search (Hart, Nilsson, and Raphael, 1968) Proofs of optimality and completeness Examples Iterative Deepening A Search (IDA ) Simplified Memory-Bounded A (SMA ).

Informed Search - UVM CEMSrsnapp/teaching/cs251/lectures/heuristics.pdf · Informed Search • Heuristic functions ... • Simplified Memory-Bounded A? ... i denote an A search that

Embed Size (px)

Citation preview

Informed Search

• Heuristic functions

• Greedy Search

• A? Search (Hart, Nilsson, and Raphael, 1968)

• Proofs of optimality and completeness

• Examples

• Iterative Deepening A? Search (IDA?)

• Simplified Memory-Bounded A? (SMA?).

Heuristic

Informally, a heuristic is any “rule of thumb,” or information that helps one solve

a problem.

In the context of search trees, a heuristic function, h(n), estimates the cost of

the cheapest path between node n and a goal node. Thus h(n) = 0, if n is a

goal node.

A greedy search always expands the node in the queue that is believed to be

closest to the goal state, i.e., the node in the queue with the smallest value of

h. Equivalent to a best-first search that uses h(n) to sort the queue.

Romania: h(n) = straight-line distance to Bucharest

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

Greedy Search: Arad to Bucharest

Arad

Sibiu

(h = 253)Timisoara

(h = 329)

Zerind

(h=374)

Romania: h(n) = straight-line distance to Bucharest

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

Greedy Search: Arad to Bucharest

Arad

Sibiu(h = 253)

Timisoara(h = 329)

Zerind(h=374)

Arad(h=366)

Fagaras(h = 178)

Oradea(h=380)

Rimnicu(h = 193)

Romania: h(n) = straight-line distance to Bucharest

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

Greedy Search: Arad to Bucharest

Arad

Sibiu(h = 253)

Timisoara(h = 329)

Zerind(h=374)

Arad(h=366)

Fagaras(h = 178)

Oradea(h=380)

Rimnicu(h = 193)

Sibiu(h=253)

Bucharest(h=0)

Total cost is g = 140 + 99 + 211 = 450.

Romania: h(n) = straight-line distance to Bucharest

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

Properties of Greedy Search (AIMA, pp. 95–96)

• “Greedy algorithms often perform quite well.”

• “Susceptable to false starts.”

• Time and memory complexity are both O(bm) in the worst case.

A? Search

Recall that

g(n) = the path cost from the root to node n

h(n) = the approxiate cost from n to the closest goal.

Now define,

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

The f -cost, f (n), estimates the smallest path cost to a goal node through node

n.

An A? search is a best-first search using f (n) to order the nodes in the queue.

Admissible Heuristic

• A heuristic function h(n) is said to be admissible if it never overestimates

the cost of the cheapest path between n and a goal node.

• An admissible heuristic is always optimistic.

• If h is an admissible heuristic, then f (n) = g(n)+h(n) never overestimates

the true cost of the cheapest solution path through node n.

• It is common for f (n) to be monotonic, i.e., nondecreasing along the solu-

tion path.

• WLOG (without loss of generality) one can ensure monotoniciy by adopting

the pathmax f -cost. Let n be a parent of n’. Then let

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

Romania: Contours of constant f for a monotonicf -cost

Giurgiu

Urziceni

Hirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

380

420

400

Romania: A? Search

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

A? Search: Arad to Bucharest

Arad

Sibiu

(h = 253,

f = 393)

Timisoara

(h = 329,

f = 447)

Zerind

(h = 374,

f = 449)

g = 140 118 75

Romania: A? Search

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

A? Search: Arad to Bucharest

Arad

Sibiu(h = 253,f = 393)

Timisoara(h = 329,f = 447)

Zerind(h = 374,f = 449)

g = 140

g = 280239 291

220

118 75

Arad(h = 366,f = 646)

Fagaras(h = 178,f = 417)

Oradea(h = 380,f = 671)

Rimnicu(h = 193,f = 413)

Romania: A? Search

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

A? Search: Arad to Bucharest

Arad(f = 366)

Sibiu(h = 253,f = 393)

Timisoara(h = 329,f = 447)

Zerind(h = 374,f = 449)

g = 140

g = 280

g = 366

239 291220

317 300

118 75

Arad(h = 366,f = 646)

Fagaras(h = 178,f = 417)

Oradea(h = 380,f = 671)

Rimnicu(h = 193,f = 413)

Craiova(h = 160,f = 526)

Pitesti(h = 98,f = 415)

Sibiu(h = 253,f = 553)

Romania: A? Search

Bucharest

Giurgiu

Urziceni

Hirsova

Eforie

NeamtOradea

Zerind

Arad

Timisoara

LugojMehadia

DobretaCraiova

Sibiu

Fagaras

PitestiRimnicu Vilcea

Vaslui

Iasi

Straight line distanceto Bucharest

0

160

242

161

77

151

241

366

193

178

253

329

80

199

244

380

226

234

374

98

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

Dobreta

Craiova

Sibiu Fagaras

Pitesti

Vaslui

Iasi

Rimnicu Vilcea

Bucharest

71

75

118

111

70

75

120

151

140

99

80

97

101

211

138

146 85

90

98

142

92

87

86

A? Search: Arad to Bucharest

Arad(f = 366)

Sibiu(h = 253,f = 393)

Timisoara(h = 329,f = 447)

Zerind(h = 374,f = 449)

g = 140

g = 280

g = 366

g = 455

239 291220

317

414 418

300

118 75

Arad(h = 366,f = 646)

Fagaras(h = 178,f = 417)

Oradea(h = 380,f = 671)

Rimnicu(h = 193,f = 413)

Craiova(h = 160,f = 526)

Pitesti(h = 98,f = 415)

Sibiu(h = 253,f = 553)

Craiova(h = 160,f = 615)

Rimnicu(h = 193,f = 607)

Bucharest(h = 0,

f = 418)

Optimality of the A? Search (AIMA, pp. 99–100)

Theorem 1 If h is an admissible heuristic and more than one goal exists, then

the A? search always expands the goal with the cheapest path cost first.

Let G denote an optimal goal state, with path cost f ?. Let G2 denote a subop-

timal goal, with path cost g(G2) > f ?.

Assume that A? expanded G2 and terminated, before expanding G. Let n denote

the node in the queue that lies on a solution path to G. Becauses h is admissible

f ? ≥ f (n).

Because n was not expanded before G2,

f (n) > f (G2).

Thus,

f ? ≥ f (G2) = g(G2),

a contradiction!

Locally Finite Search Trees

A search tree is said to be locally finite if it has

1. a finite branching factor, and

2. the cost of every action has a lower postive bound.

Lemma 1 At every step of the A? search before termination, there exists a node

n? in the frontier that satisfies the following three conditions:

1. n? is on an optimal path from root to a goal,

2. A? has found an optimal path from root to n?, and

3. f (n?) = g(n?) + h(n?) < f ?.

Completeness of the A? Search (AIMA, p. 100.)

Theorem 2 The the A? search, with an admissible heuristic, is complete for

every locally finite search tree.

Let G denote an optimal goal node with path cost f ?. The A? search algorithm

expands nodes in order of increasing f . Thus a goal node with path cost f ?

will be expanded after a finite number of steps.

Heuristics for the Eight Puzzle

5 4

6 1 8

7 3 2

1 2

8

3

4

7 6 5

• h1(n) = the number of misplaced tiles.

• h2(n) = the sum of the L1 distances between each tile and its home.

In this example, it can be shown that h2(n) ≥ h1(n) for every state n. In this

event, h2 is said to dominate h1.

Theorem 3 Let A?i denote an A? search that assumes the heuristic hi for i =

1, 2. If h2 dominates h1, then every state node expanded by A?2 is also expanded

by A?1 .

If several admissible heuristics are avalailabe, h1, . . . , hk, one should use

h(n) = max{h1(n), . . . , hk(n)}.

Generating Heuristics

• Effective Branching Factor β.

N = 1 + β + β2 + . . . + βd

• More efficient heuristics result in a smaller β.

• Generating heuristics using a relaxed problem: abstractions and homeo-

morphisms.

• Automatic generation of heuristics by ABSOLVER (Prieditis, 1983).

• What other heuristics can we construct for the eight puzzle?

Iterative Deepening A? Search (IDA?)

• Proposed by Richard Korf (1985), who proved its completeness.

• Like breadth-first search, A? search still has exponential complexity; usually one runs outof memory before one runs out of time. (See Figure 3.11 on p. 74 of AIMA.)

• For uniformed search, iterative deepening is complete, but uses less memory thanbreadth-first search. Can one generalize this to idea to A?.?

• Iterative deepening, but using a limit based on the f -cost estimate instead of depth:

1. Let fmax = f (n0), where n0 is the root. Note that f ? ≤ fmax.

2. Perform a depth-limited depth-first search for the goal, starting from root. Only ex-pand node n if g(n) ≤ fmax. Also, compute the f -cost of every node that is visited.Backtrack as necessary.

3. If a goal is found, terminate successfully.

4. If the goal node was not found after expanding every allowed node, then increase fmax

to the minimum f -value obtained on the nodes that were visited, but not expanded.Repeat from step 2 until either a goal is found, or the tree is exhausted.

Questions about IDA?

1. What might happen if f does not satisfy the monotonicity condition:

if n′ is a successor of n, then

h(n) ≤ c(n, n′) + h(n′) =⇒ f (n) ≤ f (n′)?

2. What happens if every node in the search space has a unique f -cost?

Recursive Best-First Search (RBFS)

• RBFS decreases the execution time of IDA? at the expense of additional

memory.