Professional Documents
Culture Documents
Chapter III
Part I
Outline
Problem-solving agents
Problem types
Problem formulation
Example problems
Problem solving
We want:
To automatically solve a problem
We need:
A representation of the problem
Algorithms that use some strategy to
solve the problem defined in that
representation
States
A problem is defined by its elements and their
relations.
A state is a representation of those elements in a
given moment.
In each instant of a problem, those elements have
specific descriptors (How to select them?) and
relations.
Two special states are defined:
– Initial state (starting point)
– Final state (goal state)
State modification: successor function
A successor function is needed to move
between different states.
A successor function is a description of
possible actions, a set of operators. It is a
transformation function on a state
representation, which convert it into another
state.
The successor function defines a relation of
accessibility among states.
State space
The state space is the set of all states
reachable from the initial state.
It forms a graph (or map) in which the
nodes are states and the arcs between
nodes are actions.
A path in the state space is a sequence
of states connected by a sequence of
actions.
Problem solution
A solution in the state space is a path from
the initial state to a goal state.
problem solving
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
Example: Romania
Problem Formulation…. Cont’d
– e.g. {<Go(Sibiu),In(Sibiu)>,
<Go(Zerind), In(Zerind)>}
Problem Formulation…. Cont’d
states?
actions?
goal test?
path cost?
Example: The 8-puzzle
states?
actions?
goal test?
path cost?
Vacuum world state space graph
Goal state:
One of the buckets has two gallons of water in it
Represented by either ( x 2 ) or ( 2 x )
Path cost:
1 per unit step
Water Pouring
Actions and Successor Function
Fill a bucket
(x y) -> (3 y)
(x y) -> (x 4)
Empty a bucket
(x y) -> (0 y)
(x y) -> (x 0)
Pour contents of one bucket into
another
Water Pouring
(0,0)
(4,0) (0,3)
(1,0) (0,1)
(3,3) (4,2)
(4,1)
(2,3)
(2,0) (0,2)
Exercise: Eight Queens
States:
Any arrangement of 0 to 8 queens on the
board
Initial state:
No queens on the board
Successor function:
Add a queen to an empty square
Goal Test:
8 queens on the board and none are
attacked
Solution for 8 Queens
Part two
Outline
Basic search Strategies
BFS
UCS
DFS
DLS
Search strategies
A search 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
space complexity: maximum number of nodes in
memory
optimality: does it always find a least-cost solution?
Time and space complexity are measured in terms
of
b: maximum branching factor of the search tree
d: depth of the least-cost solution
m: maximum depth of the state space (may be ∞)
Search Strategy Techniques
Uninformed Search Strategy: a searching technique
which have no additional information about the distance
from current state to the goal.
is a class of general purpose search algorithms that operate in
a brute-force way.
Breadth-first search
Depth-first search
Uniform-cost search
Breadth-first search
The root node is expanded first, then all the successors
of the root node, and their successors and so on
In general, all the nodes are expanded at a given depth
in the search tree before any nodes at the next level are
expanded
Expand shallowest unexpanded node
Implementation:
– fringe is a FIFO queue,
– the nodes that are visited first will be expanded first
–All newly generated successors will be put at the end
of the queue
– Shallow nodes are expanded before deeper nodes
Breadth-first Search
A
Successors: B,C,D D
B C Initial state
E F G H I J
K L M N O P Q R
Goal state
S T U
Visited:
The fringe is the data structure we use to store all of the
Fringe: A (FIFO) nodes that have been generated
Breadth-first Search
A
Next node
D
Successors: E,F B C
E F G H I J
K L M N O P Q R
S T U Visited: A
Successors: K,L
D
B C
Next node
E F G H I J
K L M N O P Q R
Visited: A, B, C, D
S T U
Successors: M
D
B C
Next node
E F G H I J
K L M N O P Q R
Visited: A, B, C, D, E
S T U
Successors: N
D
B C
Next node
E F G H I J
K N O P Q R
L M
Visited: A, B, C, D, E, F
S T U
Successors: O
D
B C
Next node
E F G H I J
K L M N O P Q R
U Visited: A, B, C, D, E, F,
S T
G
Successors: P,Q
D
B C
Next node
E F G H I J
K L M N O P Q R
S T U Visited: A, B, C, D, E, F,
G, H
Successors: R
D
B C
Next node
E F G H I J
K L M N O P Q R
Visited: A, B, C, D, E, F,
S T U G, H, I
Successors: S
D
B C
E F G H I J
Next node
K L M N O P Q R
S T U Visited: A, B, C, D, E, F,
G, H, I, J
Successors: T
D
B C
E F G H I J
Next node
K L M N O P Q R
S T U Visited: A, B, C, D, E, F,
G, H, I, J, K
Successors: T
D
B C
E F G H I J
Next node
K L M N O P Q R
S T U Visited: A, B, C, D, E, F,
G, H, I, J, K
Successors: D
B C
E F G H I J
K L M N O P Q R
Next node
S T U Visited: A, B, C, D, E, F,
G, H, I, J, K, L
E F G H I J
K L M N O P Q R
Next node
Visited: A, B, C, D, E, F,
S T U G, H, I, J, K, L, M
A
10
1
S 5 B 5 D
5
15
C
S 5 B 5 D
5
15
C
Next Node=Head of Fringe=S, S is not
goal
Updated Fringe=[A1,B5,C15]
Queue Successor(S)={C,B,A}=expand(S) but
sort them according to path cost.
Uniform Cost Search
Fringe = [S0]
A Queue
10
1
S 5 B 5 D
5
15
C
Next Node=Head of Fringe=S, S is not
goal
Updated Fringe=[A1,B5,C15]
Queue Successor(S)={C,B,A}=expand(S) but
sort them according to path cost.
Uniform Cost Search
Fringe = [A1,B5,C15]
A
10
1
S 5 B 5 D
5
15
C
Next Node=Head of Fringe=A, A is not
Updated Fringe=[B5,D11,C15] goal
Successor(A)={D}=expand(A)
Sort the queue according to path cost.
Uniform Cost Search
Fringe = [B5,D11,C15]
A
10
1
S 5 B 5 D
5
15
C
Next Node=Head of Fringe=B, B is not
goal
Updated Fringe=[D10,D11,C15]
Successor(B)={D}=expand(B)
Sort the queue according to path cost.
Uniform Cost Search
Fringe = [D10,D11,C15]
A
10
1
S 5 B 5
D
5
15
C
Next Node=Head of Fringe=D,
Always finds the
D is a GOAL (cost 10 = 5+5)
cheapest solution
SBD
Depth First Search - Method
Successors: B,C,D
D
B C Initial state
E F G H I J
K L M N O P Q R
Fringe: A (LIFO)
Depth-First Search
A
Successors: E,F
D
B C
E F G H I J
K L M N O P Q R
S T U
Visited: A
Successors: K,L D
B C
E F G H I J
K L M N O P Q R
Visited: A, B
S T U
Successors: S D
B C
E F G H I J
K L M N O P Q R
S T U Visited: A, B, E
Successors: D
B C
E F G H I J
K L M N O P Q R
S T U Visited: A, B, E, K
Successors: T D
B C
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S
S T U
Backtracking
Fringe: L,F,C,D (LIFO)
Depth-First Search
A
Successors: D
B C
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S, L
S T U
Successors: M D
B C
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S, L, T
S T U
Backtracking
Fringe: F,C,D (LIFO)
Depth-First Search
A
D
Successors: B C
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S, L, T,
S T U F
Successors: G,H D
B C
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S, L, T,
F, M
S T U
Backtracking
Fringe: C,D (LIFO)
Depth-First Search
A
Successors: N D
B C
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S, L, T,
F, M, C
S T U
E F G H I J
K L M N O P Q R
Visited: A, B, E, K, S, L, T,
S T U F, M, C, G
Once all the nodes of a given depth are explored, the current
depth is incremented.
Properties of depth limited search