An open API service indexing awesome lists of open source software.

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.

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

![Graph Coloring Example](https://github.com/user-attachments/assets/35f3045d-4937-4708-b9cb-619a276bb88f)

---

## πŸ“† 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!