Artificial Intelligence
Outline
Last Class
Properties of Search Algorithms
Uninformed Search Algorithms
Breadth-first search
Depth-first search
Depth-limited search
Uniform-cost search
Iterative deepening search
Today
Informed Search Algorithms
Heuristics function
Best first search algorithm
Greedy Best First search
A* search
Uninformed Search Algorithms
Use only the information available in the problem definition
Carried out without any additional information that is
already provided in the problem statement
How to traverse the tree, how to identify leaf and goal nodes
Solution cost is not taken into account
Breadth-first search
Depth-first search
Depth-limited search
Uniform-cost search
Iterative deepening search
Informed Search Algorithms
Informed search algorithm have information on the
goal state such as how far we are from the goal, path
cost, how to reach to goal node, etc.
This information helps agents to explore less to the
search space and find the goal node, more efficiently.
Searches the most promising branches of the state-
space first
This information is obtained by something called
a heuristic, so it is also called Heuristic search.
Heuristics function
In an informed search, a heuristic is a function that
estimates how close a state is to the goal state.
Informs about which nodes in the state-space to
expand next that lead quickly to the goal state.
Heuristics function is represented by h(n)
For example – Manhattan distance, Euclidean
distance, etc. (Lesser the distance, closer the goal.)
Manhatan= d= |x2-x1|+|y2-y1|
Euclidean= d= squareroot((x2-x1)2+(y2-y1)2)
Contd..
Admissibility of the heuristic function is given as:
h(n) <= h*(n)
Here h(n) is heuristic cost, and h*(n) is the
estimated cost.
Hence heuristic cost should be less than or equal to
the estimated cost.
Pure Heuristic Search
The simplest form of heuristic search algorithms
Expand nodes based on their heuristic value h(n).
Maintains two lists:
CLOSED list: contains all of the traversed nodes
OPEN list: keeps track of the current ‘immediate’ nodes
available for traversal (nodes which have yet not been
expanded)
The algorithm continues until a goal state is found
Informed Search Algorithms
In the informed search we will discuss two main
algorithms:
Best First Search Algorithm(Greedy search)
Greedy w.r.t heuristic value
A* Search Algorithm
Greedy best-first search algorithm
In greedy search, we expand the node closest to the goal
node.
The “closeness” is estimated by a heuristic h(n).
f(n)= h(n).
Heuristic: A heuristic h is defined as:
h(n) = Estimated cost from node n to the goal.
Lower the value of h(n), closer is the node from the goal.
Strategy: Expand the node closest to the goal state
i.e. expand the node with a lower h value.
Implemented by the priority queue.
Best first search algorithm
Let OPEN be a priority queue containing initial state.
LOOP
If OPEN is empty, stop and return failure
Else Remove the first node from OPEN with the lowest value of
h(n) and place it in the CLOSED list.
If node is a goal
Return the path from initial node to current node
Else generate all the successors of node n and put newly
generated nodes into OPEN according to their h(n) value
END LOOP
Example
For heuristic value, Straight
line distance is calculated
7 D using Euclidean distance
A 25
14 A -> G = 40
11 10 B -> G = 32
C F
B
20 C -> G = 25
8 D -> G = 35
15 G E -> G = 19
10 F -> G = 17
E 9
H H -> G = 10
G -> G = 0
Here numbers mentioned on edges are
Best-First search focuses
just cost to travel from one state to
other rather than heuristic value
only on heuristic values
D
H=35
G
C
Path: A>C>F>G
35
7 D A -> G = 40
A 25 B -> G = 32
14 17 C -> G = 25
25 D -> G = 35
11 10
32 C F
20
E -> G = 19
B F -> G = 17
8 0
H -> G = 10
15 G
10 G -> G = 0
E 9
19 H
A C F G E B D
A C F G
Contd..
Example solution on board…
It is important to note that heuristics can sometimes
misguide us.
E.g. path A -> C -> E-> H -> G has less cost
Similarly, consider that the maze has fences fixed
along some of the paths through which the smell can
pass.
Pros and Cons
Advantages
Works well with informed search problems, with
fewer steps to reach a goal
more efficient than BFS and DFS algorithms
Disadvantages
Can turn into unguided DFS in the worst case.
Can get stuck in a loop like DFS.
This algorithm is not optimal.
Performance Measurement
Complete ?
NO, GBFS can get stuck in loops
Optimal ?
NO, heuristic value may misguide.
Time ?
The worst case time complexity of Greedy best first search is
O(bm). Simply O(n)
Space ?
The worst case space complexity of Greedy best first search
is O(bm).
Task
Find the path from S to G using greedy search. The heuristic
values h of each node is given below the name of the node.
A* Search
A* (A star) is the most widely known form of Best-First search
A* Search combines the strengths of uniform-cost search and
greedy search.
It evaluates nodes by combining g(n) and h(n):
f(n) = g(n) + h(n)
Where
g(n) = cost so far to reach n (backward cost, i.e. UCS cost)
h(n) = estimated cost to goal from n (i.e. greedy search cost,
forward cost)
f(n) = estimated total cost of path through n
Same algorithm as discussed previously just with a difference of f(n)
instead of h(n)
Contd..
A* search is optimal only when for all nodes, the
forward cost for a node h(n) underestimates the actual
cost h*(n) to reach the goal. This property
of A* heuristic is called admissibility.
Admissibility
Strategy: Choose the node with the lowest f(n) value.
Example
Find the most cost-effective path to reach from start
state A to final state G using A* Algorithm.
Solution
Let’s start with node A. Since A is a starting node, therefore,
the value of g(n) for A is zero and from the graph, we get the
heuristic value of A is 11, therefore
f(n) = g(n) + h(n)
f(n) = 0+ 11 =11
Thus for A, we can write A=11
Now from A, we can go to point B or point E, so we compute
f(n) for each of them
A→B=2+6=8
A → E = 3 + 7 = 10
Since the cost for A → B is less, we move forward with this
path and compute the f(n) for the children nodes of B
Contd..
Since there is no path between C and G, the heuristic cost is
set infinity or a very high value
A → B → C = (2 + 1) + 99= 102
A → B → G = (2 + 9 ) + 0 = 11
Here the path A → B → G has the least cost but it is still more
than the cost of A → E, thus we explore this path further
A → E → D = (3 + 6) + 1 = 10
Comparing the cost of A → E → D with all the paths we got so
far and as this cost is least of all we move forward with this
path. And compute the f(n) for the children of D
A → E → D → G = (3 + 6 + 1) +0 =10
Contd..
Now comparing all the paths that lead us to the goal,
we conclude that A → E → D → G is the most cost-
effective path to get from A to G.
Task
12 11
14 4 B 5
F
S 16
12
3 11 4 G
10 E 5
C
7 2
D
6
Pros and Cons
Advantages
Best algorithm than other search algorithms.
Optimal and complete.
Can solve very complex problems.
Disadvantages
It does not always produce the shortest path as it mostly
based on heuristics and approximation.
A* search algorithm has some complexity issues.
The main drawback of A* is memory requirement as it
keeps all generated nodes in the memory.
Performance Measurement
Complete ?
YES, with finite branching factor and fixed cost
Optimal ?
YES, with admissible heuristic search.
Time ?
O(bd). depends on heuristic function, and the number of nodes
expanded is exponential to the depth of solution d
Space ?
The worst case space complexity of Greedy best first search
is O(bd).
Task
Find optimal solution using greedy and A* search.
END