artificial intelligence

18
Artificial Intelligence Intelligence Ian Gent [email protected] Search: 2

Upload: vaughan

Post on 18-Mar-2016

42 views

Category:

Documents


2 download

DESCRIPTION

Artificial Intelligence. Search: 2. Ian Gent [email protected]. Artificial Intelligence. Search 2. Part I :The Eights Puzzle Part II: Search Algorithms via lists Part II: Best First Search. The Eights Puzzle. Sliding blocks puzzle, more usually 15 puzzle - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Artificial  Intelligence

Artificial IntelligenceIntelligence

Ian [email protected]

Search: 2

Page 2: Artificial  Intelligence

Artificial IntelligenceIntelligence

Part I : The Eights PuzzlePart II: Search Algorithms via listsPart II: Best First Search

Search 2

Page 3: Artificial  Intelligence

3

The Eights PuzzleSliding blocks puzzle, more usually 15 puzzle

shows you the state of AI in the sixties how many moves between these states?

1 2 38 47 6 5

2 1 64 87 5 3

Page 4: Artificial  Intelligence

4

Search Reminder

Search states, Search trees Don’t store whole search trees, just the frontier

B(a B )

Im p os s ib le

b(a b )

Im p os s ib le

a(a)

C h oose B

B(A B C )

Im p oss ib le

b(A b C )

S o lu tion

C(A C )

C h oos e B

cA c

im p oss ib le

A(A )

C h oose C

A B C , A B c , A b C , A b c , aB C , ab C , ab cs tate = ()C h oose A

Page 5: Artificial  Intelligence

5

Frontiers as lists

One way to implement search algorithms is via lists Lists fundamental in AI programming

main data structure in Lisp, Prologmakes list processing really easy (no pointers)<end of advert for AI languages>

Lists can easily store frontier of searchEach element in list is search stateDifferent algorithms manipulate list differently

Page 6: Artificial  Intelligence

6

A general search algorithm

1. Form a one element list with null state2. Loop Until (either list empty or we have a solution)

Remove the first state X from the list Choose the next decision to make

• e.g. which letter to set in SAT, which city to choose successor in TSP Create a new state for each possible choice of decision

• e.g. upper/lower case, Walla Walla/Oberlin/Ithaca MERGE the set of new states into the list

• different algorithms will have different MERGE methods

3. If (solution in list) succeed else list must be empty, so fail

Page 7: Artificial  Intelligence

7

Depth First SearchThe most important AI search algorithm?MERGE = push

treat list as a stack new search states to explore at front of list, get treated first

What about when many new states created? We use a heuristic to decide what order to push new states all new states in front of all old states in the list

What about when no new states created? We must be at a leaf node in the search tree we have to backtrack to higher nodes

Page 8: Artificial  Intelligence

8

Breadth First SearchMERGE = add to end

treat list as a queue new search states to explore at end of list,

What about when many new states created? We use a heuristic to decide what order to add new states

Breadth first considers all states at a given depth in the search tree before going on to the next depth compare with depth-first, depth-first considers all children of current node before any other

nodes in the search tree list can be exponential size -- all nodes at given depth

Page 9: Artificial  Intelligence

9

Depth-First-Depth-Bounded SearchAs depth-first search Disallow nodes beyond a certain depth d in tree

to implement, add depth in tree to search stateCompare DFDB with Depth-first

DFDB: always finds solution at depth <= dDF may find very deep solution before shallow ones

DFDB: never goes down infinite branchrelevant if search tree contains infinite branches

• e.g. Eights puzzle DFDB: we have a resource limit (b^d if b branching rate) How do we choose d?

Page 10: Artificial  Intelligence

10

Iterative Deepening Search

No longer a simple instance of general search d = min-d Loop Until (solution found)

apply DFDB(d)d := d + increment

Why? Guarantees to find a solution if one exists (cf DFDB) Finds shallow solutions first (cf DF) Always has small frontier (cf Breadth First) Surprising asymptotic guarantees

search time typically no more than d/(d-1) as bad as DF

Page 11: Artificial  Intelligence

11

Why is Iterative deepening ok?

Suppose increment = 1, solution at depth d how much more work do we expect to do in I.D. vs DF ?

I.d. repeats work from depths 1 to d

d

i=1 bi = b d+1 / (b - 1) Ratio to b d = b d+1 / bd(b - 1) = b/(b-1) So we only do b/(b-1) times as much work as we need to

e.g. even if b=2, only do twice as much work Very often worth the overhead for the advantages

Page 12: Artificial  Intelligence

12

Comparing Search AlgorithmsDepthFirst

BreadthFirst

DepthBounded

IterativeDeepening

Always findssolution if oneexists?

Yes if noinf. branch

Yes No Yes

First solutionshallowest?

No Yes No Yes if min-d,incrementcorrect

Size of list atdepth d?

bd b^d bd bd

Revisits nodesredundantly?

No No No Yes

Page 13: Artificial  Intelligence

13

Best First Search

All the algorithms up to now have been hard wired I.e. they search the tree in a fixed order use heuristics only to choose among a small number of

choicese.g. which letter to set in SAT / whether to be A or a

Would it be a good idea to explore the frontier heuristically?

I.e. use the most promising part of the frontier?This is Best First Search

Page 14: Artificial  Intelligence

14

Best First Search

Best First Search is still an instance of general algorithm

Need heuristic score for each search stateMERGE: merge new states in sorted order of score

I.e. list always contains most promising state first can be efficiently done if use (e.g.) heap for list

• no, heaps not done for free in Lisp, Prolog.Search can be like depth-first, breadth-first, or in-

between list can become exponentially long

Page 15: Artificial  Intelligence

15

Search in the Eights Puzzle

The Eights puzzle is different to (e.g.) SAT can have infinitely long branches if we don’t check for

loopsbad news for depth-first,still ok for iterative deepening

Usually no need to choose variable (e.g. letter in SAT)there is only one piece to move (the blank)we have a choice of places to move it to

we might want to minimise length of pathin SAT just want satisfying assignment

Page 16: Artificial  Intelligence

16

Search in the Eights Puzzle

Are the hard wired methods effective? Breadth-first very poor except for very easy problems Depth-first useful without loop checking

not much good with it, either Depth-bounded -- how do we choose depth bound? Iterative deepening ok

and we can use increment = 2 (why?)still need good heuristics for move choice

Will Best-First be ok?

Page 17: Artificial  Intelligence

17

Search in the Eights Puzzle

How can we use Best-First for the Eights puzzle?We need good heuristic for rating states Ideally want to find guaranteed shortest solution

Therefore need to take account of moves so far And some way of guaranteeing no better solution

elsewhere

Page 18: Artificial  Intelligence

18

Next week in Search for AI

Heuristics for the Eights Puzzle the A* algorithm