mirror of
https://github.com/Maurice765/graph-coloring.git
synced 2026-12-05 00:55:15 +00:00
No description
- Jupyter Notebook 99.8%
- Python 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| gifs | ||
| .gitignore | ||
| animation.ipynb | ||
| compare.ipynb | ||
| enviroment.yaml | ||
| functions.py | ||
| README.md | ||
| visualization.ipynb | ||
Graph Coloring Algorithms
This project implements and compares various graph coloring algorithms using Python and NetworkX. Graph coloring is a fundamental problem in graph theory where the goal is to assign colors to vertices such that no two adjacent vertices share the same color, using the minimum number of colors possible.
Project Structure
Core Implementation
functions.py
Contains the main implementations of graph coloring algorithms:
greedy_coloring()- Basic greedy coloring algorithm that processes nodes in their natural ordergreedy_coloring_welsh_powell()- Welsh-Powell algorithm that sorts nodes by degree (highest first) before coloringgreedy_coloring_dsatur()- DSATUR algorithm that prioritizes nodes with highest saturation (number of different colored neighbors)greedy_coloring_dsatur_heap()- Optimized DSATUR implementation using a heap data structure for better performancerlf_coloring()- Recursive Largest First (RLF) algorithm that builds independent sets iteratively
Jupyter Notebooks
visualization.ipynb
Demonstrates the coloring algorithms with visual output:
- Creates a random Erdős-Rényi graph with 70 nodes
- Applies each coloring algorithm and measures execution time
- Generates colored graph visualizations using matplotlib
- Compares the number of colors used by each algorithm
animation.ipynb
Creates step-by-step animations of the coloring process:
-
Animation Functions:
animate()- Updates node colors for each animation framecreate_animation()- Main function to create and save GIF animationssave_and_display_gif()- Saves animations as GIF files in thegifs/directory
-
Step-by-step Algorithm Implementations:
greedy_coloring_steps()- Tracks each step of basic greedy coloringgreedy_coloring_welsh_powell_steps()- Tracks Welsh-Powell algorithm stepsgreedy_coloring_dsatur_steps()- Tracks DSATUR algorithm stepsrlf_coloring_steps()- Tracks RLF algorithm steps
-
Output: Generates animated GIFs showing how each algorithm colors the graph node by node
compare.ipynb
Comprehensive performance comparison of all algorithms:
- Benchmark Tests:
- Erdős-Rényi Graphs: Tests on random graphs with varying sizes (50-10,000 nodes) and edge probabilities
- Barabási-Albert Graphs: Tests on scale-free networks with different parameters
- Creates comparison tables showing execution time and color efficiency
Usage
- Run
visualization.ipynbto see basic algorithm comparisons - Run
animation.ipynbto generate step-by-step animations - Run
compare.ipynbfor comprehensive performance analysis