0% found this document useful (0 votes)
43 views33 pages

AISC-L4-L5-Problem Solving Agents - Uninformed Search

The document discusses problem solving using state space search techniques. It describes formulating problems as state spaces, drawing state space graphs, and performing uninformed searches. It also compares the performance of search techniques like breadth-first search, depth-first search, uniform cost search, and iterative deepening search.

Uploaded by

Sonu Ramani
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)
43 views33 pages

AISC-L4-L5-Problem Solving Agents - Uninformed Search

The document discusses problem solving using state space search techniques. It describes formulating problems as state spaces, drawing state space graphs, and performing uninformed searches. It also compares the performance of search techniques like breadth-first search, depth-first search, uniform cost search, and iterative deepening search.

Uploaded by

Sonu Ramani
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/ 33

PROBLEM SOLVING

AGENTS
TAKEN FROM RUSSELS AND NORWIG
RESOURCES

Dr. Rekha Ramesh


2

Learning Objectives of this session


Students will be able to----
• Formulate a given problem as a state space representation

• Draw a state space graph for a given problem

• Implement Un-informed (Blind) search techniques

• Evaluate the performance of Un-informed search techniques

for a given problem

• Compare the performance of Un-informed search techniques


State Space Search
• Formulate a problem as a state space search by
showing the legal problem states, the legal
operators, and the initial and goal states.

• A state is defined by the specification of the values of


all attributes of interest in the world
• An operator/Action changes one state into the other
• The initial state is where you start
• The goal state is the description of the solution
The Farmer-Wolf-Goat-Cabbage problem
Once upon a time, there was a Farmer who had a tiny boat. The boat
was so tiny that it could only take the Farmer himself and one additional
passenger. He wanted to move a Wolf, a Goat and a Cabbage across a
river with his tiny boat.
• But he can’t leave the Wolf alone with the Goat because the Wolf will
eat the Goat. He can’t leave the Goat alone with the Cabbage
because the Goat will eat the Cabbage.
• And of course he can only fit one more object with him on the boat
(either the Wolf, the Goat or the Cabbage).
• The question is: How can he safely transport the three of them to
the other side of the river?
State space graph of Farmer-Wolf-Goat-Cabbage problem
F, W, G, C

w, c
F, G

F, W, C
G

C w
F, W, G F, G, C

F, G, C F, W, G
w C

G
F, W, C

F, G
w, c

F, W, G, C
The Farmer-Wolf-Goat-Cabbage riddle
• States: F, W, G and C are in Left or Right bank
(FWGC - Φ) start state
(Φ - FWGC ) end state
(WC – FG) intermediate state

• Actions: Take any one of (W, G, C) from L to R


or R-L
• Goal test: All are taken to R safely
• Path cost: Each safe trip 1 point
Vacuum world state space graph

L R

L R

• States: integer (location) , dirt and robot


• Actions: Left, Right, Suck, NoOp
• Goal test: no dirt
• Path cost: 1 per action (0 for NoOp)
8-puzzle problem

7
0 0 QJ 0 0
0 0 0 0 0
0 0 QJ 0 0
··,tart ,tate o:a.l .t:ate

• state: integer locations of tiles


• actions: move blank left, right, up, down
• goal test: = goal state (given)
• path cost: 1 per move
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
Node Representation
• Node is a data structure constituting part of a search tree
• STATE: The state to which the node corresponds

• PARENT NODE: the node I the search tree that generated this node

• ACTION: the action that was applied to the parent node to generate
this node

• PATH COST: the path from initial state to the node g(n)

• DEPTH: the number of steps along the path from the initial state

• FRINGE: collection of nodes that have been generated but not yet
expanded. Each element of fringe is a leaf node
Evaluating Search strategies
• Completeness: Is the strategy guaranteed to find a
solution if one exists?

• Optimality: Does the solution have low cost or the


minimal cost?

• What is the search cost associated with the time and


memory required to find a solution?
• Time complexity: Time taken (number of nodes expanded) (worst
or average case) to find a solution.
• Space complexity: Space used by the algorithm measured in
terms of the maximum size of fringe
Uninformed Search Strategies
• Breadth first search
• Depth first search
• Depth Limited Search
• Iterative deepening search
BFS
• Algorithm

B1~eadth first search


Let fringe be a list containing the initial state
Loop
iffringe is ernpty retmn failure
1

Node f- remove-first (f1inge)


ifNode is a goal
then Ietun1 the patli frorn initial state to ode
1
els e generate all succ ess0Is of Node,,and
1 1 1

(n1erge the newly generated nodes into fringe)


add generat,ed nodes to the back of fringe
End Loop
Example graph and search tree

A State Space Graph

Search tree for the state space


graph
Ste Action Fringe
p
1 ---- A
2 Remove A BC
3 Remove B CDE
4 Remove C DEDG
5 Remove D EDGCF
6 Remove E DGCF
7 Remove D GCFBF
8 G is removed and is
a Goal State
Properties of BFS
• Breadth first search is:
• Complete?? Yes (if b is finite)
• Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e.,
exponential in d
• Space?? O(bd+1) (keeps every node in memory)
• Optimal?? Yes (if cost = 1 per step); not optimal in general
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(bC∗/ԑ) where


C∗ is the cost of the optimal solution

• Space?? # of nodes with g ≤ cost of optimal solution, O(bC∗/ԑ)

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


Depth first Search
• Algorithm

Depth First Search 1

Letfrin,ge be a hst containing the imtial state


Loop
if frin,ge is 1eu1pty retmn fai]ure
ode f- I emove-f1rst (fringe)
1 1

if ode is a g:oal
then Ieturn the path :fi~on1 initial state to ode
1

else geneiate all successors of Node and


meige the 11ewly generated nodes intofringe
1 1 1

add generated nodes to the front offringe


EndLoo 1
Ste Action Fringe
p
1 ---- A
2 Remove A BC
3 Remove B DEC
4 Remove D CFEC
5 Remove C GFEC
6 G is removed and is
a Goal State
Properties of DFS
• Complete?? No: fails in infinite-depth spaces, spaces with
loops
Modify to avoid repeated states along path ⇒ complete in
finite spaces

• Time?? O(bm): terrible if m is much larger than d but if


solutions are dense, may be much faster than breadth-first

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

• Optimal?? No
Depth Limited Search
• Depth-first search with depth limit l,
i.e., nodes at depth l have no successors
De :th limited search
1

Let fring e be a list containing tl1e i11itial state


1 1 1

Loop
1

if fii·ng e is empty retu1n failure


1

Nod.e ~ remove-first (fringe)


if ·.·.ode is a goal
1

thei:1 retu111 tl1e path from initial state to Node


1

els e if dep th of· ode == limit rehtrn cutoff


1 1 1

else add generated nodes to the front of fri11ge


1 1 1 1

E·ndLoop
Depth-First Iterative Deepening (DFID)
• First do DFS to depth 0 (i.e., treat start node as having no
successors), then, if no solution
found, do DFS to depth 1, etc

DFID
until soluti,o,n f oun,d do,
DFS with depth c·u toff c
,c = c+l

Advantage
• Linear memory requirements of depth-first
search
• Guarantee for goal node of minimal depth
Successive depth-first searches are conducted
– each with depth bounds increasing by 1

pth b un l = I p h b und = pth b lll I= I th b und =4


Properties of DFID
• Complete
• Optimal/Admissible if all operators have the same cost.
Otherwise, not optimal but guarantees finding solution of
shortest length (like BFS).
• Time complexity: a little worse than BFS or DFS. The
worst case time complexity is still exponential, O(bd)
• If branching factor is b and solution is at depth d, then
nodes at depth d are generated once, nodes at depth d-1
are generated twice, etc.
Hence bd + 2b(d-1) + ... + db <= bd / (1 - 1/b)2 = O(bd).
• Space complexity: Linear O(bd), like DFS
Bi-directional search
• Bidirectional search involves alternate searching from the start
state toward the goal and from the goal state toward the start.
The algorithm stops when the frontiers intersect.
Start

States examined by
forward search only

States examined by
combination of
forward and
Goal backward search
Properties of Bidirectional Search
• The algorithm works well only when there are unique start and
goal states.

• Time and Space Complexities


Consider a search space with branching factor b. Suppose that
the goal is d steps away from the start state. Breadth first
search will expand O(bd) nodes.

• If we carry out bidirectional search, the frontiers may meet


when both the forward and the backward search trees have
depth = d/2.

• Time for bidirectional search will be O((bd/2).

• The space complexity is also O((bd/2)


Comparing Search Strategies

Breadth Depth first Iterative Bidirectional


first deepening (if applicable)

Time bd bd bd bd/2
Space bd bm bd bd/2
Optimum? Yes No Yes Yes
Complete? Yes No Yes Yes
Activity Time (5 mins)

Give the initial state, goal test, successor function, and cost
function for the following.

Missionaries & Cannibals problem: 3 missionaries & 3


cannibals are on one side of the river. 1 boat carries 2.
Missionaries must never be outnumbered by cannibals.
Give a plan for all to cross the river
Missionaries & Cannibals problem: 3 missionaries & 3
cannibals are on one side of the river. 1 boat carries 2.
Missionaries must never be outnumbered by cannibals.
Give a plan for all to cross the river

State : <#M, #C, P>


#M = Number of missionaries on bank L
#C = Number of cannibals on bank L
P = Position of the boat
Missionaries & Cannibals problem: 3 missionaries & 3
cannibals are on one side of the river. 1 boat carries 2.
Missionaries must never be outnumbered by cannibals.
Give a plan for all to cross the river

State : <#M, #C, P>


#M = Number of missionaries on bank L
#C = Number of cannibals on bank L
P = Position of the boat

S0 = <3, 3, L>
G = < 0, 0, R >
Activity Time (10 mins)
Suppose you have the following search space:
a) Draw the state space of this problem.
tat@ nre .t co.st
b) Assume that the initial state is A and
A H 4
the goal state is G.
A C l
H'
. D ], Show how each of the following search
H :E I strategies would create a search tree to
C C 0 find a path from the initial state to the
goal state:
C D l
• Breadth-first search
C :F
' • Depth-first search
D C l
• Uniform cost search
D :E 4 • Iterative deepening search
:E G' l

:F G I At each step of the search algorithm, how


which node is being expanded, and the
content of fringe. Also report the eventual
solution found by each algorithm, and the
solution cost.
Solve on paper and show me the result, then you can
leave the class

• •
33

Any Questions?

You might also like