Top Banner
Problem solving and search Chapter 3 Chapter 3 1
90

Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Mar 29, 2018

Download

Documents

VuHuong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Problem solving and search

Chapter 3

Chapter 3 1

Page 2: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

What is impact of sequences of Percepts?

Percept sequence [A, Clean] [A, Dirty] [B, Clean] [B, Dirty] [A, Clean], [A, Clean] [A, Clean], [A, Dirty] …

Action Right Suck Left Suck Right Suck …

Page 3: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

What is difference between agent function and agent program?

Percept sequence [A, Clean] [A, Dirty] [B, Clean] [B, Dirty] [A, Clean], [A, Clean] [A, Clean], [A, Dirty] …

Action Right Suck Left Suck Right Suck …

function REFLEX-VACUUM-AGENT([location, status]) returns an action if status == Dirty then return Suck else if location == A then return Right else if location == B then return Left

Page 4: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Outline

♦ Problem-solving agents

♦ Problem types

♦ Problem formulation

♦ Example problems

♦ Basic search algorithms

Chapter 3 3

Page 5: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Problem-solving agents

Restricted form of general agent:

function Simple-Problem-Solving-Agent( percept) returns an action

static: seq, an action sequence, initially empty

state, some description of the current world state

goal, a goal, initially null

problem, a problem formulation

state←Update-State(state, percept)

if seq is empty then

goal←Formulate-Goal(state)

problem←Formulate-Problem(state, goal)

seq←Search( problem)

action←Recommendation(seq, state)

seq←Remainder(seq, state)

return action

Note: this is offline problem solving; solution executed “eyes closed.”Online problem solving involves acting without complete knowledge.

Chapter 3 4

Page 6: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: Romania

On holiday in Romania; currently in Arad.Flight leaves tomorrow from Bucharest

Formulate goal:be in Bucharest

Formulate problem:states: various citiesactions: drive between cities

Find solution:sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest

Chapter 3 5

Page 7: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: Romania

Giurgiu

UrziceniHirsova

Eforie

Neamt

Oradea

Zerind

Arad

Timisoara

Lugoj

Mehadia

DobretaCraiova

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

Chapter 3 6

Page 8: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Problem types

Deterministic, fully observable =⇒ single-state problemAgent knows exactly which state it will be in; solution is a sequence

Non-observable =⇒ conformant problemAgent may have no idea where it is; solution (if any) is a sequence

Nondeterministic and/or partially observable =⇒ contingency problempercepts provide new information about current statesolution is a contingent plan or a policyoften interleave search, execution

Unknown state space =⇒ exploration problem (“online”)

Chapter 3 7

Page 9: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world

Single-state, start in #5. Solution??1 2

3 4

5 6

7 8

Chapter 3 8

Page 10: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world

Single-state, start in #5. Solution??[Right, Suck]

Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8}e.g., Right goes to {2, 4, 6, 8}. Solution??

1 2

3 4

5 6

7 8

Chapter 3 9

Page 11: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world

Single-state, start in #5. Solution??[Right, Suck]

Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8}e.g., Right goes to {2, 4, 6, 8}. Solution??[Right, Suck, Left, Suck]

Contingency, start in #5Murphy’s Law: Suck can dirty a clean carpetLocal sensing: dirt, location only.Solution??

1 2

3 4

5 6

7 8

Chapter 3 10

Page 12: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world

Single-state, start in #5. Solution??[Right, Suck]

Conformant, start in {1, 2, 3, 4, 5, 6, 7, 8}e.g., Right goes to {2, 4, 6, 8}. Solution??[Right, Suck, Left, Suck]

Contingency, start in #5Murphy’s Law: Suck can dirty a clean carpetLocal sensing: dirt, location only.Solution??[Right, if dirt then Suck]

1 2

3 4

5 6

7 8

Chapter 3 11

Page 13: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Single-state problem formulation

• A problem is defined by five components: – Initial state e.g., In(Arad) – Actions ACTIONS(s)

• e.g., {Go(Sibiu), Go(Timisoara), Go(Zerind)} – Transition model RESULT(s,a)

• e.g, RESULT(In(Arad),Go(Zerind)) = In(Zerind) • Successor: any state reachable from given state by single action

– Goal test, can be: • Explicit: e.g., x = In(Bucharest) • Implicit: e.g., NoDirt(x)

– Path cost (additive) • e.g., sum of distances, number of actions executed, etc. • c(s, a, s’) is the step cost, assumed to be ≥ 0

• A solution is a sequence of actions leading from initial state to a goal state

12

Page 14: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Selecting a state space

Real world is absurdly complex⇒ state space must be abstracted for problem solving

(Abstract) state = set of real states

(Abstract) action = complex combination of real actionse.g., “Arad → Zerind” represents a complex set

of possible routes, detours, rest stops, etc.For guaranteed realizability, any real state “in Arad”

must get to some real state “in Zerind”

(Abstract) solution =set of real paths that are solutions in the real world

Each abstract action should be “easier” than the original problem!

Chapter 3 13

Page 15: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world state space graphR

L

S S

S S

R

L

R

L

R

L

S

SS

S

L

L

LL R

R

R

R

states??actions??goal test??path cost??

Chapter 3 14

Page 16: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world state space graphR

L

S S

S S

R

L

R

L

R

L

S

SS

S

L

L

LL R

R

R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.)actions??goal test??path cost??

Chapter 3 15

Page 17: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world state space graphR

L

S S

S S

R

L

R

L

R

L

S

SS

S

L

L

LL R

R

R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.)actions??: Left, Right, Suck, NoOpgoal test??path cost??

Chapter 3 16

Page 18: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world state space graphR

L

S S

S S

R

L

R

L

R

L

S

SS

S

L

L

LL R

R

R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.)actions??: Left, Right, Suck, NoOpgoal test??: no dirtpath cost??

Chapter 3 17

Page 19: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: vacuum world state space graphR

L

S S

S S

R

L

R

L

R

L

S

SS

S

L

L

LL R

R

R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.)actions??: Left, Right, Suck, NoOpgoal test??: no dirtpath cost??: 1 per action (0 for NoOp)

Chapter 3 18

Page 20: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5

1

2

3

4

6

7

8

5

states??actions??goal test??path cost??

Chapter 3 19

Page 21: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5

1

2

3

4

6

7

8

5

states??: integer locations of tiles (ignore intermediate positions)actions??goal test??path cost??

Chapter 3 20

Page 22: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5

1

2

3

4

6

7

8

5

states??: integer locations of tiles (ignore intermediate positions)actions??: move blank left, right, up, down (ignore unjamming etc.)goal test??path cost??

Chapter 3 21

Page 23: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5

1

2

3

4

6

7

8

5

states??: integer locations of tiles (ignore intermediate positions)actions??: move blank left, right, up, down (ignore unjamming etc.)goal test??: = goal state (given)path cost??

Chapter 3 22

Page 24: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5

1

2

3

4

6

7

8

5

states??: integer locations of tiles (ignore intermediate positions)actions??: move blank left, right, up, down (ignore unjamming etc.)goal test??: = goal state (given)path cost??: 1 per move

[Note: optimal solution of n-Puzzle family is NP-hard]

Chapter 3 23

Page 25: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Example: robotic assembly

R

RRP

R R

states??: real-valued coordinates of robot joint anglesparts of the object to be assembled

actions??: continuous motions of robot joints

goal test??: complete assembly with no robot included!

path cost??: time to execute

Chapter 3 24

Page 26: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Problem Formulation #1

Give a problem formulation for the following:

1) Using only four colors, you have to color a planar map in such a way that no two adjacent regions have the same color

Initial state? Actions? Goal test? Path cost?

Page 27: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Problem Formulation #2

Give a problem formulation for the following:

2) A 3-foot-tall monkey is in a room where some bananas are suspended from the 8-foot ceiling. He would like to get the bananas. The room contains two stackable, movable, climbable 3-foot-high crates.

Initial state? Actions? Goal test? Path cost?

Page 28: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Problem Formulation #3

Give a problem formulation for the following:

3) You have 3 jugs, measuring 12 gallons, 8 gallons, and 3 gallons, and a water faucet. You can fill the jugs up or empty them out from one to another or onto the ground. You need to measure out exactly one gallon.

Initial state? Actions? Goal test? Path cost?

Page 29: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Tree search algorithm

• Basic idea: – Offline, simulated exploration of state space by

generating successors of already-explored states (i.e., expanding states)

25

function TREE-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problem loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution expand the chosen node, adding the resulting nodes to the frontier

Page 30: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Graph search algorithm

25

function GRAPH-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problem initialize the explored set to be empty loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution add the node to the explored set expand the chosen node, adding the resulting nodes to the frontier only if not in the frontier or explored set

Page 31: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Tree search example

Rimnicu Vilcea Lugoj

ZerindSibiu

Arad Fagaras Oradea

Timisoara

AradArad Oradea

Arad

Chapter 3 26

Page 32: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Tree search example

Rimnicu Vilcea LugojArad Fagaras Oradea AradArad Oradea

Zerind

Arad

Sibiu Timisoara

Chapter 3 27

Page 33: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Tree search example

Lugoj AradArad OradeaRimnicu Vilcea

Zerind

Arad

Sibiu

Arad Fagaras Oradea

Timisoara

Chapter 3 28

Page 34: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Implementation: states vs. nodes

A state is a (representation of) a physical configurationA node is a data structure constituting part of a search tree

includes parent, children, depth, path cost g(x)States do not have parents, children, depth, or path cost!

1

23

45

6

7

81

23

45

6

7

8

State Node depth = 6

g = 6

state

parent, action

The Expand function creates new nodes, filling in the various fields andusing the SuccessorFn of the problem to create the corresponding states.

Chapter 3 29

Page 35: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

What’s the difference between a world state, a state description, and a search node?

• World state:

• State description:

• Search nodes:

Page 36: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Search strategies

A strategy is defined by picking the order of node expansion

Strategies are evaluated along the following dimensions:completeness—does it always find a solution if one exists?time complexity—number of nodes generated/expandedspace complexity—maximum number of nodes in memoryoptimality—does it always find a least-cost solution?

Time and space complexity are measured in terms ofb—maximum branching factor of the search treed—depth of the least-cost solutionm—maximum depth of the state space (may be ∞)

Chapter 3 31

Page 37: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Uninformed search strategies

Uninformed strategies use only the information availablein the problem definition

Breadth-first search

Uniform-cost search

Depth-first search

Depth-limited search

Iterative deepening search

Chapter 3 32

Page 38: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Breadth-first search

Expand shallowest unexpanded node

Implementation:fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

Chapter 3 33

Page 39: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Breadth-first search

Expand shallowest unexpanded node

Implementation:fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

Chapter 3 34

Page 40: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Breadth-first search

Expand shallowest unexpanded node

Implementation:fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

Chapter 3 35

Page 41: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Breadth-first search

Expand shallowest unexpanded node

Implementation:fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

Chapter 3 36

Page 42: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of breadth-first search

Complete??

Chapter 3 37

Page 43: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time??

Chapter 3 38

Page 44: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d

Space??

Chapter 3 39

Page 45: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d

Space?? O(bd+1) (keeps every node in memory)

Optimal??

Chapter 3 40

Page 46: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d

Space?? O(bd+1) (keeps every node in memory)

Optimal?? Yes (if cost = 1 per step); not optimal in general

Space is the big problem; can easily generate nodes at 100MB/secso 24hrs = 8640GB.

Chapter 3 41

Page 47: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Uniform-cost search

Expand least-cost unexpanded node

Implementation:fringe = queue ordered by path cost, lowest first

Equivalent to breadth-first if step costs all equal

Complete?? Yes, if step cost ≥ ε

Time?? # of nodes with g ≤ cost of optimal solution, O(bdC∗/εe)

where C∗ is the cost of the optimal solution

Space?? # of nodes with g ≤ cost of optimal solution, O(bdC∗/εe)

Optimal?? Yes—nodes expanded in increasing order of g(n)

Chapter 3 42

Page 48: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 43

Page 49: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 44

Page 50: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 45

Page 51: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 46

Page 52: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 47

Page 53: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 48

Page 54: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 49

Page 55: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 50

Page 56: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 51

Page 57: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 52

Page 58: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 53

Page 59: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-first search

Expand deepest unexpanded node

Implementation:fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

Chapter 3 54

Page 60: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of depth-first search

Complete??

Chapter 3 55

Page 61: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loopsModify to avoid repeated states along path⇒ complete in finite spaces

Time??

Chapter 3 56

Page 62: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loopsModify to avoid repeated states along path⇒ complete in finite spaces

Time?? O(bm): terrible if m is much larger than dbut if solutions are dense, may be much faster than breadth-first

Space??

Chapter 3 57

Page 63: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loopsModify to avoid repeated states along path⇒ complete in finite spaces

Time?? O(bm): terrible if m is much larger than dbut if solutions are dense, may be much faster than breadth-first

Space?? O(bm), i.e., linear space!

Optimal??

Chapter 3 58

Page 64: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loopsModify to avoid repeated states along path⇒ complete in finite spaces

Time?? O(bm): terrible if m is much larger than dbut if solutions are dense, may be much faster than breadth-first

Space?? O(bm), i.e., linear space!

Optimal?? No

Chapter 3 59

Page 65: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Depth-limited search

• Same as depth-first search, but with depth limit l – i.e., nodes at depth l have no successors

25

function DEPTH-LIMITED-SEARCH (problem, limit) returns a solution, or failure/cutoff return Recursive-DLS(MAKE-NODE(problem, INITIAL-STATE), problem, limit) function RECURSIVE-DLS(node, problem, limit) returns a solution, or failure/cutoff if problem.GOAL-TEST(node.STATE) then return SOLUTION(node) else if limit = 0 then return cutoff else cutoff_occurred? ← false for each action in problem.ACTIONS(node.STATE) do child ← Child-Node(problem, node, action) result ← Recursive-DLS(child, problem, limit – 1) if result = cutoff then cutoff_occurred? ← true else if result ≠ failure then return result if cutoff_occurred? then return cutoff else return failure

Page 66: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Iterative deepening search

function Iterative-Deepening-Search( problem) returns a solution

inputs: problem, a problem

for depth← 0 to ∞ do

result←Depth-Limited-Search( problem, depth)

if result 6= cutoff then return result

end

Chapter 3 61

Page 67: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Iterative deepening search l = 0

Limit = 0 A A

Chapter 3 62

Page 68: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Iterative deepening search l = 1

Limit = 1 A

B C

A

B C

A

B C

A

B C

Chapter 3 63

Page 69: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Iterative deepening search l = 2

Limit = 2 A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

Chapter 3 64

Page 70: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Iterative deepening search l = 3

Limit = 3

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H J K L M N OI

A

B C

D E F G

H I J K L M N O

Chapter 3 65

Page 71: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of iterative deepening search

Complete??

Chapter 3 66

Page 72: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of iterative deepening search

Complete?? Yes

Time??

Chapter 3 67

Page 73: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of iterative deepening search

Complete?? Yes

Time?? (d + 1)b0 + db1 + (d− 1)b2 + . . . + bd = O(bd)

Space??

Chapter 3 68

Page 74: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of iterative deepening search

Complete?? Yes

Time?? (d + 1)b0 + db1 + (d− 1)b2 + . . . + bd = O(bd)

Space?? O(bd)

Optimal??

Chapter 3 69

Page 75: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Properties of iterative deepening search

Complete?? Yes

Time?? (d + 1)b0 + db1 + (d− 1)b2 + . . . + bd = O(bd)

Space?? O(bd)

Optimal?? Yes, if step cost = 1Can be modified to explore uniform-cost tree

Numerical comparison for b = 10 and d = 5, solution at far right leaf:

N(IDS) = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450

N(BFS) = 10 + 100 + 1, 000 + 10, 000 + 100, 000 + 999, 990 = 1, 111, 100

IDS does better because other nodes at depth d are not expanded

BFS can be modified to apply goal test when a node is generated

Chapter 3 70

leparker
Typewritten Text
leparker
Typewritten Text
XXXXXXXXXXXXXXXXX
leparker
Typewritten Text
leparker
Typewritten Text
leparker
Typewritten Text
= 111,110
leparker
Typewritten Text
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
leparker
Typewritten Text
XX
leparker
Typewritten Text
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Page 76: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Summary of algorithms

Criterion Breadth- Uniform- Depth- Depth- IterativeFirst Cost First Limited Deepening

Complete? Yes∗ Yes∗ No Yes, if l ≥ d YesTime bd+1 bdC

∗/εe bm bl bd

Space bd+1 bdC∗/εe bm bl bd

Optimal? Yes∗ Yes No No Yes∗

Chapter 3 71

leparker
Typewritten Text
* If b is finite
leparker
Typewritten Text
leparker
Typewritten Text
#
leparker
Typewritten Text
# Complete if step costs positive
leparker
Typewritten Text
leparker
Typewritten Text
**
leparker
Typewritten Text
leparker
Typewritten Text
** Optimal if step costs are all identical
leparker
Typewritten Text
*
leparker
Typewritten Text
*
leparker
Typewritten Text
leparker
Typewritten Text
**
Page 77: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Bidirectional search

• Run two simultaneous searches – one forward from initial state, and the other backward from the goal – We hope they meet in the middle!

• Implemented by changing goal test with a check to see whether the frontiers of the two searches intersect – If they do, then a solution is found

• Difficult to use when there are multiple possible goal states

• Complete? Yes (if b is finite, and both directions use BFS) • Time: 𝑂(𝑏𝑑 2⁄ ) • Space: 𝑂(𝑏𝑑 2⁄ ) • Optimal? Yes (if step costs are identical and both directions use BFS)

25

Page 78: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Repeated states

Failure to detect repeated states can turn a linear problem into an exponentialone!

A

B

C

D

A

BB

CCCC

Chapter 3 72

Page 79: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search • Consider the search space below, where S is the start node and G1, G2,

and G3 satisfy the goal test. Arcs are labeled with the cost of traversing them. Nodes are removed from fringe in alphabetical order.

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 80: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 81: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 82: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 83: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 84: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A B – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 85: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A B C – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 86: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A B C S – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 87: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A B C S A – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 88: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A B C S A E – Which goal state is reached?

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 89: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Exercise – Search (con’t) • Iterative Deepening:

– What is order that nodes are removed from fringe? S S A B C S A E G1 – Which goal state is reached? G1

G3

G1

B

6

C

5

2

7

5

2

11

0

10

1

1

4

2

A

F

D

G2

3

E

S

Page 90: Chapter 3web.eecs.utk.edu/~leparker/Courses/CS594-fall13/Lectures/3-Search... · often interleave search, execution Unknown state space =) ... A node is a data structure constituting

Summary

Problem formulation usually requires abstracting away real-world details todefine a state space that can feasibly be explored

Variety of uninformed search strategies

Iterative deepening search uses only linear spaceand not much more time than other uninformed algorithms

Graph search can be exponentially more efficient than tree search

Chapter 3 74

leparker
Typewritten Text
Iterative deepening is the preferred uninformed search method when the search space is large and the depth of the solution is not known.
leparker
Typewritten Text
leparker
Typewritten Text
leparker
Typewritten Text
leparker
Typewritten Text