0% found this document useful (0 votes)
9 views

01. [AI - Slides] Search - Uninformed Search

ai

Uploaded by

alieslam20014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

01. [AI - Slides] Search - Uninformed Search

ai

Uploaded by

alieslam20014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Uninformed Search

1
Models To Be Studied in CS 540

State-based Models
– Model task as a graph of all possible states
⚫ 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
Goal is to find a sequence of actions

⚫ Puzzles
⚫ Games
⚫ Navigation
⚫ Assignment
⚫ Motion planning
⚫ Scheduling
⚫ Routing
Search Example: Route Finding

Actions: go straight, turn left, turn right


Goal: shortest? fastest? most scenic?
Search Example: River Crossing Problem

Goal: All on
right side of river

Rules:
1) Farmer must row the boat
2) Only room for one other Actions: F>, F<,
3) Without the farmer present: FC>, FC<, FD>,
• Dog bites sheep FD<, FS>, FS<
• Sheep eats cabbage
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 3
Search Example: Robot Motion Planning

Actions: translate and rotate


joints

Goal: fastest? most energy


efficient? safest?
Search Example: 8-Queens
What Knowledge does the Agent
Need?

⚫ The information needs to be


– sufficient to describe all relevant aspects for reaching
the goal
– adequate to describe the world state (aka situation)

⚫ Fully observable assumption, also known as the


closed world assumption, means
– All necessary information about a problem domain
is accessible so that each state is a complete
description of the world; there is no missing (or noisy)
information at any point in time
11
How should the Environment be
Represented?
⚫ Determining what to represent is difficult and is
usually left to the system designer to specify

⚫ Problem State = representation of all necessary


information about the environment

⚫ State Space (aka Problem Space) = all possible valid


configurations of the environment

12
What Goal does the Agent want to
Achieve?
⚫ How do you know when the goal is reached?
– with a goal test that defines what it means
to have achieved the goal
– or, with a set of goal states

⚫ Determining the goal is usually left to the system


designer or user to specify

13
What Actions does the Agent Need?

⚫ Discrete and Deterministic task assumptions imply

⚫ Given:
– an action (aka operator or move)
– a description of the current state of the world

⚫ 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)
14
What Actions does the Agent Need?

⚫ 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

⚫ The number of actions needed depends on how the


world states are represented

15
Search Example: 8-Puzzle

⚫ States = configurations
⚫ 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?

4 3
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, *)
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

⚫ 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
⚫ Each node is a data structure that contains:
– a state description
– other information such as:
⚫ link to parent node
⚫ name of action that generated this node (from its
parent)
⚫ other bookkeeping data

19
Formalizing Search in a State Space

⚫ 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

⚫ Each arc has a fixed, positive cost:


– corresponds to the cost of the action

20
Formalizing Search in a State Space

⚫ 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

⚫ Expanding a node means:


– generate all successor nodes
– add them and their associated arcs to the state-
space search tree

21
Formalizing Search in a State Space

⚫ One or more nodes are designated as start nodes


⚫ A goal test is applied to a node's state to determine
if it is a goal node
⚫ A solution is a sequence of actions associated with
a path in the state space from a start to a goal node:
– just the goal state (e.g., cryptarithmetic)
– a path from start to goal state (e.g., 8-puzzle)
⚫ The cost of a solution is the sum of the arc costs
on the solution path

22
Search Summary

• Solution is an ordered sequence of


primitive actions (steps)
f(x) = a1, a2, …, an where x is the input
• Model task as a graph of all possible states
and actions, and a solution as a path
• A state captures all the relevant information
about the past
What are the Components of
Formalizing Search in a State Space?
A State Space Graph

a GOAL
t

b c

e
d
f

START h

p r
q
u

What is the corresponding search tree?


Uninformed Search on Trees
⚫ Uninformed means we only know:
– The goal test
– The successors() function

⚫ But not which non-goal states are better

⚫ 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

⚫ Search process constructs a "search tree"


– root is the start state
– leaf nodes are:
⚫ unexpanded nodes (in the Frontier list)
⚫ "dead ends" (nodes that aren't goals and have no
successors because no operators were possible)
⚫ goal node is last leaf node found
⚫ Loops in graph may cause "search tree" to be infinite
even if state space is small
⚫ Changing the Frontier ordering leads to different
search strategies

28
8-Puzzle State-Space Search Tree
(Not all nodes shown;
e.g., no “backwards”
moves)
Uninformed Search Strategies

Uninformed Search: strategies that order nodes


without using any domain specific information, i.e.,
don’t use any information stored in a state

⚫ BFS: breadth-first search


– Queue (FIFO) used for the Frontier
– remove from front, add to back

⚫ DFS: depth-first search


– Stack (LIFO) used for the Frontier
– remove from front, add to front
30
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
called if Frontier is empty then return failure
“expanding” pick a node, n, from Frontier
node n
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
31
Breadth-First Search (BFS)
Expand the shallowest node in the tree first:
1. Examine states one step away from the initial state
2. Examine states two steps away from the initial state
3. and so on

Goal
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 0, expanded: 0 start
expnd. node Frontier list
{S} 5 2 4

A B C

9 4 6 2
6 G 1
D E goal F

H
33
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 1, expanded: 1 start
expnd. node Frontier list
{S} 5 2 4
S not goal {A,B,C}
A B C

9 4 6 2
6 G 1
D E goal F

H
34
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 2, expanded: 2 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A not goal {B,C,D,E}
9 4 6 2
6 G 1
D E goal F

H
35
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 3, expanded: 3 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B not goal {C,D,E,G}
9 4 6 2
6 G 1
D E goal F

H
36
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 4, expanded: 4 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C not goal {D,E,G,F}
6 G 1
D E goal F

H
37
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 5, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D not goal {E,G,F,H} D E goal F

H
38
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 6, expanded: 6 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D {E,G,F,H} D E goal F
E not goal {G,F,H,G}
7

H
39
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 7, expanded: 6 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D {E,G,F,H} D E goal F
E {G,F,H,G}
G goal {F,H,G} no expand 7

H
40
Breadth-First Search (BFS)

generalSearch(problem, queue)
S
# of nodes tested: 7, expanded: 6 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D {E,G,F,H} D E goal F
E {G,F,H,G}
G {F,H,G} 7
path: S,B,G
H cost: 8
41
Evaluating Search Strategies

⚫ Completeness
If a solution exists, will it be found?
– a complete algorithm will find a solution (not all)

⚫ Optimality / Admissibility
If a solution is found, is it guaranteed to be optimal?
– an admissible algorithm will find a solution with
minimum cost

43
Evaluating Search Strategies

⚫ Time Complexity
How long does it take to find a solution?
– usually measured for worst case
– measured by counting number of nodes expanded,
including goal node, if found

⚫ Space Complexity
How much space is used by the algorithm?
– measured in terms of the maximum size
of Frontier during the search

44
What’s in the Frontier for BFS?

⚫ If goal is at depth d, how big is the Frontier (worst


case)?

Goal
Breadth-First Search (BFS)

⚫ Complete?
– Yes

⚫ 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)

46
Breadth-First Search (BFS)

⚫ 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

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


because must look at all shorter length possibilities first

47
Breadth-First Search (BFS)

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


1 + b + b2 + ... + bd = (b(d+1) - 1) / (b-1)
– d: the tree's depth
– b: the branching factor at each non-leaf node
⚫ For example: d = 12, b = 10
1 + 10 + 100 + ... + 1012 = (1013 - 1)/9 = O(1012)
– 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!

48
Depth-First Search
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

Goal
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 0, expanded: 0 start
expnd. node Frontier
{S} 5 2 4

A B C

9 4 6 2
6 G 1
D E goal F

H
53
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 1, expanded: 1 start
expnd. node Frontier
{S} 5 2 4
S not goal {A,B,C}
A B C

9 4 6 2
6 G 1
D E goal F

H
54
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 2, expanded: 2 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A not goal {D,E,B,C}
9 4 6 2
6 G 1
D E goal F

H
55
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 3, expanded: 3 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D not goal {H,E,B,C}
9 4 6 2
6 G 1
D E goal F

H
56
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 4, expanded: 4 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H not goal {E,B,C}
6 G 1
D E goal F

H
57
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 5, expanded: 5 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H {E,B,C}
6 G 1
E not goal {G,B,C} D E goal F

H
58
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H {E,B,C}
6 G 1
E {G,B,C} D E goal F
G goal {B,C} no expand
7

H
59
Depth-First Search (DFS)

generalSearch(problem, stack)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H {E,B,C}
6 G 1
E {G,B,C} D E goal F
G {B,C}
7
path: S,A,E,G
H cost: 15
60
Depth-First Search (DFS)
⚫ May not terminate without a depth bound
i.e., cutting off search below a fixed depth, D

⚫ Not complete
– with or without cycle detection
– and, with or without a depth cutoff

⚫ Not optimal / admissible

⚫ Can find long solutions quickly if lucky

63
Depth-First Search (DFS)

⚫ 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
⚫ 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

64
Uniform-Cost Search (UCS)

⚫ Use a Priority Queue to order nodes in Frontier,


sorted by path cost
⚫ Let g(n) = cost of path from start node s to current
node n
⚫ Sort nodes by increasing value of g

65
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 0, expanded: 0 start
expnd. node Frontier list
{S} 5 2 4

A B C

9 4 6 2
6 G 1
D E goal F

H
66
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 1, expanded: 1 start
expnd. node Frontier list
{S:0} 5 2 4
S not goal {B:2,C:4,A:5}
A B C

9 4 6 2
6 G 1
D E goal F

H
67
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 2, expanded: 2 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B not goal {C:4,A:5,G:2+6}
9 4 6 2
6 G 1
D E goal F

H
68
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 3, expanded: 3 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C not goal {A:5,F:4+2,G:8}
9 4 6 2
6 G 1
D E goal F

H
69
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 4, expanded: 4 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A not goal {F:6,G:8,E:5+4,
D:5+9} 6 G 1
D E goal F

H
70
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 5, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A {F:6,G:8,E:9,D:14}
6 G 1
F not goal {G:4+2+1,G:8,E:9, D E goal F
D:14}
7

H
71
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A {F:6,G:8,E:9,D:14}
6 G 1
F {G:7,G:8,E:9,D:14} D E goal F
G goal {G:8,E:9,D:14}
no expand 7

H
72
Uniform-Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A {F:6,G:8,E:9,D:14}
6 G 1
F {G:7,G:8,E:9,D:14} D E goal F
G {G:8,E:9,D:14}
7
path: S,C,F,G
H cost: 7
73
Uniform-Cost Search (UCS)

⚫ Called Dijkstra's Algorithm in the algorithms


literature
⚫ Similar to Branch and Bound Algorithm
in Operations Research literature

⚫ Complete
⚫ Optimal / Admissible
– requires that the goal test is done when a node is
removed from the Frontier rather than when the
node is generated by its parent node

76
Uniform-Cost Search (UCS)

⚫ 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

⚫ More precisely, time and space complexity is


O(bC*/ε ) where all edge costs are ε, ε > 0, and C* is
the best goal path cost

77
Example

S
1 5 8

A B C
3 7 9 4 5 How are nodes expanded by

D E G • Depth First Search


• Breadth First Search
• Uniform Cost Search
• Iterative Deepening

Are the solutions the same?


Nodes Expanded by:
⚫ Depth-First Search: S A D E G
Solution found: S A G

⚫ Breadth-First Search: S A B C D E G
Solution found: S A G

⚫ Uniform-Cost Search: S A D B C E G
Solution found: S B G

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy