Implemented and evaluated three different search algorithms for finding a path in a maze using Prolog. The algorithms used were:
- Depth-first search
- Iterative-deepening search
- A*
To run the search alogrithms:
-
Open SWI-Prolog
-
Go to "File" --> "Consult" and choose the search algorithm you wish to run
-
To run the search algorithm, type the following command:
solveMaze.
-
To view the peformance time of the search algorithm, type the following command:
time((solveMaze)).
To evaluate the search algorithms, the following mazes were used and implemented in Prolog:
Sample Maze 1 | Sample Maze 2 |
---|---|
We will performing the following actions to obtain the solution to the maze:
1. Selecting a direction to move from the current position
2. Moving in the selected direction from the current position
3. Checking to see if the newly selected direction has been visited before
- If it has been visited before, then this command is skipped
4. The newly selected direction is added to the final solutions list and the algorithm is recursively called again
5. The final solution is then displayed
We will performing the following actions to obtain the solution to the maze:
1. Obtaining the max depth of the maze by multiplying the maze row by the maze column
2. Selecting a direction to move from the current position
3. Moving in the selected direction from the current position
4. Checking to see if the newly selected direction has been visited before
- If it has been visited before, then this command is skipped
5. Increasing the depth by 1
6. The newly selected direction is added to the final solutions list and the algorithm is recursively called again
7. The final solution is then displayed
We will performing the following actions to obtain the solution to the maze:
1. Obtaining the heuristic value of the algorithm by calculating the Manhattan distance
2. Generating the children of a node/position & checking all the move directions allowed in that node/position.
3. Using the calculated cost function, the node/position is added to the list of already generated children and the algorithm is recursively called again
4. The final solution is then displayed
|-- Code
| |-- Sample Maze 1
| | |-- a_star_search_algorithm.pl
| | |-- depth_first_search_algorithm.pl
| | '-- iterative_deep_search_algorithm.pl
| |-- Sample Maze 2
| | |-- a_star_search_algorithm.pl
| | |-- depth_first_search_algorithm.pl
| | '-- iterative_deep_search_algorithm.pl