This is a Python application that demonstrates the Bellman-Ford algorithm for finding shortest paths in a weighted directed graph. The application provides a graphical user interface (GUI) that allows users to:
- Create a graph with a specified number of vertices
- Add weighted edges to the graph
- Calculate shortest paths between vertices
- Visualize the graph and highlighted shortest paths
- Interactive graph creation
- Edge addition with custom weights
- Shortest path calculation using Bellman-Ford algorithm
- Real-time graph visualization
- Path highlighting
- Error handling for graph and path calculations
- Python 3.8+
- Required Libraries:
- tkinter (usually comes pre-installed with Python)
- networkx
- matplotlib
git clone https://github.com/yourusername/bellman-ford-visualization.git
cd bellman-ford-visualization
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activate
pip install networkx matplotlib
python bellman_ford_app.py
-
Create Graph
- Enter the number of vertices
- Click "Créer Graphe" (Create Graph)
-
Add Edges
- Enter source vertex, destination vertex, and edge weight
- Click "Ajouter Arête" (Add Edge)
- Repeat for all desired edges
-
Calculate Shortest Path
- Enter source vertex
- Optionally enter destination vertex
- Click "Calculer Chemin" (Calculate Path)
- View results in the text area
- Shortest path will be highlighted in red on the graph
- Create a graph with 5 vertices
- Add edges:
- 0 -> 1 (weight 4)
- 0 -> 2 (weight 2)
- 1 -> 3 (weight 3)
- 2 -> 1 (weight 1)
- 2 -> 3 (weight 5)
- Calculate path from vertex 0 to vertex 3
The Bellman-Ford algorithm finds the shortest paths from a source vertex to all other vertices in a weighted graph. It can handle graphs with negative edge weights and detect negative weight cycles.
- O(VE), where V is the number of vertices and E is the number of edges
- Can handle negative edge weights
- Slower than Dijkstra's algorithm
- Detects negative weight cycles
- Add more graph generation options
- Implement step-by-step algorithm visualization
- Support for loading graphs from files
- More detailed error handling
Contributions are welcome! Please feel free to submit a Pull Request.