Chapter 3 Solving Problems by Searching1
Chapter 3 Solving Problems by Searching1
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.
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
successor> pairs
– 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.
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
Initial state
D
B C
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
S T U Visited: A, B, C, D, E, F,
G
Successors: P,Q
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
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
Visited: A, B, C, D, E, F,
S T U
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
Visited: A, B, C, D, E, F,
S T U
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
Visited: A, B, C, D, E, F,
S T U
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
Visited: A, B, C, D, E, F,
S T U
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
Successors: B,C,D
Initial state
D
B C
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
Fringe: B,C,D (LIFO)
Depth-First Search
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
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, 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
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
Arad (366)
Sibiu(253)
Timisoara Zerind(374)
(329)
The first expansion step produces:
Sibiu, Timisoara and Zerind
Greedy best-first will select Sibiu.
Greedy search example
Arad
Sibiu
Arad
Sibiu
Fagaras
Sibiu Bucharest
(253) (0)
Formally:
1. h(n) <= h*(n) where h*(n) is the true cost from n
2. h(n) >= 0 so h(G)>= 0 for any goal G.
Optimal? Yes
Hill-climbing search
Hill-climbing search is a local search algorithm
that iteratively improves a solution by making
incremental changes that maximize a heuristic
evaluation function.
It repeatedly selects the neighbor with the highest
heuristic value, moving towards the direction of
increasing values. However, it may get stuck in
local optima and struggle with plateaus.
Simulated annealing search
Simulated annealing search is a probabilistic
optimization algorithm inspired by the annealing
process in metallurgy.
It explores the search space by randomly accepting
moves that improve the solution or moves to less
optimal solutions based on a temperature parameter.
Over time, the temperature decreases, reducing the
likelihood of accepting worse solutions, ultimately
converging towards the global optimum.
?