https://github.com/ratna-babu/generating-graphs
Generate, color, and visualize random graphs using Python's NetworkX and Matplotlib. Includes compression and storage of graph data with .gz and pickle. Ideal for exploring graph coloring and greedy algorithms in graph theory.
https://github.com/ratna-babu/generating-graphs
data-visualization erdos-renyi graph-coloring graph-theory greedy-algorithm matplotlib networkx python random-graph random-graph-generation
Last synced: 6 months ago
JSON representation
Generate, color, and visualize random graphs using Python's NetworkX and Matplotlib. Includes compression and storage of graph data with .gz and pickle. Ideal for exploring graph coloring and greedy algorithms in graph theory.
- Host: GitHub
- URL: https://github.com/ratna-babu/generating-graphs
- Owner: Ratna-Babu
- Created: 2025-01-26T13:02:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-22T09:31:37.000Z (11 months ago)
- Last Synced: 2025-04-22T10:55:19.503Z (11 months ago)
- Topics: data-visualization, erdos-renyi, graph-coloring, graph-theory, greedy-algorithm, matplotlib, networkx, python, random-graph, random-graph-generation
- Language: Jupyter Notebook
- Homepage:
- Size: 91.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π¨ Graph Coloring Visualization and Compression
This project demonstrates the generation of random graphs, the application of graph coloring algorithms, visualization of the results, and saving the graph data in a compressed `.gz` format using Python. It uses the `networkx` library for graph operations and `matplotlib` for visualization.
---
## π Features
- β
Generate random undirected graphs using the ErdΕsβRΓ©nyi model
- π¨ Color graphs using a greedy algorithm (`largest_first` strategy)
- πΌοΈ Visualize colored graphs using Matplotlib
- π Save the graph and its coloring in a compressed `.gz` format
---
## π οΈ Technologies Used
- [NetworkX](https://networkx.org/) - Graph generation and algorithms
- [Matplotlib](https://matplotlib.org/) - Visualization
- [NumPy](https://numpy.org/) - Math utility
- [Gzip](https://docs.python.org/3/library/gzip.html) - Compression
- [Pickle](https://docs.python.org/3/library/pickle.html) - Object serialization
---
## π Getting Started
### π§ Installation
Make sure you have Python 3.x installed. Then install the required libraries:
```bash
pip install networkx matplotlib numpy
```
### βΆοΈ Running the Code
This project is implemented in a Jupyter Notebook named `Generating_Random_Graph.ipynb`. Open the notebook and run the cells sequentially to:
1. Generate a random graph with `num_nodes` and `num_edges`
2. Apply a greedy coloring algorithm
3. Display the graph with nodes colored by their assigned color
4. Save the graph and its coloring to `graph_coloring_data.gz`
---
## π File Overview
| File | Description |
|-------------------------------|--------------------------------------------------------------|
| `Generating_Random_Graph.ipynb` | Jupyter Notebook to generate, color, visualize, and save a graph |
| `graph_coloring_data.gz` | Compressed file containing the graph object and coloring dict|
| `README.md` | Youβre reading it! |
---
## π§ Understanding Graph Coloring
Graph coloring is the assignment of labels (colors) to vertices of a graph so that no two adjacent vertices share the same color. It's used in:
- Scheduling problems
- Map coloring
- Register allocation in compilers
- Frequency assignment
This project uses the **greedy coloring algorithm** with the `largest_first` strategy, which colors the nodes in descending order of their degrees.
---
## π Example Output

---
## π Output
After execution, a file named `graph_coloring_data.gz` will be created, containing:
```python
{
'graph': ,
'coloring': {0: 0, 1: 1, 2: 0, ...}
}
```
To load this file later:
```python
import gzip, pickle
with gzip.open('graph_coloring_data.gz', 'rb') as f:
data = pickle.load(f)
G = data['graph']
coloring = data['coloring']
```
---
## π€ Contributing
Contributions, issues, and feature requests are welcome!
1. Fork the repository
2. Create your branch: `git checkout -b feature/your-feature`
3. Commit your changes: `git commit -m 'Add your message'`
4. Push to the branch: `git push origin feature/your-feature`
5. Open a pull request
---
## π License
This project is licensed under the [MIT License](LICENSE).
---
## βοΈ Show Your Support
If you found this project useful, please βοΈ the repository to help others discover it!