Unit 2 - A Star
Unit 2 - A Star
Unit 2 - A Star
ी हष अ ी
Heuristics Search Method
ी हष अ ी
Heuristics Search
• Heuristics are problem-solving strategies which in many cases find a solution faster than uninformed
search.
• Heuristic decisions are closely linked with the need to make real-time decisions with limited resources.
• Heuristic search is also called guided search because in this, the search is guided in a specific direction.
• Heuristic is only an informed guess of the next step to be taken for solving a problem.
• Additional information or knowledge about the problems is given in the form of clues or guidelines, which
are called ‘heuristics.’
• A heuristic evaluation function f(s) for states is used to mathematically model a heuristic. The goal is to
find a solution with little effort and with minimal total cost.
• The best heuristic would be a function that calculates the actual costs from each node to the goal.
Heuristic Function = Cost from start state to current state + Estimated distance from state to a goal
Cost Heuristic
ी हष अ ी
A* Search
ी हष अ ी
Heuristics Search
A* Search Algorithm
2D Grid having several obstacles and start from a source n
cell (colored red below) to reach towards a goal cell (colored
green below)
▪ The estimated cheapest cost function f(n) used by A*, for the current node n during the search
process is given by
f(n)=g(n) + h(n),
where, g(n) = the cost of reaching the node n from the root,
h(n) = heuristic function is the estimated movement cost from node n to goal node
▪ The list OPEN stores the nodes which have been generated but not expanded and are available
(are “open”) for expansion, that is, their child nodes are yet to be identified.
▪ The list CLOSED stores the nodes that have been expanded and are not available (are “closed”)
for further expansion. ी हष अ ी
Heuristics Search
A* Search Algorithm Issues
❑ This is required only in the case when the data structure being used for
the search is a graph rather than a tree.
ी हष अ ी
Heuristics Search
A* Search Algorithm
1. Initialize: Set OPEN={s}, CLOSED={ },
g(s)=0 and f(s)=h(s).
2. Fail: if OPEN={ }; terminate and fail.
3. Select: Select the minimum cost state, n from OPEN. Save n in CLOSED.
4. Terminate: If n ∈ G, where G is the set of goal states, terminate with success and return f(n).
If m ∈ [OPEN ∪ CLOSED]
Set g(m) = min {g(m), g(n) + C(n, m)}
Set f(m) = g(m) + h(m)
If f(m) has decreased and m ∈ CLOSED, move m to OPEN.
B C-
- 2
4 3
4 D 3
-
2
1
C(n,m)
E
-
3
20
F
-
0
ी हष अ ी
OPEN CLOSED
A(5)
A(5)
Initial statecost
Minimum of OPEN
state inand
OPEN
CLOSED.
is A. Put
g(A)=0,
A in CLOSED.
f(A)=h(A)=5.
A does not belong to G.
ी हष अ ी
OPEN CLOSED
A(5)
B(7) C(25) A(5)
A(5) B(7)
Minimum
Expand Acost state B
to obtain inand
OPEN is does
C. B B. Putnot
B belong
in CLOSED. B does
to [OPEN notCLOSED].
union belong to G.
Therefore, set g(B)=g(A) + C(A, B) = 0 + 3 = 3.
And, set f(B) = g(B) + h(B) = 3 + 4 = 7. Place B on OPEN.
Similarly, g(C)=0 + 2 = 2 and f(C)=2+23=25. Place C in OPEN. Return to step 2.
ी हष अ ी
OPEN CLOSED
A(5)
B(7) C(25) A(5)
MinimumBcost
Expand to obtain
state D.
in OPEN
D doesisnot
D. belong
Put D intoCLOSED.
[OPEN union
D does
CLOSED].
not belong to G.
Therefore, set g(D)=g(B) + C(B, D) = 3 + 4 = 7.
And, set f(D) = g(D) + h(D) = 7 + 2 = 9. Place D in OPEN. Return to step 2.
ी हष अ ी
OPEN CLOSED
A(5)
B(7) C(25) A(5)
MinimumDcost
Expand to obtain
state E.
in OPEN
E doesisnot
E. belong
Put E intoCLOSED.
[OPEN union
E does
CLOSED].
not belong to G.
Therefore, set g(E)=g(D) + C(D, E) = 7 + 1 = 8.
And, set f(E) = g(E) + h(E) = 8 + 3 = 11. Place E in OPEN. Return to step 2.
ी हष अ ी
OPEN CLOSED
A(5)
B(7) C(25) A(5)
Minimum
Expand Ecost state F.
to obtain in FOPEN
does is
notC.belong
Put C to
in CLOSED. C does
[OPEN union not belong to G.
CLOSED].
Therefore, set g(F)=g(E) + C(E, F) = 8 + 20 = 28.
And, set f(F) = g(F) + h(F) = 28 + 0 = 28. Place F in OPEN. Return to step 2.
ी हष अ ी
OPEN CLOSED
A(5)
B(7) C(25) A(5)
A(5)
B(7) C(25) A(5)
A(5)
B(7) C(25) A(5)
F(26)
F(28) A(5) B(7) C(25) D(7) E(9)
Expand
MinimumEcost
to obtain
state F.
in FOPEN
belongs toPut
is E. [OPEN
E in union CLOSED]
CLOSED. E doesasnot
it isbelong
in OPEN.
to G.
Therefore, set g(F)=min{g(F), g(E) + C(E, F)} = min{28, 6 + 20} = 26.
Minimum cost state in OPEN is F with the cost 26. F belongs to G. Therefore, return f(F)=26. This is
And,
the set f(F) = g(F)
minimum cost +ofh(F) = 26 +the
reaching 0 =goal
26. node
As f(F)
F. has decreased from 28 to 26, but F does not belong to
CLOSED, it is already in OPEN. Replace it. Return to step 2.
ी हष अ ी
References
Book:
Artificial Intelligence: A Modern Approach by Stuart J. Russell and Peter Norvig
Web Links:
https://stackoverflow.com/questions/10680180/what-is-the-difference-between-graph-search-and-tree-search
https://www.baeldung.com/cs/graph-search-vs-tree-like-search
https://towardsdatascience.com/10-graph-algorithms-visually-explained-e57faa1336f3
https://cs.stanford.edu/people/abisee/gs.pdf
https://www.edureka.co/blog/breadth-first-search-algorithm/
https://medium.com/@dpthegrey/iterative-deepening-search-5f702cce97d5
https://iq.opengenus.org/iterative-deepening-search/
https://www.educba.com/iterative-deepening-depth-first-search/
https://ai-master.gitbooks.io/heuristic-search/content/what-is-greedy-best-first-search.html
https://www.mygreatlearning.com/blog/best-first-search-bfs/
https://medium.com/hengky-sanjaya-blog/informed-search-local-search-664888a32cf1
https://iq.opengenus.org/best-first-search/
https://www.analyticsvidhya.com/blog/2021/10/an-introduction-to-problem-solving-using-search-algorithms-for-beginners/
https://www.brainkart.com/article/Best-First-Search--Concept,-Algorithm,-Implementation,-Advantages,-Disadvantages_8881/
https://www.section.io/engineering-education/understanding-search-algorithms-in-ai/
https://www.educba.com/depth-limited-search/
https://www.analyticsvidhya.com/blog/2021/02/uninformed-search-algorithms-in-ai/
https://www.geeksforgeeks.org/a-search-algorithm/
https://towardsdatascience.com/search-algorithm-dijkstras-algorithm-uniform-cost-search-with-python-ccbee250ba9
https://iq.opengenus.org/bidirectional-search/
https://www.analyticsvidhya.com/blog/2021/02/uninformed-search-algorithms-in-ai/
ी हष अ ी