Professional Documents
Culture Documents
AI SMPS AStar Variations
AI SMPS AStar Variations
Deepak Khemani
Department of Computer Science & Engineering
IIT Madras
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
The Pull and the Push
Consider the function
f(n) = g(n) + w×h(n)
where w determines how much weight we give to the heuristic function.
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
An illustrative example Best First and wA* take the
upper path
108
start goal
24
w=1 70 60 50 40 30 36
94 96 98 100 102
36 48 60 72 g-values
164
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
The problem graph for wA* The values outside the nodes
220 13
are 2×Manhattan Distance
280 200 160
A B C D
23
23
240
33
24
33 These are used in wA* where
37 100
22
E
35
F
160
G f(n) = g(n) + 2×h(n)
29 22
200 180 64
H
240
22 start
I 12
J 12
K
160
Next we trace the progress of
22 21 21 33
this weighted A* algorithm
120 80
23 200 21
L M N
23 33 21
21
200 160 140 80
O 22 P 12
Q R
32 43
21 160 100
44
S T
21 35 33
120 40 0
41
U V 22
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n) With weight = 2 the search
220
algorithm gives greater
257 importance to the heuristic
value. Observe the
240 37
269 2×h(n) values in cyan.
29
262
240 22 start
200
200
12
180
192 We take up the action after
22 it has expanded the start
222 200
21 node.
160
181
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n) Initially the behavior is
220 simililar both to A* and the
257
Best First algorithms
240 37
269
29
21
222 200
21
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n) Unlike Best First Search the
Weighted A* algorithm does
220
257 look back to consider the g-
values and prefers this node
240 37
269 to its child which is closer to
29
the goal.
24022 start 200 180
12 12 160
262 200 192 226
22 It will in fact find a better path
222 200
21 to its child than the one
21
33 already found
200 160 140
243 22 181 12 173
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n)
220
257 Observe that the value of
this node has reduced
240 37
269 from 226 to 184.
29
21
222 200
33
21
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n)
220
All algorithms explore
257 this dead-end because it
240 37
appears to be closest to
269
35
206
160
the goal.
29 22
21 120
222 200 165
33
21
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n)
220
257
240 37
35 160
269 206
29 22
21 120
222 200 165
33
21
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n)
220
257 270
200 The rapidly decreasing
23
weighted heuristic pushes
24
269
240 37
35
206
160 the search faster towards the
29 22 goal, exploring less of the
24022 start
200
200
12
180
12
184
160
64
state space than the A*
262 192
22 21 21 algorithm.
21 120 80
222 200 165 190
33
21
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A8 finds the goal faster than A*
220
200
257 270
23
240 37 24
35 160 100
269 206 245
29 22
200 180 64
24022 start 12 12 160
262 200 192 184
22 21 21 33
21 120 80
222 200 165 190
33 21
21
0
153
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Weighted A*: f(n) = g(n) + 2×h(n) Weighted A* finds a path
220
to the goal after
200
257 270
23
inspecting 9 nodes.
240 37 24
35 160 100
269 206 245 But it finds a more
29 22
64
expensive path to the
24022 200 18012
262
start
200
12
192 184
160
goal than A*.
22 21 21 33
222 200
21
165
120
190
80
Cost of path = 153
33 21
21
0
153
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Path found by Best First Search
110 13
100 8 nodes inspected
23 Cost of Solution = 195
33
120 37 24
35 80 50
6
29 22
120 100 90 64
22 start 12 12 80
1 4
22 21 21 33
21 60 40
23 100
5 7
23 33 21
21
100 80 70 40
22 2 12 3
43
44
8
0
W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Branch & Bound : f(n) = g(n) + 0×h(n) B&B explores
the entire graph before
13
44 37 50 73 finding the optimal path
23
23
33
24
33 to the goal node.
37
22 35
29 46 106
29 22 No looking ahead!
64
22 start 12 12
22 0 12 24
22 21 21 33 Nodes are labeled with
23
22
21
45 110
g*(n) values.
23 33 21
21
43 22 21 33 131
12
32 43
21 44
64 120
21 35 33
41
85 126 22 148
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
A*: The Solution
14 nodes inspected
110 13
184
140
147 150
100
Cost of solution = 148
33
120 37 24
22 35 80
149 126
29 22
120 100 90 64
22 start 12 12 80
142 100 102 104
22 21 21
21 60 40
23 100
122 105 150
23 33
21
100 80 70
143 22 101 103
12
21 80 50
144 170
21 35 33
60 41 20 0
145 146 22 148
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
f(n) = g(n) + w×h(n): B&B - A* - wA* - Best First
B&B wA*
Nodes 23 Nodes 9
Cost 148 Cost 153
A* Best First
Nodes 14 Nodes 8
Cost 148 Cost 195
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Next
Admissible Variations on A*
Leaner, meaner versions...
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Complexity A2 A1
Goal
Start
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Depth Bounded DFS (DBDFS) (recap)
Goal
Start
d
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
DFID: cost of extra work
For every new layer in the search tree that DFID
explores, it searches the entire tree up to that layer
all over again. I internal nodes
L leaves
DFID inspects (L+I) nodes whereas
Breadth First would have inspected L nodes
NDFID = NBFS (L+I)
L
But L = (b−1)*I + 1 for a full tree with branching factor b
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Iterative Deepening A* (IDA*)
IterativeDeepeingA*(start)
1 depthBound ß f(S)
2 while TRUE
3 do DepthBoundedDFS(start, depthBound)
4 depthBound ß f(N) of cheapest unexpanded node on OPEN
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
IDA*: nodes explored by DFS In the next cycle cutoff to lowest
unexplored f-value node
Start
Goal
o The other problem is that in each cycle it extends the bound only
to the next f-value
• This means that the number of cycles may become too large
specially if the nodes have all different f-values
• One option is to extend the bound by a certain constant
amount each time, with a limited compromise on the cost
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
IDA*: Incrementing bound by d DFS may terminate before
looking at a cheaper solution.
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
50
RBFS: Roll back
50
59 55 60 62
59 60 62
61 61 56 60
Backed up f-value
60 56 62 New Search
60
57 60 67 60
61
Lowest f-values are
64 60 58
backed up at each level
when RBFS rolls back
63 61 62
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
An exercise problem Yet to be
generated
CLOSED
645 500
OPEN
Draw the graph after 690
2 expansions, and 670 640 630
mark the 3rd node 660 700
550
RBFS will pick 720 660
690
720 700 720
570
740 770
730 710
710
720 590 690
650
700 680
710
720 620
650 660 700 730 700
710
740 710
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
The Monotone Condition
The monotone property or the consistency property for a heuristic function
says that for a node n that is a successor to a node m on a path to the goal
being constructed by the algorithm A* using the heuristic function h(x),
This means that this is true for any two nodes M and N
connected by an edge.
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
h(M) − h(N) ≤ k(M,N) The nodes are placed on a grid
110
where each edge is 10km, and
140
A B h(n) is the Manhattan distance
23
33
120 37
22
E
29
Even on an optimal path to the
120 100 90
h(H) − h(O) = 20 ≤ 23 = k(H,O) goal the difference in h-values
22 start
H I 12
J is less than the edge cost
22 h(E) − h(B) = 10 ≤ 33 = k(E,P)
23 100 21
L h(L) − h(P) = 20 ≤ 21 = k(L,P)
23
21
100 80 70 h(S) − h(U) = 20 ≤ 21 = k(S,U)
O 22 P 12
Q
60 0
U W
10 goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Monontone condition à non-decreasing f-values
Given that we started from start S, we can add the term g(m)
to both sides to get,
Therefore
h(m) + g(m) ≤ h(n) + g(n),
or f(m) ≤ f(n)
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
L7: Monotone condition à when A* picks a node n, g(n) = g*(n)
Proof: Let A* expand node n with cost g(n).
Let nL be the last node on the optimal path from S to n that has been
expanded. Let nL+I be the successor of nL that must be on OPEN.
nL nL+1 n Goal G
OPEN List
Optimal path to N
Start
Path to node N
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Proof (continued): g(n) = g*(n)
Given that f(nL) ≤ f(nL+1) the following property holds,
By transitivity of ≤ the above property holds true for any two nodes on the optimal
path. In particular it holds for nL+I and node n. That is,
That is,
f(nL+I) ≤ h(n) + g*(n)
because nL+1 is on the optimal path to n
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Proof (continued): g(n) = g*(n)
But since A* is about to pick node n instead,
f(n) ≤ f(nL+I)
That is,
h(n) + g(n) ≤ f(nL+I)
or h(n) + g(n) ≤ h(nL+I) + g*(nL+I)
Therefore
h(n) + g(n) ≤ h(n) + g*(n)
or g(n) ≤ g*(n)
or g(n) = g*(n)
because g(n) cannot be less than g*(n) the optimal cost.
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
The consequences: CLOSED is closed
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Next
We look at a problem in which pruning the
CLOSED would be desirable:
Sequence Alignment in Biology
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
DNA sequences
A nucleic acid sequence is a succession of letters that indicate the
order of nucleotides forming alleles within a DNA (using GACT) or
RNA (GACU) molecule.
https://www.geeksforgeeks.org/sequence-alignment-problem/
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Cost of alignment
Given two sequences composed of the characters C, A, G and T the
task of sequence alignment is to list the two alongside with the option
of inserting a gap in either sequence.
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Best alignment depends on penalties
https://www.geeksforgeeks.org/
indel = 3, mismatch = 7 total penalty = 6 sequence-alignment-problem/
X=CG X=CG_
Y=CA Y=C_ A
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Similarity functions
A similarity function is a kind of inverse of the distance function.
Match: +1
Mismatch or Indel: −1
Match = 0
Indel = −1
Mismatch = −10
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
A fine grained similarity function
A G C T
Highest weight to aligning A with A A 10 -1 -3 -4
No penalty for aligning T with C
Other mismatches have negative weight G -1 7 -5 -3
C -3 -5 9 0
The alignment: T -4 -3 0 8
AGACTAGTTAC
CGA - - - GACGT
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Sequence alignment as graph search
Let X and Y be the first characters of the two strings.
There are three possibilities Insert gap before Y
1. Align X with Y
2. Insert blank before X
3. Insert blank before Y X
Before considering X and Y Align X and Y
Y
There are three moves from each node
Each move has an associated penalty or cost (mismatch or indel)
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
The graph for the sequence alignment problem
G C A T G C U
start If we had a longer
horizontal sequence the
G last column would come
into play
A
A goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Four alignments
GCATGCU GCATG -CU
G C A T G C U
GATTACA G - ATTACA
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Complexity for A*
The state space grows quadratically with depth
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
OPEN grows Linearly, CLOSED quadratically
G C A T G C U In biology the sequences to be
start aligned may have hundreds of
G
thousands of characters.
A goal
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras
Next
Pruning CLOSED
Artificial Intelligence: Search Methods for Problem Solving Deepak Khemani, IIT Madras