state space search

19
State Space Search

Upload: ida

Post on 23-Feb-2016

29 views

Category:

Documents


0 download

DESCRIPTION

State Space Search. Backtracking. Suppose We are searching depth-first No further progress is possible (i.e., we can only generate nodes we’ve already generated), then backtrack. The algorithm: First Pass. Pursue path until goal is reached or dead end If goal, quit and return the path - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: State Space Search

State Space Search

Page 2: State Space Search

Backtracking

Suppose We are searching depth-first No further progress is possible (i.e.,

we can only generate nodes we’ve already generated), then backtrack.

Page 3: State Space Search

The algorithm: First Pass

1. Pursue path until goal is reached or dead end

2. If goal, quit and return the path3. If dead end, backtrack until you

reach the most recent node whose children have not been fully examined

Page 4: State Space Search

BT maintains Three Lists and A State

SL– List of nodes in current path being tried. If goal

is found, SL contains the path NSL

– List of nodes whose descendents have not been generated and searched

DE– List of dead end nodes

All lists are treated as stacks CS

– Current state of the search

Page 5: State Space Search

The Algorithm

Page 6: State Space Search

State Spacea

b

F

g

c

a

d

h

i

j

A as a child of C is intentional

Page 7: State Space Search

TraceGoal: J, Start: ANSL SL CS DEA A ABCDA BA BFBCDA FBA FGFBCDA GFBA GFBCDA FBA F FGBCDA BA B BFGCDA A C

CA CDA DA DJDA JDA J(GOAL)

Page 8: State Space Search

Depth-First: A Simplification of BT

Eliminate saved path Results in Depth-First search

– Goes as deeply as possible– Is not guaranteed to find a shortest path– Maintains two lists

Open List– Contains states generated– Children have not been examined (like NSL)– Open is implemented as a stack

Closed List– Contains states already examined– Union of SL and DE

Page 9: State Space Search

bool Depth-First(Start){

open = [Start];closed = [];while (!isEmpty.open()){

CS = open.pop();if (CS == goal)

return true; else { generate children of CS; closed.push(CS); eliminate children from CS that are on open or closed;

while (CS has more children) open.push(child of CS);

} } return false;}

Page 10: State Space Search

State Spacea

b

E

g

c

a

d

h

i

j

A as a child of C is intentional

Page 11: State Space Search

Goal: JStart: AOpen CS Closed

A [][] A

ABCDCD B

BAECDCD E BA

EBAGCDCD G

GEBAD C[] D

DJHH J(return true)

Page 12: State Space Search

Breadth-First Search: DF but with a Queue

bool Breadth-First(Start){

open = [Start];closed = [];while (!isEmpty.open()){

CS = open.dequeue();if (CS == goal)

return true; else { generate children of CS; closed.enqueue(CS); eliminate children from CS that are on open or closed;

while (CS has more children) open.enqueue(child of CS);

} } return false;}

Page 13: State Space Search

Trace

If you trace this, you’ll notice that the algorithm examines each node at each level before descending to another level

You will also notice that open contains:1. Unopened children of current state2. Unopened states at current level

Page 14: State Space Search

Both Algorithms

1. Open forms frontier of search2. Path can be easily reconstructed

Each node is an ordered pair (x,y) X is the node name Y is the parent When goal is found, search closed for

parent, the parent of the parent, etc., until start is reached.

Page 15: State Space Search

Breadth-First Finds shortest solution If branching factor is high, could require a

lot of storageDepth-First If it is known that the solution path is long,

DF will not waste time searching shallow states

DF can get lost going too deep and miss a shallow solution

DF and BF follow for the 8-puzzle

Page 16: State Space Search

8 Puzzle—DF (p. 105)Depth First Search of 8-Puzzle (p. 105)

Depth Bound = 5Search Protocol: L, U, R, D

If each state has B children on average, requires that we store B * N states to go N levels deep

Page 17: State Space Search

8 Puzzle-BF (p. 103)Depth Bound = 5

Search Protocol: L,U,R,DIf each state has on average B children, requires that we store B * the number of states

on the previous level for a total of BN states at level N.

Page 18: State Space Search

Problem with Depth Bounds What happens if we don’t reach the

goal at a given depth bound? Fail

Page 19: State Space Search

Solution Depth-first iterative deepening

– Perform DF search, Depth Bound = 1– If fail, Perform DF search, Depth Bound = 2– …– If fail, Perform DF search …

At each iteration, alg. Perform a complete search to the current depth

Guaranteed to find shortest path—because is searches level by level

Attractive properties:– Space usage is B X N where B is the avg number children and N the level– Time complexity how many nodes have to be search worst case: O(BN)– Just like depth-first and depth-first. – Why goes back to the def. of O: (BN + BN-1 + … + 1)