Solving Problems by Searching Chapter 3 Ch. 03 p.1/49 Outline - - PowerPoint PPT Presentation

solving problems by searching
SMART_READER_LITE
LIVE PREVIEW

Solving Problems by Searching Chapter 3 Ch. 03 p.1/49 Outline - - PowerPoint PPT Presentation

Solving Problems by Searching Chapter 3 Ch. 03 p.1/49 Outline Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms Ch. 03 p.2/49 Problem-solving agents


slide-1
SLIDE 1

Solving Problems by Searching

Chapter 3

  • Ch. 03 – p.1/49
slide-2
SLIDE 2

Outline

Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms

  • Ch. 03 – p.2/49
slide-3
SLIDE 3

Problem-solving agents

function SIMPLE-PROBLEM-SOLVING-AGENT (percept) returns an action inputs: percept a percept 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 do goal

  • FORMULATE-GOAL (state)

problem

  • FORMULATE-PROBLEM (state,goal)

seq

  • SEARCH (problem)

action

  • FIRST (seq)

seq

  • REST (seq)

return action

  • Ch. 03 – p.3/49
slide-4
SLIDE 4

Problem-solving agents (cont’d)

Restricted form of general agent This is offline problem solving; solution executed “eyes closed” Online problem solving involves acting without complete knowledge Assumes: static, observable, discrete, deterministic

  • Ch. 03 – p.4/49
slide-5
SLIDE 5

Example: Romania

On holiday in Romania; currently in Arad Flight leaves tomorrow from Bucharest Formulate goal: be in Bucharest Formulate problem: states: various cities actions: drive between cities Find solution: sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest

  • Ch. 03 – p.5/49
slide-6
SLIDE 6

Example: Romania

Giurgiu Urziceni Hirsova Eforie Neamt Oradea Zerind Arad Timisoara Lugoj Mehadia Dobreta Craiova 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

  • Ch. 03 – p.6/49
slide-7
SLIDE 7

Problem types

Deterministic, fully observable

single-state problem Agent knows exactly which state it will be in; solution is a sequence Non-observable

conformant problem Agent may have no idea where it is; solution (if any) is a sequence Nondeterministic and/or partially observable

contingency problem percepts provide new information about current state solution is a tree or policy

  • ften interleave search, execution

Unknown state space

exploration problem (“online”)

  • Ch. 03 – p.7/49
slide-8
SLIDE 8

Example: vacuum world

1 2 8 7 5 6 3 4

  • Ch. 03 – p.8/49
slide-9
SLIDE 9

Example: vacuum world

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

✂☎✄ ✆ ✝✟✞ ✠☛✡ ☞ ✌ ✍
  • Ch. 03 – p.9/49
slide-10
SLIDE 10

Example: vacuum world

Conformant, start in

✞ ✂ ✞ ✄ ✞ ☎ ✞ ✆ ✞ ✝ ✞ ✞ ✞ ✟ ✠

. e.g.,

✁ ✂☎✄ ✆ ✝

goes to

✞ ☎ ✞ ✝ ✞ ✟ ✠

. Solution??

✂☎✄ ✆ ✝✟✞ ✠☛✡ ☞ ✌ ✞ ✡☞☛ ✌ ✝ ✞ ✠☛✡ ☞ ✌ ✍
  • Ch. 03 – p.10/49
slide-11
SLIDE 11

Example: vacuum world

Contingency, start in #5 or #7 Murphy’s Law: if a carpet can get dirty it will Local sensing: dirt, location only. Solution??

✂☎✄ ✆ ✝✟✞

if

✁ ✝

then

✠☛✡ ☞ ✌ ✍
  • Ch. 03 – p.11/49
slide-12
SLIDE 12

Single-state problem formulation

A problem is defined by four items: initial state e.g., “at Arad” successor function

  • ✁✄✂

= set of action–state pairs e.g.,

✆✞✝ ✟ ✠ ☎
  • ✡☞☛
✆ ✝ ✟ ✠ ✌ ✍✏✎ ✝ ✑✓✒ ✠✕✔ ✍✏✎ ✝ ✑✓✒ ✠✗✖ ✔✘ ✘ ✘ ✙

goal test, can be explicit, e.g.,

= “at Bucharest” implicit, e.g.,

✚✏✛ ✜ ✑ ✝ ✢ ✁ ✂ ☎

path cost (additive) e.g., sum of distances, number of actions executed, etc.

✣ ✁ ✂ ✔ ✟ ✔ ✤ ☎

is the step cost, assumed to be

✥ ✦

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

  • Ch. 03 – p.12/49
slide-13
SLIDE 13

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 actions e.g., “Arad

Zerind” represents a complex set

  • f 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!

  • Ch. 03 – p.13/49
slide-14
SLIDE 14

Example: vacuum world state space graph

R L S S S S R L R L R L S S S S L L L L R R R R

  • Ch. 03 – p.14/49
slide-15
SLIDE 15

Example: vacuum world state space graph

states: integer dirt and robot locations (ignore dirt amounts) actions:

✡☞☛ ✌ ✝

,

✁ ✂☎✄ ✆ ✝

,

✠☛✡ ☞ ✌

,

✂✁ ✄✆☎

goal test: no dirt path cost: 1 per action (0 for

✂✁ ✄✆☎

)

  • Ch. 03 – p.15/49
slide-16
SLIDE 16

Example: The 8-puzzle

2

Start State Goal State

1 3 4 6 7 5 1 2 3 4 6 7 8 5 8

  • Ch. 03 – p.16/49
slide-17
SLIDE 17

Example: The 8-puzzle

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

  • Puzzle family is NP-hard
  • Ch. 03 – p.17/49
slide-18
SLIDE 18

Example: robotic assembly

R R R P R R

  • Ch. 03 – p.18/49
slide-19
SLIDE 19

Example: robotic assembly

states: real-valued coordinates of robot joint angles parts 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

  • Ch. 03 – p.19/49
slide-20
SLIDE 20

Tree search algorithms

Basic idea: offline, simulated exploration of state space by generating successors of already-explored states (a.k.a. expanding states)

  • Ch. 03 – p.20/49
slide-21
SLIDE 21

Tree search algorithms

function TREE-SEARCH (problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem loop do if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree end

  • Ch. 03 – p.21/49
slide-22
SLIDE 22

Tree search example

(a) The initial state (b) After expanding Arad (c) After expanding Sibiu

Rimnicu Vilcea

Lugoj Arad Fagaras Oradea Arad Arad Oradea

Rimnicu Vilcea

Lugoj Zerind Sibiu Arad Fagaras Oradea

Timisoara

Arad Arad Oradea Lugoj Arad Arad Oradea Zerind Arad Sibiu

Timisoara

Arad

Rimnicu Vilcea

Zerind Arad Sibiu Arad Fagaras Oradea

Timisoara

  • Ch. 03 – p.22/49
slide-23
SLIDE 23

Implementation: states vs. nodes

1 2 3 4 5 6 7 8

1 2 3 4 5 6 7 8

Node

DEPTH = 6 STATE PARENT-NODE ACTION = right

  • PATH-COST = 6
  • Ch. 03 – p.23/49
slide-24
SLIDE 24

Implementation: states vs. nodes

A state is a (representation of) a physical configuration A node is a data structure constituting part of a search tree includes parent, children, depth, path cost

States do not have parents, children, depth, or path cost! The EXPAND function creates new nodes, filling in the various fields and using the SUCCESSORFN of the problem to create the corresponding states.

  • Ch. 03 – p.24/49
slide-25
SLIDE 25

Implementation: general tree search

function TREE-SEARCH (problem, fringe) returns a solution, or failure fringe

  • INSERT(MAKE-NODE(INITIAL-STATE [problem]),fringe)

loop do if EMPTY?(fringe) then return failure node

  • REMOVE-FIRST(fringe)

if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) fringe

  • INSERT-ALL(EXPAND(node, problem), fringe)
  • Ch. 03 – p.25/49
slide-26
SLIDE 26

Implementation: general tree search

function EXPAND (node, problem) returns a set of nodes successors

  • the empty set

for each

  • action, result

in SUCCESSOR-FN [problem(STATE[node]) do s

  • a new NODE

STATE[s]

  • result

PARENT-NODE[s]

  • node

ACTION[s]

  • action

PATH-COST[s]

  • PATH-COST[node] + STEP-COST(node,action,s)

DEPTH[s]

  • DEPTH[node] +1

add s to successors return successors

  • Ch. 03 – p.26/49
slide-27
SLIDE 27

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

  • ne exists?

time complexity—number of nodes generated/expanded space complexity—maximum number of nodes in memory

  • ptimality—does it always find a least-cost

solution?

  • Ch. 03 – p.27/49
slide-28
SLIDE 28

Search strategies

Time and space complexity are measured in terms

  • f
  • —maximum branching factor of the search tree
  • —depth of the least-cost solution

—maximum depth of the state space (may be

)

  • Ch. 03 – p.28/49
slide-29
SLIDE 29

Uninformed search strategies

Uninformed strategies use only the information available in the problem definition Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search Iterative broadening search (not in the textbook)

  • Ch. 03 – p.29/49
slide-30
SLIDE 30

Breadth-first search

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

  • Ch. 03 – p.30/49
slide-31
SLIDE 31

Progress of breadth-first search

A B C E F G D A B D E F G C A C D E F G B B C D E F G A

  • Ch. 03 – p.31/49
slide-32
SLIDE 32

Properties of breadth-first search

Complete: Yes (if

  • is finite)

Time:

  • ✁✂
  • ✄✂
☎ ☎ ☎
✝ ✁ ✂ ✞ ✄
✟ ✠ ✂

, i.e., exponential in

  • Space:
✟ ✠ ✂

(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 10MB/sec so 24hrs = 860GB.

  • Ch. 03 – p.32/49
slide-33
SLIDE 33

Uniform-cost search

Expand least-cost unexpanded node Implementation: fringe = queue ordered by path cost Equivalent to breadth-first if step costs all equal

  • Ch. 03 – p.33/49
slide-34
SLIDE 34

Properties of uniform-cost search

Complete: Yes, if step cost

✂✁

Time: # of nodes with

✄ ✄

cost of optimal solution,

✆ ✝ ✞✠✟ ✡ ✂

where

☛ ☞

is the cost of the optimal solution Space: # of nodes with

✄ ✄

cost of optimal solution,

✆ ✝ ✞✠✟ ✡ ✂

Optimal: Yes—nodes expanded in increasing order

  • f
  • Ch. 03 – p.34/49
slide-35
SLIDE 35

Depth-first search

Expand deepest unexpanded node Implementation: fringe = LIFO queue, i.e., put successors at front

  • Ch. 03 – p.35/49
slide-36
SLIDE 36

Progress of depth-first search

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 I J K L M N O A B C D E F G H I J K L M N O

  • Ch. 03 – p.36/49
slide-37
SLIDE 37

Properties of depth-first search

Complete: No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path

  • complete in finite spaces

Time:

: terrible if

is much larger than

  • but if solutions are dense, may be much faster than

breadth-first Space:

, i.e., linear space! Optimal: No

  • Ch. 03 – p.37/49
slide-38
SLIDE 38

Depth-limited search

= depth-first search with depth limit

  • ,

i.e., nodes at depth

  • have no successors

A recursive implementation is shown on the next page

  • Ch. 03 – p.38/49
slide-39
SLIDE 39

Depth-limited search

function DEPTH-LIMITED-SEARCH (problem, limit) returns a solution, or failure/cutoff return RECURSIVE-DLS(MAKE-NODE( INITIAL-STATE[problem]), problem,limit) function RECURSIVE-DLS (node, problem, limit) returns a solution, or failure/cutoff cutoff-occured?

  • false

if GOAL-TEST[problem](STATE[node]) then return SOLUTION(node) else if DEPTH[node]=limit then return cutoff else for each successor in EXPAND(node, problem) do result

  • RECURSIVE-DLS(successor, problem, limit)

if result = cutoff then cutoff-occurred?

  • true

else if result

✂✁

failure then return result if cutoff-occurred? then return cutoff else return failure

  • Ch. 03 – p.39/49
slide-40
SLIDE 40

Properties of depth-limited search

Complete: No (similar to DFS) Time:

, where

  • is the depth-limit

Space:

, i.e., linear space (similar to DFS) Optimal: No

  • Ch. 03 – p.40/49
slide-41
SLIDE 41

Iterative deepening search

Do iterations of depth-limited search starting with a limit of 0 . If you fail to find a goal with a particular depth limit, increment it and continue with the iterations. Combines the linear space complexity of DFS with the completeness property of BFS.

  • Ch. 03 – p.41/49
slide-42
SLIDE 42

Iterative deepening search

function ITERATIVE-DEEPENING-SEARCH(problem) returns a solution, or failure inputs: problem, a problem for depth

  • 0 to
  • do

result

  • DEPTH-LIMITED-SEARCH(problem, depth)

if result

✂✁

cutoff then return result

  • Ch. 03 – p.42/49
slide-43
SLIDE 43

Iterative deepening search

Limit = 3 Limit = 2 Limit = 1 Limit = 0

A A A B C A B C A B C A B C 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 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 O I A B C D E F G H I J K L M N O

  • Ch. 03 – p.43/49
slide-44
SLIDE 44

Properties of iterative deepening search

Complete: Yes Time:

✁ ✂
  • ✁✂
☎ ☎ ☎
✞ ✄

Space:

Optimal: Yes, if step cost = 1 Can be modified to explore uniform-cost tree Numerical comparison for

✁ ✁

and

, solution at far right:

  • IDS
✂ ✞ ✆ ✁
✁ ✁
✞ ✁ ✁ ✁
✁ ✞ ✁ ✁ ✁
✁ ✁ ✞ ✁ ✁ ✁ ✞ ✁ ✂ ✄ ✞ ☎ ✆ ✁
  • BFS
✂ ✞ ✁ ✁
✁ ✁
✞ ✁ ✁ ✁
✁ ✞ ✁ ✁ ✁
✁ ✁ ✞ ✁ ✁ ✁
✂ ✂ ✞ ✂ ✂ ✁ ✞ ✁ ✞ ✁ ✁ ✁ ✞ ✁ ✁ ✁
  • Ch. 03 – p.44/49
slide-45
SLIDE 45

Iterative broadening search

Iterative deepening is iterations of DFS with a depth

  • cutoff. Iterative broadening is iterations of DFS with

a breadth cutoff. Iterate

from

to

  • , where
  • is the maximum

branching factor. At every iteration, take only

children of every node expanded, simply discard the remaining children. Algorithm?? Properties??

  • Ch. 03 – p.45/49
slide-46
SLIDE 46

Summary of algorithms

Criterion Breadth- Uniform- Depth- Depth- Iterative First Cost First Limited Deepening Complete? Yes

  • Yes
  • No

Yes, if

✁ ✂ ✄

Yes Time

☎ ✆ ✝ ✞ ☎ ✟ ✠ ✡ ☛ ☞ ✌ ☎ ✍ ☎ ✎ ☎ ✆

Space

☎ ✆ ✝ ✞ ☎ ✟ ✠ ✡ ☛ ☞ ✌ ☎ ✏ ☎ ✁ ☎ ✄

Optimal? Yes

  • Yes
  • No

No Yes

  • Ch. 03 – p.46/49
slide-47
SLIDE 47

Repeated states

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

A B C D A B B C C C C A (c) (b) (a)

  • Ch. 03 – p.47/49
slide-48
SLIDE 48

Graph search

function GRAPH-SEARCH (problem, fringe) returns a solution, or failure closed

  • an empty set

fringe

  • INSERT(MAKE-NODE(INITIAL-STATE [problem]),fringe)

loop do if EMPTY?(fringe) then return failure node

  • REMOVE-FIRST(fringe)

if GOAL-TEST[problem] applied to STATE[node] succeeds then return SOLUTION(node) if STATE[node] is not in closed then add STATE[node] to closed fringe

  • INSERT-ALL(EXPAND(node, problem), fringe)
  • Ch. 03 – p.48/49
slide-49
SLIDE 49

Summary

Problem formulation usually requires abstracting away real-world details to define a state space that can feasibly be explored Variety of uninformed search strategies Iterative deepening search uses only linear space and not much more time than other uninformed algorithms

  • Ch. 03 – p.49/49