0% found this document useful (0 votes)
3 views

A Star Algorithm

Uploaded by

Sushil Azad
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

A Star Algorithm

Uploaded by

Sushil Azad
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

A* Algorithm

Prof. Sushil Kumar Azad


Uninformed &
In A* search algorithm, we use search heuristic as well as the cost to reach the Informed Search
node. Hence, we can combine both costs as following, and this sum is called as
a fitness number (Evaluation Function).

f(n) = g(n) + h(n)

Estimated cost of the Cost to reach node n Cost to reach from node
cheapest solution. from start state. n to goal node.

Fig 9 Evaluation function f(n) in A* Algorithm

A* algorithm evaluation function f(n) is defined as f(n)=g(n)+h(n)


Where g(n) = sum of edge costs from start state to n
And h(n) = estimate of lowest cost path from node n goal node.
If h(n) is admissible then search will find optimal solution. Admissible means
underestimates cost of any solution which can reached from node. In other
words, a heuristic is called admissible if it always under-estimates, that is, we
always have h(n) ≤ h^* (n), where h*(n) denotes the minimum distance to a
goal state from state n.
A* search begins at root node and then search continues by visiting the next
node which has the least evaluation value f(n).
It evaluates nodes by using the following evaluation function
f(n) = h(n) +g(n) = estimated cost of the cheapest solution through n.
Where,
g(n): the actual shortest distance traveled from initial node to current node, it
helps to avoid expanding paths that are already expansive

h(n): the estimated (or “heuristic”) distance from current node to goal, it
estimates which node is closest to the goal node. Nodes are visited in this
manner until a goal is reached.
Algorithm A*
1. Initialize: Set OPEN = (s), CLOSED = {}, g(s) = 0, f(s) = h(s)
2. Fail: If OPEN = { }, Terminate & fail
3. Select : Select the minimum cost state, n, from OPEN, Save n in CLOSED.
4. Terminate: If n ∈ G, terminate with success, and return f(n)
5. Expand: For each successor, m, of n If m ∉ [OPEN ∪
CLOSED]
Set g(m) = g(n) + C(n,m)
Set f(m) = g(m) +h(m)

If m ∈ [OPEN ∪ CLOSED]
Insert m in OPEN

If f(m) has decreased and m ∈CLOSED, move m to OPEN


Set g(m) = min {min {g(m), g(n) + C(n,m)} Set f(m) = g(m) + h(m)
steps for working of A* algorithm:

Step-1: Define a list OPEN. Initially, OPEN consists of a single node, the
start node S.
Step-2: If the list is empty, return failure and exit.
Step-3: Remove node n with the smallest value of f(n) from OPEN and move it to list CLOSED.
If node n is a goal state, return success and exit.
Step-4: Expand node n.
Step-5: If any successor to n is the goal node, return success and the solution by tracing the path from
goal node to S.
Otherwise, go to Setp-6.
Step-6: For each successor node,
Apply the evaluation function f to the node.
If the node has not been in either list, add it to OPEN.
Step-7: Go back to Step-2
Example 1 Step-1:
We start with node A. Node B and Node F can be reached from node A. A* Algorithm calculates f(B)
and f(F). Estimated Cost f(n) = g(n) +h(n) for Node B and Node F is:
f(B) = 6+8=14
f(F) = 3+6=9
Since f(F) < f(F), so it decides to go to node F.
 Closed list (F)
Path- A →F

Step-2: Node G and Node H can be reached from node F. A* Algorithm


calculates f(G) and f(H).
f(G) = (3+1)=5=9
f(H) = (3+7) +5=13
Since f(G) < f(H), so it decides to go to node G.
 Closed list (G)
Path- A→F→G

Step-4: Node E, Node H and Node J can be reached from node I. A* Algorithm
Step-3: Node I can be reached from node G. A* Algorithm calculates f(E), f(H), f(J).
f(E) = (3+1+3+5) + 3 =15
calculates f(I). f(I)=(3+1+3)+1=8; It decides to go to node I. f(H) = (3+1+3+2) + 3 = 12
f(J) = (3+1+3+3) +0 = 10
 Closed list (I). Since f(J) is least, so it decides to go to node J.
 Closed list (J)
Path- A→F→G→I
Shortest Path - A→F→G→I→J Path Cost is
3+1+3+3=10
Example 2

Steps 5-6:
S→A→C→G=1+1+4=6
Steps 1-4: S→A→B→D=1+2+5+6=14
1. S→A=1+3=4
Steps 7-8:
2. S→G=10+0=10
S→A→C→D→G=1+1+3+2=7
3. S→A→B=1+2+4=7
S→A→B→D→G=1+2+5+2=10
4. S→A→C=1+1+2=4 S→A→C→D=1+1+3+6=11

You might also like