Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imdeep2905/kcol-graph
A minimalistic python package to generate a k-colorable graph.
https://github.com/imdeep2905/kcol-graph
graph graph-coloring graph-generation graph-generator k-colorable
Last synced: about 1 month ago
JSON representation
A minimalistic python package to generate a k-colorable graph.
- Host: GitHub
- URL: https://github.com/imdeep2905/kcol-graph
- Owner: imdeep2905
- License: mit
- Created: 2023-05-13T23:52:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-19T01:48:51.000Z (over 1 year ago)
- Last Synced: 2024-04-30T00:47:00.798Z (8 months ago)
- Topics: graph, graph-coloring, graph-generation, graph-generator, k-colorable
- Language: Python
- Homepage: https://pypi.org/project/kcol-graph-gen/
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kcol_graph_gen [![Downloads](https://static.pepy.tech/personalized-badge/kcol-graph-gen?period=total&units=international_system&left_color=black&right_color=blue&left_text=Downloads)](https://pepy.tech/project/kcol-graph-gen)
![Cover Logo](https://github.com/imdeep2905/kcol-graph/blob/main/assets/cover.png?raw=true)
_A minimalistic python package to generate a k-colorable graph._
# Installation
Just run `pip install kcol-graph-gen` and you are good to go!
# Usage
Before generating the graph you have to make an object of the class `KColorableGraphGenerator`. You can specify an optional `seed` for the default `random` package which is used during the generation of the graph.
Once the object is crated, you can use `generate` method to generate the graphs. This takes three arguments `n` : number of vertices, `k` : specifying the number of colors, `p(optional, default=0.5)` : Probability with which any edge is added into the graph. Higher the value of `p` denser the resulting graph will be.
Below is the code snippet which demonstrates the usage:
```
from kcol_graph_gen import KColorableGraphGeneratorgenerator = KColorableGraphGenerator(seed=42)
edges = generator.generate(4, 2, 0.3) # Create a bipartite graphprint(edges) # Printing the list of edges
# > [(2, 3), (2, 4), (1, 2)]edges = generator.generate(
6, 3, 0.9
) # Create a 3-colorable dense graph with 6 verticesprint(edges) # Printing the list of edges
# > [(2, 4), (1, 2), (3, 4), (1, 5), (2, 3), (4, 5), (2, 6), (5, 6), (3, 6), (2, 5), (1, 3)]```