State space representations and search strategies Spring 2007, Juris Vīksna.

44
State space representations and search strategies Spring 2007, Juris Vīksn

Transcript of State space representations and search strategies Spring 2007, Juris Vīksna.

Page 1: State space representations and search strategies Spring 2007, Juris Vīksna.

State space representations and search strategies

Spring 2007, Juris Vīksna

Page 2: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - 8-puzzle

[Adapted from C.Arany, R.Barak, M.Dang]

Page 3: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - 8-puzzle

[Adapted from C.Arany, R.Barak, M.Dang]

Page 4: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - 8 queens

[Adapted from C.Arany, R.Barak, M.Dang]

Page 5: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - 8 queens

[Adapted from C.Arany, R.Barak, M.Dang]

Page 6: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - 8 queens

[Adapted from C.Arany, R.Barak, M.Dang]

Page 7: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - Cryptarithmetic

[Adapted from C.Arany, R.Barak, M.Dang]

Page 8: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - Cryptarithmetic

[Adapted from C.Arany, R.Barak, M.Dang]

Page 9: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - River crossing puzzles

[Adapted from C.Arany, R.Barak, M.Dang]

Page 10: State space representations and search strategies Spring 2007, Juris Vīksna.

Sample problems - River crossing puzzles

[Adapted from C.Arany, R.Barak, M.Dang]

Page 11: State space representations and search strategies Spring 2007, Juris Vīksna.

Real world problems

[Adapted from C.Arany, R.Barak, M.Dang]

Page 12: State space representations and search strategies Spring 2007, Juris Vīksna.

Real world problems - Route finding

[Adapted from C.Arany, R.Barak, M.Dang]

Page 13: State space representations and search strategies Spring 2007, Juris Vīksna.

Real world problems - Travelling salesman

[Adapted from C.Arany, R.Barak, M.Dang]

Page 14: State space representations and search strategies Spring 2007, Juris Vīksna.

Real world problems - VLSI layout

[Adapted from C.Arany, R.Barak, M.Dang]

Page 15: State space representations and search strategies Spring 2007, Juris Vīksna.

State spaces

<S,P,I,G,W> - state space

S - set of statesP= {(x,y)|x,yS} - set of production rulesIS - initial stateGS - set of goal states W: PR+ - weight function

Page 16: State space representations and search strategies Spring 2007, Juris Vīksna.

State spaces

<S,P,I,G,W> - state space

The problem

• find a goal state• find a path from the initial state to a goal state• find a shortest path from the initial state to a goal state• find a path with minimal weight from the initial state to a goal state

Page 17: State space representations and search strategies Spring 2007, Juris Vīksna.

River crossing puzzle

[Adapted from R.Shinghal]

Page 18: State space representations and search strategies Spring 2007, Juris Vīksna.

River crossing puzzle[Adapted from R.Shinghal]

Page 19: State space representations and search strategies Spring 2007, Juris Vīksna.

River crossing puzzle

[Adapted from R.Shinghal]

Page 20: State space representations and search strategies Spring 2007, Juris Vīksna.

River crossing puzzle

[Adapted from R.Shinghal]

Page 21: State space representations and search strategies Spring 2007, Juris Vīksna.

River crossing puzzle

[Adapted from R.Shinghal]

Page 22: State space representations and search strategies Spring 2007, Juris Vīksna.

8-puzzle

[Adapted from R.Shinghal]

Page 23: State space representations and search strategies Spring 2007, Juris Vīksna.

8-puzzle

[Adapted from G.Luger, W.Stubblefield]

Page 24: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Data Driven

[Adapted from G.Luger, W.Stubblefield]

Page 25: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Goal Driven

[Adapted from G.Luger, W.Stubblefield]

Page 26: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Bi-directional

[Adapted from G.Luger, W.Stubblefield]

Page 27: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Bi-directional

[Adapted from G.Luger, W.Stubblefield]

Page 28: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies -

BFS

[Adapted from G.Luger, W.Stubblefield]

Page 29: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - BFS

[Adapted from G.Luger, W.Stubblefield]

Page 30: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - BFS

BreadthFirstSearch(state space =<S,P,I,G,W>)Open {I}Closed while Open do

x DeQueue(Open)if Goal(x, ) then return xInsert(x,Closed)for y Child(x ,) do

if yClosed and yOpen thenEnQueue(y,Open)

return fail

Open is implemented as queue (FIFO); Closed can be an arbitrary data structure for sets

Page 31: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Uniform Cost Search

UniformCostSearch(state space =<S,P,I,G,W>)Open {<0,I>}Closed while Open do

<wx,x> ExtractMin(Open)if Goal(x, ) then return xInsert(x,Closed)for y Child(x ,) do

if yClosed thenwy wx + W((x,y))Insert(<wy,y>,Open)

return fail

Open is implemented as a priority queue

Page 32: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - DFS

[Adapted from G.Luger, W.Stubblefield]

Page 33: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies -

DFS

[Adapted from G.Luger, W.Stubblefield]

Page 34: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - DFS

[Adapted from J.Pearl]

Page 35: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - DFS

DepthFirstSearch(state space =<S,P,I,G,W>)Open {I}Closed while Open do

x Pop(Open)if Goal(x, ) then return xInsert(x,Closed)for y Child(x ,) do

if yClosed and yOpen thenPush(y,Open)

return fail

Open is implemented as stack (LIFO); Closed can be an arbitrary data structure for sets

Page 36: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - DFS

DepthFirstSearch(state space =<S,P,I,G,W>)Closed return DFSVisit(I,Closed,)

DFSVisit(x,Closed,) if Goal(x, ) then return xInsert(x,Closed)

for y Child(x ,) doif y Closed then

value DFSVisit(y,Closed,) if value fail then return value

return fail

Page 37: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Backtracking

[Adapted from J.Pearl]

Page 38: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Backtracking

BacktrackingSearch(state space =<S,P,I,G,W>)Open {I}Closed while Open do

x Pop(Open)if Goal(x, ) then return xInsert(x,Closed)if there exists y Child(x ,) and yClosed

and yOpen then Push(y,Open)

return fail

Open is implemented as stack (LIFO); Closed can be an arbitrary data structure for sets

Page 39: State space representations and search strategies Spring 2007, Juris Vīksna.

Heuristic function

<S,P,I,G,W> - state space

S - set of statesP= {(x,y)|x,yS} - set of production rulesIS - initial stateGS - set of goal states W: PR+ - weight function

d: SR+

d(x) - a shortest distance fromx to the closest goal state

f: SR+ - heuristic estimate of d

(if xG we usually assume f(x)=0)

Page 40: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Hill climbing

HCSearch(state space =<S,P,I,G,W>,f)HCVisit(I,,f)

HCVisit(x,,f) if Goal(x, ) then return xfind y Child(x ,) with the smallest f(y) valueHCVisit(y,,f)

Page 41: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Best first

[Adapted from J.Pearl]

Page 42: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies - Best first

BestFirstSearch(state space =<S,P,I,G,W>,f)Open {<f(I),I>}Closed while Open do

<wx,x> ExtractMin(Open)if Goal(x, ) then return xInsert(x,Closed)for y Child(x ,) do

if yClosed thenInsert(<f(y),y>,Open)

return fail

Open is implemented as a priority queue

Page 43: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies

[Adapted from J.Pearl]

Page 44: State space representations and search strategies Spring 2007, Juris Vīksna.

Search strategies

[Adapted from R.Shinghal]