Searching Techniques in AI: Overview
Searching Techniques in AI: Overview
Searching Techniques
• Ideas in searching
• Searching tree representation
• Uninformed and informed search
• Game playing search
Problem as a State Space Search
•Classical graph
applications.
•Introduced by Leonhard
Euler.
•Problem: Can a person
walk around the city
crosses each bridge
exactly once?
Example: The Bridges of Konigsberg
Problem (cont)
A
b6
b1
b3
b5 C
B
b4
b7
b2
D
Starting
position
goal
position
Node expansion (initial)
Node expansion (expanding Arad)
Node expansion (expanding Sibiu)
Measuring Searching Performance
•The output from problem-solving (searching) algorithm is
either FAILURE or SOLUTION.
•Four ways:
•Completeness : is guaranteed to find a solution?
•Optimality: does it find optimal solution ?
•Time complexity: how long?
•Space complexity: how much memory?
•Complexity : branching factor (b), depth (d), and
max. depth (m)
Searching Strategies
(Number of nodes)N = 1 + b + b2 + … + bd
Multiplying both sides by b
or N*b = b + b2 + b3 + …… + bd + bd+1
Subtracting 1st equation from 2nd
or (b -1) N = bd+1 -1
or N = (bd+1 -1) / (b -1) = bd+1
• Visiting : To select a node
• Exploring : finding the children of a selected node
Blind Search : Breadth First Search
1 2
3 4
Queue
Enqueue dequeue
1 2 3
4 5 N+1
…….
Visiting list A A,B A,B,D A,B,D,E
Push Push Push Pop Push Pop Pop
Stack
D E
B B B B B
A A A A A A A
Pop Pop Push Pop Push Push
G F
C C C C C
A A A A A A
A,B,D,E,C,F,G A,B,D,E,C
A,B,D,E,C,F
Blind Search : Depth First Search (DFS)
Limit =2
A A A A
B C B C B C B C
D E F G D E F G D E F G D E F G
A A A
B C B C B C
D E F G D E F G D E F G
TIN 5013: Artificial Intelligence
Blind Search : Iterative Deepening DFS
(ID-DFS)
•Strategy ~ combines DFS with best depth limits.
•Gradually increase the limit; L=0, L=1… and so on.
•Complete ?: Yes (if b is finite)
•Complexity: bd
•Space : bd
•Optimality ? : yes (if path costs are all identical)
Comparison of uninformed searches
D
A
C
B E
H G1 F G2
Solve the given problem with bfs, dfs, dls=3 and id-dfs (dfid). While
exploring select in alphabetical order
HIM KAN
EVE
KWO
NEC
LEC
PUL SAG
JEC
ADV
DHA
CHI THA
KEC
WRC
Visited list
Uniform Cost search S S,A,D,B,C
S 1
5 S,A S,A,D
S S,A,D,B
6 D 5 6 S,A,D,B,C,E
9 6
A 3 2 9 D
2 6
1 A 2
2 C 5 2
B E 3 B C E
9 8
2 8
9 9
5 7 7 B 1
5 7
8 C 7
G1 G2 8 G1
F G3
9
14 G2 G3
F
13
15 15
Goal State
Initial State A
A D Heuristic value = 5
B D B
C E C E
D -1
A -1 A +1 A -1
B +1 D -1 B +1 B +1 D -1 B +1
A -1 C +1 E +1 C +1 E +1 D -1 C +1 E +1 C +1 E +1
Heuristic value = 1 Heuristic value = 1 Heuristic value = 3 Heuristic value = 1
A A
Goal
B D 3 D State
C E B
C E
B -1
A -1 A +1 A +1
B +1 D -1 D -1 B +1 D -1 D -1
C +1 E +1 C +1 E +1 B -1 C +1 E +1 A -1 C +1 E +1
H(n) = +1 H(n) = +1 H(n) = +1 H(n) = +1
D -4
A -3 A -3 A -3
B +2 D -2 B +2 B +2 D -2 B +2
A -1 C +1 E +1 C +1 E +1 D -1 C +1 E +1 C +1 E +1
B -3
B -2 D -2 D -2 D -2
A -1 C +1 E +1 A -1 C +1 E +1 A -1 C +1 E +1 B -1
H(n) = -3 H(n) = -4 H(n) = -2
D +3
D -2 B +2 B +2 B +2
A -1 C +1 E +1 A -1 C +1 E +1 A -1 D -1 C +1 E +1
-3 A A -3
+2 B D -2 +2 B D -2 H(n) = -1
H(n) = -1
+1 C E +1 +1 C E +1
D +3 Goal State
A
H(n) = +6
B +2 D
A -1 C +1 E +1 B
C E
A +4 -4 E
D +3 D +3 D +3 +3 D
B +2 A -2 B +2 E -2 B +2 +2 B
C +1 E +1 C +1 E +1 A -1 C +1 -1 A +1 C
H(n) =+3 H(n) =-1
H(n) =+5 H(n) =+11
Goal State
Hill Climbing Problems
Hill climbing cannot reach the optimal/best state(global
maximum) if it enters any of the following regions :
[Link] maximum : At a local maximum all neighboring
states have a values which is worse than the current state.
Since hill-climbing uses a greedy approach, it will not move
to the worse state and terminate itself. The process will end
even though a better solution may exist.
To overcome local maximum problem
: Utilize backtracking technique. Maintain a list of visited
states. If the search reaches an undesirable state, it can
backtrack to the previous configuration and explore a new
path.
[Link] : On plateau all neighbors have same value .
Hence, it is not possible to select the best direction.
To overcome plateaus : Make a big jump. Randomly
select a state far away from the current state. Chances are
that we will land at a non-plateau region
[Link] : Any point on a ridge can look like peak because
movement in all possible directions is downward. Hence the
algorithm stops when it reaches this state.
To overcome Ridge : In this kind of obstacle, use two or
more rules before testing. It implies moving in several
directions at once.
Heuristic Search : Heuristic Function
176
Heuristic Search :Greedy-Best Search
176
2
Heuristic Search :Greedy-Best Search
3
Heuristic Search : A* Algorithm
A 6 4
6 E 4
13 6 1 0
5 3
17 S B 2
F G
7
10 4
D 6
C 6
A* Example
S
16 14
18
A C
B
16 18
E D
31 17
B F
A* Example
S
16 14
18
A C
B
16 18
E D
17
F
2 19
4
D G
A* Example
S
16 14
18
A C
B
16 18
E D
23
36
17 B F
F
19
G
A* Example
S
16 14
18
A C
B
16 18
14 15
E D E D
22 19
17
F C F
19
G
A* Example
S
16 14
A 18
C
B
16
14 15
E D E
16
27
17
F A F
19 23 18
G D G
A* Example Solution
10
A 6 4
6 E 4
13 6 1 0
5 3
17 S B 2
F G
7
10 4
D 6
C 6
The A* Algorithm
• This algorithm uses following functions:
1. f’: Heuristic function that estimates the merits of each node we generate. f’
represents an estimate of the cost of getting from the initial state to a goal state along
with the path that generated the current node. f’ = g + h’
2. g: The function g is a measure of the cost of getting from initial state to the current
node.
3. h’: The function h’ is an estimate of the additional cost of getting from the current
node to a goal state.
• Mini-Max Algorithm
• Alpha-beta Algorithm
• Game Playing is an important domain of Artificial Intelligence.
• There are two reasons that games appeared to be a good domain.
1. They provide a structured task in which it is very easy to measure success or failure.
2. They are easily solvable by a straightforward search from the starting state to a
winning position.
• Games require only the domain knowledge such as the rules, legal moves and
the conditions of winning or losing the game.
• In a two-player game, both the players try to win the game. So, both of them
try to make the best move possible at each turn.
• To improve the effectiveness of a search based problem solving program two
things can be done.
1. Improve generate procedure so that only good moves are generated.
2. Improve test procedure so that the best move will be recognized and explored first.
Introduction
• If we use legal-move generator then the test procedure will have to look at
each of them, because the test procedure must look at so many possibilities
and it must be fast.
• The depth of the resulting tree or graph and its branching factor will be too
large.
• Instead of legal-move generator we can use plausible-move generator in which
only some small numbers of promising moves are generated.
• As the number of legal available moves increases it becomes increasingly
important in applying heuristics to select only those moves that seem more
promising.
• The performance of overall system can be improved by adding heuristic
knowledge into both the generator and the tester.
• It is possible to search tree only ten or twenty moves deep then in order to
choose the best move, the resulting board positions must be compared to
discover which is most advantageous.
Introduction
• This is done using static evaluation function, which uses whatever information
it has to evaluate individual board position by estimating how likely they are to
lead eventually to a win.
• The most common search technique in game playing is Minimax search
procedure. 17 MAX (player)
14 17 5 MIN (opponent)
14 27 17 21 14 5 MAX (player)
3 14 12 27 17 2 6 21 14 3 5 1 MIN (opponent)
The MINIMAX Search Procedure
• The Minimax search is a depth first and depth limited procedure.
• The idea is to start at the current position and use the plausible-move
generator to generate the set of possible successor positions.
• Now we can apply the static evaluation function to those positions and simply
choose the best one.
• After doing so, we can back that value up to the starting position.
• Here, we assume that static evaluation function returns larger values to
indicate good situations for us.
• So our goal is to maximize the value of the static evaluation function of the
next board position.
• The opponents’ goal is to minimize the value of the static evaluation function.
The MINIMAX Search Procedure
• The alternation of maximizing and minimizing at alternate ply when
evaluations are to be pushed back up corresponds to the opposing strategies of
the two players is called MINIMAX.
MAX
A 2
MIN C 2
B -1
MAX
D 8 E -1 F 2 G 4
H I J K L M N O
-1 8 -3 -1 2 1 -3 4
Alpha-Beta Pruning Algorithm
• Cut-off search by exploring less no of nodes.
• Alpha is calculated at max level
• Beta is calculated at min level
• Initialize the initial value of alpha = - infinity and beta =
+infinity
• Alpha tries to increase the value while beta tries to decrease
the value.
• If alpha is greater than beta then prune the search tree.
Alpha-Beta Pruning Algorithm
MAX A α = 3- ∞
α>= β α pruning
So prune
V=3
MIN B β = +∞ C β=2
∞
β = 3 α>= β
So prune, V=2
V=3 α=-∞ β pruning
MAX D α
α= 3 E α = -7 ∞ F α=-∞ G α
α=2
α>= β α>= β
So prune, So prune
α pruning α pruning
V=3 V =7 V=2
MIN H β=+ ∞ I β = 2∞ J
β=+ β
β==-7∞ K β L β=∞ M β=∞ N β O β
β=2 β=1
β=3
β=3 β=4 β = 7β = 8 β=2
P Q R S T U V W X Y Z a b c d e
3 4 2 1 7 8 9 10 2 11 1 12 14 9 13 16
4
Alpha-Beta Pruning
• Alpha-beta pruning is a modified version of the Minimax algorithm. It is an
optimization technique for the Minimax algorithm.
• In the Minimax search algorithm, the number of game states to be examined
can be exponential in the depth of a tree.
• Hence there is a technique by which without checking each node of the game
tree we can compute the correct Minimax decision, and this technique is called
pruning.
• This involves two threshold parameter Alpha and beta for future expansion, so
it is called alpha-beta pruning. It is also called as Alpha-Beta Algorithm.
• Alpha-beta pruning can be applied at any depth of a tree, and sometimes not
only it prunes the tree leaves but also entire sub-tree.
Alpha-Beta Pruning
• Alpha-beta pruning technique maintains two bounds:
1. Alpha (𝜶): The best (highest-value) choice we have found so far at any point along the
path of Maximizer. The initial value of alpha is -∞. A lower bound on best, i.e., Max
2. Beta (𝜷): The best (lowest-value) choice we have found so far at any point along the
path of Minimizer. The initial value of beta is +∞. An upper bound on what the
opponent can achieve
Min B C D
Max E F G J K
H I
3 8
4 5 6
L M N O
3 4 7 9
Minimax with Alpha-beta Pruning – Example 2
Max A
Min B C D
Max E F G H I J
2 3 5 9 1 0 7 4 2 1 5 6
Minimax with Alpha-beta Pruning – Example 3
6 MAX
(player)
3 6 5 MIN
(opponent
5 6 7 5 8 )
3 MAX
(player)
5 4 3 6 6 7 5 8 6 MIN
(opponent
)
5 6 7 4 5 3 6 6 9 7 5 9 8 6
MAX
(player)
MIN-MAX Algorithm
• Back-tracking Algorithm
• Assume you are player at Max position then, Max will try to maximize
its utility (Best Move)
• Min will try to minimize utility(worst move)
• Time complexity = bd
properties
• Back-tracking Algorithm
• Assume you are player at Max position then, Max will try to maximize
its utility (Best Move)
• Min will try to minimize utility(worst move)
• Time complexity = bd/2
Thank you