Skip to main content

Graph package

Project description

grphpkg

grphpkg is a simple graph library that has DFS and BFS implemented that you can create your own operation.

Graph

from grphpkg import Graph
matrix_representation = [
    [0, 1, 0, 1, 0, 0, 0, 0, 1],
    [1, 0, 1, 0, 0, 1, 0, 0, 0],
    [0, 1, 0, 0, 0, 0, 1, 0, 0],
    [1, 0, 0, 0, 1, 0, 0, 1, 0],
    [0, 0, 0, 1, 0, 1, 0, 0, 0],
    [0, 1, 0, 0, 1, 0, 1, 0, 0],
    [0, 0, 1, 0, 0, 1, 0, 1, 0],
    [0, 0, 0, 1, 0, 0, 1, 0, 1],
    [1, 0, 0, 0, 0, 0, 0, 1, 0]
]

g = Graph(matrix_representation)                    # Initialize weighted graph with a matrix
g.print_graph()                                     # Print the graph
g.dfs(0, lambda x: print(str(x)+" ", end=""))       # Run DFS or BFS with custom callback
g.draw_graph()                                      # Graph visualization

Create your callback function and pass it in dfs or bfs to execute your operation

Weighted Graph

from grphpkg import Graph

matrix = [
    [0, 2, 3, float('inf')],
    [2, 0, 1, 4],
    [3, 1, 0, 5],
    [float('inf'), 4, 5, 0]
]

weighted_graph = WeightedGraph(matrix)              # Initialize weighted graph with a matrix
weighted_graph.print_graph()                        # Print the graph
mst_edges, mst_cost = weighted_graph.prim_mst(0)    # Get minimun spanning and the edges
weighted_graph.draw_graph()                         # Graph visualization

Graph visualization

Call draw graph function

g.draw_graph()

Installing

pip install grphpkg

Documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grphpkg-0.0.4.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

grphpkg-0.0.4-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file grphpkg-0.0.4.tar.gz.

File metadata

  • Download URL: grphpkg-0.0.4.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for grphpkg-0.0.4.tar.gz
Algorithm Hash digest
SHA256 6a1f940e21676abd7eaf582b6e4ad872ccc1be64adf20bb7b6a7ee297323c2bc
MD5 1fcc433a9c0531d40ef39c42dd18fd6f
BLAKE2b-256 db50987e75c9bfd5f1e12d71bab8c5db6ac53ae112404f6e2aa276730c5f6bb9

See more details on using hashes here.

File details

Details for the file grphpkg-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: grphpkg-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for grphpkg-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f020521aef68948dff7773f1b358a286316195f378cebdc1bc35817542f19a89
MD5 c493564fcba8de220b9ffb9b9ab3445e
BLAKE2b-256 d8fd2863b44493f4849e402c20989bb81ac076585288007c12d2c9fbf3613d77

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page