5 Solving Problems by Searching
5 Solving Problems by Searching
states
( Remove detail from representation)
Conclusion: Only the most important parts that are
- Be In Amman
2. Formulate Problem
- States : Cities
- actions : Drive Between Cities
3. Find Solution
Real-world problems
tend to be more difficult and whose
solutions people actually care about
E.g., Design, planning, etc.
Toy problems
Example: vacuum world
Toy problems
Example: vacuum world
Number of states: 8
Initial state: Any
Number of actions: 4
left, right, suck, noOp
Path Cost:
Each step costs 1
The 8-puzzle
The 8-puzzle
States:
a state description specifies the location of each of
the eight tiles and blank in one of the nine squares
Initial State:
Any state in state space
Successor function:
the blank moves Left, Right, Up, or Down
Goal test:
current state matches the goal configuration
Path cost:
each step costs 1, so the path cost is just the length
of the path
The 8-queens
There are two ways to formulate the
problem
All of them have the common followings:
Goal test: 8 queens on board, not attacking
to each other
The 8-queens
(1) Incremental formulation
involves operators that augment the state
description starting from an empty state
Each action adds a queen to the state
States:
any arrangement of 0 to 8 queens on board
Successor function:
add a queen to any empty square
The 8-queens
(2) Complete-state formulation
startswith all 8 queens on the board
move the queens individually around
States:
any arrangement of 8 queens, one per column in
the leftmost columns
Operators: move an attacked queen to a row,
not attacked by any other
The 8-queens
Conclusion:
the right formulation makes a big difference
to the size of the search space
Examples
Route finding problem
Touring problem
VLSI layout
Robot navigation
Automatic assembly sequence
Protein design
Internet searching
3.3 Searching for solutions
3.3 Searching for solutions
Finding out a solution is done by
searching through the state space
All problems are transformed
as a search tree
generated by the initial state and
successor function
Search tree
Initial state
The root of the search tree is a search node
Expanding
applying successor function to the current state
thereby generating a new set of states
leaf nodes
thestates having no successors
Fringe : Set of search nodes that have not been
expanded yet.
Refer to next figure
Tree search example
Tree search example
Search tree
The essence of searching
in case the first choice is not correct
choosing one option and keep others for later
inspection
Hence we have the search strategy
which determines the choice of which state to
expand
good choice fewer work faster
Important:
state space ≠ search tree
Search tree
A node is having five components:
STATE: which state it is in the state space
PARENT-NODE: from which node it is generated
to generate it
PATH-COST: the cost, g(n), from initial state to
initial state
Search tree
Bidirectional search
Breadth-first search
The root node is expanded first (FIFO)
All the nodes generated by the root
node are then expanded
And then their successors and so on
Breadth-First Strategy
New nodes are inserted at the end of FRINGE
2 3 FRINGE = (1)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (2, 3)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (3, 4, 5)
4 5 6 7
Breadth-First Strategy
2 3 FRINGE = (4, 5, 6, 7)
4 5 6 7
Breadth-first search (Analysis)
Breadth-first search
Complete – find the solution eventually
Optimal, if step cost is 1
The disadvantage
if the branching factor of a node is large,
Backtracking search
only one successor is generated on expansion
rather than all successors
fewer memory
Depth-first search
Expand deepest unexpanded node
fringe = LIFO queue, i.e., put successors at front
Implementation:
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
Expand deepest unexpanded node
Implementation:
fringe = LIFO queue, i.e., put successors at front
Depth-first search
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Depth-first search (Analysis)
Not complete
because a path may be infinite or looping
then the path will never fail and go back try
another option
Not optimal
it doesn't guarantee the best solution
It overcomes
the time and space complexities
Properties of depth-first search
Complete? No: fails in infinite-depth spaces,
spaces with loops
Modify to avoid repeated states along path
Optimal? No
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Iterative deepening search
No choosing of the best depth limit
It tries all possible depth limits:
first
0, then 1, 2, and so on
combines the benefits of depth-first and
breadth-first search
Iterative deepening search
Iterative deepening search
(Analysis)
optimal
complete
Time and space complexities
reasonable
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
G 25
Comparing search strategies