Uploaded by David Santamonica

Maze Problem Solving with A* Algorithm

advertisement
MAZE PROBLEM 7Cs
CAPTURE
In this problem we will have to find a way out given a text file representing the
maze, a start node and a goal node.
Questions for clarification:
What happens if there is no way out of the maze?
In this case the program will return an output saying that it has not found a
path.
What will the structure of the text file look like?
The value 0 in the maze means a free path or a passable cell, where the
agent can move.
The value 1 means an obstacle or blocked cell, a cell where it is not possible
to move.
Is it necessary to minimize the number of cells?
It is not strictly necessary, but as a decision of the problem, the A* algorithm
will be implemented to minimise the number of cells visited and find the
shortest path.
What will be the time complexity of the algorithm?
Because I have decided to implement the A* algorithm, the worst case
complexity will be O(b^d) where b is the average number of edges per node
and d is the number of nodes in the resulting path. The time complexity with
the A* algorithm applied will depend on the heuristic used and the search size.
What the spatial complexity will be:
The spatial complexity will be O(V), where V is the nodes in a data structure.
Since the program will have to store all nodes.
What is heuristics? The heuristic is a function that calculates the approximate
cost to reach the solution. It is used to optimize searches and avoid having to
use exhaustive searches.
What happens if the text file is incorrect?
If the input file does not have the correct format, the program will return an
output indicating a formatting error in the input provided.
CONTEMPLATE
- The input will be the text file representing the structure of the maze. The file
shall be represented as follows:
010
010
000
The program should read the file and transform those 0s and 1s into a
two-dimensional array.
Example of maze already in the program:
maze = [
[0, 1, 0],
[0, 1, 0],
[0, 0, 0]
]
This data structure represents all existing nodes and connections.
- The corresponding output will be the path from the start node to the goal
node.
- The subproblems are divided into the following key functions:
● get_neighbors: A function that gets the neighbour nodes of the current
node being evaluated.
● reconstruct_path: A function to reconstruct the path once the target
node has been reached.
● Maze execution: A main function to initialise and execute the process.
This function will initialise:
● A list to evaluate the nodes.
● A set where the nodes needed to reconstruct the path will be stored.
● A dictionary to store the nodes together with their associated costs.
CONTRACT
The name of the program is Maze Problem.
Input:
The input to the program will be a two-dimensional array (grid) where:
● 0s represent passable cells, indicating areas where traversal is
possible.
● 1s represent non-passable cells, marking obstacles that cannot be
crossed.
Output:
The output will be a list of coordinates that defines the path from the start
node to the goal node. Each coordinate will represent a specific cell in the
grid, forming a step-by-step solution through the maze.
Example: (0,0),(1,0),(2,0),(2,1),(2,2)
Download