A modern toolkit for creating, visualizing, and coloring graphs. Includes multiple coloring algorithms (greedy variants, DSATUR, backtracking, ILP hooks), graph generators, benchmarking, and an interactive Streamlit UI.
- Multiple coloring algorithms: Greedy (largest-first, smallest-last, random), WelshβPowell, DSATUR, Backtracking (exact for small graphs)
- Graph generators: complete, bipartite, cycle, path, planar-ish, ErdΕsβRΓ©nyi, and special graphs
- Interactive visualizer (Plotly + Streamlit) and static export (Matplotlib)
- Benchmarking harness to compare runtime and quality across algorithms
- Command-line and programmatic APIs
Clone, create a venv, install, and run the Streamlit UI:
git clone https://github.com/SpaceCodelab/Graph-visualizer.git "Graph Project"
cd "Graph Project"
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
streamlit run app.pyUse the library modules directly from Python scripts or REPL:
from src.graph_generator import GraphGenerator
from src.algorithms import ColoringSolver
g = GraphGenerator().complete_graph(6)
solver = ColoringSolver(g)
res = solver.solve('dsatur')
print('colors used', res['num_colors'])
print(res['coloring'])Run the test suite (inside the activated virtualenv):
pytest -qLinting and static checks can be added via flake8/ruff/mypy if desired.
Graph Project/
βββ src/ # core library code (graph, algorithms, visualizer)
βββ tests/ # unit tests
βββ app.py # Streamlit UI
βββ requirements.txt # deps
βββ README.md # β you are here
Contributions are welcome. A good workflow:
- Fork the repo
- Create a feature branch
- Add tests for new behavior
- Open a pull request
Please follow the repository's coding style and include tests for new features.
Add compelling screenshots or a short demo GIF in assets/ and reference them above. Example files:
assets/demo.gifβ animated demo of the visualizerassets/screenshot-graph.pngβ static screenshot for the project page
- Consider adding a GitHub Action to run tests and show a build badge.
- Add an
assets/folder with a 600Γ300 hero image or a short GIF for the repo landing page. - If you publish to PyPI, add the PyPI badge and version badge.
This project is open-source β see the LICENSE file for details.
Made with β€οΈ by the SpaceCodelab team.
- Parallel Execution: Run multiple algorithms in parallel
- Weighted Coloring: Color graphs where colors have associated costs
- ILP Integration: Solve using Integer Linear Programming (PuLP or OR-Tools)
- Dynamic Recoloring: Handle graph modifications (add/remove vertices/edges) with dynamic recoloring
- Chromatic number bounds (lower and upper)
- Clique number
- Independence number
- Chromatic polynomial approximation
- Connectivity, bipartiteness, planarity checks
- Graph density and degree statistics
- Python 3.8 or higher
- pip (Python package manager)
-
Clone or download the project:
cd "Graph Project"
-
Create a virtual environment:
# On Windows python -m venv venv venv\Scripts\activate # On Linux/Mac python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Activate the virtual environment (if not already activated):
# Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Run the Streamlit application:
streamlit run app.py
-
Open your browser to the URL shown in the terminal (usually
http://localhost:8501)
-
Load or Generate a Graph:
- Go to "Graph Input" to load a graph from various formats
- Go to "Graph Generator" to create test graphs
-
Solve Coloring Problem:
- Go to "Coloring Algorithms"
- Select an algorithm
- Click "Solve" to get the coloring
-
Benchmark Algorithms:
- Go to "Benchmarking"
- Click "Run Benchmark" to compare all algorithms
-
Explore Applications:
- Go to "Real-World Applications"
- Select an application type
- Enter your data and solve
You can also use the modules programmatically:
from src.graph import Graph
from src.graph_generator import GraphGenerator
from src.algorithms import ColoringSolver
from src.visualizer import Visualizer
# Generate a graph
generator = GraphGenerator()
graph = generator.complete_graph(5)
# Solve coloring
solver = ColoringSolver(graph)
result = solver.solve('dsatur')
print(f"Number of colors: {result['num_colors']}")
print(f"Coloring: {result['coloring']}")
# Visualize
visualizer = Visualizer(graph)
fig = visualizer.visualize_coloring_plotly(result['coloring'])
fig.show()Run the test suite using pytest:
# Activate virtual environment first
pytest tests/Or run specific test files:
pytest tests/test_algorithms.py
pytest tests/test_graph.py
pytest tests/test_applications.pyGraph Project/
βββ src/
β βββ __init__.py
β βββ graph.py # Graph data structure
β βββ graph_generator.py # Graph generators
β βββ algorithms.py # Coloring algorithms
β βββ graph_properties.py # Graph properties calculator
β βββ visualizer.py # Visualization tools
β βββ benchmarker.py # Benchmarking module
β βββ applications.py # Real-world applications
β βββ advanced.py # Advanced features
βββ tests/
β βββ __init__.py
β βββ test_graph.py
β βββ test_algorithms.py
β βββ test_applications.py
βββ app.py # Streamlit application
βββ requirements.txt # Python dependencies
βββ setup_venv.bat # Windows setup script
βββ setup_venv.sh # Linux/Mac setup script
βββ .gitignore
βββ README.md
| Algorithm | Time Complexity | Space Complexity | Optimal |
|---|---|---|---|
| Greedy (Largest-First) | O(V + E) | O(V) | No |
| Greedy (Smallest-Last) | O(VΒ²) | O(V) | No |
| Welsh-Powell | O(VΒ²) | O(V) | No |
| DSATUR | O(VΒ²) | O(V) | No |
| Backtracking | O(V * k^V) | O(V) | Yes (for small graphs) |
| ILP | Exponential (worst case) | O(VΒ²) | Yes |
Where:
- V = number of vertices
- E = number of edges
- k = number of colors
- Best Case: Trees and bipartite graphs (2 colors)
- Worst Case: Complete graphs (n colors for n vertices)
- Best Case: Similar to greedy, but often uses fewer colors
- Worst Case: Still not optimal, but better than simple greedy
- Best Case: Small graphs with low chromatic number
- Worst Case: Large graphs (exponential time)
-
Welsh, D. J. A., & Powell, M. B. (1967). An upper bound for the chromatic number of a graph and its application to timetabling problems. The Computer Journal, 10(1), 85-86.
-
BrΓ©laz, D. (1979). New methods to color the vertices of a graph. Communications of the ACM, 22(4), 251-256.
-
Chaitin, G. J. (1982). Register allocation & spilling via graph coloring. ACM SIGPLAN Notices, 17(6), 98-105.
-
Appel, K., & Haken, W. (1977). Every planar map is four colorable. Illinois Journal of Mathematics, 21(3), 429-567.
-
Garey, M. R., & Johnson, D. S. (1979). Computers and Intractability: A Guide to the Theory of NP-Completeness. W. H. Freeman.
The application includes comprehensive error handling for:
- Invalid input formats
- Disconnected graphs
- Self-loops (not allowed in simple graphs)
- Multigraphs (handled appropriately)
- Invalid algorithm parameters
- File I/O errors
All errors provide informative messages and suggestions for correction.
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is open source and available for educational and research purposes.
- NetworkX for graph data structures and algorithms
- Matplotlib and Plotly for visualization
- Streamlit for the interactive web interface
- All contributors to the open-source libraries used in this project
Potential future improvements:
- GPU acceleration for large graphs
- More approximation algorithms with guaranteed bounds
- Support for directed graphs
- Graph isomorphism checking
- Chromatic polynomial exact calculation for small graphs
- Integration with more optimization libraries
- Mobile-friendly UI
- Cloud deployment support
