Path Finding in a Maze Using the A Search Algorithm
Problem Statement
Pathfinding is an important Artificial Intelligence problem in which an agent must find the shortest path from a starting position to a goal position while avoiding obstacles.
In this practical, the A* Search Algorithm is implemented using Python to solve a pathfinding problem in a two-dimensional maze. A* selects the most promising cell by considering both:
where:
- = actual cost from the start cell to the current cell
- = estimated distance from the current cell to the goal
- = estimated total cost of the path
Example of A* Cost Calculation
Consider the following small grid:
Column 0 1 2 Row 0 S 0 0 Row 1 0 A 0 Row 2 0 0 G
Where
- S = Start = (0,0)
- A = Current Cell = (1,1)
- G = Goal = (2,2)
Suppose the A* algorithm is currently at cell A (1,1).
Step 1: Calculate g(n)
The value g(n) represents the actual distance travelled from the Start node to the Current node.
From the start,
(0,0) ↓ (1,0) → (1,1)
The algorithm has taken 2 steps.
Therefore,
g(n) = 2Step 2: Calculate h(n)
The heuristic value is calculated using the Manhattan Distance.
Formula:
Current Cell
(1,1)
Goal Cell
(2,2)
Calculation
h(n) = |1-2| + |1-2| = 1 + 1 = 2
Therefore,
h(n)=2
Step 3: Calculate f(n)
Formula
Substitute the values
f(n)
= 2 + 2 = 4Therefore,
f(n)=4
0 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏