Skip to main content

dijkstra is a native Python implementation of Dijkstra's shortest path algorithm.

Project description

Dijkstra

Python CI Coverate Status

Package author: Jukka Aho (@ahojukka5, ahojukka5@gmail.com)

Package implements Dijkstra's shortest path finding algorithm.

Installing package

To install the most recent package from Python Package Index (PyPi), use git:

pip install dijkstra

To install the development version, you can install the package directly from the GitHub:

pip install git+git://github.com/ahojukka5/dijkstra.git

Usage

Package implements two classes, DijkstraSPF and Graph. The above example can be solved with the following code:

S, T, A, B, C, D, E, F, G = list("STABCDEFG")

graph = Graph()
graph.add_edge(S, A, 4)
graph.add_edge(S, B, 3)
graph.add_edge(S, D, 7)
graph.add_edge(A, C, 1)
graph.add_edge(B, S, 3)
graph.add_edge(B, D, 4)
graph.add_edge(C, E, 1)
graph.add_edge(C, D, 3)
graph.add_edge(D, E, 1)
graph.add_edge(D, T, 3)
graph.add_edge(D, F, 5)
graph.add_edge(E, G, 2)
graph.add_edge(G, E, 2)
graph.add_edge(G, T, 3)
graph.add_edge(T, F, 5)

dijkstra = DijkstraSPF(graph, S)

It's not mandatory to use Graph. To use your own data structure for graph, you need to subclass AbstractDijkstraSPF and implement two functions connecting graph object to the shortest path finder algorithms: get_adjacent_nodes and get_edge_weight. For example, implementation using Graph is the following:

class DijkstraSPF(AbstractDijkstraSPF):

    @staticmethod
    def get_adjacent_nodes(G, u):
        return G.get_adjacent_nodes(u)

    @staticmethod
    def get_edge_weight(G, u, v):
        return G.get_edge_weight(u, v)

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

dijkstra-0.2.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

dijkstra-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file dijkstra-0.2.0.tar.gz.

File metadata

  • Download URL: dijkstra-0.2.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for dijkstra-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6935b248bde99d015b067232272a2e69bd2f624cbdd2c4182c362bf087e27747
MD5 3c6bb8d10d83f98b8042160bfa1b398f
BLAKE2b-256 b74b3be7ebf0f8ddca8db581041a91012bb4857ebbf8f9e8093fc361736d8093

See more details on using hashes here.

File details

Details for the file dijkstra-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dijkstra-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

File hashes

Hashes for dijkstra-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bcc4df5483b8c3d5bd26c086345375dc57865a4ad9e4e39627ec3a8f7551a78
MD5 fdae04890fd0c10e901ff2d54d4e95ae
BLAKE2b-256 d10a16982957797648b7bbf2f08f362e47d66b8a27f86c73297293b6cdc9af93

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