Docsity

Heuristic Search Algorithms: Best-first, Greedy, and A*, Study notes of Computer Science

Partial preview of the text

Download Heuristic Search Algorithms: Best-first, Greedy, and A* and more Study notes Computer Science in PDF only on Docsity!

Artificial Intelligence

Programming^ Heuristic Search

Chris Brooks

Department of Computer Science

University of San Francisco

Overview Heuristic Search - exploiting knowledge about theproblem Heuristic Search Algorithms

“Best-first” search Greedy Search A* Search Extensions to A* Constructing Heuristics

Department of Computer Science — University of San Francisco – p.1/

Best-first Search Recall Uniform-cost search

Nodes were expanded based on their total path cost A priority queue was used to implement this. Path cost is an example of an

evaluation function

We’ll use the notation

f^

(n

)^ to refer to an evaluation

function. An evaluation function tells us how promising a node is. Indicates the quality of the solution that node leads to.

Department of Computer Science — University of San Francisco – p.3/

Best-first Search By ordering and expanding nodes according to their

f

value, we search the “best” nodes “first” If^ f

was perfect, we would expand a straight path from the initial state to the goal state.

Arad, Sibiu, Rimnicu Vilcea, Pitesti, Bucharest Of course, if we had a perfect

f^ , we wouldn’t need to

solve the problem in the first place. Instead, we’ll try to develop heuristic functions

h(

n)

that

help us estimate

f^

(n

Department of Computer Science — University of San Francisco – p.4/

Greedy Search Let’s start with the opposite of uniform-cost search UCS used the solution cost to date as an estimate of

f

Greedy search

uses an estimate of distance to the goal

for

f^. Rationale: Always pick the node that looks like it will getyou closest to the solution. Let’s start with a simple estimate of

f^

for the Romania

domain.

h(

city

) =

Straight-line distance between that city and

Bucharest.

Department of Computer Science — University of San Francisco – p.6/

Greedy Search Notice that there wasn’t anything in the problemdescription about straight-line distance or the fact thatthat would be a useful estimate. We used our knowledge about the way roads generallywork. This is sometimes called

common sense

knowledge. Department of Computer Science — University of San Francisco – p.7/

Issues with Greedy Search Sometimes the optimal solution to a problem involvesmoving ‘away’ from the goal. For example, to solve 8-puzzle, you often need to ‘undo’a partial solution. Greedy search has many of the same appeals andweaknesses as DFS.

Expands a linear number of nodes Is not complete or optimal Its ability to cut toward a goal is appealing - can wesalvage this?

Department of Computer Science — University of San Francisco – p.9/

A* search A* search is a combination of uniform cost search andgreedy search. A node’s

f^

(n

) =

g(

n) +

h(

n)

g(

n)

= current path cost h(

n)

= heuristic estimate of distance to goal.

Favors nodes that have a cheap solution to date andalso look like they’ll get close to the goal. If^ h

(n

)^ satisfies certain conditions, A* is both complete (always finds a solution) and optimal (always finds thebest solution).

Department of Computer Science — University of San Francisco – p.10/

A* example - Romania

MehadiaNeamtOradeaPitestiRimnicu VilceaSibiuTimisoara UrziceniVasluiZerind

AradBucharestCraiovaDobretaEforieFagarasGiurgiuHirsovaIasiLugoj

3660 16024216117677151226244

24123438010019325332980199374

(dequeue P: g = 317) T = 118 + 329 = 447, Z = 374 + 75= 449,

B = 518 + 0 = 518

, C = 366 + 160 = 526, B = 550

  • 0 = 550, S = 300 + 253 = 553, S = 338 + 253 = 591,

RV

= 414 + 193 = 607

,^ C = 455 + 160 = 615

, A = 280 + 336 =

616, O = 291 + 380 = 671 (dequeue T: g = 118) Z = 374 + 75 = 449,

L = 229 + 244

= 473

, B = 518 + 0 = 518, C = 366 + 160 = 526, B = 550

  • 0 = 550, S = 300 + 253 = 553,

A = 236 + 336 = 572

, S =

338 + 253 = 591, RV = 414 + 193 = 607, C = 455 + 160 =615, A = 280 + 336 = 616, O = 291 + 380 = 671 (dequeue Z: g = 75) L = 229 + 244 = 473,

A = 150 + 336

= 486

, B = 518 + 0 = 518,

O = 146 + 380 = 526

, C = 366

  • 160 = 526, B = 550 + 0 = 550, S = 300 + 253 = 553, A =236 + 336 = 572, S = 338 + 253 = 591, RV = 414 + 193 =607, C = 455 + 160 = 615, A = 280 + 336 = 616, O = 291+ 380 = 671

Department of Computer Science — University of San Francisco – p.12/

A* example - Romania

MehadiaNeamtOradeaPitestiRimnicu VilceaSibiuTimisoara UrziceniVasluiZerind

AradBucharestCraiovaDobretaEforieFagarasGiurgiuHirsovaIasiLugoj

366016024216117677151226244

24123438010019325332980199374

(dequeue L: g = 229) A = 150 + 336 = 486, B = 518 + 0 =518, O = 146 + 380 = 526, C = 366 + 160 = 526,

M = 299

  • 241 = 540

, B = 550 + 0 = 550, S = 300 + 253 = 553, A =

236 + 336 = 572, S = 338 + 253 = 591, RV = 414 + 193 =607, C = 455 + 160 = 615, A = 280 + 336 = 616,

T = 340

  • 329 = 669

, O = 291 + 380 = 671

(dequeue A: g = 150) B = 518 + 0 = 518, O = 146 + 380 =526, C = 366 + 160 = 526, M = 299 + 241 = 540,

S = 290

  • 253 = 543

, B = 550 + 0 = 550, S = 300 + 253 = 553, A =

236 + 336 = 572, S = 338 + 253 = 591,

T = 268 + 329 =

597

,^ Z = 225 + 374 = 599

, RV = 414 + 193 = 607, C =

455 + 160 = 615, A = 280 + 336 = 616, T = 340 + 329 =669, O = 291 + 380 = 671 (dequeue B: g = 518) solution. A -> S -> RV -> P -> B

Department of Computer Science — University of San Francisco – p.13/

Optimality of A* Notice that we can’t discard repeated states.

We could always keep the version of the state withthe lowest

g

More simply, we can also ensure that we alwaystraverse the best path to a node first. a^ monotonic

heuristic guarantees this.

A heuristic is monotonic if, for every node

n

and each of

its successors

(n

h(

n)

is less than or equal to

stepCost

(n, n

′) +

h(

′n)

In geometry, this is called the triangle inequality.

Department of Computer Science — University of San Francisco – p.15/

Optimality of A* SLD is monotonic. (In general, it’s hard to find realisticheuristics that are admissible but not monotonic). Corollary: If

h^

is monotonic, then

f^

is nondecreasing as

we expand the search tree. Alternative proof of optimality. Notice also that UCS is A* with

h(

n) = 0

A* is also

optimally efficient

No other complete and optimal algorithm isguaranteed to expand fewer nodes.

Department of Computer Science — University of San Francisco – p.16/

Another A* example

Node:

Queue

:

A^

[(C

f^

= 22,

g^

=^ 7,

h^

=^ 15),

(B

f^

= 28,

g^

=^ 8,

h^

=^ 20)]

Department of Computer Science — University of San Francisco – p.18/

Another A* example

Node:

Queue

:

C^

[(D

f^

=^ 23,

g^

=^ 15,

h^

= 8),

(B

f^

=^ 28,

g^

=^ 8,

h^

=^ 20)]

Department of Computer Science — University of San Francisco – p.19/