Docsity

Understanding State Space Search: Components, Strategies, and Algorithms, Study notes of Advanced Algorithms

Toggle sidebar
bg1
1
1
Uninformed Search
Chapter 3.1 –3.4
Models To Be Studied in CS 540
State-based Models
–Model task as a graph of all possible states
lCalled a “state-space graph”
–A state captures all the relevant information about
the past in order to act (op timally) in the future
–Actions correspond to transitions from one state to
another
–Solutions are defined as a sequence of
steps/actions (i.e., a path in the graph)
Many AI (and non-AI) Tasks can be
Formulated as Search Problems
lPuzzles
lGames
lNavigation
lAssignment
lMotion planning
lScheduling
lRouting
Goal is to find a sequence of actions
Search Example: Route Finding
Actions: go straight, turn left, turn right
Goal: shortest? fastest? most scenic?
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Understanding State Space Search: Components, Strategies, and Algorithms and more Study notes Advanced Algorithms in PDF only on Docsity!

Uninformed Search

Chapter 3.1 – 3.

Models To Be Studied in CS 540

State-based Models

  • Model task as a graph of all possible states

l Called a “state-space graph”

  • A state captures all the relevant information about

the past in order to act (optimally) in the future

  • Actions correspond to transitions from one state to

another

  • Solutions are defined as a sequence of

steps/actions (i.e., a path in the graph)

Many AI (and non-AI) Tasks can be

Formulated as Search Problems

l Puzzles

l Games

l Navigation

l Assignment

l Motion planning

l Scheduling

l Routing

Goal is to find a sequence of actions

Search Example: Route Finding

Actions: go straight, turn left, turn right

Goal: shortest? fastest? most scenic?

Search Example: River Crossing Problem

Rules:

1) Farmer must row the boat

2) Only room for one other

3) Without the farmer present:

  • Dog bites sheep
  • Sheep eats cabbage

Actions: F>, F<,

FC>, FC<, FD>,

FD<, FS>, FS<

Goal: All on

right side of river

Search Example: 8-Puzzle

Actions: move tiles (e.g., Move2Down)

Goal: reach a certain configuration

Search Example: Water Jugs Problem

Given 4-liter and 3-liter pitchers, how do you get

exactly 2 liters into the 4-liter pitcher?

(^4 ) Search Example: Robot Motion Planning

Actions: translate and rotate

joints

Goal: fastest? most energy

efficient? safest?

What Actions does the Agent Need?

l Discrete and Deterministic task assumptions imply

l Given:

  • an action (aka operator or move )
  • a description of the current state of the world

l Action completely specifies:

  • if that action can be applied (i.e., is it legal)
  • what the exact state of the world will be after the

action is performed in the current state (no "history"

information needed to compute the successor state)

What Actions does the Agent Need?

l A finite set of actions/operators needs to be

  • decomposed into atomic steps that are discrete and

indivisible, and therefore can be treated as

instantaneous

  • sufficient to describe all necessary changes

l The number of actions needed depends on how the

world states are represented

Search Example: 8-Puzzle

l States = configurations

l Actions = up to 4 kinds of moves: up, down, left,

right

Water Jugs Problem

Given 4-liter and 3-liter pitchers, how do you get exactly 2

liters into the 4-liter pitcher?

State: ( x, y ) for # liters in 4-liter and 3-liter pitchers, respectively

Actions: empty, fill, pour water between pitchers

Initial state: (0, 0)

Goal state: (2, *)

4 3

Action / Successor Functions

1. ( x, y | x < 4) (4 , y ) “Fill 4”

2. ( x, y | y < 3) ( x, 3 ) “Fill 3”

3. ( x, y | x > 0) (0 , y) “Empty 4”

4. ( x, y | y > 0) ( x, 0) “Empty 3”

5. ( x, y | x+y ≥ 4 and y > 0) (4 , y - (4 - x ))

“Pour from 3 to 4 until 4 is full”

6. ( x, y | x+y ≥ 3 and x > 0) ( x - (3 - y ) , 3)

“Pour from 4 to 3 until 3 is full”

7. ( x, y | x+y ≤ 4 and y > 0) ( x+y, 0)

“Pour all water from 3 to 4”

Formalizing Search in a State Space

l A state space is a directed graph : ( V, E )

  • V is a set of nodes (vertices)
  • E is a set of arcs (edges)

each arc is directed from one node to another node

l Each node is a data structure that contains:

  • a state description
  • other information such as:

l link to parent node

l name of action that generated this node (from its

parent)

l other bookkeeping data

Formalizing Search in a State Space

l Each arc corresponds to one of the finite number of

actions:

  • when the action is applied to the state associated

with the arc's source node

  • then the resulting state is the state associated with

the arc's destination node

l Each arc has a fixed, positive cost:

  • corresponds to the cost of the action

Formalizing Search in a State Space

l Each node has a finite set of successor nodes:

  • corresponding to all the legal actions

that can be applied at the source node's state

l Expanding a node means:

  • generate all successor nodes
  • add them and their associated arcs to the state-

space search tree

Formalizing Search

A search problem has five components:

S , I, G , actions , cost

1. State space S^ : all valid configurations

2. Initial states I ⊆ S : a set of start states

3. Goal states G ⊆ S : a set of goal states

4. An action function successors ( s ) ⊆ S : states

reachable in one step (one arc) from s

5. A cost function cost( s, s’ ): The cost of moving from

s to s’

l The goal of search is to find a solution path from a

state in I to a state in G

I = {(FCDS,)} ⊆ S

G = {(,FCDS)} ⊆ S

successors ((FCDS,)) = {(CD,FS)}

successors ((CDF,S)) = {(CD,FS), (D,FCS), (C,FSD)}

F C D S

F C D S

State Space = A Directed Graph

l In general, there will be many generated, but un-

expanded, states at any given time during a search

l One has to choose which one to “expand” next

CSDF, CD,SF CDF, S D, CFS C, DSF DFS, C CSF, D S, CFD SF, CD , CSDF

Start Goal

Different Search Strategies

l The generated, but not yet expanded, states

define the Frontier (aka Open or Fringe ) set

l The essential difference is, which state in the

Frontier to expand next?

CSDF, CD,SF CDF, S D, CFS C, DSF DFS, C CSF, D S, CFD SF, CD , CSDF

Start Goal

Formalizing Search in a State Space

State-space search is the process of searching through

a state space for a solution by making explicit a

sufficient portion of an implicit state-space graph , in

the form of a search tree , to include a goal node:

TREE SEARCH Algorithm : Frontier = { S }, where S is the start node Loop do if Frontier is empty then return failure pick a node, n , from Frontier if n is a goal node then return solution Generate all n ’s successor nodes and add them all to Frontier Remove n from Frontier called “ expanding ” node n

Formalizing Search in a State Space

l This algorithm does NOT detect a goal when

the node is generated

l This algorithm does NOT detect loops (i.e.,

repeated states) in state space

l Each node implicitly represents

  • a partial solution path from the start node to the

given node

  • cost of the partial solution path

l From this node there may be

  • many possible paths that have this partial path

as a prefix

  • many possible solutions A State Space Graph START

GOAL

d b p q c e h a f r t u v

What is the corresponding search tree?

Uninformed Search on Trees

l Uninformed means we only know:

  • The goal test
  • The successors () function

l But not which non-goal states are better

l For now, also assume state space is a tree

  • That is, we won’t worry about repeated states
  • We will fix this later

Key Issues of State-Space Search Algorithm

l Search process constructs a "search tree"

  • root is the start state
  • leaf nodes are:

l unexpanded nodes (in the Frontier list)

l "dead ends" (nodes that aren't goals and have no

successors because no operators were possible)

l goal node is last leaf node found

l Loops in graph may cause "search tree" to be infinite

even if state space is small

l Changing the Frontier ordering leads to different

search strategies

Breadth-First Search (BFS)

of nodes tested: 0 , expanded: 0

expnd. node Frontier list {S} 5 2 9 6

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 1 , expanded: 1

expnd. node Frontier list {S} S not goal {A,B,C}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 2 , expanded: 2

expnd. node Frontier list {S} S {A,B,C} A not goal {B,C,D,E}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 3 , expanded: 3

expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B not goal {C,D,E,G}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 4 , expanded: 4

expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C not goal {D,E,G,F}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 5 , expanded: 5

expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D not goal {E,G,F,H}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 6 , expanded: 6

expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D {E,G,F,H} E not goal {G,F,H,G}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

of nodes tested: 7 , expanded: 6

expnd. node Frontier list {S} S {A,B,C} A {B,C,D,E} B {C,D,E,G} C {D,E,G,F} D {E,G,F,H} E {G,F,H,G} G goal {F,H,G} no expand

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, queue)

Breadth-First Search (BFS)

l Complete?

  • Yes

l Optimal / Admissible?

  • Yes, if all operators (i.e., arcs) have the same

constant cost, or costs are positive, non-decreasing

with depth

  • otherwise, not optimal but does guarantee finding

solution of shortest length (i.e., fewest arcs)

Breadth-First Search (BFS)

l Time and space complexity: O ( bd ) (i.e., exponential)

  • d is the depth of the solution
  • b is the branching factor at each non-leaf node

l Very slow to find solutions with a large number of steps

because must look at all shorter length possibilities first

Breadth-First Search (BFS)

l A complete search tree has a total # of nodes =

1 + b + b^2 + ... + bd^ = ( b ( d +1)^ - 1) / ( b- 1)

  • d : the tree's depth
  • b : the branching factor at each non-leaf node

l For example: d = 12 , b = 10

1 + 10 + 100 + ... + 10^12 = (10^13 - 1)/9 = O (10^12 )

  • If BFS expands 1,000 nodes/sec and each node

uses 100 bytes of storage, then BFS will take 35

years to run in the worst case, and it will use 111

terabytes of memory!

Depth-First Search Goal

Expand the deepest node first

1. Select a direction, go deep to the end

2. Slightly change the end

3. Slightly change the end some more…

Use a Stack to order nodes in Frontier

of nodes tested: 0 , expanded: 0

Depth-First Search (DFS) expnd. node Frontier {S}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, stack)

of nodes tested: 1 , expanded: 1

Depth-First Search (DFS) expnd. node Frontier {S} S not goal {A,B,C}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, stack)

of nodes tested: 2 , expanded: 2

Depth-First Search (DFS) expnd. node Frontier {S} S {A,B,C} A not goal {D,E,B,C}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, stack)

of nodes tested: 3 , expanded: 3

Depth-First Search (DFS) expnd. node Frontier {S} S {A,B,C} A {D,E,B,C} D not goal {H,E,B,C}

S

start

A

D E F

B

G

goal

C

H

generalSearch(problem, stack)

Depth-First Search (DFS)

l May not terminate without a depth bound

i.e., cutting off search below a fixed depth, D

l Not complete

  • with or without cycle detection
  • and, with or without a depth cutoff

l Not optimal / admissible

l Can find long solutions quickly if lucky

Depth-First Search (DFS)

l Time complexity: O ( bd ) exponential

Space complexity: O ( bd ) linear

  • d is the depth of the solution
  • b is the branching factor at each non-leaf node

l Performs “chronological backtracking”

  • i.e., when search hits a dead end, backs up one

level at a time

  • problematic if the mistake occurs because of a bad

action choice near the top of search tree

Uniform-Cost Search (UCS)

l Use a Priority Queue to order nodes in Frontier ,

sorted by path cost

l Let g ( n ) = cost of path from start node s to current

node n

l Sort nodes by increasing value of g

of nodes tested: 0 , expanded: 0

generalSearch(problem, priorityQueue)

Uniform-Cost Search (UCS) expnd. node Frontier list {S} 5 2 9 6

S

start

A

D E F

B

G

goal

C

H

of nodes tested: 1 , expanded: 1

generalSearch(problem, priorityQueue)

Uniform-Cost Search (UCS) expnd. node Frontier list {S:0} S not goal {B:2,C:4,A:5}

S

start

A

D E F

B

G

goal

C

H

of nodes tested: 2 , expanded: 2

generalSearch(problem, priorityQueue)

Uniform-Cost Search (UCS) expnd. node Frontier list {S} S {B:2,C:4,A:5} B not goal {C:4,A:5,G:2+6}

S

start

A

D E F

B

G

goal

C

H

of nodes tested: 3 , expanded: 3

generalSearch(problem, priorityQueue)

Uniform-Cost Search (UCS) expnd. node Frontier list {S} S {B:2,C:4,A:5} B {C:4,A:5,G:8} C not goal {A:5,F:4+2,G:8}

S

start

A

D E F

B

G

goal

C

H

of nodes tested: 4 , expanded: 4

generalSearch(problem, priorityQueue)

Uniform-Cost Search (UCS) expnd. node Frontier list {S} S {B:2,C:4,A:5} B {C:4,A:5,G:8} C {A:5,F:6,G:8} A not goal {F:6,G:8,E:5+4, D:5+9}

S

start

A

D E F

B

G

goal

C

H

Uniform-Cost Search (UCS)

l Time and space complexity: O ( bd ) (i.e., exponential)

  • d is the depth of the solution
  • b is the branching factor at each non-leaf node

l More precisely, time and space complexity is

O ( b C /ε^ ) where all edge costs are ε, ε > 0, and C __ is

the best goal path cost

Iterative-Deepening Search (IDS)

l requires modification to DFS search algorithm:

  • do DFS to depth 1

and treat all children of the start node as leaves

  • if no solution found, do DFS to depth 2
  • repeat by increasing “depth bound” until a solution

found

l Start node is at depth 0

deepeningSearch(problem)

depth: 1 , # of nodes expanded: 0 , tested: 0 Iterative-Deepening Search (IDS) expnd. node Frontier {S} 5 2 9 6

S

start

A

D E F

B

G

goal

C

H

deepeningSearch(problem)

depth: 1 , # of nodes tested: 1 , expanded: 1 Iterative-Deepening Search (IDS)

S

start

A

D E F

B

G

goal

C

H

expnd. node Frontier {S} S not goal {A,B,C}

deepeningSearch(problem)

depth: 1 , # of nodes tested: 2 , expanded: 1 Iterative-Deepening Search (IDS)

S

start

A

D E F

B

G

goal

C

H

expnd. node Frontier {S} S {A,B,C} A not goal {B,C} no expand

deepeningSearch(problem)

depth: 1 , # of nodes tested: 3 , expanded: 1 Iterative-Deepening Search (IDS)

S

start

A

D E F

B

G

goal

C

H

expnd. node Frontier {S} S {A,B,C} A {B,C} B not goal {C} no expand

deepeningSearch(problem)

depth: 1 , # of nodes tested: 4 , expanded: 1 Iterative-Deepening Search (IDS)

S

start

A

D E F

B

G

goal

C

H

expnd. node Frontier {S} S {A,B,C} A {B,C} B {C} C not goal { } no expand-FAIL

deepeningSearch(problem)

depth: 2 , # of nodes tested: 4(1), expanded: 2 Iterative-Deepening Search (IDS)

S

start

A

D E F

B

G

goal

C

H

expnd. node Frontier {S} S {A,B,C} A {B,C} B {C} C { } S no test {A,B,C}