Lec3 AI
Lec3 AI
Search Methods :
Uninformed (Blind) search
Dr. Manel Mrabet
Search Methods
Once we have defined the problem space (state representation, the initial state, the
goal state and operators) is all done?
A farmer wishes to carry a wolf, a duck and corn across a river, from the south to the
north shore. The farmer is the proud owner of a small rowing boat called Bounty
which he feels is easily up to the job. Unfortunately the boat is only large enough to
carry at most the farmer and one other item. Worse again, if left unattended the wolf
will eat the duck and the duck will eat the corn.
River
boat
Farmer, Wolf,
Duck and Corn
How can the farmer safely transport the wolf, the duck and the corn to the opposite
shore?
Dr. Manel Mrabet 2
Search Methods
The River Problem:
F=Farmer W=Wolf D=Duck C=Corn /=River
-/FWCD
FWCD/-
How can the farmer safely transport the wolf, the duck and
the corn to the opposite shore?
Dr. Manel Mrabet 3
Search Methods
Problem formulation:
Initial State: farmer, wolf, duck and corn in the south shore
FWDC/-
Operators: the farmer takes in the boat at most one item from one side to
the other side
(F-Takes-W, F-Takes-D, F-Takes-C, F-Takes-Self [himself only])
WD C D C W C WD
Dead ends
F F W F D F C
Illegal states
F W C F WD C
D
repeated state F
W
D
C
F WD
C
F
W
D C
intermediate state
F C F W C F D C F W F WD F W C
WD D W D C C D
D C C D WD D W
F W F WD F W C F C F W C F D C
F D F WD F D C
W C C W
F W
D
C F WD C
Dr. Manel
Goal Mrabet
state 5
Search Methods
Searching for a solution: F WD C
W C C W
…really large… DC C D WD D W
FW F WD FW C F C FW C F DC
D
FW C F WD C
Breadth-first search
Uniform-cost search
Depth-first search
Depth-limited search
Iterative deepening search
Bidirectional search
Main idea: Expand all nodes at depth (i) before expanding nodes at depth (i + 1)
Level-order Traversal.
Implementation: Use of a First-In-First-Out queue (FIFO). Nodes visited first
are expanded first. Enqueue nodes in FIFO (first-in, first-out) order.
• Complete? Yes.
• Optimal? Yes, if path cost is nondecreasing function of depth
• Time Complexity: O(bd)
• Space Complexity: O(bd), note that every node in the fringe is kept in the queue.
Dr. Manel Mrabet 14
Breadth First Search
QUEUING-FN:- successors added to end
of queue Arad
Arad
Arad Oradea
Oradea Fagaras
Arad Lugoj
Rimnicu Vilcea
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
Goal state
4 5
5 2
[5] [2]
5 2
[5] [2]
1 7
[3] [9]
5 2
[5] [2]
1 7
[3] [9]
4 5
[7] [8]
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
5 2
[5] [2]
Goal state
1 4 1
path cost 7
g(n)=[6] [3] [9]
[9]
4 5
[7] [8]
5 2
[5] [2]
1 4 1 7
[6] [3] [9]
[9]
4 5
[7] [8]
Implementation:
Enqueue nodes in order of cost g(n).
QUEUING-FN:- insert in order of increasing path cost.
Enqueue new node at the appropriate position in the queue so that we
dequeue the cheapest node.
Complete? Yes.
Optimal? Yes, if path cost is nondecreasing function of depth
Time Complexity: O(bd)
Space Complexity: O(bd), note that every node in the fringe keep in the queue.
• Optimal? No
Arad Oradea
Depth Bound = 3
Dr. Manel Mrabet 32
Depth-Limited Search (DLS)
It is simply DFS with a depth bound.
Searching is not permitted beyond the depth bound.
Termination is guaranteed.
Implementation:
Enqueue nodes in LIFO (last-in, first-out) order. But limit depth to L
• Optimal? No
function ITERATIVE-DEEPENING-SEARCH():
IDS combines the benefits of BFS and DFS: Like DFS the memory
requirements are very modest (O(bd)). Like BFS, it is complete
when the branching factor is finite.
L=0
L=1
L=2
L=3
Dr. Manel Mrabet 38
Iterative Deepening Search (IDS)
Complete? Yes
Optimal? Yes
Time Complexity: O(bd/2), where
d is the depth of the solution.
Space Complexity: O(bd/2), where
d is the depth of the solution.
Dr. Manel Mrabet 42
Basic Search Algorithms
b: Branching factor
d: Depth of solution
m: Maximum depth
l : Depth Limit
Dr. Manel Mrabet 44
Blind Search Algorithms
Tree Search:
BFS, DFS, DLS, IDS
Basic Search Algorithms
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 47
Breadth First Search
A,
B C D E
B C D E
F G
B C D E
F G H
B C D E
F G H I J
B C D E
F G H I J
B C D E
F G H I J
B C D E
F G H I J
K L
B C D E
F G H I J
K L
B C D E
F G H I J
K L M
B C D E
F G H I J
K L M N
B C D E
F G H I J
K L M N
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 59
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L, M, A
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 60
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L, M,N, A
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 61
Breadth First Search
A,
B,C,D,E,
F,G,H,I,J,
K,L, M,N, A
Goal state: O
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 62
Breadth First Search
The returned solution is the sequence of operators in the path:
A, B, G, L, O
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 63
Basic Search Algorithms
B C D E
F G H I J
K L M N
O
Dr. Manel Mrabet 65
Depth First Search
A,
B C D E
B C D E
F G
B C D E
F G
B C D E
F G
K L
B C D E
F G
K L
B C D E
F G
K L
O
Dr. Manel Mrabet 71
Depth First Search
A,B,F,
G,K,
L, O: Goal State
A
B C D E
F G
K L
O
Dr. Manel Mrabet 72
Depth First Search
The returned solution is the sequence of operators in the path:
A, B, G, L, O
B C D E
F G
K L
O
Dr. Manel Mrabet 73
Basic Search Algorithms
Depth-Limited Search
DLS
Depth-Limited Search (DLS)
Application3:
Given the following state space (tree search), give the sequence
of visited nodes when using DLS (Limit = 2):
Limit = 0 A
Limit = 1 B C D E
Limit = 2 F G H I J
K L M N
O
Dr. Manel Mrabet 75
Depth-Limited Search (DLS)
A,
B C D E
Limit = 2
B C D E
Limit = 2 F G
B C D E
Limit = 2 F G
B C D E
Limit = 2 F G
B C D E
Limit = 2 F G H
B C D E
Limit = 2 F G H
B C D E
Limit = 2 F G H I J
B C D E
Limit = 2 F G H I J
Limit = 2 F G H I J
Limit = 2 F G H I J
Limit = 2 F G H I J
B C D E
Limit = 2 F G H I J
K L M N
O
Dr. Manel Mrabet 87
Basic Search Algorithms
Limit = 0 A
Limit = 1 B C D E
Limit = 2 F G H I J
Limit = 3 K L M N
Limit = 4 O
Dr. Manel Mrabet 89
Iterative Deepening Search
(IDS)
Limit = 0 A
Limit = 0 A
Limit = 1 B C D E
Limit = 1 B C D E
Limit = 1 B C D E
Limit = 1 B C D E
Limit = 1 B C D E
Limit = 1 B C D E
B C D E
Limit = 2
B C D E
Limit = 2 F G
B C D E
Limit = 2 F G
B C D E
Limit = 2 F G
B C D E
Limit = 2 F G H
B C D E
Limit = 2 F G H
B C D E
Limit = 2 F G H I J
B C D E
Limit = 2 F G H I J
Limit = 2 F G H I J
Limit = 2 F G H I J
Limit = 2 F G H I J
K L M N
O
Dr. Manel Mrabet 110
Iterative Deepening Search
(IDS)
B C D E
Limit = 3
B C D E
F G
Limit = 3
B C D E
F G
Limit = 3
B C D E
F G
Limit = 3 K L
B C D E
F G
Limit = 3 K L
B C D E
F G
Limit = 3 K L
B C D E
F G H
Limit = 3 K L
B C D E
F G H
Limit = 3 K L
F G H I J
Limit = 3 K L
F G H I J
Limit = 3 K L M
F G H I J
Limit = 3 K L M
F G H I J
Limit = 3 K L M N
F G H I J
Limit = 3 K L M N
Limit = 3 K L M N
Limit = 3 K L M N
O
Dr. Manel Mrabet 126
Iterative Deepening Search
(IDS)
B C D E
Limit = 4
Dr. Manel Mrabet 128
Iterative Deepening Search (IDS)
A,B,
B C D E
F G
Limit = 4
Dr. Manel Mrabet 129
Iterative Deepening Search (IDS)
A,B,F,
B C D E
F G
Limit = 4
Dr. Manel Mrabet 130
Iterative Deepening Search (IDS)
A,B,F,
G,
B C D E
F G
K L
Limit = 4
Dr. Manel Mrabet 131
Iterative Deepening Search (IDS)
A,B,F,
G,K,
B C D E
F G
K L
Limit = 4
Dr. Manel Mrabet 132
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L,
A
B C D E
F G
K L
Limit = 4 O
Dr. Manel Mrabet 133
Iterative Deepening Search (IDS)
A,B,F,
G,K,
L, O: Goal State
A
B C D E
F G
K L
Limit = 4 O
Dr. Manel Mrabet 134
Iterative Deepening Search (IDS)
The returned solution is the sequence of operators in the path:
A, B, G, L, O
B C D E
F G
K L
O
Dr. Manel Mrabet 135
Summary
Search: process of constructing sequences of actions that achieve a goal given a
problem.
The studied methods assume that the environment is observable, deterministic,
static and completely known.
Goal formulation is the first step in solving problems by searching. It facilitates
problem formulation.
Formulating a problem requires specifying four components: Initial states,
operators, goal test and path cost function. Environment is represented as a
state space.
A solution is a path from the initial state to a goal state.
Search algorithms are judged on the basis of completeness, optimality, time
complexity and space complexity.
Several search strategies: BFS, DFS, DLS, IDS,…