Lecture5 - 6 Ch3
Lecture5 - 6 Ch3
- Be In Amman
2. Formulate Problem
- States : Cities
- actions : Drive Between Cities
3. Find Solution
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
Single-state problem formulation
A problem is defined by four items:
initial state e.g., "at Arad"
1. actions or successor function S(x) = set of action–state pairs
e.g., S(Arad) = {<Arad Zerind, Zerind>, … }
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
Number of states: 8
Initial state: Any
Number of actions: 4
left, right, suck,
noOp
Goal: clean up all dirt
Goal states: {7, 8}
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
Path cost: zero
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
starts with 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
Example: River Crossing
Items: Man, Wolf, Corn, Chicken.
Man wants to cross river with all items.
Wolf will eat Chicken
Chicken will eat corn.
leaf nodes
the states 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
State space
has unique states {A, B}
while a search tree may have cyclic paths:
A-B-A-B-A-B- …
A good search strategy should avoid
such paths
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
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 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
Breadth-First Strategy
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,
Implementation:
fringe = queue ordered by path cost
Equivalent to breadth-first if step costs all equal
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
complete in finite spaces
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
suitable for the problem
having a large search space
and the depth of the solution is not known
Properties of iterative deepening
search
Complete? Yes
Space? O(bd)
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