AI Chapter Three
AI Chapter Three
Chapter 3
Solving problems by searching
3-2
Objectives
Identify the type of agent that solve problem by searching
Problem formulation and goal formulation
Types of problem based on environment type
Discuss various techniques of search strategies
Type of agent that solve problem by searching
Such agent is not reflex or model based reflex agent because this agent needs to
400
330
Jima
Addis Ababa
100
430 Adama 370
Awasa
Example: Road map of Ethiopia
Current position of the agent: Awasa.
Needs to arrive to: Gondar
Formulate goal:
be in Gondar
Formulate problem:
states: various cities
actions: drive between cities
Find solution:
sequence of cities, e.g., Awasa, Adama, Addis Ababa, Dessie, Godar
3-7
BahrDar AA
Lalibela AA Gondar
Gondar Debre M.
Implementation: general tree search
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?
Breadth-First Search
The figure shows the progress of the search on a simply binary tree
BFS trees after 0, 1, 2, 3, and 4 nodes expansion
3-16
Breadth-First Search- Example
A D
• Move downwards, level
B D A E by level, until goal is
reached.
C E E B B F
D F B F C E A C G
G C G F
G
3-17
Breadth-First Search algorithm
• Pick one of the children at every node visited, and work forward from that child.
• Always expands the deepest node reached so far (and therefore searches one path to
a leaf before allowing up any other path).
• Thus, it finds the left most solution
3-22
Depth-first search- Chronological backtracking
• Select a child
S
• convention: left-to-right
A • Repeatedly go to next child, as long as possib
• Return to left-over alternatives (higher-u
B D when needed.
C E
D F
G
3-23
1. DEPTH <-- 1
• It is a strategy that avoids (sidesteps) the issue of choosing the best depth limit by
trying all possible depth limits
• Finds the best depth limit by gradually increase the limit -> 0, 1, 2, …until goal is
found at depth limit d
3-30
• Implementation:
• fringe = queue ordered by path cost
Bidirectional search
Bidirectional search algorithm runs two simultaneous searches, one form initial
state called as forward-search and other from goal node called as backward-
search, to find the goal node.
The search stops when these two graphs intersect each other.
Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
Advantages:
Bidirectional search is fast.
Bidirectional search requires less memory
Disadvantages:
Implementation of the bidirectional search tree is difficult.
3-35
S
Forward
A D Backwards
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
3-36
Search
Bi-directional Search
* Completeness: yes
* Optimality: yes d/2
* Time complexity: O(bd/2)
d
* Space complexity: O(bd/2)
O(bd) vs. O(bd/2) ? with b=10 and d=6 results in 1,111,111 vs. 2,222.
Informed search
• Informed search algorithms
Best-first search
Memory Bound Best First search
Iterative improvement algorithm (Local search algorithms)
1 8
Expanded Node OPEN list
5
(S:8)
A B C
S not goal (C:3,B:4,A:8) h=8 h=4 h=3
9 4
3
7 5
D G
E
h= h=0
h=
3-42
Greedy Search
f(n)= h(n)
# of nodes tested 2, expanded 2
S
Expanded Node OPEN list
h=8
(S:8) 1 8
5
S (C:3,B:4,A:8)
A B C
C not goal (G:0,B:4,A:8) h=8 h=4 h=3
9 4
3
7 5
D G
E
h= h=0
h=
3-43
Greedy Search
f(n)= h(n)
# of nodes tested 3, expanded 2
S
Expanded Node OPEN list h=8
(S:8) 1 8
5
S (C:3,B:4,A:8)
A B C
h=8 h=4 h=3
C (G:0,B:4,A:8)
9 4
G goal (B:4.A:8) 3
5
no expand 7
D G
E
h= h=0
h=
3-44
Greedy Search
f(n)= h(n)
# of nodes tested 3, expanded 2
S
Expanded Node OPEN list h=8
(S:8) 1 8
5
S (C:3,B:4,A:8)
A B C
C (G:0,B:4,A:8) h=8 h=4 h=3
G goal (B:4.A:8) 9 4
3
7 5
D G
E
* Fast but not optimal h= h=
h=0
Path: S,C,G
Cost: 13
Greedy best-first search
Evaluation function f(n) = h(n) (heuristic) = estimate of cost from n to goal
That means the agent prefers to choose the action which is assumed to be best
after every action.
e.g., hSLD(n) = straight-line distance from n to Bucharest
Greedy best-first search expands the node that appears to be closest to goal (It
tries to minimizes the estimated cost to reach the goal)
Example One
Greedy best-first search example
Show the flow to move from Awasa to Gondar using the given
road map graph
Ethiopia Map with step costs in km Straight Line distance to
Gondar
Aksum
100 Gondar 0
200
Mekele Aksum 100
Gondar
180
80
Mekele 150
Lalibela
110 250
Lalibela 110
Bahr dar
150
Desseie 210
Dessie Bahrdar 90
170
Debre Markos 170
Debre markos 330
Dire Dawa Addis Ababa 321
230
Jima 300
Jima
330
400
Diredawa 350
Addis Ababa
100 Adama 340
430 Adama 370
Gambela 410
Gambela 230 320 Nekemt Awasa 500
Nekemt 420
Awasa
Example Two:- Greedy best-first search example
I G3 J J G ---------------- 8
G1,G2,G3 G ------------ 0
Properties of greedy best-first search
Complete? Yes if repetition is controlled otherwise it can can get stuck in loops
Time? O(bm), but a good heuristic can give dramatic improvement
Space? O(bm), keeps all nodes in memory
Optimal? No
A* search
• Idea: Avoid expanding paths that are already expensive
• Evaluation function f(n) = g(n) + h(n) where
• g(n) = cost so far to reach n
• h(n) = estimated cost from n to goal
• f(n) = estimated total cost of path through n to goal
• It tries to minimizes the total path cost to reach into the goal at every node N.
• Example two
by using map of Ethiopia in previous slid , Indicate the flow of search to move from
Awasa to Gondar using A*
Example Two
Given the following tree structure, show the content Heuristic
of the open list and closed list generated by A* best R G -------------- 100
first search algorithm.
A G -------------- 60
B G -------------- 80
R C G -------------- 70
70
35
40
D G -------------- 65
A B C
E G -------------- 40
25 10 62 45
18 21
F G -------------- 45
D E F G1 H G2
H G ---------------10
15 20 5
I G ---------------- 20
I G3 J J G ---------------- 8
G1,G2,G3 G ------------ 0
3-51
Admissible heuristics
A heuristic h(n) is admissible if for every node n,
h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n.
An admissible heuristic never overestimates the cost to reach the goal, i.e., it is
optimistic
Example: hSLD(n) (never overestimates the actual road distance)
Theorem:
If h(n) is admissible, A* using TREE-SEARCH is optimal
Example 3-52
h1(S) = ?
h2(S) = ?
Iterative Improvement Algorithm (Local search algorithms)
• also called Gradient Descent if the evaluation function is a cost rather than
a quality
Simulated Annealing
1. Hill-climbing search
Tries to make changes that improve the current state cost
It continually move in the direction of increasing value
The node data structure maintain only records of state and evaluation cost
6-56
Hill-climbing (Gradient Descent) search
• Tries to make changes that improve the current state cost
Problem:
1. Depending on initial state, can get stuck in local
maxima
2. Plateaux (after some progress the algorithm will
make a random walk)
3. Ridges (a place where two sloppy sides meet). In this
case the search may oscillate from side to side
Exercise 1
Consider the search space with start S and goal G states. S
h=1
The value of heuristics h are shown at each node.
The cost associated with the each arc is not known.
h=3
However, the trace of the OPEN list produced by the
A B
execution of A* algorithm is available(given below) h=5
along with the f values.
Determine the arc cost of arcs. C h=2
1. { (S, f=1)}
2. {(B, f=5), (A, f=6)}
D
3. {(A, f=6), (C, f=7)} G
4. {(C, f=6)} h=0 h=0
5. {(D, f=5), (G, f=7)}
6. {(G,f=6)}
Exercise 2. list out all nodes to reach the goal with Greedy best and A* search
and which one is optimal
A
S A 1
S B 3 2 10
2
S C 5
S G 9 5 5
A B 1 S B G
A C 3
A G 3 2
10
B C 2 5
B G 4
C G 4 C
6-59
Exercises
Exercises
Thanks!!!