Module 3 AI BAD402
Module 3 AI BAD402
A heuristic function, often denoted as h(n), is a function that estimates the cost
of the cheapest path from a given node n to the goal node in a search problem.
It is used to provide an educated guess about which path to take, rather than
exploring all possible paths.
1. Grid-Based Pathfinding
where (x1,y1) and (x2,y2) are the coordinates of the current state and
the goal state, respectively.
ii. Euclidean Distance: Used when diagonal movement is allowed. It is calculated as:
where (x1,y1) and (x2,y2) are the coordinates of the current state and
the goal state, respectively.
i. Misplaced Tiles: Counts the number of tiles that are not in their goal
position:
ii. Manhattan Distance: The sum of the Manhattan distances of each tile from its goal
position:
𝟖
where (xi,yi) is the current position of tile i and (𝒙∗𝒊 , 𝒚∗𝒊 ) is its goal
position.
Consider the 8-puzzle problem, where the goal is to move tiles on a 3x3 board
to achieve a specific configuration, typically with the blank space in the
bottom-right corner. Two common heuristics for this problem are the number
of misplaced tiles and the Manhattan distance.
This heuristic counts how many tiles are not in their goal position. It is simple
but not always very informative.
This heuristic sums the distances each tile is from its goal position, measured
in grid moves.
Calculation Example:
1. Heuristic Function (h(n)): An estimate of the cost to reach the goal from
node n. The quality of the heuristic function significantly impacts the
efficiency of the search.
2. Evaluation Function (f(n)): Combines the cost to reach the node and the
heuristic estimate. For example, in A* search, the evaluation function is
f(n)=g(n)+h(n)f(n) where g(n) is the cost to reach node n from the start
node.
3. Admissibility: A heuristic is admissible if it never overestimates the cost
to reach the goal, i.e., h(n)≤h∗(n) for all nodes n, where h∗(n) is the true
cost to reach the goal from n.
4. Consistency (Monotonicity): A heuristic is consistent if, for every node
n and every successor n′ of n, the estimated cost of reaching the goal
from n is no greater than the cost of getting from n to n′ plus the
estimated cost from n′ to the goal.
It is the combination of boh depth first search and breadth first search
algorithms and uses the heuristic value for searching operation from the node
n to goal node.
In the best first search algorithm we expand the node which is closest to the
goal node and the minimum cost is estimated using the heuristic function.
Algorithm of GBFS:
1. Initialize the open list with the initial state.
2. Loop until the open list is empty or the goal is found:
o Select the node with the lowest heuristic value h(n) from the open
list.
o If this node is the goal, return the path to the goal.
o Otherwise, expand the node and add its successors to the open
list.
3. If the open list is empty and the goal is not found, return failure.
𝒇(𝒏) = 𝒉(𝒏)
Where h(n) is the estimated heuristic cost from node n to the goal node and
that cost is an approximate cost but not an actual cost.
Iteration 1:
Iteration 2:
Iteration 3:
So now the goal node G has been reached and the path we will follow is A->C-
>F->G.
Consider the following graph and find the minimum cost to reach the
goal node I from the start node A using GBFS technique?
3.2. A* Algorithm:
A* Algorithm is a searching algorithm that is used to find the shortest path
between the source node to the destination node.
It is a handy algorithm that is often used for map traversal to find the
shortest path from source to the destination.
This algorithm is used for development of games and web based maps to
find the shortest path efficiently.
A* Algorithm is one of the best and popular technique used for path finding
and graph traversal. Since it finds the goal node from the source node it is
considered as optimal and complete.
Algorithm of A* search:
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value of
evaluation function (g+h), if node n is goal node then return success and
stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into
the closed list. For each successor n', check whether n' is already in the
OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be
attached to the back pointer which reflects the lowest g(n') value.
Step 6: Return to Step 2.
Sol: Iteration 1: We start the traversal from the start state A, Since A is the
start state the Actual cost g(n) is 0 and the estimated cost as shown in the
graph is 10. Using the formula f(n)=h(n)+g(n) we need to calculate the cost
function
f(A)=g(A)+h(A)= 0+10=10---(1)
Now from A we can traverse towards B or F, i:e AB or AF. Considering both
the paths we need to find the cost function.
f(AF)=g(F)+h(F)=3+6=09---(3)
Comparing above two cost functions of (2) and (3) we need to consider the
lowest cost function and neglect the other cost function which is maximum.
Here the lowest cost function is 9 from the path (AF).
3
A F
10 6
f(AFH)= g(H)+h(H)=7+3=10---(4)
Comparing above two cost functions of (4) and (5), Here the lowest cost
function is 9 from the path (AFG).
10 3 6
A F
5 G
Iteration 3: Now we need to traverse from G to I i:e AFGI. Using the
formula f(n)=h(n)+g(n) we need to calculate the cost function.
f(AFGI)=g(I)+h(I) =3+1=4---(6)
Since we have only one path from G to I we need to consider the above cost
function for further traversal. Here the lowest cost function is 4 from the path
(AFGI).
10 3 6
A F
5
G
I 1
f(AFGIJ)=g(J)+h(J)= 3+0=3---(7)
f(AFGIE)=g(E)+h(E)=5+3=8---(8)
f(AFGIJ)=g(J)+h(J)= 2+3=5---(9)
from the above cost function we have identified that the lowest cost function is
3 and hence the traversal takes place from AFGIJ. Hence we have
reached the goal state J.
10 3 6
A F
1
G
3
J
0
■ AO* algorithm is a best first search algorithm. This algorithm uses the
concept of AND_OR graphs to decompose any given complex problem, into
set of smaller problems which can be solved easily.
■ Once all the smaller problems are solved these solved problem solutions are
combined together to provide the final result.
■ The complex problem can be broken down into smaller problems using the
logic of AND-OR graph technique.
f(n)= g(n)+h(n)
Where:
g(n): is the actual cost of traversal from initial state to the current state.
h(n): is the estimated cost of the traversal from current state to the goal
state.
f(n): is the actual cost of the traversal from initial state to the goal state.
1. Anytime Nature:
AO* provides solutions incrementally, allowing users to interrupt the
search at any time and retrieve the best solution found so far. This
feature is crucial in real-time systems where immediate responses are
necessary.
2. Optimistic Search:
AO* maintains an "optimistic" cost estimate for each state, which serves
as a lower bound on the true cost. This estimate helps prioritize
promising paths during the search.
3. Adaptive Behaviour:
AO* can adapt its search strategy based on the available computational
resources and user requirements. It can allocate more time for an
exhaustive search if needed or return a solution quickly when
computational resources are limited.
4. Heuristic Function:
Like other informed search algorithms, AO* relies on a heuristic function
that estimates the cost from the current state to the goal state. This
function guides the search by prioritizing states that appear more
promising.