Unit 2 - A Star

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Subject: Artificial Intelligence (CSE 472)

Unit 2 : Problem Solving Agents


Course : B.Tech. - CSE
Semester : VII
Faculty Teaching : Dr. Shree Harsh Attri
Designation : Associate Professor
Department : Computer Sc. & Engineering

Sharda University, Greater Noida, U.P ी हष अ ी


Contents
1. Problem Solving using Search Techniques
2. Uninformed Search Strategies
i. Breadth First Search (BFS)
ii. Depth First Search (DFS)
iii. Depth Limited Search (DLS)
iv. Uniform Cost Search (UCS)
v. Iterative Deepening Depth First Search (IDFS)
vi. Bidirectional Search (BDS)
3. Informed Search Strategies
i. Greedy Best Search
ii. Heuristic Functions
iii. A* search

ी हष अ ी
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

Start State Current State Goal State

Cost Heuristic

Function = 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

▪ When will a node have to be moved from CLOSED to OPEN?

❑ This is required only in the case when the data structure being used for
the search is a graph rather than a tree.

❑ In the case of a graph, the moving of a node from CLOSED to OPEN


indicates a backtracking and that the path followed till the node being
moved is not the best path and there are other alternative paths which
may be better.

ी हष अ ी
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).

5. Expand: For each child m of n


if m ∉ [OPEN ∪ CLOSED]

Set g(m) = g(n) + C(n, m)


Set f(m) = g(m) + h(m)
Insert m in OPEN. C(n, m) is the cost of moving from node n to node m.

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.

6. Return: Return to Step 2.


ी हष अ ी
Heuristics Search
A* Search Algorithm Dry Run
A
h(n)
-
3 5 2

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)

C(25) D(9) A(5) B(7)

A(5) B(7) D(9)

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)

C(25) D(9) A(5) B(7)

C(25) E(11) A(5) B(7) D(9)

A(5) B(7) D(9) E(11)

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)

C(25) D(9) A(5) B(7)

C(25) E(11) A(5) B(7) D(9)

C(25) F(28) A(5) B(7) D(9) E(11)

A(5) B(7) D(9) E(11) C(25)

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)

C(25) D(9) A(5) B(7)

C(25) E(11) A(5) B(7) D(9)

C(25) F(28) A(5) B(7) D(9) E(11)

F(28) D(7) A(5) B(7) D(9) C(25) C(25)


E(11) E(11)

Expand C to obtain D. D belongs to [OPEN union CLOSED] as it is in CLOSED.


Therefore, set g(D)=min{g(D), g(C) + C(C, D)} = min{7, 2 + 3} = 5.
And, set f(D) = g(D) + h(D) = 5 + 2 = 7. As f(D) has decreased from 9 to 7, and D belongs to CLOSED,
therefore move D from CLOSED to OPEN. Return to step 2.
ी हष अ ी
OPEN CLOSED

A(5)
B(7) C(25) A(5)

C(25) D(9) A(5) B(7)

C(25) E(11) A(5) B(7) D(9)

C(25) F(28) A(5) B(7) D(9) E(11)

F(28) D(7) A(5) B(7) E(11) C(25)

F(28) E(9) A(5) B(7) C(25 C(25)


E(11 D(7) D(7)

Expand D to obtain E. E belongs to [OPEN union CLOSED] as it is in CLOSED.


Minimum cost state in OPEN is D. Put D in CLOSED. D does not belong to G.
Therefore, set g(E)=min{g(E), g(D) + C(D, E)} = min{8, 5 + 1} = 6.
And, set f(E) = g(E) + h(E) = 6 + 3 = 9. As f(E) has decreased from 11 to 9, and E belongs to CLOSED,
therefore move E from CLOSED to OPEN. Return to step 2.
ी हष अ ी
OPEN CLOSED

A(5)
B(7) C(25) A(5)

C(25) D(9) A(5) B(7)

C(25) E(11) A(5) B(7) D(9)

C(25) F(28) A(5) B(7) D(9) E(11)

F(28) D(7) A(5) B(7) E(11) C(25)

F(28) E(9) A(5) B(7) C(25) D(7)

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/

ी हष अ ी

You might also like