This project implements graph traversal algorithms using Prolog, specifically focusing on breadth-first search (BFS). It allows finding the shortest path between nodes in both directed and undirected graphs.
- Graph Representation: The graph is represented using Prolog predicates to define the edges between nodes.
- Breadth-First Search (BFS): Implements BFS algorithm recursively to find the shortest path between two nodes in a given graph.
- Test Cases: Includes several test cases to validate the correctness of the BFS implementation.
- Graph Representation: Define the graph using predicates for the edges between different nodes.
- BFS Algorithm: Implement the BFS algorithm to explore the graph level by level using a queue to manage the traversal.
- Testing: Run test cases to ensure the BFS implementation correctly finds the shortest paths in various graph configurations.
- Graph Representation: Predicates to define edges.
- BFS Implementation: Recursive BFS function to find shortest paths.
- Test Cases: Predefined test cases to validate the algorithm.
- Ensure a Prolog interpreter is installed on your system. Common Prolog interpreters include SWI-Prolog and GNU Prolog.
-
Download or Copy Code: Download or copy the code from
main.pl
. -
Open Terminal/Command Prompt: Open your terminal or command prompt.
-
Navigate to Directory: Use
cd
to navigate to the directory containingmain.pl
. -
Launch Prolog Interpreter: Enter the command to launch the Prolog interpreter:
swipl
-
Load the File: Once inside the Prolog interpreter, load the main.pl file using the following command:
?- [main].
-
Run the Test: After loading the file, you can run the predefined test cases by typing:
?- test.
Using Breadth-First Search (BFS), this Prolog implementation finds the shortest path among all paths between two nodes in a graph. The graph is defined using predicates for edges, and BFS is implemented recursively, exploring nodes level by level with a queue. The project tests BFS on both directed and undirected graphs, providing correct results across various test cases, demonstrating Prolog's effectiveness and flexibility for graph traversal problems.